*/ /** * patTemplate-function to display banner items * * * @version 0.2.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Mandatorlist extends patTemplate_Function { /** * name of the function * @access private * @var string */ public $_name = 'Mandatorlist'; /** * tell that this function has to be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * template engine * @var patTemplate */ private $tmpl; /** * Mandator * @var WBMandator */ protected $mandator; /** * Request * @var WBRequest */ private $req; /** * 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) { $this->mandator = WBClass::create('WBMandator'); if (!$this->mandator->isMaster()) { return ''; } $paramsDef = array( 'tmpl' => 'default', 'class' => '' ); $params = array_merge($paramsDef, $params); $this->tmpl = WBClass::create('patTemplate'); $this->tmpl->addGlobalVars($params, 'param_'); $this->tmpl->readTemplatesFromInput(sprintf('Mandator/list/%s.tmpl', $params['tmpl'])); $this->req = WBClass::create('WBRequest'); $list = $this->req->export(); $filter = array(); $input = array(); $select = 0; $get = array(); foreach ($list as $key => $value) { if (0 != strncmp('filter_', $key, 7)) { continue; } if ('filter_' . $this->mandator->getIdentifier() == $key) { $select = $value; continue; } if (is_array($value)) { foreach ($value as $v) { $get[] = sprintf('%s[]=%s', $key, urlencode($v)); $input[] = sprintf('', $key, addslashes($v)); } } else { $get[] = sprintf('%s=%s', $key, urlencode($value)); $input[] = sprintf('', $key, addslashes($value)); } } $this->tmpl->addGlobalVar('search_filter_url', implode('&', $get)); $this->tmpl->addGlobalVar('search_filter_input_hidden', implode(' ', $input)); $this->tmpl->addGlobalVar('searchquery_url', urlencode($this->req->get('searchquery'))); $this->tmpl->addGlobalVar('searchquery', $this->req->get('searchquery')); $list = $this->mandator->getVisible(false); array_unshift($list, $this->mandator->getMaster()); foreach ($list as &$l) { if ($l['id'] == $select) { $l['class'] = 'active'; $l['selected'] = 'selected="selected"'; } } $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'); } }