* @package Newsletter */ /** * Load base class */ WBClass::load('WBContent' , 'WBContent_Newsletter'); /** * Content component: Newsletter Register * * @version 0.1.2 * @package Newsletter */ class WBContent_Newsletter_Register extends WBContent_Newsletter { /** * default config of this component * @var array */ protected $config = array( 'tmpl' => 'default', 'class' => '', 'mandator' => '-1', 'action' => 'register' ); /** * @var WBDatasource_Newsletter_Subscriber */ private $sub; /** * Current Mandator * @var WBMandator */ protected $mandator; /** * Run component * * @return array config */ public function run() { // action is "register", always if ('register' != $this->config['action']) { $this->loadTemplates('invalid'); return $this->config; } $this->mandator = WBClass::create('WBMandator'); $this->mandator->setId($this->config['mandator']); $this->tmpl->addGlobalVar('mandator', $this->mandator->getId()); $this->tmpl->addGlobalVars($this->mandator->get(), 'mandator_'); if (!$this->mandator->hasNewsletter()) { $this->loadTemplates('noNewsletter'); return $this->config; } $sub = false; $this->sub = WBClass::create('WBDatasource_Newsletter_Subscriber'); if ($this->user->isAuthenticated()) { $this->sub->setUser($this->user); $this->tmpl->addGlobalVars($this->user->getData(), 'user_current_'); $sub = $this->sub->loadByUser(); } $data = $this->req->export(); $topic = $this->req->get('topicid', ''); if (empty($topic)) { $topic = array(); } if (!is_array($topic)) { $topic = array_map('trim', explode(',', trim($topic))); if (empty($topic[0])) { $topic = array(); } } $this->tmpl->addGlobalVar('topicid', implode(',', $topic)); $data['topicid'] = $topic; $save = $this->req->get('save', ''); if (empty($save)) { $suf = 'New'; if (!empty($sub)) { $this->tmpl->addGlobalVars($this->sub->get(), 'sub_'); $suf = 'Subriber'; if (!$this->sub->hasMandator($this->mandator->getId())) { $suf = 'Mandator'; } } $this->loadTemplates($this->config['tmpl'] . $suf); return $this->config; } // register if($this->sub->add2Mandator($this->mandator->getId(), $data)) { $this->loadTemplates($this->config['tmpl'] . 'Registered'); $this->tmpl->addGlobalVars($this->sub->get()); return $this->config; } // if registered failed but subscriber exists if ($this->sub->isOK()) { $this->loadTemplates($this->config['tmpl'] . 'Registered'); $this->tmpl->addGlobalVars($this->sub->get()); return $this->config; } // it went completely wrong $this->loadTemplates($this->config['tmpl'] . 'RegisterFailed'); return $this->config; } }