Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_show_if_edit_fns.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area_edit_fns.inc';
18 
31 {
32 
33 
38  function __construct()
39  {
40  $this->static_screens['details']['force_unlock'] = FALSE;
41  parent::__construct();
42 
43  }//end constructor
44 
45 
55  public function _processContents(Design_Area_Show_If $asset, Array &$contents)
56  {
57  $then_element = FALSE;
58  $else_element = FALSE;
59 
60  if (!$this->_setVariables($asset, $contents)) {
61  return FALSE;
62  }
63 
64  // Check if the provided condition exists on the system
65  $condition = $asset->attr('condition');
66  if (!$GLOBALS['SQ_SYSTEM']->am->installed('condition_'.$condition)) {
67  trigger_localised_error('CORE0148', E_USER_WARNING, $condition, $asset->name);
68  return FALSE;
69  }
70 
71  // see if our asset element has any then/else elements in it
72  foreach ($contents as $index => $element) {
73  if ($element['_type'] != 'TAG') continue;
74 
75  switch ($element['operation']) {
76  case 'then' :
77  if (!$then_element) {
78  if (!$asset->setAttrValue('then_contents', $element['contents'])) {
79  return FALSE;
80  }
81  } else {
82  trigger_localised_error('CORE0214', E_USER_WARNING, $asset->name);
83  return FALSE;
84  }
85 
86  $then_element = TRUE;
87 
88  // Now we want to remove the Then section
89  array_splice($contents, $index, 1);
90  break;
91 
92  case 'else' :
93  if (!$else_element) {
94  if (!$asset->setAttrValue('else_contents', $element['contents'])) {
95  return FALSE;
96  }
97  } else {
98  trigger_localised_error('CORE0147', E_USER_WARNING, $asset->name);
99  return FALSE;
100  }
101 
102  $else_element = TRUE;
103 
104  // Now we want to remove the Else section
105  array_splice($contents, $index, 1);
106  break;
107 
108  }//end switch
109 
110  }//end foreach
111 
112  if (!$then_element && !$else_element) {
113  trigger_localised_error('CORE0169', E_USER_WARNING, $asset->name);
114  return FALSE;
115  }
116 
117  $GLOBALS['SQ_PROCESSED_DESIGN_AREAS'][$asset->attr('id_name')] = TRUE;
118  return $asset->saveAttributes();
119 
120  }//end _processContents()
121 
122 
133  public function paintConditionType(Design_Area_Show_If $asset, Backend_Outputter $o, $prefix)
134  {
135  $names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($GLOBALS['SQ_SYSTEM']->am->getTypeDescendants('condition'), 'name');
136  if ($asset->writeAccess('attributes')) {
137  combo_box($prefix.'_condition_type', $names, FALSE, 'condition_'.$asset->attr('condition'));
138  return TRUE;
139  } else {
140  echo array_get_index($names, 'condition_'.$asset->attr('condition'), $asset->attr('condition'));
141  return FALSE;
142  }
143 
144  }//end paintConditionType()
145 
146 
157  public function processConditionType(Design_Area_Show_If $asset, Backend_Outputter $o, $prefix)
158  {
159  if (isset($_POST[$prefix.'_condition_type']) && ($_POST[$prefix.'_condition_type'] != 'condition_'.$asset->attr('condition'))) {
160  $this->_tmp['condition_type_changed'] = TRUE;
161  return $asset->setAttrValue('condition', substr($_POST[$prefix.'_condition_type'], strlen('condition_')));
162  }
163  return FALSE;
164 
165  }//end processConditionType()
166 
167 
178  public function paintConditionDetails(Design_Area_Show_If $asset, Backend_Outputter $o, $prefix)
179  {
180  echo translate('condition_'.$asset->attr('condition').'_true');
181  $edit_fns_classname = 'condition_'.$asset->attr('condition').'_edit_fns';
182  $GLOBALS['SQ_SYSTEM']->am->includeAsset('condition_'.$asset->attr('condition'), TRUE);
183  call_user_func(Array($edit_fns_classname, 'paintEditInterface'), $asset->attr('condition_data'), $o, $prefix.'_condition', $asset->writeAccess('attributes'), Array());
184 
185  }//end paintConditionDetails()
186 
187 
198  public function processConditionDetails(Design_Area_Show_If $asset, Backend_Outputter $o, $prefix)
199  {
200  if (!array_get_index($this->_tmp, 'condition_type_changed')) {
201  $edit_fns_classname = 'condition_'.$asset->attr('condition').'_edit_fns';
202  $GLOBALS['SQ_SYSTEM']->am->includeAsset('condition_'.$asset->attr('condition'), TRUE);
203  $res = call_user_func(Array($edit_fns_classname, 'processEditInterface'), $o, $prefix.'_condition');
204  return $asset->setAttrValue('condition_data', $res);
205  }
206  return FALSE;
207 
208  }//end processConditionDetails()
209 
210 
211 }//end class
212 ?>