*/ class TaggingReloadedWBBMessageFormListener implements EventListener { protected $tags = array(); protected $eventObj; protected $className; /** * @see EventListener::execute() */ public function execute($eventObj, $className, $eventName) { $this->eventObj = $eventObj; $this->className = $className; switch ($eventName) { case 'readData': $this->readData(); break; case 'readFormParameters': $this->readFormParameters(); break; case 'assignVariables': $this->assignVariables(); break; case 'saved': $this->saved(); break; } } /** * @see Page::readData() */ protected function readData () { if($this->eventObj instanceof PostEditForm) { $sql = "SELECT tag, weight FROM wcf".WCF_N."_taggingreloaded NATURAL JOIN wbb".WBB_N."_taggingreloaded NATURAL JOIN wbb".WBB_N."_post p WHERE p.postID = {$this->eventObj->postID};"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $this->tags[$row['tag']] = $row['weight']; } } } /** * @see Form::readFormParameters() */ protected function readFormParameters () { if (isset($_REQUEST['taggingname']) && isset($_REQUEST['taggingval'])) { $this->tags = array_combine($_REQUEST['taggingname'], $_REQUEST['taggingval']); } // forgotten to press the add button? if (isset($_REQUEST['inputTagging']) && !empty($_REQUEST['inputTagging'])) { foreach(explode(' ', $_REQUEST['inputTagging']) as $tag) { if(!array_key_exists($tag, $this->tags)) { $this->tags[$tag] = 100; } } } } /** * @see Form::assignVariables() */ protected function assignVariables () { $tags = '"; WCF::getTPL()->append('additionalSubTabs', $tags); } /** * @see Form::saved() */ protected function saved () { $postID = 0; $i = 0; switch ($this->className) { case 'ThreadAddForm': $postID = $this->eventObj->newThread->firstPostID; break; case 'PostAddForm': case 'PostEditForm': $postID = $this->eventObj->postID; break; } // CLEANUP own tags and system tags (user -1) $sql = "DELETE FROM wbb".WBB_N."_taggingreloaded, wcf".WCF_N."_taggingreloaded USING wbb".WBB_N."_taggingreloaded LEFT JOIN wcf".WCF_N."_taggingreloaded ON wbb".WBB_N."_taggingreloaded.taggingID = wcf".WCF_N."_taggingreloaded.taggingID WHERE userID IN (".WCF::getUser()->userID.",-1) AND postID = {$postID};"; WBBCore::getDB()->sendQuery($sql); // save own tags if(count($this->tags) > 0) { // INSERT tagging<->post $sql = "INSERT INTO wbb".WBB_N."_taggingreloaded (postID) VALUES ({$postID});"; WBBCore::getDB()->sendQuery($sql); $taggingID = WBBCore::getDB()->getInsertID(); TaggingReloadedUtil::tags2db($taggingID, $this->tags); } } } ?>