Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_session_var.inc
1 <?php
18 require_once SQ_SYSTEM_ROOT.'/core/attributes/parameter_map/parameter_map.inc';
19 
41 {
42 
43 
50  function Trigger_Action_Set_Session_Var($assetid=0)
51  {
52  parent::__construct($assetid);
53  }//end constructor
54 
55 
67  public static function processInterface(&$settings, $request_data)
68  {
69 
70  $settings['name'] = $request_data['name'];
71  $settings['value'] = $request_data['value'];
72  $settings['value_map'] = '';
73 
74  $new_prefix = str_replace(array('[',']'), '_', array_get_index($request_data, 'new_prefix', ''));
75  if ($new_prefix) {
76  $atr_parameter_map = new Asset_Attribute_Parameter_Map();
77  $atr_parameter_map->process($new_prefix.'_parameter_map');
78  $settings['value_map'] = $atr_parameter_map->value;
79  }
80 
81  return FALSE;
82 
83  }//end processInterface()
84 
85 
105  public static function execute($settings, &$state)
106  {
107  // check required settings
108  $var_name = @$settings['name'];
109  if (empty($var_name)) return FALSE;
110 
111  if (empty($state['asset'])) {
112  // grab the asset if assetid is given, but not the asset.
113  if (empty($state['assetid'])) {
114  return FALSE;
115  } else {
116  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
117  }
118  }
119 
120  $old_current_asset = $GLOBALS['SQ_SYSTEM']->getGlobalDefine('CURRENT_ASSET', NULL);
121  $GLOBALS['SQ_SYSTEM']->setGlobalDefine('CURRENT_ASSET', $state['asset']);
122 
123  $parameter_map_value = array_get_index($settings, 'value_map', serialize(Array()));
124  $atr_parameter_map = new Asset_Attribute_Parameter_Map(0, $parameter_map_value);
125  $param_map_value = $atr_parameter_map->getParameterValue('value');
126 
127  if (is_null($old_current_asset)) {
128  $GLOBALS['SQ_SYSTEM']->unsetGlobalDefine('CURRENT_ASSET');
129  } else {
130  $GLOBALS['SQ_SYSTEM']->setGlobalDefine('CURRENT_ASSET', $old_current_asset);
131  }
132 
133  // settings contains the 'fallback' static value.
134  if (!empty($param_map_value)) {
135  $value = $param_map_value;
136  } else {
137  $value = $settings['value'];
138  }
139 
140  $_SESSION[SQ_SESSION_SANDBOX_INDEX][$var_name] = $value;
141 
142  return Array(
143  'name' => $var_name,
144  'value' => $value,
145  );
146 
147  }//end execute()
148 
149 
160  public static function getInterface($settings, $prefix, $write_access=FALSE)
161  {
162  // begin buffering basic options
163  ob_start();
164  $name = array_get_index($settings, 'name');
165  if ($write_access) {
166  text_box($prefix.'[name]', $name);
167  } else {
168  echo '<b>'.$name.'</b>';
169  }
170  $name_input = ob_get_clean();
171 
172  ob_start();
173  $value = array_get_index($settings, 'value');
174  if ($write_access) {
175  text_box($prefix.'[value]', $value);
176  } else {
177  echo '<b>'.$value.'</b>';
178  }
179  $value_input = ob_get_clean();
180 
181  ob_start();
182  echo '<div>';
183  $new_prefix = str_replace(array('[',']'), '_', $prefix);
184  hidden_field($prefix.'[new_prefix]', $new_prefix);
185 
186  $parameter_map_value = array_get_index($settings, 'value_map', serialize(Array()));
187  $atr_parameter_map = new Asset_Attribute_Parameter_Map(0, $parameter_map_value);
188 
189  $atr_parameter_map->setParameter('value', 'Value');
190  echo $atr_parameter_map->paint($new_prefix.'_parameter_map');
191  echo '</div>';
192 
193  $parameter_map_input = ob_get_clean();
194 
195  $output = translate('trigger_set_session_var_interface', $name_input, $value_input, $parameter_map_input);
196 
197  return $output;
198 
199  }//end getInterface()
200 
201 
202 }//end class
203 
204 ?>