/** * Parses and intantiates templates. * This method is invoked when <b>OnDataBinding</b> event is raised. * It parses and instantiates all assoicated templates for the * repeater control and raises related events. * This method should only used by control developers. * @param TEventParameter event parameter */ protected function onDataBinding($param) { parent::onDataBinding($param); $this->setViewState('Items', null, null); $this->removeChildren(); $this->removeBodies(); $this->items = array(); $this->itemCount = 0; $this->header = null; $this->footer = null; $showEmpty = count($this->dataSource) <= 0 && strlen($this->emptyTemplate); if (is_null($this->dataSource)) { return; } if (strlen($this->headerTemplate) && !$showEmpty) { $header = pradoGetApplication()->createComponent('TRepeaterItem', self::ID_HEADER); $header->setType(TRepeaterItem::TYPE_HEADER); $header->instantiateTemplate($this->headerTemplate); $this->header = $header; $this->addChild($header); $this->addBody($header); $p = new TRepeaterItemEventParameter(); $p->item = $header; $this->onItemCreated($p); } $count = 0; //when the datasource is empty if ($showEmpty) { $empty = pradoGetApplication()->createComponent('TRepeaterItem', self::ID_EMPTY); $empty->setType(TRepeaterItem::TYPE_EMPTY); $empty->instantiateTemplate($this->emptyTemplate); $this->addChild($empty); $this->addBody($empty); $p = new TRepeaterItemEventParameter(); $p->item = $empty; $this->onItemCreated($p); } foreach ($this->dataSource as $key => $value) { if ($this->itemCount > 0 && strlen($this->separatorTemplate)) { $separator = pradoGetApplication()->createComponent('TRepeaterItem'); $separator->setType(TRepeaterItem::TYPE_SEPARATOR); $separator->instantiateTemplate($this->separatorTemplate); $separator->setID(self::ID_SEPARATOR . "{$count}"); $this->addChild($separator); $this->addBody($separator); $p = new TRepeaterItemEventParameter(); $p->item = $separator; $this->onItemCreated($p); } $item = null; if ($count % 2 == 1 && strlen($this->alternatingItemTemplate)) { $item = pradoGetApplication()->createComponent('TRepeaterItem'); $item->instantiateTemplate($this->alternatingItemTemplate); } else { if (strlen($this->itemTemplate)) { $item = pradoGetApplication()->createComponent('TRepeaterItem'); $item->instantiateTemplate($this->itemTemplate); } } if (!is_null($item)) { $item->setID(self::ID_ITEM . "{$count}"); $item->setIndex($key); $item->setItemIndex($count); $item->setData($value); $this->addChild($item); $this->addBody($item); $this->items[$this->itemCount] = $item; $this->itemCount++; $p = new TRepeaterItemEventParameter(); $p->item = $item; $this->onItemCreated($p); } $count++; } if (strlen($this->footerTemplate) && !$showEmpty) { $footer = pradoGetApplication()->createComponent('TRepeaterItem', self::ID_FOOTER); $footer->setType(TRepeaterItem::TYPE_FOOTER); $footer->instantiateTemplate($this->footerTemplate); $this->footer = $footer; $this->addChild($footer); $this->addBody($footer); $p = new TRepeaterItemEventParameter(); $p->item = $footer; $this->onItemCreated($p); } }