PEEL Shopping
Open source ecommerce : PEEL Shopping
smarty_internal_compile_for.php
Go to the documentation of this file.
1 <?php
19 
39  public function compile($args, $compiler, $parameter)
40  {
41  if ($parameter == 0) {
42  $this->required_attributes = array('start', 'to');
43  $this->optional_attributes = array('max', 'step');
44  } else {
45  $this->required_attributes = array('start', 'ifexp', 'var', 'step');
46  $this->optional_attributes = array();
47  }
48  // check and get attributes
49  $_attr = $this->getAttributes($compiler, $args);
50 
51  $output = "<?php ";
52  if ($parameter == 1) {
53  foreach ($_attr['start'] as $_statement) {
54  $output .= " \$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
55  $output .= " \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n";
56  }
57  $output .= " if ($_attr[ifexp]){ for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[step]){\n";
58  } else {
59  $_statement = $_attr['start'];
60  $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
61  if (isset($_attr['step'])) {
62  $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
63  } else {
64  $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = 1;";
65  }
66  if (isset($_attr['max'])) {
67  $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int)min(ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step)),$_attr[max]);\n";
68  } else {
69  $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int)ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step));\n";
70  }
71  $output .= "if (\$_smarty_tpl->tpl_vars[$_statement[var]]->total > 0){\n";
72  $output .= "for (\$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value], \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration = 1;\$_smarty_tpl->tpl_vars[$_statement[var]]->iteration <= \$_smarty_tpl->tpl_vars[$_statement[var]]->total;\$_smarty_tpl->tpl_vars[$_statement[var]]->value += \$_smarty_tpl->tpl_vars[$_statement[var]]->step, \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration++){\n";
73  $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->first = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == 1;";
74  $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->last = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == \$_smarty_tpl->tpl_vars[$_statement[var]]->total;";
75  }
76  $output .= "?>";
77 
78  $this->openTag($compiler, 'for', array('for', $compiler->nocache));
79  // maybe nocache because of nocache variables
80  $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
81  // return compiled code
82  return $output;
83  }
84 
85 }
86 
94 
103  public function compile($args, $compiler, $parameter)
104  {
105  // check and get attributes
106  $_attr = $this->getAttributes($compiler, $args);
107 
108  list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
109  $this->openTag($compiler, 'forelse', array('forelse', $nocache));
110  return "<?php }} else { ?>";
111  }
112 
113 }
114 
122 
131  public function compile($args, $compiler, $parameter)
132  {
133  // check and get attributes
134  $_attr = $this->getAttributes($compiler, $args);
135  // must endblock be nocache?
136  if ($compiler->nocache) {
137  $compiler->tag_nocache = true;
138  }
139 
140  list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
141 
142  if ($openTag == 'forelse') {
143  return "<?php } ?>";
144  } else {
145  return "<?php }} ?>";
146  }
147  }
148 
149 }
150 
151 ?>
compile($args, $compiler, $parameter)
Compiles code for the {/for} tag.
compile($args, $compiler, $parameter)
Compiles code for the {for} tag.
openTag($compiler, $openTag, $data=null)
Push opening tag name on stack.
getAttributes($compiler, $attributes)
This function checks if the attributes passed are valid.
closeTag($compiler, $expectedTag)
Pop closing tag.
compile($args, $compiler, $parameter)
Compiles code for the {forelse} tag.

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:17 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.