*/ /** * patTemplate-function to display banner items * * * @version 0.2.1 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Banner extends patTemplate_Function { const TABLE_BANNER = 'banner'; /** * name of the function * @access private * @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) { $paramsDef = array( 'tmpl' => 'default', 'class' => '', 'namespace' => '', 'id' => '' ); $params = array_merge($paramsDef, $params); if (empty($params['id'])) { $params['id'] = 'wb-banner-' . substr(md5(rand()), -8); } $this->tmpl = WBClass::create('patTemplate'); $this->tmpl->addGlobalVars($params, 'param_'); $this->tmpl->readTemplatesFromInput(sprintf('Banner/%s.tmpl', $params['tmpl'])); $this->table = WBClass::create('WBDatasource_Table'); $clause = array(); $clause[] = array( 'field' => 'enabled', 'value' => 1 ); if (!empty($params['namespace'])) { $clause[] = array( 'field' => 'namespace', 'value' => $params['namespace'] ); } $list = $this->table->get(self::TABLE_BANNER, null, null, $clause); $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'); } }