17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
52 public static function execute($settings, &$state)
54 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
55 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
58 if (empty($settings[
'schemaid']))
return FALSE;
60 if (empty($state[
'asset'])) {
62 if (empty($state[
'assetid'])) {
65 $state[
'asset'] = $am->getAsset($state[
'assetid']);
69 if (is_null($state[
'asset']))
return FALSE;
71 $granted = array_get_index($settings,
'granted', TRUE);
72 $cascade = array_get_index($settings,
'cascade', FALSE);
73 $cascade_to_new = array_get_index($settings,
'cascade_to_new', TRUE);
75 $schema = $am->getAsset($settings[
'schemaid']);
76 if (is_null($schema))
return FALSE;
77 if ($schema->type() !=
'metadata_schema')
return FALSE;
81 $result = $mm->setSchema($state[
'asset']->
id, $schema->id, $granted, $cascade_to_new);
83 $schema_vars[] = Array(
84 'assetids' => Array($state[
'asset']->
id),
85 'granted' => $granted,
86 'schemaid' => $settings[
'schemaid'],
87 'cascades' => $cascade_to_new,
88 'previous_access' => NULL,
91 'schema_changes' => $schema_vars,
94 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
95 $errors = $hh->freestyleHIPO(
'hipo_job_edit_metadata_schemas', $vars);
96 $result = empty($errors);
104 'assetid' => $state[
'asset']->
id,
105 'schemaid' => $settings[
'schemaid'],
106 'granted' => $granted,
107 'cascade' => $cascade,
124 public static function getInterface($settings, $prefix, $write_access=FALSE)
126 $current_schemaid = array_get_index($settings,
'schemaid', 0);
127 $granted = array_get_index($settings,
'granted', 1);
128 $cascade = array_get_index($settings,
'cascade', FALSE);
129 $cascade_to_new = array_get_index($settings,
'cascade_to_new', TRUE);
132 TRUE => translate(
'apply'),
133 FALSE => translate(
'deny'),
139 combo_box($prefix.
'[granted]', $options, FALSE, $granted);
140 $combo_box = ob_get_clean();
141 echo translate(
'trigger_schema_apply-deny_the_following_schema', $combo_box).
' ';
142 asset_finder($prefix.
'[schemaid]', $current_schemaid, Array(
'metadata_schema' =>
'I'));
144 check_box($prefix.
'[cascade]',
'1', $cascade);
145 label(translate(
'cascade_schema_changes'), $prefix.
'[cascade]');
147 check_box($prefix.
'[cascade_to_new]',
'1', $cascade_to_new);
148 label(translate(
'cascade_schema_changes_to_new_children'), $prefix.
'[cascade_to_new]');
151 if (!empty($current_schemaid)) {
152 $schema_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($current_schemaid));
153 echo translate(
'trigger_schema_apply-deny_the_following_schema', $options[$granted]).
' ';
154 echo
'<b>'.$schema_info[$current_schemaid][
'name'].
' (#'.$current_schemaid.
')</b>';
156 echo translate(
'trigger_schema_apply-deny_the_following_schema', $options[$granted]).
' ';
157 echo
'<b>'.translate(
'trigger_schema_no_schema_specified').
'</b>';
160 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($cascade ?
'tick' :
'cross').
'.gif" alt="'.($cascade ? translate(
'yes') : translate(
'no')).
'" /> ';
161 echo translate(
'cascade_schema_changes');
163 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($cascade_to_new ?
'tick' :
'cross').
'.gif" alt="'.($cascade_to_new ? translate(
'yes') : translate(
'no')).
'" /> ';
164 echo translate(
'cascade_schema_changes_to_new_children');
167 $output = ob_get_contents();
188 $schema_info = array_get_index($request_data,
'schemaid', Array(
'assetid' => 0));
189 $settings[
'schemaid'] = array_get_index($schema_info,
'assetid', 0);
190 $settings[
'granted'] = array_get_index($request_data,
'granted', TRUE);
191 $settings[
'cascade'] = array_get_index($request_data,
'cascade', FALSE);
192 $settings[
'cascade_to_new'] = array_get_index($request_data,
'cascade_to_new', FALSE);
207 public static function getLocks($settings, &$state)
209 return Array($state[
'assetid'] => Array(
'metadata'));