* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_Renderer'); /** * Datasource renderer CSV * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_Renderer_HTML extends WBDatasource_Renderer { /** * template engine * @var patTemplate */ protected $tmpl; /** * simple meta data * @var array */ protected $meta = array( 'count' => 0, 'datasource' => '' ); protected $list = array(); /** * start rendering * * @param string $ds datasource name */ public function start($ds) { $this->list = array(); $this->meta['datasource'] = $ds; $this->meta['count'] = 0; $this->tmpl = WBClass::create('patTemplate'); // allow to transport placeholder to surrounding templates $this->tmpl->setDefaultAttribute('unusedvars', 'ignore'); // add user data WBClass::load('WBUser'); $user = WBUser::getCurrent(); if ($user->isAuthenticated()) { $this->tmpl->addGlobalVars($user->getData(), 'user_current_'); } // load template $this->tmpl->readTemplatesFromInput(sprintf('Datasource/%s.tmpl', $ds)); } /** * render single item * * The consumer for data source iteratrion * @param array $item */ public function renderItem($item) { $this->list[] = $item; } /** * end of iteration * */ public function end() { $this->meta['count'] = count($this->list); $this->tmpl->addRows('list_entry', $this->list); $this->tmpl->addGlobalVars($this->meta); $this->list = array(); } /** * get actual html * * @return WBFile */ public function getHtml() { return $this->tmpl->getParsedTemplate('snippet'); } } ?>