root/taggingreloaded/optionals/de.easy-coding.wbb.taggingreloaded/files/lib/system/event/listener/TaggingReloadedWBBMessageFormListener.class.php @ 89

Revision 89, 3.4 kB (checked in by d0nut, 6 years ago)

is this the optimization to avoid postID=0 taggers?

Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/system/event/EventListener.class.php');
4
5// wbb imports
6require_once(WBB_DIR.'lib/form/PostEditForm.class.php');
7
8/**
9 * Displays the tab for tagging
10 *
11 * @author      Torben Brodt
12 * @package     de.easy-coding.wbb.taggingreloaded
13 * @license     GNU General Public License <http://opensource.org/licenses/gpl-3.0.html>
14 */
15class TaggingReloadedWBBMessageFormListener implements EventListener {
16        protected $tags = array();
17
18        protected $eventObj;
19        protected $className;
20
21        /**
22         * @see EventListener::execute()
23         */
24        public function execute($eventObj, $className, $eventName) {
25                $this->eventObj = $eventObj;
26                $this->className = $className;
27
28                switch ($eventName) {
29                        case 'readData':
30                                $this->readData();
31                                break;
32                        case 'readFormParameters':
33                                $this->readFormParameters();
34                                break;
35                        case 'assignVariables':
36                                $this->assignVariables();
37                                break;
38                        case 'saved':
39                                $this->saved();
40                                break;
41                }
42        }
43       
44        /**
45         * @see Page::readData()
46         */
47        protected function readData () {
48                if($this->eventObj instanceof PostEditForm) {
49                        $sql = "SELECT          tag,
50                                                weight
51                                FROM            wcf".WCF_N."_taggingreloaded
52                                NATURAL JOIN    wbb".WBB_N."_taggingreloaded
53                                NATURAL JOIN    wbb".WBB_N."_post p
54                                WHERE           p.postID = {$this->eventObj->postID};";
55                        $result = WCF::getDB()->sendQuery($sql);
56                        while ($row = WCF::getDB()->fetchArray($result)) {
57                                $this->tags[$row['tag']] = $row['weight'];
58                        }
59                }
60        }
61       
62
63        /**
64         * @see Form::readFormParameters()
65         */
66        protected function readFormParameters () {
67                if (isset($_REQUEST['taggingname']) && isset($_REQUEST['taggingval'])) {
68                        $this->tags = array_combine($_REQUEST['taggingname'], $_REQUEST['taggingval']);
69                }
70
71                // forgotten to press the add button?
72                if (isset($_REQUEST['inputTagging']) && !empty($_REQUEST['inputTagging'])) {
73                        foreach(explode(' ', $_REQUEST['inputTagging']) as $tag) {
74                                if(!array_key_exists($tag, $this->tags)) {
75                                        $this->tags[$tag] = 100;
76                                }
77                        }
78                }
79        }
80       
81        /**
82         * @see Form::assignVariables()
83         */
84        protected function assignVariables () {
85                $tags = '<script type="text/javascript">//<![CDATA['."\n";
86                foreach($this->tags as $tag => $weight) {
87                        $tags .= "tagging.add('{$tag}',{$weight});";
88                }
89                $tags .= "\n//]]></script>";
90                WCF::getTPL()->append('additionalSubTabs', $tags);
91        }
92
93        /**
94         * @see Form::saved()
95         */
96        protected function saved () {
97                $postID = 0;
98                $i = 0;
99               
100                switch ($this->className) {
101                        case 'ThreadAddForm':
102                                $postID = $this->eventObj->newThread->firstPostID;
103                                break;
104                        case 'PostAddForm':
105                        case 'PostEditForm':
106                                $postID = $this->eventObj->postID;
107                                break;
108                }
109               
110                // CLEANUP own tags and system tags (user -1)
111                $sql = "DELETE FROM     wbb".WBB_N."_taggingreloaded,
112                                        wcf".WCF_N."_taggingreloaded
113                        USING           wbb".WBB_N."_taggingreloaded
114                        LEFT JOIN       wcf".WCF_N."_taggingreloaded
115                        ON              wbb".WBB_N."_taggingreloaded.taggingID = wcf".WCF_N."_taggingreloaded.taggingID
116                        WHERE           userID IN (".WCF::getUser()->userID.",-1)
117                        AND             postID = {$postID};";
118
119                WBBCore::getDB()->sendQuery($sql);
120               
121                // save own tags
122                if(count($this->tags) > 0) {
123                        // INSERT tagging<->post
124                        $sql = "INSERT INTO     wbb".WBB_N."_taggingreloaded
125                                                (postID)
126                                VALUES          ({$postID});";
127
128                        WBBCore::getDB()->sendQuery($sql);
129                        $taggingID = WBBCore::getDB()->getInsertID();
130
131                        TaggingReloadedUtil::tags2db($taggingID, $this->tags);
132                }
133        }
134}
135?>
Note: See TracBrowser for help on using the browser.