*/ /** * patTemplate-function to display banner items * * * @version 0.3.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Banner extends patTemplate_Function { const TABLE_BANNER = 'banner'; const TABLE_TEASER = 'teaser'; /** * Name of the Function * @var string */ public $_name = 'Banner'; /** * Tell that this function has to be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * Template Engine * @var patTemplate */ private $tmpl; /** * Table Datasource * @var WBDatasource_Table */ private $table; /** * Call the function * * @access public * @param array $params parameters of the function (= attributes of the tag) * @param string $content inside tag * @return string content to insert into the template */ public function call($params, $content) { $table = self::TABLE_TEASER; if ('Teaser' != $this->_name) { $table = self::TABLE_BANNER; } $paramsDef = array( 'tmpl' => 'default', 'class' => '', 'namespace' => '', 'id' => '', 'limit' => -1, 'offset' => -1 ); $params = array_merge($paramsDef, $params); if (empty($params['id'])) { $params['id'] = sprintf('wb-%s-%s', strtolower($this->_name), substr(md5(rand()), -8)); } $this->tmpl = WBClass::create('patTemplate'); $this->tmpl->addGlobalVars($params, 'param_'); $this->tmpl->readTemplatesFromInput(sprintf('%s/%s.tmpl', $this->_name, $params['tmpl'])); $this->table = WBClass::create('WBDatasource_Table'); $option = array(); if (0 < $params['limit']) { $option['limit'] = $params['limit']; } if (0 < $params['offset']) { $option['offset'] = $params['offset']; } $clause = array(); $clause[] = array( 'field' => 'enabled', 'value' => 1 ); if (!empty($params['namespace'])) { $clause[] = array( 'field' => 'namespace', 'value' => $params['namespace'] ); } $list = $this->table->get($table, null, null, $clause, $option); $this->tmpl->addGlobalVar('list_count', count($list)); if ($this->tmpl->exists('list_entry')) { $this->tmpl->addRows('list_entry', $list); $max = WBParam::get('wb/template/listtemplatemax', 10); for ($i = 1; $i < $max; ++$i) { if (!$this->tmpl->exists('list_entry_' . $i)) { break; } $this->tmpl->addRows('list_entry_' . $i, $list); } } return $this->tmpl->getParsedTemplate('snippet'); } }