18 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
60 public static function evaluate($settings, &$state)
62 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
64 $assetid = $state[
'assetid'];
66 $link_type = array_get_index($settings,
'link_type');
67 if (empty($link_type)) $link_type = SQ_SC_LINK_ALL;
68 $is_parent = array_get_index($settings,
'is_major', FALSE);
69 $link_side = $is_parent ?
'major' :
'minor';
70 $value = array_get_index($settings,
'value');
71 $dependant = array_get_index($settings,
'is_dependant');
72 $exclusive = array_get_index($settings,
'is_exclusive');
74 $selector_type = array_get_index($settings,
'selector_type', FALSE);
76 if (!$selector_type)
return FALSE;
79 $use_current_link = array_get_index($settings,
'use_current_link', array_get_index($settings,
'use_new_link', FALSE));
82 $current_link = array_get_index($state[
'event'][
'data'],
'link_info');
85 if ($use_current_link) {
86 if ($state[
'event'][
'name'] !=
'trigger_event_link_created' && $state[
'event'][
'name'] !=
'trigger_event_link_deleted' && is_null($current_link)) {
92 switch ($selector_type) {
94 $selected_type = array_get_index($settings,
'asset_type');
95 if (empty($selected_type))
return FALSE;
96 $links = $am->getLinks($assetid, $link_type, $selected_type, TRUE, $link_side, $value, $dependant, $exclusive);
101 $selected_id = array_get_index($settings,
'asset_id');
102 if (!isset($selected_id))
return FALSE;
104 if (empty($link_type)) $link_type = NULL;
107 $links = $am->getLinkByAsset($assetid, $selected_id, $link_type, $value, $link_side, TRUE, $dependant, $exclusive);
111 case 'only_link_info':
113 if (!$use_current_link) {
115 }
else if (!is_null($value) && ($value != $current_link[
'value'])) {
117 }
else if (!is_null($dependant) && ($dependant != $current_link[
'is_dependant'])) {
119 }
else if (!is_null($exclusive) && ($exclusive != $current_link[
'is_exclusive'])) {
121 }
else if (!is_null($link_type) && !($link_type | $current_link[
'link_type'])) {
123 }
else if ($assetid != $current_link[$link_side.
'id']) {
136 if (empty($links))
return FALSE;
138 if ($use_current_link) {
139 foreach ($links as $link) {
140 if ($current_link[
'linkid'] == $link[
'linkid']) {
162 public static function getInterface($settings, $prefix, $write_access=FALSE)
165 $is_major = array_get_index($settings,
'is_major', FALSE);
166 $selected_link_type = array_get_index($settings,
'link_type');
167 $value = array_get_index($settings,
'value');
168 $is_dependant = array_get_index($settings,
'is_dependant');
169 $is_exclusive = array_get_index($settings,
'is_exclusive');
171 $selector_type = array_get_index($settings,
'selector_type',
'asset_type');
172 $asset_id = array_get_index($settings,
'asset_id');
173 $asset_type = array_get_index($settings,
'asset_type');
177 $use_current_link = array_get_index($settings,
'use_current_link', array_get_index($settings,
'use_new_link', FALSE));
179 $is_major_list = Array(
180 0 => translate(
'parent'),
181 1 => translate(
'child'),
184 $link_type_list = Array(
'' =>
'--- '.translate(
'any').
' ---');
185 $link_type_list = $link_type_list + get_link_type_names();
187 $dependant_options = Array(
188 '' =>
'--- '.translate(
'any').
' ---',
189 '1' => translate(
'yes'),
190 '0' => translate(
'no'),
193 $exclusive_options = Array(
194 '' =>
'--- '.translate(
'any').
' ---',
195 '1' => translate(
'yes'),
196 '0' => translate(
'no'),
199 if (!$write_access) {
200 $form_element_extras =
'disabled="disabled"';
202 $form_element_extras =
'';
207 combo_box($prefix.
'[is_major]', $is_major_list, FALSE, $is_major, NULL, $form_element_extras);
208 $major_selector = ob_get_clean();
211 radio_button($prefix.
'[selector_type]',
'asset_type', $selector_type ==
'asset_type', NULL, $form_element_extras);
212 $asset_type_option = ob_get_clean();
216 asset_type_chooser($prefix.
'[asset_type]', FALSE, $asset_type);
219 echo $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset_type,
'name');
222 $asset_type_selector = ob_get_clean();
225 radio_button($prefix.
'[selector_type]',
'asset_id', $selector_type ==
'asset_id', NULL, $form_element_extras);
226 $asset_id_option = ob_get_clean();
230 asset_finder($prefix.
'[asset_id]', $asset_id);
233 $asset_name = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($asset_id), Array(), TRUE,
'name');
234 text_box($prefix.
'[assetid]', $asset_name[$asset_id].
' (#'.$asset_id.
')',
'',
'', FALSE, $form_element_extras);
236 text_box($prefix.
'[assetid]',
'',
'',
'', FALSE, $form_element_extras);
239 $asset_id_selector = ob_get_clean();
242 radio_button($prefix.
'[selector_type]',
'only_link_info', $selector_type ==
'only_link_info', NULL, $form_element_extras);
243 $only_link_option = ob_get_clean();
246 check_box($prefix.
'[use_current_link]',
'1', $use_current_link, NULL, $form_element_extras, NULL, $form_element_extras);
247 label(translate(
'match_current_link_only'), $prefix.
'[use_current_link]');
248 $current_link_enabler = ob_get_clean();
253 combo_box($prefix.
'[link_type]', $link_type_list, FALSE, $selected_link_type, NULL, $form_element_extras);
254 $link_type_selector = ob_get_clean();
257 combo_box($prefix.
'[is_dependant]', $dependant_options, FALSE, $is_dependant, NULL, $form_element_extras);
258 $dependent_selector = ob_get_clean();
261 combo_box($prefix.
'[is_exclusive]', $exclusive_options, FALSE, $is_exclusive, NULL, $form_element_extras);
262 $exclusive_selector = ob_get_clean();
265 text_box($prefix.
'[value]', $value, 60, NULL, FALSE, $form_element_extras);
266 $link_value = ob_get_clean();
269 $contents = translate(
'trigger_link_exists_basic', $major_selector, $asset_type_option, $asset_type_selector, $asset_id_option, $asset_id_selector, $only_link_option, $current_link_enabler).
271 '<b>'.translate(
'triggers_advanced_user_options').
'</b><br />'.
272 translate(
'trigger_link_exists_advanced', $link_type_selector, $dependent_selector, $exclusive_selector, $link_value);
290 $settings[
'is_major'] = !empty($request_data[
'is_major']);
292 $settings[
'selector_type'] = array_get_index($request_data,
'selector_type');
293 switch ($settings[
'selector_type']) {
295 $settings[
'asset_type'] = array_get_index($request_data,
'asset_type');
296 if (is_null($settings[
'asset_type']) || empty($settings[
'asset_type'])) {
297 return 'Invalid asset type selected. This condition will always fail.';
302 $id_selector = array_get_index($request_data,
'asset_id');
303 $settings[
'asset_id'] = array_get_index($id_selector,
'assetid');
305 if (empty($settings[
'asset_id'])) {
306 return 'Asset id is not specified.';
310 case 'only_link_info':
319 return 'You have to choose the appropriate asset ID or asset type selector';
322 $link_type = array_get_index($request_data,
'link_type');
323 $settings[
'link_type'] = is_null($link_type) ? SQ_SC_LINK_ALL : $link_type;
324 $value = trim(array_get_index($request_data,
'value'));
326 $settings[
'value'] = NULL;
328 $settings[
'value'] = $value;
331 $settings[
'is_dependant'] = array_get_index($request_data,
'is_dependant');
332 $settings[
'is_exclusive'] = array_get_index($request_data,
'is_exclusive');
333 $settings[
'use_current_link'] = isset($request_data[
'use_current_link']);
335 foreach ($settings as $key => $value) {
336 if ($value ===
'') $settings[$key] = NULL;
353 public static function setHash(&$settings, &$hash)
355 if (isset($settings[
'selector_type']) && isset($settings[
'is_major'])) {
356 switch ($settings[
'selector_type']) {
358 if (isset($settings[
'asset_type'])) {
359 $hash->setLinkedType($settings[
'asset_type'], $settings[
'is_major']);
364 if (isset($settings[
'asset_id'])) {
365 $hash->setLinkedID($settings[
'asset_id'], $settings[
'is_major']);