Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_metadata_set.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_condition/trigger_condition.inc';
18 
31 {
32 
33 
50  public static function evaluate($settings, &$state)
51  {
52  if (empty($settings['asset_id'])) return FALSE;
53 
54  $metadata_value = $GLOBALS['SQ_SYSTEM']->getMetadataManager()->getMetadataValueByAssetid($state['assetid'], $settings['asset_id'], TRUE);
55  $default_value = $GLOBALS['SQ_SYSTEM']->getMetadataManager()->getMetadataFieldDefaultValue($settings['asset_id']);
56 
57  //if the metadatavalue is empty or same as default, that means its not set
58  if ( $metadata_value == '' || ($metadata_value === $default_value)) return FALSE;
59 
60  // if we have metadata set for this field give mission GO!!!
61  return TRUE;
62 
63  }//end evaluate()
64 
65 
76  public static function getInterface($settings, $prefix, $write_access=FALSE)
77  {
78  $selected_asset_id = array_get_index($settings, 'asset_id', 0);
79  $am = $GLOBALS['SQ_SYSTEM']->am;
80  if (!empty($selected_asset_id)) {
81  $selected_asset = $am->getAsset($selected_asset_id);
82  } else {
83  $selected_asset = '';
84  }
85 
86  // asset finder - to pick the metadata field
87  ob_start();
88  if ($write_access) {
89  $restricted_types['metadata_field_text'] = 'I';
90  $restricted_types['metadata_field_thesaurus'] = 'I';
91  $restricted_types['metadata_field_select'] = 'I';
92  $restricted_types['metadata_field_wysiwyg'] = 'I';
93  $restricted_types['metadata_field_multiple_text'] = 'I';
94  asset_finder($prefix.'[asset_id]', $selected_asset_id, $restricted_types);
95  } else {
96  if (!empty($selected_asset_id)) {
97  echo get_asset_tag_line($selected_asset_id);
98  } else {
99  echo 'None selected';
100  }
101  }
102  $asset_id_component = ob_get_contents();
103  ob_end_clean();
104 
105  return translate('trigger_metadata_set', $asset_id_component);
106 
107  }//end getInterface()
108 
109 
120  public static function processInterface(&$settings, $request_data)
121  {
122  if (empty($request_data)) {
123  return translate('trigger_input_data_error');
124  }
125 
126  $asset_id = array_get_index($request_data, 'asset_id', FALSE);
127  if (!$asset_id) {
128  return translate('trigger_asset_not_supplied');
129  }
130 
131  if (!empty($asset_id['assetid'])) {
132  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($asset_id['assetid']);
133  $settings['asset_id'] = $asset_id['assetid'];
134  }
135 
136  return FALSE;
137 
138  }//end processInterface()
139 
140 
148  public static function allowMultiple()
149  {
150 
151  return TRUE;
152 
153  }//end allowMultiple()
154 
155 
156 }//end class
157 
158 ?>