*/ /** * patTemplate function Drop Down Menu * * @todo use actual menu maker * @todo remove constant menu items * @version 0.3.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_DropDownMenu extends patTemplate_Function { /** * Function Type * @var integer */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * Configuration * @var array */ private $config = array( 'area' => 'user', 'type' => 0, 'tmpl' => 'default', 'text' => '{FORENAME}', 'tooltip' => 'Angemeldet als {FORENAME} {SURNAME}', 'icon' => 'user' ); /** * @var WBUser_Auth */ private $user; /** * @var patTemplate */ private $tmpl; /** * @var WBConfig */ private $conf; /** * constructor * */ public function __construct() { WBClass::load('WBUser_Auth'); $this->user = WBUser_Auth::getCurrent(); $this->tmpl = WBClass::create('patTemplate'); $this->conf = WBClass::create('WBConfig'); } /** * Call the Function * * @param array parameters of the function (= attributes of the tag) * @param string content of the tag * @return string content to insert into the template */ public function call($params, $content) { if (!$this->user->isAuthenticated()) { return ''; } if (!is_array($params)) { $params = array(); } if (empty($params['area'])) { $params['area'] = $this->config['area']; } if (!$this->conf->load('menumaker/dropdown/' . $params['area'], true)) { return ''; } // merge config with loaded config foreach (array('uri', 'text', 'tooltip', 'icon') as $k) { $v = $this->conf->get('dropdown/' . $k); if (!empty($v)) { $this->config[$k] = $v; } } $v = $this->conf->get('dropdown/template'); if (!empty($v)) { $this->config['tmpl'] = $v; } // override config with parameters $params = array_merge($this->config, $params); $user = $this->user->getData(); $item = $this->conf->get('dropdown/menu', array()); if (!is_array($item)) { $item = array(); } if (empty($item)) { return ''; } $list = array(); foreach ($item as $i) { if (!is_array($i['required'])) { $i['required'] = trim($i['required']); } if (!$this->user->isInGroup($i['required'])) { continue; } unset($i['required']); $i['text'] = WBString::populate($i['text'], $user); $i['tooltip'] = WBString::populate($i['tooltip'], $user); $list[] = $i; } if (empty($list)) { return ''; } $params['text'] = WBString::populate($params['text'], $user); $params['tooltip'] = WBString::populate($params['tooltip'], $user); $this->tmpl->clearAllTemplates(); $this->tmpl->addGlobalVars($params, 'ATT_'); $this->tmpl->readTemplatesFromInput('MenuMaker/DropDownMenu/' . $params['tmpl'] . '.tmpl'); $this->tmpl->addGlobalVar('list_count', count($list)); $this->tmpl->addRows('list_entry', $list); return $this->tmpl->getParsedTemplate('snippet'); } }