15 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
50 public static function execute($settings, &$state)
52 $mm =& $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
55 if (empty($settings[
'fieldid']))
return FALSE;
60 if (array_key_exists(
'contextid', $settings) === FALSE) {
61 $settings[
'contextid'] = NULL;
64 if ($settings[
'contextid'] === NULL) {
65 $settings[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
68 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
69 if (array_key_exists($settings[
'contextid'], $all_contexts) === FALSE) {
73 $GLOBALS[
'SQ_SYSTEM']->changeContext($settings[
'contextid']);
76 $value = date(
'Y-m-d H:i:s', strtotime(
'+'.$settings[
'offset_months'].
' month '.$settings[
'offset_days'].
' day '.$settings[
'offset_hours'].
' hour '.$settings[
'offset_mins'].
' min'));
78 if (empty($state[
'asset'])) {
80 if (empty($state[
'assetid'])) {
81 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
84 $state[
'asset'] = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
89 $success = $mm->isMetadataFieldAssetid($settings[
'fieldid']);
91 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
96 $asset =& $state[
'asset'];
99 $metadata = $mm->getMetadata($asset->id);
103 if (isset($metadata[$settings[
'fieldid']])) {
104 $field_name = $metadata[$settings[
'fieldid']][0][
'name'];
109 $value = str_replace(
'=',
'\=', $value);
112 $metadata[$settings[
'fieldid']] = Array(
114 'name' => $field_name,
119 $success = $mm->setMetadata($asset->id, $metadata);
123 $field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'fieldid']);
126 if ($field->attr(
'is_contextable')) {
127 $mm->generateContentFile($asset->id);
129 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
130 foreach ($all_contexts as $contextid => $context_data) {
131 $mm->generateContentFile($asset->id, FALSE, $contextid);
136 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
141 'fieldid' => $settings[
'fieldid'],
142 'field_name' => $field_name,
162 public static function getInterface($settings, $prefix, $write_access=FALSE)
164 $metadata_fieldid = array_get_index($settings,
'fieldid', 0);
165 $metadata_field_value = array_get_index($settings,
'value', NULL);
170 echo translate(
'trigger_metadata_date_select_field');
171 asset_finder($prefix.
'[fieldid]', $metadata_fieldid, Array(
'metadata_field' =>
'D'));
173 echo translate(
'trigger_metadata_date_show_field');
174 echo $metadata_fieldid;
178 $disabled = ($write_access ?
'' :
'disabled=disabled');
180 text_box($prefix.
'[offset_months]', array_get_index($settings,
'offset_months', 0), 5, 2, FALSE, $disabled);
182 text_box($prefix.
'[offset_days]', array_get_index($settings,
'offset_days', 0), 5, 2, FALSE, $disabled);
184 text_box($prefix.
'[offset_hours]', array_get_index($settings,
'offset_hours', 0), 5, 2, FALSE, $disabled);
186 text_box($prefix.
'[offset_mins]', array_get_index($settings,
'offset_mins', 0), 5, 2, FALSE, $disabled);
187 list($text_box_months, $text_box_days, $text_box_mins, $text_box_hours) = explode(
'|', ob_get_clean());
188 echo translate(
'trigger_metadata_date_offset', $text_box_months, $text_box_days, $text_box_mins, $text_box_hours);
189 $output = ob_get_clean();
192 $current_context = array_get_index($settings,
'context_to_select', NULL);
194 $contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
195 $context_list = Array(
196 '-default-' => translate(
'trigger_use_currently_active_context'),
197 '-sep-' =>
'----------------------',
199 foreach ($contexts as $context_item_id => $context_item) {
200 if ((
int)$current_context === (
int)$context_item_id) {
201 $context_name = $context_item[
'name'];
204 $context_list[rawurlencode($context_item[
'name'])] = $context_item[
'name'];
207 $default = Array(
'-default-');
208 if (array_key_exists($current_context, $contexts) === TRUE) {
209 $default = Array($current_context);
212 if ($metadata_fieldid) {
213 label(translate(
'trigger_set_value_in_this_context'), $prefix.
'[context_to_select]');
216 combo_box($prefix.
'[context_to_select]', $context_list, FALSE, $default);
218 if ($current_context === NULL) {
219 echo translate(
'trigger_use_currently_active_context');
220 }
else if (array_key_exists($current_context, $contexts) === TRUE) {
221 echo $contexts[$current_context][
'name'];
223 echo
'<span class="sq-backend-warning">'.translate(
'trigger_context_deleted_fail_until_changed').
'</span>';
227 $output_context_select = ob_get_clean();
228 $output .=
'<br />'.$output_context_select;
249 $fieldid_data = array_get_index($request_data,
'fieldid', 0);
250 $fieldid = $fieldid_data[
'assetid'];
253 $settings[
'fieldid'] = $fieldid;
254 foreach (Array(
'offset_months',
'offset_days',
'offset_hours',
'offset_mins') as $field_name) {
255 $settings[$field_name] = array_get_index($request_data, $field_name,
'0');
258 $metadata_field =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($fieldid);
262 if (!$metadata_field->attr(
'editable')) {
263 trigger_localised_error(
'CORE0246', E_USER_WARNING, $metadata_field->name, $metadata_field->id);
267 $settings[
'field_name'] = $metadata_field->name;
269 $new_context = array_get_index($request_data,
'context_to_select', 0);
270 if (is_numeric($new_context) === TRUE) {
271 $new_context = (int)$new_context;
272 $contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
273 if (array_key_exists($new_context, $contexts) === TRUE) {
274 $settings[
'contextid'] = $new_context;
276 trigger_localised_error(
'TRIG0005', E_USER_WARNING, $new_context);
278 }
else if ($new_context ===
'-default-') {
279 $settings[
'contextid'] = NULL;
297 public static function getLocks($settings, &$state)
299 return Array($state[
'assetid'] => Array(
'all'));