Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_paint_layout.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 require_once SQ_SYSTEM_ROOT.'/core/attributes/parameter_map/parameter_map.inc';
19 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
20 
21 
34 {
35 
36 
55  public static function execute($settings, &$state)
56  {
57  if (empty($settings['layout_assetid']) && empty($settings['override_layout_assetid'])) {
58  // if no settings, fail
59  return FALSE;
60  }
61 
62  // state
63  if (empty($state['asset'])) {
64  // grab the asset if assetid is given, but not the asset.
65  if (empty($state['assetid'])) {
66  return FALSE;
67  } else {
68  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
69  }
70  }
71 
72  $am = $GLOBALS['SQ_SYSTEM']->am;
73 
74  if (isset($settings['layout_map'])) {
75  // parameter map
76  $parameter_map_value = array_get_index($settings, 'layout_map', serialize(Array()));
77  $attr_parameter_map = new Asset_Attribute_Parameter_Map(0, $parameter_map_value);
78  $layouts['paint_layout::system::frontend'] = $attr_parameter_map->getParameterValue('parameter_map_layout_assetid');
79  $layouts['override::paint_layout::system::frontend'] = $attr_parameter_map->getParameterValue('parameter_map_override_layout_assetid');
80  }
81 
82  // if any parameter map values are present, they take priority
83  $layouts['paint_layout::system::frontend'] = empty($layouts['paint_layout::system::frontend']) ? array_get_index($settings, 'layout_assetid', 0) : $layouts['paint_layout::system::frontend'];
84  $layouts['override::paint_layout::system::frontend'] = empty($layouts['override::paint_layout::system::frontend']) ? array_get_index($settings, 'override_layout_assetid', 0) : $layouts['override::paint_layout::system::frontend'];
85 
86  if (!$state['asset']->setPaintLayouts($layouts)) {
87  return FALSE;
88  }
89 
90  return Array(
91  'assetid' => $state['asset']->id,
92  'layout' => isset($settings['layout_assetid']) ? $settings['layout_assetid'] : '',
93  'override_layout' => isset($settings['override_layout_assetid']) ? $settings['override_layout_assetid'] : '',
94  );
95 
96  }//end execute()
97 
98 
109  public static function getInterface($settings, $prefix, $write_access=FALSE)
110  {
111  $selected_layout_assetid = empty($settings['layout_assetid']) ? 0 : $settings['layout_assetid'];
112  $selected_override_layout_assetid = empty($settings['override_layout_assetid']) ? 0 : $settings['override_layout_assetid'];
113 
114  // check if the selected layouts are valid
115  if ($selected_layout_assetid && !$GLOBALS['SQ_SYSTEM']->am->assetExists($selected_layout_assetid)) {
116  $selected_layout_assetid = 0;
117  }
118  if ($selected_override_layout_assetid && !$GLOBALS['SQ_SYSTEM']->am->assetExists($selected_override_layout_assetid)) {
119  $selected_override_layout_assetid = 0;
120  }
121 
122  // attribute friendly prefix
123  $new_prefix = str_replace(array('[',']'), '_', $prefix);
124  hidden_field($prefix.'[new_prefix]', $new_prefix);
125 
126  ob_start();
127  if (!$write_access) {
128  $layout_wa = !empty($selected_layout_assetid) ? get_asset_tag_line($selected_layout_assetid) : '<i>'.translate('none').'</i>';
129  $override_layout_wa = !empty($selected_override_layout_assetid) ? get_asset_tag_line($selected_override_layout_assetid) : '<i>'.translate('none').'</i>';
130  }
131 
132  $layout_buttons = empty($selected_layout_assetid) ? Array('clear') : Array('clear', 'reset');
133  $override_layout_buttons = empty($selected_override_layout_assetid) ? Array('clear') : Array('clear', 'reset');
134 
135  ?>
136  <table>
137  <tr>
138  <td><?php echo translate('trigger_set_paint_layout_select'); ?> </td>
139  <td><?php echo $write_access ? translate('trigger_set_paint_layout', asset_finder($prefix.'[layout_assetid]', $selected_layout_assetid, Array('paint_layout_page' => 'D'), 'sq_sidenav', FALSE, 'null', $layout_buttons)) : $layout_wa; ?> </td>
140  </tr><tr>
141  <td><?php echo translate('trigger_set_override_paint_layout_select'); ?></td>
142  <td><?php echo $write_access ? translate('trigger_set_override_paint_layout', asset_finder($prefix.'[override_layout_assetid]', $selected_override_layout_assetid, Array('paint_layout_page' => 'D'), 'sq_sidenav', FALSE, 'null', $override_layout_buttons)) : $override_layout_wa; ?> </td>
143  </tr></tr>
144  </table>
145  <?php
146 
147  $basic_contents = ob_get_clean();
148 
149  // parameter map options
150  ob_start();
151  $parameter_map_value = array_get_index($settings, 'layout_map', serialize(Array()));
152  $attr_parameter_map = new Asset_Attribute_Parameter_Map(0, $parameter_map_value);
153  $attr_parameter_map->setParameter('parameter_map_layout_assetid', 'Paint Layout Asset ID');
154  $attr_parameter_map->setParameter('parameter_map_override_layout_assetid', 'Override Paint Layout Asset ID');
155  echo $attr_parameter_map->paint($new_prefix.'_parameter_map', !$write_access);
156  $parameter_map_contents = ob_get_clean();
157 
158  return $basic_contents.'<b>'.translate('trigger_set_paint_layout_parameter_map', $parameter_map_contents).'</b>';
159 
160  }//end getInterface()
161 
162 
174  public static function processInterface(&$settings, $request_data)
175  {
176  if (empty($request_data['layout_assetid']['assetid']) && empty($request_data['override_layout_assetid']['assetid'])) {
177  return 'Paint layout not specified';
178  }
179 
180  $settings['layout_assetid'] = $request_data['layout_assetid']['assetid'];
181  $settings['override_layout_assetid'] = $request_data['override_layout_assetid']['assetid'];
182 
183  $new_prefix = str_replace(array('[',']'), '_', array_get_index($request_data, 'new_prefix', ''));
184  $attr_parameter_map = new Asset_Attribute_Parameter_Map();
185  $attr_parameter_map->process($new_prefix.'_parameter_map');
186  $settings['layout_map'] = $attr_parameter_map->value;
187 
188  return FALSE;
189 
190  }//end processInterface()
191 
192 
202  public static function getLocks($settings, &$state)
203  {
204  return Array(
205  $state['assetid'] => Array(
206  'links',
207  'lookups',
208  ),
209  );
210 
211  }//end getLocks()
212 
213 
214 }//end class
215 
216 ?>