*/ /** * patTemplate modfifier Newsletterissue * * @version 0.1.0 */ class patTemplate_Modifier_Newsletterissue extends patTemplate_Modifier { /** * @var WBDatasource_Newsletter_Issue */ static $issue; /** * @var WBDatasource_Newsletter_Receiver */ static $rcpt; /** * Get Issue instance * * @return WBDatasource_Newsletter_Issue */ private function getIssue($id) { if (empty(self::$issue)) { self::$issue = WBClass::create('WBDatasource_Newsletter_Issue'); } self::$issue->load($id); return self::$issue; } /** * Get Rcpts * * @return WBDatasource_Newsletter_Receiver */ private function getRcpt() { if (empty(self::$rcpt)) { self::$rcpt = WBClass::create('WBDatasource_Newsletter_Receiver'); self::$rcpt->useLang(true); } return self::$rcpt; } /** * Modify Value * * @param string value * @param array attributes * @return string modified value */ public function modify($value, $params = array()) { if (empty($value)) { return 0; } $defParams = array( 'count' => '', 'display' => '', ); $params = array_merge($defParams, $params); $iss = $this->getIssue($value); $sent = $iss->getSentDate(); $top = $iss->getTopic(); switch ($params['count']) { case 'topic': return count($top); break; case 'rcpt': // potential recipients if (empty($sent)) { $rcpt = $this->getRcpt(); $rcpt->setIssue($iss); $rcpt->setLang($iss->getLang()); $rcpt->useTopic($top); return $rcpt->count(); } // actual recipients return $iss->countRcpt(); break; default: break; } switch ($params['display']) { case 'topic': $tmp = array(); foreach ($top as $t) { $tmp[] = strip_tags($t['title']); } return implode(', ', $tmp); break; default: break; } return 0; } }