* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_Renderer'); /** * Datasource renderer CSV * * @version 1.0.1 * @package WB * @subpackage db */ class WBDatasource_Renderer_HTML extends WBDatasource_Renderer { /** * Configuration parameters */ protected $config = array( 'tmpl' => '' ); /** * template engine * @var patTemplate */ protected $tmpl; /** * simple meta data * @var array */ protected $meta = array( 'count' => 0, 'datasource' => '' ); /** * Buffer List for all Items * @var array */ protected $list = array(); /** * Start Rendering * * Start and configure template engine. Read templates from input. * Add date of current user (USER_CURRENT_*) and Configuration as * global config vars (CONFIG_*) * * @param string $ds datasource name */ public function start($ds) { $this->list = array(); $this->meta['datasource'] = $ds; $this->meta['count'] = 0; $this->meta['list_entry_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_'); } $tmpl = $ds; if (!empty($this->config['tmpl'])) { $tmpl = $this->config['tmpl']; } // load template $this->tmpl->readTemplatesFromInput(sprintf('Datasource/%s.tmpl', $tmpl)); // add config as global vars $this->tmpl->addGlobalVars($this->config, 'config_'); $this->tmpl->addGlobalVars($this->vars, 'att_'); } /** * Render Single Item * * Well simply collect rows in member variable * @see $list * @param array $item */ public function renderItem($item) { $this->list[] = $item; } /** * End of Iteration * * Add rows to template engine. * * Count number of rows, add rows to default template "list_entry". * In case there are additional templates named "list_entry_*", add rows to them as well. * Finally flush current list of rows. */ public function end() { $this->meta['list_entry_count'] = count($this->list); $this->meta['count'] = $this->meta['list_entry_count']; $this->tmpl->addRows('list_entry', $this->list); $this->tmpl->addGlobalVars($this->meta); $tmpl = $this->tmpl->getList(); $prefix = 'list_entry_'; foreach ($tmpl as $t) { if (0 == strncmp($prefix, $t, strlen($prefix))) { $this->tmpl->addRows($t, $this->list); } } $this->list = array(); } /** * Get Actual HTML * * Get parsed template * @return string */ public function getHtml() { return $this->tmpl->getParsedTemplate('snippet'); } }