* @package WB */ /** * Load base class */ WBClass::load( 'WBContent' ); /** * Content component: FAQ * * @version 0.1.2 * @package WB */ class WBContent_FAQ extends WBContent { /** * FAQ parameter list * @var array */ protected $config = array( 'id' => '', 'goto' => '0', 'limit' => 20, ); /** * @var WBFormProcessor_Filter */ protected $filter; /** * pager information * @var array */ protected $pagerInfo = array(); /** * 2nd constructor * * Called after configuration was done */ protected function init() { $this->table = WBClass::create('WBDatasource_Table'); } /** * run * * run component * * @return array parameter list */ public function run() { $this->config['searchfields'] = array('question', 'answer'); $this->initFilter(); $this->addConfigAsGlobalVars(); $this->bubbles['title'] = $this->config['title']; if ($this->displayArticleById($this->config['id'])) { return $this->config; } $this->displayList(); return $this->config; } /** * displayArticle * * displays single FAQ article * * @param int faqid * @return bool */ private function displayArticleById($id) { if (empty($id)) { return false; } $options = array(); $clause = array(); $clause[] = array( 'field' => 'enabled', 'value' => 1 ); $faq = $this->table->get('faq', $id, null, $clause); if (1 != count($faq)) { return false; } $faq = $faq[0]; $this->loadTemplates('article'); $this->tmpl->addGlobalVars($faq); $this->bubbles['title'] = $faq['question'] . ' - ' . $this->bubbles['title']; return true; } /** * Initialize Filter, if configured * */ protected function initFilter() { $this->filter = WBClass::create('WBFormProcessor_Filter'); $this->filter->setRequest($this->req); $this->filter->setTemplate($this->tmpl, $this->config['tmplDir']); $this->filter->buildClause($this->config['searchfields']); } /** * displayList * * displays list of FAQ entrys with pagination * * @return array parameter list */ private function displayList() { $options = array( 'limit' => $this->config['limit'], ); $clause = array(); $clause = $this->filter->getClause(); $clause[] = array( 'field' => 'enabled', 'value' => 1 ); $pager = $this->table->getPager($this->part . __CLASS__, 'faq', null, $clause, $options); $this->pagerInfo = $pager->browse($this->config['goto']); $faq = $pager->get(); $this->loadTemplates('list'); $this->tmpl->addRows('list_entry', $faq); $this->tmpl->addGlobalVar('page_entry_count', count($faq)); $this->tmpl->addGlobalVars($this->pagerInfo, 'pager_'); $total = $this->table->count('faq', null, null, $clause, $options); $this->tmpl->addGlobalVar('total_count', $total); } }