Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_update_link.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
18 
30 {
31 
32 
56  public static function execute($settings, &$state)
57  {
58  $am = $GLOBALS['SQ_SYSTEM']->am;
59 
60  if (empty($state['asset'])) {
61  // grab the asset if assetid is given, but not the asset.
62  if (empty($state['assetid'])) {
63  return FALSE;
64  } else {
65  $state['asset'] = $am->getAsset($state['assetid']);
66  }
67  }
68 
69  if (is_null($state['asset'])) return FALSE;
70 
71  $linkid = array_get_index($settings, 'linkid', '');
72 
73  $new_value = array_get_index($settings, 'new_value', NULL);
74  $new_link_type = array_get_index($settings, 'new_link_type', NULL);
75 
76  $result = TRUE;
77  if (!empty($linkid)){
78  $result = $am->updateLink($linkid, $new_link_type, $new_value);
79  } else {
80  $type_code = array_get_index($settings, 'type_code', '');
81  if (empty($type_code)) return FALSE;
82 
83  $link_type = array_get_index($settings, 'link_type', 0);
84  if (empty($link_type)) return FALSE;
85 
86  $side_of_link = array_get_index($settings, 'side_of_link', '');
87  if (!in_array($side_of_link, Array('minor', 'major'))) return FALSE;
88 
89  $value = array_get_index($settings, 'value', NULL);
90 
91  $links = $am->getLinks($state['asset']->id, $link_type, $type_code, TRUE, $side_of_link, $value, FALSE, FALSE);
92  if (count($links) == 1){
93  $linkid = $links[0]['linkid'];
94  $result = $am->updateLink($linkid, $new_link_type, $new_value);
95  } else {
96  trigger_localised_error('TRIG0007', E_USER_NOTICE);
97  return FALSE;
98  }
99  }
100 
101  return $result;
102 
103  }//end execute()
104 
105 
116  public static function getInterface($settings, $prefix, $write_access=FALSE)
117  {
118  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
119  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
120 
121  $link_type_names = get_link_type_names();
122 
123  $linkid = array_get_index($settings, 'linkid', '');
124  $type_code = array_get_index($settings, 'type_code', '');
125  $link_type = array_get_index($settings, 'link_type', key($link_type_names));
126  $side_of_link = array_get_index($settings, 'side_of_link', 'major');
127  $value = array_get_index($settings, 'value', '');
128 
129  $new_value = array_get_index($settings, 'new_value', '');
130  $new_link_type = array_get_index($settings, 'new_link_type', key($link_type_names));
131 
132  ob_start();
133  ?>
134  <div style="padding: 10px">
135  <p class="sq-backend-section-subheading"><?php echo translate('link_characteristics'); ?></p>
136  <p><?php echo translate('link_characteristics_note');?></p>
137  <?php
138  echo 'Link Id: ';
139  if ($write_access) {
140  int_text_box($prefix.'[linkid]', $linkid, FALSE, '', NULL, NULL, '', FALSE, TRUE);
141  } else {
142  if (!empty($linkid)){
143  echo $linkid;
144  } else {
145  echo '<i>Not specified</i>';
146  }
147  }
148  echo '&nbsp;&nbsp;<span style="color:red; font-weight:bold;"> OR </span><br /><br />';
149  ?>
150 
151  <table class="sq-backend-table">
152  <col width="10%" />
153  <col width="40%"/>
154  <col width="10%" />
155  <col width="40%"/>
156  <tr>
157  <th><?php echo translate('link_type'); ?>:</th>
158  <td><?php
159  if ($write_access) {
160  combo_box($prefix.'[link_type]', $link_type_names, FALSE, $link_type);
161  } else {
162  echo $link_type_names[$link_type];
163  }
164  ?></td>
165  <th><?php echo translate('side_of_link'); ?>:</th>
166  <td><?php
167  $side_of_link_options = Array('major' => 'Parent', 'minor' => 'Child');
168  if ($write_access) {
169  combo_box($prefix.'[side_of_link]', $side_of_link_options, FALSE, $side_of_link);
170  } else {
171  echo $side_of_link_options[$side_of_link];
172  }
173  ?></td>
174  </tr>
175  <tr>
176  <th><?php echo translate('link_value'); ?>:</th>
177  <td><?php
178  if ($write_access) {
179  text_box($prefix.'[value]', $value);
180  } else {
181  echo $value;
182  }
183  ?></td>
184  <th><?php echo translate('asset_type'); ?>:</th>
185  <td><?php
186  if ($write_access) {
187  asset_type_chooser($prefix.'[type_code]', FALSE, $type_code, TRUE);
188  } else {
189  echo ucwords(str_replace('_', ' ',$type_code));
190  }
191  ?></td>
192  </tr>
193  </table>
194  </div>
195  <div style="padding: 10px">
196  <p class="sq-backend-section-subheading"><?php echo translate('new_link_characteristics'); ?></p>
197  <p><?php echo translate('new_link_characteristics_note');?></p>
198  <table class="sq-backend-table" style="width:50%;">
199  <col width="20%" />
200  <col width="80%"/>
201  <tr>
202  <th><?php echo translate('link_type'); ?>:</th>
203  <td><?php
204  if ($write_access) {
205  combo_box($prefix.'[new_link_type]', $link_type_names, FALSE, $new_link_type);
206  } else {
207  echo $link_type_names[$new_link_type];
208  }
209  ?></td>
210  </tr>
211  <tr>
212  <th><?php echo translate('link_value'); ?>:</th>
213  <td><?php
214  if ($write_access) {
215  text_box($prefix.'[new_value]', $new_value);
216  } else {
217  echo $new_value;
218  }
219  ?></td>
220  </tr>
221  </table>
222  </div>
223  <?php
224 
225  $output = ob_get_contents();
226  ob_end_clean();
227 
228  return $output;
229 
230  }//end getInterface()
231 
232 
244  public static function processInterface(&$settings, $request_data)
245  {
246  $settings['linkid'] = array_get_index($request_data, 'linkid', '');
247  $settings['side_of_link'] = array_get_index($request_data, 'side_of_link', '');
248  $settings['link_type'] = array_get_index($request_data, 'link_type', 0);
249  $settings['link_type'] = (int)$settings['link_type'];
250 
251  $settings['type_code'] = array_get_index($request_data, 'type_code', '');
252  if (empty($settings['type_code'])) return 'You must specify an Asset Type';
253 
254  $settings['value'] = array_get_index($request_data, 'value', NULL);
255  $settings['value'] = trim($settings['value']);
256  if (empty($settings['value'])) $settings['value'] = NULL;
257 
258  $settings['new_value'] = array_get_index($request_data, 'new_value', NULL);
259  $settings['new_link_type'] = array_get_index($request_data, 'new_link_type', NULL);
260  if (!is_null($settings['new_link_type'])) $settings['new_link_type'] = (int)$settings['new_link_type'];
261 
262  return FALSE;
263 
264  }//end processInterface()
265 
266 
276  public static function getLocks($settings, &$state)
277  {
278  return Array($state['assetid'] => Array('links'));
279 
280  }//end getLocks()
281 
282 
283 }//end class
284 
285 ?>