Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_asset_id.inc
1 <?php
31 {
32 
33 
50  public static function evaluate($settings, &$state)
51  {
52  // grab the data we need to check the condition, if it's not already cached
53  // note that new state is modified and new data is available to other conditions
54  if (!isset($state['assetid'])) {
55  if (isset($state['asset'])) {
56  $state['assetid'] = $state['asset']->id();
57  } else {
58  return FALSE;
59  }
60  }
61 
62  // check the condition
63  // no need to check if $settings['assetid'] is pointing to a valid asset, $state takes care of that for us
64  if ($state['assetid'] == $settings['assetid']) {
65  return TRUE;
66  } else {
67  return FALSE;
68  }
69 
70  }//end evaluate()
71 
72 
83  public static function getInterface($settings, $prefix, $write_access=FALSE)
84  {
85  $selected_assetid = array_get_index($settings, 'assetid', 0);
86 
87  // check if the selected asset is valid
88  if ($selected_assetid && !$GLOBALS['SQ_SYSTEM']->am->assetExists($selected_assetid)) {
89  $selected_assetid = 0;
90  }
91 
92  if (!$write_access) {
93  $form_element_extras = 'disabled="disabled"';
94  } else {
95  $form_element_extras = '';
96  }
97 
98  // begin buffering basic options
99  ob_start();
100  if ($write_access) {
101  asset_finder($prefix.'[assetid]', $selected_assetid);
102  } else {
103  if ($selected_assetid) {
104  $selected_assetname = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($selected_assetid), Array(), TRUE, 'name');
105  text_box($prefix.'[assetid]', $selected_assetname[$selected_assetid].' (#'.$selected_assetid.')', '', '', FALSE, $form_element_extras);
106  } else {
107  text_box($prefix.'[assetid]', '', '', '', FALSE, $form_element_extras);
108  }
109  }
110 
111  $basic_part_1 = ob_get_contents();
112  ob_end_clean();
113 
114  return translate('trigger_asset_id', $basic_part_1);
115 
116  }//end getInterface()
117 
118 
128  public static function processInterface(&$settings, $request_data)
129  {
130  if (empty($request_data)) {
131  return 'There was an error with input data';
132  }
133 
134  if (empty($request_data['assetid']) || empty($request_data['assetid']['assetid'])) {
135  return 'Asset id is not specified';
136  }
137 
138  $assetid = $request_data['assetid']['assetid'];
139  $settings['assetid'] = $assetid;
140 
141  return FALSE;
142 
143  }//end processInterface()
144 
145 
156  public static function setHash(&$settings, &$hash)
157  {
158  if (isset($settings['assetid'])) {
159  $hash->setAssetID($settings['assetid']);
160  }
161  return FALSE;
162 
163  }//end setHash()
164 
165 
166 }//end class
167 
168 ?>