* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBAjax'); /** * Simple AJAX stub: Newsletter * * Subscribe to Newsletter * * @version 0.1.2 * @package WB * @subpackage base */ class WBAjax_Newsletter extends WBAjax { /** * @var WBDatasource_Newsletter_Subscriber */ private $sub; /** * second construcotr * * Called by constructer of super class. * * @see include/WB/WBAjax#init() */ protected function init() { $this->sub = WBClass::create('WBDatasource_Newsletter_Subscriber'); if ($this->user->isAuthenticated()) { $this->sub->setUser($this->user); $this->sub->loadByUser($this->user->getId()); } } /** * Subscribe to Newsletter * * @return string comment list HTML */ protected function register() { $data = array(); $data['email'] = $this->req->get('email', ''); $data['lang'] = $this->req->get('lang', ''); if (empty($data['lang'])) { $data['lang'] = patI18n::getLocale(patI18n::LOCALE_TYPE_LANG); } $mId = $this->req->get('mandator', 0); if(!$this->sub->add($data, $mId)) { $this->loadTemplates('Register/ajax/failed'); return $this->tmpl->getParsedTemplate('snippet'); } $this->sub->add4Mandator($mId); $this->sub->setAllTopic($mId); $this->tmpl->addGlobalVars($this->sub->get(), 'SUB_'); $this->loadTemplates('Register/ajax/subscribed'); return $this->tmpl->getParsedTemplate('snippet'); } /** * Add Subscriber 4 Mandator * * @return string comment list HTML */ protected function add4Mandator() { $mId = $this->req->get('mandatorid', 0); $this->sub->add4Mandator($mId); $this->tmpl->addGlobalVars($this->sub->get(), 'SUB_'); $this->loadTemplates('Register/ajax/subscribed'); return $this->tmpl->getParsedTemplate('snippet'); } }