Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_menu_recursive.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_areas/menu/design_area_menu_type/design_area_menu_type.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
55  public function printStaticInitOutput()
56  {
57  parent::printStaticInitOutput();
58 
59  // Stuff that is only needed once per design file
60  if (empty($GLOBALS['SQ_'.__CLASS__.__FUNCTION__.'_RUN_'.$GLOBALS['DESIGN_BEING_GENERATED']->id])) {
61  echo '
62  // because we need to be able to get to this with the recurse fn
63  $GLOBALS[\'RECURSIVE_MENU_ASSET_LINEAGE\'] = &$ASSET_LINEAGE;
64  ';
65  $GLOBALS['SQ_'.__CLASS__.__FUNCTION__.'_RUN_'.$GLOBALS['DESIGN_BEING_GENERATED']->id] = TRUE;
66  }
67 
68  }//end printStaticInitOutput()
69 
70 
77  public function printInitOutput()
78  {
79  parent::printInitOutput();
80  $this->printRecursiveFn();
81 
82  }//end printInitOutput()
83 
84 
92  public function printRecursiveFn()
93  {
94  echo '
95 
96  function '.$this->attr('id_name').'_recursive_fn($level, $parentid, $'.$this->attr('id_name').'_base_url)
97  {
98  global $RECURSIVE_MENU_ASSET_LINEAGE;
99  static $'.$this->attr('id_name').'_settings = '.var_export($this->_getSettingsArray(), TRUE).';
100 
101  $'.$this->attr('id_name').'_lineage_assetid = (empty($RECURSIVE_MENU_ASSET_LINEAGE[$level + 1])) ? 0 : $RECURSIVE_MENU_ASSET_LINEAGE[$level + 1][\'assetid\'];
102  $'.$this->attr('id_name').'_lineage_setting = (count($RECURSIVE_MENU_ASSET_LINEAGE) - 1 == $level + 1) ? \'current\' : \'hierarchy\';
103  $'.$this->attr('id_name').'_urls = $GLOBALS[\'SQ_SYSTEM\']->am->getAssetURL(array_keys($GLOBALS[\'MENU_DATA\'][\''.$this->attr('id_name').'\'][$parentid]), $'.$this->attr('id_name').'_base_url);
104 
105  ?', '>
106  <ul>
107  <', '?php
108  $num_kids = count($GLOBALS[\'MENU_DATA\'][\''.$this->attr('id_name').'\'][$parentid]);
109  $i = 0;
110  foreach ($GLOBALS[\'MENU_DATA\'][\''.$this->attr('id_name').'\'][$parentid] as $'.$this->attr('id_name').'_row) {
111  $i++;
112  $end = ($i == $num_kids);
113  // if not live, we have to get the proper object, sorry
114  if (((int) $'.$this->attr('id_name').'_row[\'status\'] & SQ_STATUS_LIVE) == 0) {
115  $'.$this->attr('id_name').'_obj = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($'.$this->attr('id_name').'_row[\'assetid\'], $'.$this->attr('id_name').'_row[\'type_code\']);
116  } else {
117  unset($'.$this->attr('id_name').'_obj);
118  }
119  $'.$this->attr('id_name').'_current_setting = ($'.$this->attr('id_name').'_lineage_assetid == $'.$this->attr('id_name').'_row[\'assetid\']) ? $'.$this->attr('id_name').'_lineage_setting : \'normal\';
120 # pre_echo("CURRENT SETTING : ".$'.$this->attr('id_name').'_current_setting);
121 
122  ?', '>
123  ';
124  if ($asset_contents = $this->attr('asset_contents')) {
125  $this->_tmp['outputting_asset_section'] = TRUE;
126  foreach ($asset_contents as $item) {
127  $this->_printContentItemCode($item);
128  }
129  unset($this->_tmp['outputting_asset_section']);
130  }//end if
131  echo '
132  <', '?php
133  ';
134 
135  // if we are to show a minimum number of levels, add an extra bit to the condition
136 
137  $recurse_condition = '$'.$this->attr('id_name').'_current_setting != \'normal\'';
138 
139 
140  if ($this->attr('min_num_levels') > 0) {
141  $recurse_condition = '$level < '.($this->attr('min_num_levels') + $this->attr('level') - 1).' || '.$recurse_condition;
142  }
143 
144  if ($this->attr('max_num_levels') > 0) {
145  $recurse_condition = '$level < '.($this->attr('max_num_levels') + $this->attr('level') - 1).' && ('.$recurse_condition.')';
146  }
147  echo '
148  if (('.$recurse_condition.') && !empty($GLOBALS[\'MENU_DATA\'][\''.$this->attr('id_name').'\'][$'.$this->attr('id_name').'_row[\'assetid\']])) {
149  '.$this->attr('id_name').'_recursive_fn($level + 1, $'.$this->attr('id_name').'_row[\'assetid\'], $'.$this->attr('id_name').'_urls[$'.$this->attr('id_name').'_row[\'assetid\']]);
150  } // end if
151 
152  }//end for
153  ?', '>
154  </ul>
155  <', '?php
156 
157  }//end '.$this->attr('id_name').'_recursive_fn()
158 
159  ';
160 
161  }//end printRecursiveFn()
162 
163 
171  public function printDataCollection()
172  {
173  $parent_menu = $this->getParentMenu();
174  $ignore_permissions = $this->attr('ignore_permissions') ? ' , TRUE' : ' , FALSE';
175 
176  echo '
177  $'.$this->attr('id_name').'_num_repeats = count($ASSET_LINEAGE) - $'.$this->attr('id_name').'_level;
178  ';
179 
180  if ($this->attr('min_num_levels') > 0) {
181  echo '
182  if ($'.$this->attr('id_name').'_num_repeats < '.((int) $this->attr('min_num_levels')).') $'.$this->attr('id_name').'_num_repeats = '.((int) $this->attr('min_num_levels')).';
183  ';
184  }
185  if ($this->attr('max_num_levels') > 0) {
186  echo '
187  if ($'.$this->attr('id_name').'_num_repeats > '.((int) $this->attr('max_num_levels')).') $'.$this->attr('id_name').'_num_repeats = '.((int) $this->attr('max_num_levels')).';
188  ';
189  }
190 
191  // if we aren't a sub menu, or if our parent is only showing subs if we are in the lineage,
192  // we just need a blank assetids array for now
193  if (is_null($parent_menu) || $parent_menu->attr('show_subs') == 'on_current') {
194  echo '
195  $'.$this->attr('id_name').'_assetids = Array();';
196  // otherwise our parent wants all kids printed for everything so grab its assetids
197  } else {
198  echo '
199  $'.$this->attr('id_name').'_assetids = $'.$parent_menu->attr('id_name').'_assetids;';
200  }//end if
201 
202  echo '
203  for ($'.$this->attr('id_name').'_i = 0; $'.$this->attr('id_name').'_i < $'.$this->attr('id_name').'_num_repeats; $'.$this->attr('id_name').'_i++) {
204 
205  ';
206 
207  // if there is a minimum number of levels, then display everything for all those levels
208  // and only the current lineage thereafter
209  if ($this->attr('min_num_levels') > 0) {
210  // if we have no parent, or they only want us to display on current,
211  // then for the first round we need to read from the asset lineage
212  if (is_null($parent_menu) || $parent_menu->attr('show_subs') == 'on_current') {
213  $min_levels_extra_cond = '$'.$this->attr('id_name').'_i > 0 &&';
214  } else {
215  $min_levels_extra_cond = '';
216  }
217 
218  echo '
219  if ('.$min_levels_extra_cond.' $'.$this->attr('id_name').'_i < '.((int) $this->attr('min_num_levels')).') {
220  $'.$this->attr('id_name').'_assetids_cond = $'.$this->attr('id_name').'_assetids;
221  } else {
222  $'.$this->attr('id_name').'_assetids_cond = Array((int) $ASSET_LINEAGE[$'.$this->attr('id_name').'_level + $'.$this->attr('id_name').'_i][\'assetid\']);
223  }
224  ';
225  $majorids = '$'.$this->attr('id_name').'_assetids_cond';
226  } else {
227  $majorids = 'Array((int) $ASSET_LINEAGE[$'.$this->attr('id_name').'_level + $'.$this->attr('id_name').'_i][\'assetid\'])';
228  }
229 
230  echo '
231  unset($'.$this->attr('id_name').'_assetids);
232  $'.$this->attr('id_name').'_assetids = menu_get_assets(\''.$this->attr('id_name').'\', '.$majorids.' '.$ignore_permissions.');
233 
234  }//end for '.$this->attr('id_name').'_i
235 
236  ';
237 
238  }//end printDataCollection()
239 
240 
252  public function printVar($var, Array $args, $value_prefix='', $value_suffix='')
253  {
254  if ($var == 'asset_short_name' && $this->attr('ellipsis_length') > 0) {
255  $value_prefix = 'ellipsisize('.$value_prefix;
256  $value_suffix = $value_suffix.', '.$this->attr('ellipsis_length').' - (2 * $depth_count))';
257  }//end if
258 
259  parent::printVar($var, $args, $value_prefix, $value_suffix);
260 
261  }//end printVar()
262 
263 
272  protected function _printContentItemCode(Array $element)
273  {
274  switch (array_get_index($element, 'operation')) {
275  case 'asset' :
276 
277  echo '<', '?php
278  ';
279 
280  $parent_menu = $this->getParentMenu();
281  // if we aren't a sub menu
282  if (is_null($parent_menu)) {
283  $parent_assetid_name = '$ASSET_LINEAGE[$'.$this->attr('id_name').'_level][\'assetid\']';
284 
285  echo '
286  $'.$this->attr('id_name').'_base_url = (empty($ASSET_LINEAGE[$'.$this->attr('id_name').'_level])) ? \'\' : current_protocol().\'://\'.$ASSET_LINEAGE[$'.$this->attr('id_name').'_level][\'url\'];
287  ';
288 
289  // else we are a sub menu
290  } else {
291  $parent_assetid_name = '$'.$parent_menu->attr('id_name').'_row[\'assetid\']';
292 
293  echo '
294  $'.$this->attr('id_name').'_base_url = $'.$parent_menu->attr('id_name').'_urls[$'.$parent_menu->attr('id_name').'_row[\'assetid\']];
295  ';
296 
297  }//end if
298 
299  echo '
300  '.$this->attr('id_name').'_recursive_fn($'.$this->attr('id_name').'_level, '.$parent_assetid_name.', $'.$this->attr('id_name').'_base_url);
301  ?', '>';
302 
303  return TRUE;
304 
305 
306  case 'sub' :
307  // there ain't going to be any subs :)
308  return TRUE;
309 
310  default :
311  return parent::_printContentItemCode($element);
312  }//end switch
313 
314  }//end _printContentItemCode()
315 
316 
317 }//end class
318 ?>