Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_show_if.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
58  public function setAttrValue($name, $value)
59  {
60  if ((substr($name, 0, 10) == 'condition_') && ($name != 'condition_data')) {
61  // this is some condition data we need to save and pass to the
62  // condition asset's evaluate() function
63  $data_key = substr($name, 10);
64 
65  $condition_data = $this->attr('condition_data');
66  $condition_data[$data_key] = $value;
67  return parent::setAttrValue('condition_data', $condition_data);
68  } else {
69  return parent::setAttrValue($name, $value);
70  }
71 
72  }//end setAttrValue()
73 
74 
83  protected function _printInitCode()
84  {
85  $condition = $this->attr('condition');
86  $condition_data = $this->attr('condition_data');
87  $condition_data['id_name'] = $this->attr('id_name');
88  $id_name = $this->attr('id_name');
89  $cond_var_name = '$'.$this->attr('id_name').'_condition_result';
90  echo '<','?php
91  $GLOBALS[\'SQ_SYSTEM\']->am->includeAsset(\'condition_'.$condition.'\');
92  $'.$id_name.'_condition_data = '.var_export($condition_data, TRUE).';
93  '.$cond_var_name.' = condition_'.$condition.'::evaluate($ASSET, $'.$id_name.'_condition_data);';
94  echo '?', '>
95  ';
96 
97  }//end _printInitCode()
98 
99 
109  protected function _printPaintingCode()
110  {
111  $then = $this->attr('then_contents');
112  $else = $this->attr('else_contents');
113  $cond_var_name = '$'.$this->attr('id_name').'_condition_result';
114 
115  echo '<','?php';
116  echo '
117  if ('.$cond_var_name.') {
118  ';
119 
120  // the multiple echo statements are required to get content to print at line 1,
121  // character 1 of the potential output (i.e. the DocType). Otherwise, it may get
122  // ignored
123  if (!empty($then)) {
124  echo '?', '>';
125  foreach ($then as $index => $element) {
126  $this->_printContentItemCode($element);
127  }
128  echo '<', '?php ; '."\n";
129  } else {
130  echo 'echo \'\';'."\n";
131  }
132 
133  echo '} else {'."\n";
134 
135  if (!empty($else)) {
136  echo '?', '>';
137  foreach ($else as $index => $element) {
138  $this->_printContentItemCode($element);
139  }
140  echo '<', '?php ; ';
141  } else {
142  echo 'echo \'\';';
143  }
144 
145  echo '}
146  ?','>
147  ';
148  return TRUE;
149 
150  }//end _printPaintingCode()
151 
152 
159  public function canBeCached()
160  {
161  return FALSE;
162 
163  }//end canBeCached()
164 
165 
175  public function getProtectedAttrs()
176  {
177  $attrs = parent::getProtectedAttrs();
178  $attrs[] = 'condition_data';
179  return $attrs;
180 
181  }//end getProtectedAttrs()
182 
183 
184 }//end class
185 ?>