*/ /** * patTemplate-function: Newsletter * * Allow to subcribe newsletter * * @version 0.1.1 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Newsletter extends patTemplate_Function { /** * Name of the function * @var string */ public $_name = 'Newsletter'; /** * Tell that this function has to be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * Template Engine * @var patTemplate */ private $tmpl; /** * Subscriber * @var WBDatasource_Newsletter_Subscriber */ private $sub; /** * Mandator * @var WBMandator */ private $mandator; /** * Call the function * * Simply show newsletter registration form, depending on current user * * @param array $params parameters of the function (= attributes of the tag) * @param string $content inside tag * @return string content to insert into the template */ public function call($params, $content) { $this->tmpl = WBClass::create('patTemplate'); $paramsDef = array( 'tmpl' => 'default', 'class' => '', 'mandator' => '-1' ); $params = array_merge($paramsDef, $params); $this->tmpl->addGlobalVars($params); $this->mandator = WBClass::create('WBMandator'); if(!$this->hasMandatorNewsletter($params['mandator'])) { return $content; } $this->tmpl->addGlobalVar('mandator', $this->mandator->getId()); $this->tmpl->addGlobalVars($this->mandator->get(), 'mandator_'); $this->sub = WBClass::create('WBDatasource_Newsletter_Subscriber'); $user = WBUser::getCurrent(); $sub = false; if ($user->isAuthenticated()) { $this->sub->setUser($user); $this->tmpl->addGlobalVars($user->getData(), 'user_current_'); $sub = $this->sub->loadByUser(); } $suf = 'New'; if (!empty($sub)) { $this->tmpl->addGlobalVars($this->sub->get(), 'sub_'); $suf = 'Subriber'; if (!$this->sub->hasMandator($params['mandator'])) { $suf = 'Mandator'; } } $this->tmpl->readTemplatesFromInput('Newsletter/Register/' . $params['tmpl'] . $suf. '.tmpl'); return $this->tmpl->getParsedTemplate('snippet'); } /** * Check If Mandator Has Newsletter * * @param string mandatorid * @return bool */ private function hasMandatorNewsletter($manId) { if ('-1' == $manId) { return false; } $this->mandator->setId($manId); if ($this->mandator->hasNewsletter()) { return true; } return false; } }