Esempio n. 1
0
File: Loop.php Progetto: ssrsfs/blg
 public function process(Pagemill_Tag $tag, Pagemill_Data $data, Pagemill_Stream $stream)
 {
     $attributes = array();
     $name = $this->_loopAttributes;
     $parts = explode(' ', $name, 2);
     $attributes['name'] = $parts[0];
     if (isset($parts[1])) {
         $attributes['as'] = $parts[1];
     }
     $loop = new Pagemill_Tag_Loop('loop', $attributes, null, $tag->doctype());
     $temptag = new Pagemill_Tag($tag->name(), $tag->attributes(), null, $tag->doctype());
     foreach ($tag->children() as $child) {
         $temptag->appendChild($child);
     }
     $loop->appendChild($temptag);
     $loop->process($data, $stream);
     foreach ($temptag->children() as $child) {
         $tag->appendChild($child);
     }
     return false;
 }
Esempio n. 2
0
File: Loop.php Progetto: ssrsfs/blg
 protected function processIteration($key, $value, $delimit, $loopTimes)
 {
     $oldPointer = self::$_pointer;
     self::$_pointer .= '[' . $key . ']';
     $this->_data->set('pointer', self::$_pointer);
     $n = new Pagemill_Data();
     $resetKeys = array();
     $resetKeys[] = $this->_name;
     if ($this->_as) {
         $this->_data[$this->_as] = $value;
         $resetKeys[] = $this->_as;
     } else {
         if (is_array($value) || $value instanceof ArrayAccess) {
             foreach ($value as $k => $v) {
                 $this->_data[$k] = $v;
                 $resetKeys[] = $k;
             }
         } else {
             $this->_data['loop_value'] = $value;
             $resetKeys[] = 'loop_value';
         }
     }
     if ($this->_cycle) {
         $this->_data['cycle'] = $this->_cycle[$loopTimes % count($this->_cycle)];
         $resetKeys[] = 'cycle';
     }
     $this->_data['loop_index'] = $loopTimes;
     $resetKeys[] = 'loop_index';
     if ($this->_asKey) {
         $this->_data[$this->_asKey] = $key;
         $resetKeys[] = $this->_asKey;
     }
     foreach ($this->children() as $child) {
         $child->process($this->_data, $this->_stream);
     }
     if ($delimit) {
         $this->_stream->puts($this->_delimiter);
     }
     foreach ($resetKeys as $k) {
         if (isset($this->_originalData[$k])) {
             $this->_data[$k] = $this->_originalData[$k];
         } else {
             unset($this->_data[$k]);
         }
     }
     self::$_pointer = $oldPointer;
     $this->_data->set('pointer', self::$_pointer);
 }