Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_declared_vars_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
55  public function _processContents(Design_Area_Declared_Vars $asset, Array $contents)
56  {
57  $vars = Array();
58  $declared_vars = Array();
59  // firstly let's check to see if all the design areas have unique names
60  foreach ($contents as $index => $element) {
61  if ($element['_type'] != 'TAG' || $element['operation'] != 'declare') {
62  continue;
63  }
64 
65  // if there is a name and it's not the the same type as the current design area
66  if (empty($element['attributes']['name']) || empty($element['attributes']['type'])) {
67  trigger_localised_error('CORE0141', E_USER_WARNING);
68  continue;
69  }//end if
70 
71  if (!isset($element['attributes']['value'])) {
72  $element['attributes']['value'] = '';
73  }
74  if (!isset($element['attributes']['description'])) {
75  $element['attributes']['description'] = '';
76  }
77 
78  $name = preg_replace('/[^a-z0-9_]/i', '_', $element['attributes']['name']);
79  if ($name != $element['attributes']['name']) {
80  trigger_localised_error('CORE0150', E_USER_WARNING, $element['attributes']['name'], $asset->attr('id_name'), $name);
81  }
82 
83  // make sure this is a valid attribute type
84  if (!$GLOBALS['SQ_SYSTEM']->am->validAttributeType($element['attributes']['type'])) {
85  trigger_localised_error('CORE0152', E_USER_WARNING, $name, $asset->attr('id_name'), $element['attributes']['type']);
86  return FALSE;
87  }//end if
88 
89  // check that the value is valid
90  require_once(SQ_ATTRIBUTES_PATH.'/'.$element['attributes']['type'].'/'.$element['attributes']['type'].'.inc');
91  $class = 'Asset_Attribute_'.$element['attributes']['type'];
92  $attr = new $class();
93  if (!$attr->validateValue($element['attributes']['value'])) {
94  trigger_localised_error('CORE0151', E_USER_WARNING, $name, $asset->attr('id_name'), $element['attributes']['value'], $element['attributes']['type']);
95  return FALSE;
96  }//end if
97 
98  $declared_vars[$name] = Array(
99  'type' => $element['attributes']['type'],
100  'value' => $element['attributes']['value'],
101  'description' => $element['attributes']['description'],
102  );
103  }//end foreach
104 
105  // now make sure we save our changes
106  $GLOBALS['SQ_PROCESSED_DESIGN_AREAS'][$asset->attr('id_name')] = TRUE;
107  return $asset->setAttrValue('declared_vars', $declared_vars);
108 
109  // NOTE: we deliberately don't set the 'contents' as is done in other design areas
110 
111  }//end _processContents()
112 
113 
124  public function paintDecVars(Design_Area_Declared_Vars $asset, Backend_Outputter $o, $prefix)
125  {
126  $attrs = $asset->getDeclaredVarAttributes();
127  foreach ($attrs as $name => $attr) {
128  $o->openField($name);
129  if ($asset->writeAccess('attributes')) {
130  $attr->paint($prefix.'_'.$name);
131  } else {
132  echo $attr->value;
133  }
134  if ($asset->vars['declared_vars']['value'][$name]['description']) {
135  $o->note($asset->vars['declared_vars']['value'][$name]['description']);
136  }
137 
138  }// end foreach
139 
140  }//end paintDecVars()
141 
142 
153  public function processDecVars(Design_Area_Declared_Vars $asset, Backend_Outputter $o, $prefix)
154  {
155  $save = FALSE;
156  $attrs = $asset->getDeclaredVarAttributes();
157  $declared_vars = $asset->attr('declared_vars');
158  foreach ($attrs as $name => $attr) {
159  $attr->process($prefix.'_'.$name);
160  if ($attr->processed) {
161  $declared_vars[$name]['value'] = $attr->value;
162  $save = TRUE;
163  }
164  }
165 
166  if ($save) {
167  // now make sure we save our changes
168  $asset->setAttrValue('declared_vars', $declared_vars);
169  return TRUE;
170  } else {
171  return FALSE;
172  }
173 
174  }//end processDecVars()
175 
176 
177 }//end class
178 ?>