2 namespace wcf\data\tag
;
3 use wcf\data\DatabaseObjectEditor
;
7 * Provides functions to edit tags.
9 * @author Tim Duesterhus, Marcel Werk
10 * @copyright 2001-2015 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package com.woltlab.wcf
13 * @subpackage data.tag
14 * @category Community Framework
16 class TagEditor
extends DatabaseObjectEditor
{
18 * @see \wcf\data\DatabaseObjectEditor::$baseClass
20 protected static $baseClass = 'wcf\data\tag\Tag';
23 * Adds the given tag, and all of it's synonyms as a synonym.
25 * @param \wcf\data\tag\Tag $synonym
27 public function addSynonym(Tag
$synonym) {
28 if ($synonym->tagID
== $this->tagID
) return;
30 // assign all associations for the synonym with this tag
31 $sql = "UPDATE IGNORE wcf".WCF_N
."_tag_to_object
34 $statement = WCF
::getDB()->prepareStatement($sql);
35 $statement->execute(array($this->tagID
, $synonym->tagID
));
37 // remove remaining associations (object was tagged with both tags => duplicate key previously ignored)
38 $sql = "DELETE FROM wcf".WCF_N
."_tag_to_object
40 $statement = WCF
::getDB()->prepareStatement($sql);
41 $statement->execute(array($synonym->tagID
));
43 $editor = new TagEditor($synonym);
44 $editor->update(array(
45 'synonymFor' => $this->tagID
48 $synonymList = new TagList();
49 $synonymList->getConditionBuilder()->add('synonymFor = ?', array($synonym->tagID
));
50 $synonymList->readObjects();
52 foreach ($synonymList as $synonym) {
53 $this->addSynonym($synonym);