Commit | Line | Data |
---|---|---|
04c06e85 MW |
1 | <?php |
2 | namespace wcf\data\tag; | |
3 | use wcf\data\DatabaseObjectEditor; | |
4 | use wcf\system\WCF; | |
5 | ||
6 | /** | |
7 | * Provides functions to edit tags. | |
8 | * | |
9 | * @author Tim Duesterhus, Marcel Werk | |
2b6cb5c2 | 10 | * @copyright 2001-2015 WoltLab GmbH |
04c06e85 | 11 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
f4f05aa5 | 12 | * @package com.woltlab.wcf |
04c06e85 MW |
13 | * @subpackage data.tag |
14 | * @category Community Framework | |
15 | */ | |
16 | class TagEditor extends DatabaseObjectEditor { | |
17 | /** | |
0ad90fc3 | 18 | * @see \wcf\data\DatabaseObjectEditor::$baseClass |
04c06e85 MW |
19 | */ |
20 | protected static $baseClass = 'wcf\data\tag\Tag'; | |
21 | ||
22 | /** | |
23 | * Adds the given tag, and all of it's synonyms as a synonym. | |
24 | * | |
0ad90fc3 | 25 | * @param \wcf\data\tag\Tag $synonym |
04c06e85 MW |
26 | */ |
27 | public function addSynonym(Tag $synonym) { | |
6f3395ad | 28 | if ($synonym->tagID == $this->tagID) return; |
ea3185a0 | 29 | |
a026765c AE |
30 | // assign all associations for the synonym with this tag |
31 | $sql = "UPDATE IGNORE wcf".WCF_N."_tag_to_object | |
32 | SET tagID = ? | |
33 | WHERE tagID = ?"; | |
04c06e85 | 34 | $statement = WCF::getDB()->prepareStatement($sql); |
a026765c | 35 | $statement->execute(array($this->tagID, $synonym->tagID)); |
04c06e85 | 36 | |
a026765c | 37 | // remove remaining associations (object was tagged with both tags => duplicate key previously ignored) |
04c06e85 MW |
38 | $sql = "DELETE FROM wcf".WCF_N."_tag_to_object |
39 | WHERE tagID = ?"; | |
40 | $statement = WCF::getDB()->prepareStatement($sql); | |
a026765c | 41 | $statement->execute(array($synonym->tagID)); |
04c06e85 MW |
42 | |
43 | $editor = new TagEditor($synonym); | |
44 | $editor->update(array( | |
45 | 'synonymFor' => $this->tagID | |
46 | )); | |
47 | ||
48 | $synonymList = new TagList(); | |
49 | $synonymList->getConditionBuilder()->add('synonymFor = ?', array($synonym->tagID)); | |
50 | $synonymList->readObjects(); | |
51 | ||
52 | foreach ($synonymList as $synonym) { | |
53 | $this->addSynonym($synonym); | |
54 | } | |
55 | } | |
56 | } |