* @package Palas * @subpackage content */ /** * Load base class */ WBClass::load('WBContent' , 'patI18n'); /** * Content component: Contact Manager * * @version 0.2.0 * @package wombat * @subpackage content */ class WBContent_Contact_Manager extends WBContent implements WBDatasource_Callback { /** * my parameter list * @var array */ protected $config = array( 'requiredgroup' => 'staff', 'action' => 'list', 'goto' => '0' ); /** * @var WBDatasource_ContactRequest */ private $cr; /** * Mandator * @var WBMandator */ private $mandator; /** * List Of Namespace Info * * @var array */ private $info; /** * 2nd constructor * * Called after configuration was done */ protected function init() { parent::init(); $this->mandator = WBClass::create('WBMandator'); $parameter = array( 'mandator' => $this->mandator, // 'table' => $this->table ); $this->cr = WBClass::create('WBDatasource_ContactRequest', $parameter); $this->config['usefilter'] = 1; $this->config['searchfields'] = array('message', 'forename', 'surname', 'emaillocal', 'emaildomain', 'company'); $this->config['mandator'] = $this->mandator->getMasterId(); if (!$this->mandator->isEnabled()) { return; } // allow to "become" other mandator if ($this->mandator->isMaster()) { $this->tmpl->addGlobalVar('mandator_master', 1); // change mandator? $mId = $this->req->get('filter_' . $this->mandator->getIdentifier()); if (!empty($mId) && $this->mandator->getId() != $mId) { $this->mandator->setId($mId); } } $this->config['mandator'] = $this->mandator->getId(); $this->config['table'] = WBDatasource::TABLE_CONTACTREQUEST; /** @var WBFormProcessor_Fiddler_Mandator */ $fiddler = WBClass::create('WBFormProcessor_Fiddler_Mandator', $parameter); $this->addFiddler($fiddler); $this->addFilterFiddler($fiddler); } /** * Location of Form Config * * Return directory where form definition is found * * @return string folder */ protected function getFormConfigDir() { return 'contact/manager'; } /** * run * * run component * * @return array parameter list */ public function run() { $this->addConfigAsGlobalVars(); // $this->mandator->setId(1005); if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->loadTemplates('anon'); return $this->config; } $this->initFilter(); switch ($this->config['action']) { case 'spam': $this->cr->load($this->req->get('id', '')); $this->cr->markAsSpam(); break; case 'read': $this->cr->load($this->req->get('id', '')); $this->cr->markAsRead(); break; case 'do': $this->cr->load($this->req->get('id', '')); $this->cr->markAsDone(); break; case 'list': default: break; } $this->loadTemplates('list'); $clause = $this->filter->getClause(); $opt = $this->filter->getOptions(); $opt['callback'] = $this; $pager = $this->cr->getPager($clause, $opt); $this->tmpl->addGlobalVars($pager->browse($this->config['goto']), 'pager_'); $this->tmpl->addRows('list_entry', $pager->get()); return $this->config; } /** * callback when receive whole entry * * @param string $src name of source * @param string $key * @param array $data loaded data * @return bool true on success */ public function onDatasourceGet($src, $key, &$data) { $ns = $data['namespace']; if (empty($ns)) { return true; } if (empty($this->info[$ns])) { if (WBClass::load('WBDatasource_ContactRequest_Info_' . ucfirst($ns))) { $this->info[$ns] = WBClass::create('WBDatasource_ContactRequest_Info_' . ucfirst($ns)); } else { $this->info[$ns] = WBClass::create('WBDatasource_ContactRequest_Info'); } } $this->info[$ns]->setData($data); $info = $this->info[$ns]->getInfo(); foreach ($info as $k => $v) { $data['info_' . $k] = $v; } return true; } }