* @package WB * @subpackage Event */ WBClass::load('WBEvent_Handler' , 'WBString'); /** * WBEvent_Handler_Comment * * Add comment to record * * @version 0.1.0 * @package Wombat * @subpackage Event */ class WBEvent_Handler_Comment extends WBEvent_Handler { /** * Mode: Plain * * Set plain comment */ const MODE_PLAN = 'plain'; /** * Mode: Template * * In template mode, load template directly and create HTML comment by adding global vars * and parsing the template. After that, the database holds the finalized comment including markup. * @see WBEvent_Handler_ITS_Comment::MODE_XML * @deprecated in favour of plain */ const MODE_TEMPLATE = 'template'; /** * Mode: XML * * In XML mode, the comment will be created as XML tag: This tag contains all the * event's data as well as the name of the template to render actual output. HTML output will be created * by WBMarkup_Converter_Wb_Comment whenever needed. This approach allows to display translated comment * messages, or even mend the layout afterwards. * @see WBEvent_Handler_ITS_Comment::MODE_HTML */ const MODE_XML = 'xml'; /** * Handler Config * * Parameters: * - "user" user id or "auto" to load from event data 'uid' * - "namespace" comment namespace * - "approve" approve comment on the fly * - "mode" either template or xml * - "tmpl" named template to load * * @var array */ protected $config = array( 'text' => 'Comment', 'tmpl' => 'created', 'user' => 'auto', 'defaultuser' => '1', 'namespace' => 'user', 'approve' => 1, 'mode' => self::MODE_PLAN ); /** * Comment * @var WBDatasource_Comment */ private $cmt; /** * Write comment * * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { // load user id from event's data if ('auto' == $this->config['user']) { $this->config['user'] = $e->get('uid'); if (empty($this->config['user'])) { $this->config['user'] = $this->config['defaultuser']; } } // $this->mandator->setId($e->get($this->mandator->getIdentifier())); $parameter = array( 'user' => $this->config['user'], 'mandator' => $this->mandator ); $this->cmt = WBClass::create('WBDatasource_Comment', $parameter); $this->cmt->useEventTrigger(false); $this->cmt->setNamespace($this->config['namespace']); $this->cmt->setXId($e->get('id')); $approve = intval($this->config['approve']); if (1 > $approve) { $approve = false; } else { $approve = true; } $comment = $this->mkComment($e->get()); $this->cmt->add($comment, $approve); return true; } private function mkComment($data) { $comment = $this->config['text']; $comment = WBString::populate($comment, $data); return $comment; } }