17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_condition/trigger_condition.inc';
53 public static function evaluate($settings, &$state)
55 if (empty($settings[
'asset_id']))
return FALSE;
56 if (!isset($settings[
'value']) || ($settings[
'value'] ==
''))
return FALSE;
57 if (!isset($state[
'asset']) || is_null($state[
'asset'])) $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getasset($state[
'assetid']);
59 $compared_value = $settings[
'value'];
60 replace_global_keywords($compared_value);
62 $unfiltered_metadata_value = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager()->getMetadataValueByAssetid($state[
'assetid'], $settings[
'asset_id'], TRUE);
63 $keywords = extract_keywords($unfiltered_metadata_value);
65 $replacement = Array();
66 foreach ($keywords as $keyword) {
67 $replacement[$keyword] = $state[
'asset']->getKeywordReplacement($keyword);
70 $metadata_value = replace_keywords( $unfiltered_metadata_value, $replacement);
72 if (!is_null($metadata_value)) {
73 switch (array_get_index($settings,
'match',
'exact')) {
75 return ($compared_value == $metadata_value);
77 if (empty($compared_value)) {
78 return ($compared_value == $metadata_value);
80 return (strpos($metadata_value, $compared_value) !== FALSE);
82 return (preg_match(
'/'.str_replace(
'/',
'\/', $compared_value).
'/', $metadata_value) > 0);
101 public static function getInterface($settings, $prefix, $write_access=FALSE)
103 $selected_asset_id = array_get_index($settings,
'asset_id', 0);
104 $am = $GLOBALS[
'SQ_SYSTEM']->am;
105 if (!empty($selected_asset_id)) {
106 $selected_asset = $am->getAsset($selected_asset_id);
108 $selected_asset =
'';
111 $type_of_search = Array(
112 'exact' => translate(
'exact_match'),
113 'partial' => translate(
'partial_match'),
114 'regex' => translate(
'regex_match'),
118 if (!array_key_exists(
'match', $settings)) {
119 $settings[
'match'] =
'exact';
123 if (!array_key_exists(
'value', $settings)) {
124 $settings[
'value'] =
'';
130 $restricted_types[
'metadata_field_text'] =
'I';
131 $restricted_types[
'metadata_field_thesaurus'] =
'I';
132 $restricted_types[
'metadata_field_select'] =
'I';
133 asset_finder($prefix.
'[asset_id]', $selected_asset_id, $restricted_types);
135 if (!empty($selected_asset_id)) {
136 echo get_asset_tag_line($selected_asset_id);
138 echo
'None selected';
141 $asset_id_component = ob_get_contents();
147 combo_box($prefix.
'[match]', $type_of_search, FALSE, $settings[
'match']);
149 echo translate($settings[
'match'].
'_match');
151 $match_component = ob_get_contents();
157 text_box($prefix.
'[value]', array_get_index($settings,
'value'));
159 echo $settings[
'value'];
161 $value_component = ob_get_contents();
164 return translate(
'trigger_metadata_value', $asset_id_component, $match_component, $value_component);
181 if (empty($request_data)) {
182 return translate(
'trigger_input_data_error');
185 $asset_id = array_get_index($request_data,
'asset_id', FALSE);
187 return translate(
'trigger_asset_not_supplied');
190 if (!empty($asset_id[
'assetid'])) {
191 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id[
'assetid']);
193 $settings[
'asset_id'] = $asset_id[
'assetid'];
194 $settings[
'match'] = array_get_index($request_data,
'match', FALSE);
195 $settings[
'value'] = array_get_index($request_data,
'value', FALSE);