1: <?php
2:
3: /**
4: * Description of ForLoop
5: *
6: * @author SARTAJ
7: */
8:
9:
10:
11: class ForEachLoop extends \Sphp\tools\Component {
12:
13: public $key = "";
14: public $item = "";
15: private $childrenroot = null;
16: private $loopobj = null;
17: public $counter = 0;
18:
19: protected function onaftercreate() {
20: //$this->fu_unsetrenderTag();
21: $this->loopobj = array();
22: $this->childrenroot = $this->frontobj->getChildrenWrapper($this);
23: }
24:
25: /**
26: * Set Object for Loop, direct read declared variables in Front File.
27: * Example:- pass 'a' mean $a
28: * @param string $name Name of Variable declare in Front File
29: */
30: public function fu_setObject($val) {
31: $this->loopobj = $this->frontobj->getMetaData($val);
32: }
33:
34: private function genrender() {
35: $stro = '';
36: foreach($this->loopobj as $key=>$val){
37: $this->key = $key;
38: $this->item = $val;
39: $this->counter += 1;
40: $stro .= $this->frontobj->parseComponentChildren($this->childrenroot);
41: }
42: return $stro;
43: }
44:
45: protected function onprerender() {
46: //delete all children nodes so stop also children Components Rendering also
47: $this->innerHTML = "";
48: }
49: protected function onrender() {
50: $this->counter = 0;
51: $this->innerHTML = $this->genrender();
52: }
53:
54: }
55:
56:
57: