17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
18 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
20 require_once SQ_SYSTEM_ROOT.
'/core/attributes/parameter_map/parameter_map.inc';
67 public static function execute($settings, &$state)
70 if (!isset($settings[
'is_major']) || empty($settings[
'link_type'])) {
74 $parameter_map_value = array_get_index($settings,
'parameter_map_target_asset', serialize(Array()));
76 $map_assetid = $attr_parameter_map->getParameterValue(
'asset');
77 $direct_links_only = $attr_parameter_map->getParameterValue(
'direct_links_only');
79 if (empty($settings[
'assetid']) && empty($map_assetid)) {
83 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetExists($settings[
'assetid'])) {
87 if (!is_null($map_assetid) && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($map_assetid)) {
92 $is_dependant = array_get_index($settings,
'is_dependant', 0);
93 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
94 $link_value = array_get_index($settings,
'link_value',
'');
96 if (empty($state[
'asset'])) {
98 if (empty($state[
'assetid'])) {
101 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
105 $am = $GLOBALS[
'SQ_SYSTEM']->am;
108 $assetid = is_null($map_assetid) ? $settings[
'assetid'] : $map_assetid;
110 $major = $am->getAsset($assetid);
111 $minor = $state[
'asset'];
113 $link_value_sql = (!empty($settings[
'link_value'])) ?
'l.value = '.
MatrixDAL::quote($settings[
'link_value']).
' AND ' :
'';
116 if (empty($link_value_sql) && (!$settings[
'any_link_value'])) {
117 $link_value_sql =
'l.value = '.MatrixDAL::quote(
'').
' AND ';
120 $link_type_sql = ($settings[
'link_type'] !=
'ANY') ?
'l.link_type = '.
MatrixDAL::quote($settings[
'link_type']).
' AND ' :
'';
121 $link_asset_type_codes_sql =
'';
123 if (!empty($settings[
'asset_types'])) {
124 $link_asset_type_codes_sql =
'AND a.type_code IN (';
125 foreach ($settings[
'asset_types'] as $asset_type) {
129 $link_asset_type_codes_sql = substr($link_asset_type_codes_sql, 0, strlen($link_asset_type_codes_sql)-1).
')';
132 $major_or_minor_link =
'minorid';
134 $broadcasting_asset_id = $state[
'assetid'];
135 $root_node_asset_id = $assetid;
138 $assets =
'SELECT DISTINCT
141 sq_ast a, sq_ast_lnk l
143 l.majorid = '.MatrixDAL::quote($root_node_asset_id).
' AND
144 a.assetid = l.minorid AND
146 $link_asset_type_codes_sql;
149 $direct_links_only = is_null($direct_links_only) ? $settings[
'direct_links_only'] : ($direct_links_only == 1);
152 if (!$direct_links_only) {
155 $tree_id_sql =
'SELECT
158 sq_ast_lnk l, sq_ast_lnk_tree t
160 t.linkid = l.linkid AND
161 l.minorid = '.MatrixDAL::quote($root_node_asset_id);
167 $assets =
'SELECT DISTINCT
170 sq_ast a, sq_ast_lnk l, sq_ast_lnk_tree t
172 t.linkid = l.linkid AND
173 t.treeid LIKE '.MatrixDAL::quote($root_node_tree_id.
'%').
' AND
175 a.assetid = l.minorid AND
177 $link_asset_type_codes_sql;
181 if ($settings[
'link_type'] & SQ_SC_LINK_SIGNIFICANT) {
182 $our_links = $am->getLinks($broadcasting_asset_id, SQ_SC_LINK_SIGNIFICANT,
'', TRUE,
'minor');
183 $num_links = count($our_links);
186 if ($num_links < 2)
return Array();
195 l.minorid = '.MatrixDAL::quote($broadcasting_asset_id).
' AND '.
206 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
208 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
211 foreach ($old_links as $old_link) {
212 $am->deleteAssetLink($old_link[
'linkid']);
215 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
217 }
catch (Exception $e) {
218 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
219 throw new Exception(
'Unable to delete links for asset: '.addslashes($assetid).
' due to database error: '.$e->getMessage());
222 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
225 $major->updateLookups();
226 $minor->updateLookups();
243 public static function getInterface($settings, $prefix, $write_access=FALSE)
246 $selected_assetid = array_get_index($settings,
'assetid', 0);
247 $is_major = array_get_index($settings,
'is_major', 1);
248 $selected_link_type = array_get_index($settings,
'link_type',
'ANY');
249 $link_value = array_get_index($settings,
'link_value',
'');
250 $is_exclusive = array_get_index($settings,
'is_exclusive', 0);
251 $any_link_value = array_get_index($settings,
'any_link_value', TRUE);
252 $direct_links_only = array_get_index($settings,
'direct_links_only', TRUE);
255 if ($selected_assetid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($selected_assetid)) {
256 $selected_assetid = 0;
259 $is_major_list = Array(0 =>
'Child', 1 =>
'Parent');
261 $link_type_list = get_link_type_names();
263 if (!$write_access) {
264 $form_element_extras =
'disabled="disabled"';
266 $form_element_extras =
'';
270 $asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
271 foreach ($asset_types as $type_code) {
272 $info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code);
273 if ($info[
'allowed_access'] !=
'system' && $info[
'instantiable']) {
274 $asset_types_options[$type_code] = $info[
'name'];
277 asort($asset_types_options);
278 $asset_types_options = array_reverse($asset_types_options, TRUE);
279 $asset_types_options[
''] =
'-- '.translate(
'all_asset_types').
' --';
280 $asset_types_options = array_reverse($asset_types_options, TRUE);
283 $settings[
'asset_types'] = isset($settings[
'asset_types']) ? $settings[
'asset_types'] : Array();
284 if (empty($settings[
'asset_types'])) {
285 $settings[
'asset_types'] = Array(0 =>
'');
293 <td valign=
"top"><b><?php echo translate(
'trigger_remove_link_matching_asset_types'); ?></b></td>
294 <td valign=
"top" style=
"padding-bottom: 10px;"><?php echo combo_box($prefix.
'[asset_types]', $asset_types_options, TRUE, $settings[
'asset_types'], 8); ?></td>
298 <td valign=
"top"><b><?php echo translate(
'trigger_remove_link_matching_asset_types'); ?></b></td>
299 <td valign=
"top" style=
"padding-bottom: 10px;"><?php
300 if (!empty($settings[
'asset_types'][0])) {
302 foreach ($settings[
'asset_types'] as $type_code) {
304 echo get_asset_type_icon($type_code);
305 echo $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code,
'name');
310 echo
' '.translate(
'all_asset_types');
317 $asset_types_combo_box = ob_get_contents();
322 asset_finder($prefix.
'[assetid]', $selected_assetid);
324 if ($selected_assetid) {
325 $selected_assetname = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($selected_assetid), Array(), TRUE,
'name');
326 text_box($prefix.
'[assetid]', $selected_assetname[$selected_assetid].
' (#'.$selected_assetid.
')',
'',
'', FALSE, $form_element_extras);
328 text_box($prefix.
'[assetid]',
'',
'',
'', FALSE, $form_element_extras);
332 $basic_part_2 = ob_get_contents();
336 $link_type_list[
'ANY'] =
'ANY TYPE';
338 combo_box($prefix.
'[link_type]', $link_type_list, FALSE, $selected_link_type, NULL, $form_element_extras);
339 $basic_part_3 = ob_get_contents();
344 $new_prefix = str_replace(array(
'[',
']'),
'_', $prefix);
345 hidden_field($prefix.
'[new_prefix]', $new_prefix);
349 $parameter_map_value = array_get_index($settings,
'parameter_map_target_asset', serialize(Array()));
351 $attr_parameter_map->setParameter(
'asset',
'Candidate Assets');
352 $attr_parameter_map->setParameter(
'direct_links_only',
'Where Candidate Assets are Directly Linked to the Root Node (1 = TRUE)');
353 echo $attr_parameter_map->paint($new_prefix.
'_parameter_map', !$write_access);
354 $basic_part_4 = ob_get_contents();
358 $link_value_onkeypress =
'';
359 $any_link_value_onclick =
'';
362 $link_value_onkeypress =
'onkeypress = "document.getElementById(\'any_link_value\').checked = false;"';
363 $any_link_value_onclick =
'onclick = "document.getElementById(\'link_value\').value = \'\';"';
366 text_box($prefix.
'[link_value]', $link_value,
'',
'', FALSE, $form_element_extras.
' '.$link_value_onkeypress.
' id="link_value"');
367 check_box($prefix.
'[any_link_value]',
'1', $any_link_value,
'', $form_element_extras.
' '.$any_link_value_onclick.
' id="any_link_value"');
368 echo translate(
'trigger_remove_link_any_link_value');
370 echo
'<p>'.translate(
'trigger_remove_link_direct_links_only');
371 check_box($prefix.
'[direct_links_only]',
'1', $direct_links_only,
'', $form_element_extras);
374 $advanced_part_1 = ob_get_contents();
377 $contents = translate(
'trigger_remove_link_basic', $basic_part_2).
'<br />'.
378 translate(
'trigger_remove_link_advanced', $basic_part_3, $advanced_part_1).
'<br /><br />'.
379 $asset_types_combo_box.
400 $is_major_list = Array(0 =>
'Child', 1 =>
'Parent');
402 $link_type_list = get_link_type_names();
403 $link_type_list[
'ANY'] =
'ANY TYPE';
406 if (empty($request_data[
'assetid'][
'assetid'])) {
407 return 'Asset ID not specified';
410 $request_data[
'is_major'] = TRUE;
411 if (!isset($request_data[
'is_major']) || !isset($is_major_list[$request_data[
'is_major']])) {
412 return 'Parent or Child link not specified';
415 if (empty($request_data[
'link_type']) || !isset($link_type_list[$request_data[
'link_type']])) {
416 return 'Link Type not specified';
419 $new_prefix = str_replace(array(
'[',
']'),
'_', array_get_index($request_data,
'new_prefix',
''));
421 $attr_parameter_map->process($new_prefix.
'_parameter_map');
422 $settings[
'parameter_map_target_asset'] = $attr_parameter_map->value;
424 $settings[
'assetid'] = $request_data[
'assetid'][
'assetid'];
425 $settings[
'link_id'] = $request_data[
'assetid'][
'linkid'];
426 $settings[
'is_major'] = $request_data[
'is_major'];
427 $settings[
'link_type'] = $request_data[
'link_type'];
430 $settings[
'asset_types'] = Array();
431 if (isset($request_data[
'asset_types']) && !empty($request_data[
'asset_types'][0])) {
432 $settings[
'asset_types'] = $request_data[
'asset_types'];
436 $settings[
'link_value'] = array_get_index($request_data,
'link_value',
'');
437 $settings[
'any_link_value'] = array_get_index($request_data,
'any_link_value', FALSE);
438 $settings[
'direct_links_only'] = array_get_index($request_data,
'direct_links_only', FALSE);