'-1', 'id' => '', 'action' => 'list', 'titleformatdisplay' => '%s - %s - Newsletter', 'titleformatlist' => '%s - Newsletter', ); /** * Newsletter Issue * @var WBDatasource_Newsletter_Issue */ private $issue; /** * Mandator * @var WBMandator */ private $mandator; /** * 2nd constructor * * Mend config for parent class * Additional parameter: * - trackingpixelpath */ protected function init() { $this->mandator = WBClass::create('WBMandator'); /* $parameter = array( 'mandator' => $this->mandator ); */ $this->issue = WBClass::create('WBDatasource_Newsletter_Issue'); // call parent's init return parent::init(); } /** * Run Component * * @return array */ public function run() { if (WBMandator::INVALID_ID == $this->config['mandator']) { $this->listMandators(); $this->addConfigAsGlobalVars(); return $this->config; } $this->mandator->setId($this->config['mandator']); if (!$this->mandator->isValid()) { $this->loadTemplates('notfound'); $this->setStatusCode(404); $this->addConfigAsGlobalVars(); return $this->config; } switch (strtolower($this->config['action'])) { case 'display': $this->runDisplay(); break; default: $this->runList(); break; } $this->addConfigAsGlobalVars(); return $this->config; } private function listMandators() { $this->loadTemplates('mandator'); $list = $this->getMandatorList(); $this->list2Template($list); } private function getMandatorList() { $table = WBClass::create('WBDatasource_Table'); $clause = array(); $clause[] = array( 'field' => 'enabled', 'value' => 1 ); $clause[] = array( 'field' => 'newsletter', 'value' => 1 ); $list = $table->get(WBDatasource::TABLE_MANDATOR, null, null, $clause); foreach ($list as &$l) { $man = $this->issue->getMandatorData($l['id']); $l = array_merge($l, $man); } return $list; } /** * Display Newsletter * */ private function runDisplay() { if (empty($this->config['id'])) { return $this->runList(); } $id = sprintf('%s-%s', $this->mandator->getId(), $this->config['id']); $this->issue->load($id); if (!$this->issue->isOk()) { $this->loadTemplates('notfound'); $this->setStatusCode(404); return; } $man = $this->issue->getMandatorData($this->mandator->getId()); $this->tmpl->addGlobalVars($man, 'MANDATOR_'); $iss = $this->issue->get($iss['title']); $this->bubbles['title'] = sprintf($this->config['titleformatdisplay'], $iss['title'], $man['customer']); $this->loadTemplates('display'); $this->tmpl->addGlobalVars($iss, 'ISSUE_'); $list = $this->issue->getArticle(); $this->list2Template($list); } /** * Display List of Newsletter * */ private function runList() { $man = $this->issue->getMandatorData($this->mandator->getId()); $this->tmpl->addGlobalVars($man, 'MANDATOR_'); $this->bubbles['title'] = sprintf($this->config['titleformatlist'], $man['customer']); $this->loadTemplates('list'); $list = $this->issue->getList($this->mandator->getId()); $this->list2Template($list); } }