Example #1
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     // update tag
     $this->objectAction = new TagAction(array($this->tagID), 'update', array('data' => array_merge($this->additionalFields, array('name' => $this->name))));
     $this->objectAction->executeAction();
     if ($this->tagObj->synonymFor === null) {
         // remove synonyms first
         $sql = "UPDATE\twcf" . WCF_N . "_tag\n\t\t\t\tSET\tsynonymFor = ?\n\t\t\t\tWHERE\tsynonymFor = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(null, $this->tagID));
         $editor = new TagEditor($this->tagObj);
         foreach ($this->synonyms as $synonym) {
             if (empty($synonym)) {
                 continue;
             }
             // find existing tag
             $synonymObj = Tag::getTag($synonym, $this->tagObj->languageID);
             if ($synonymObj === null) {
                 $synonymAction = new TagAction(array(), 'create', array('data' => array('name' => $synonym, 'languageID' => $this->tagObj->languageID, 'synonymFor' => $this->tagID)));
                 $synonymAction->executeAction();
             } else {
                 $editor->addSynonym($synonymObj);
             }
         }
     }
     $this->saved();
     // show success
     WCF::getTPL()->assign(array('success' => true));
 }
Example #2
0
 /**
  * Adds tags to a tagged object.
  * 
  * @param	string		$objectType
  * @param	integer		$objectID
  * @param	array		$tags
  * @param	integer		$languageID
  * @param	boolean		$replace
  */
 public function addObjectTags($objectType, $objectID, array $tags, $languageID, $replace = true)
 {
     $objectTypeID = $this->getObjectTypeID($objectType);
     $tags = array_unique($tags);
     // remove tags prior to apply the new ones (prevents duplicate entries)
     if ($replace) {
         $sql = "DELETE FROM\twcf" . WCF_N . "_tag_to_object\n\t\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\t\t\t\tAND objectID = ?\n\t\t\t\t\t\tAND languageID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($objectTypeID, $objectID, $languageID));
     }
     // get tag ids
     $tagIDs = array();
     foreach ($tags as $tag) {
         if (empty($tag)) {
             continue;
         }
         // enforce max length
         if (mb_strlen($tag) > TAGGING_MAX_TAG_LENGTH) {
             $tag = mb_substr($tag, 0, TAGGING_MAX_TAG_LENGTH);
         }
         // find existing tag
         $tagObj = Tag::getTag($tag, $languageID);
         if ($tagObj === null) {
             // create new tag
             $tagAction = new TagAction(array(), 'create', array('data' => array('name' => $tag, 'languageID' => $languageID)));
             $tagAction->executeAction();
             $returnValues = $tagAction->getReturnValues();
             $tagObj = $returnValues['returnValues'];
         }
         if ($tagObj->synonymFor !== null) {
             $tagIDs[$tagObj->synonymFor] = $tagObj->synonymFor;
         } else {
             $tagIDs[$tagObj->tagID] = $tagObj->tagID;
         }
     }
     // save tags
     $sql = "INSERT INTO\twcf" . WCF_N . "_tag_to_object\n\t\t\t\t\t(objectID, tagID, objectTypeID, languageID)\n\t\t\tVALUES\t\t(?, ?, ?, ?)";
     WCF::getDB()->beginTransaction();
     $statement = WCF::getDB()->prepareStatement($sql);
     foreach ($tagIDs as $tagID) {
         $statement->execute(array($objectID, $tagID, $objectTypeID, $languageID));
     }
     WCF::getDB()->commitTransaction();
 }
 /**
  * @see	\wcf\system\faker\IFaker::fake()
  */
 public function fake()
 {
     $multiWordChance = isset($this->parameters['multiWordChance']) ? $this->parameters['multiWordChance'] : 10;
     $multiWordCountMin = isset($this->parameters['multiWordCountMin']) ? $this->parameters['multiWordCountMin'] : 2;
     $multiWordCountMax = isset($this->parameters['multiWordCountMax']) ? $this->parameters['multiWordCountMax'] : 5;
     if ($this->generator->boolean($multiWordChance)) {
         // this tag will be multiple words
         $tag = $_tag = mb_substr($this->generator->words($this->generator->randomNumber($multiWordCountMin, $multiWordCountMax), true), 0, 251);
         while (\wcf\data\tag\Tag::getTag($_tag, $this->language->languageID) !== null) {
             $_tag = $tag . $this->generator->randomNumber(4);
         }
         $tag = $_tag;
     } else {
         // this tag will be a single word
         $tag = $_tag = $this->generator->word;
         while (\wcf\data\tag\Tag::getTag($_tag, $this->language->languageID) !== null) {
             $_tag = $tag . $this->generator->randomNumber(8);
         }
         $tag = $_tag;
     }
     // save tag
     $objectAction = new \wcf\data\tag\TagAction(array(), 'create', array('data' => array('name' => $tag, 'languageID' => $this->language->languageID)));
     $objectAction->executeAction();
 }
Example #4
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // save tag
     $this->objectAction = new TagAction(array(), 'create', array('data' => array_merge($this->additionalFields, array('name' => $this->name, 'languageID' => $this->languageID))));
     $this->objectAction->executeAction();
     $returnValues = $this->objectAction->getReturnValues();
     $editor = new TagEditor($returnValues['returnValues']);
     foreach ($this->synonyms as $synonym) {
         if (empty($synonym)) {
             continue;
         }
         // find existing tag
         $synonymObj = Tag::getTag($synonym, $this->languageID);
         if ($synonymObj === null) {
             $synonymAction = new TagAction(array(), 'create', array('data' => array('name' => $synonym, 'languageID' => $this->languageID, 'synonymFor' => $editor->tagID)));
             $synonymAction->executeAction();
         } else {
             $editor->addSynonym($synonymObj);
         }
     }
     $this->saved();
     // reset values
     $this->name = '';
     $this->synonyms = array();
     // show success
     WCF::getTPL()->assign(array('success' => true));
 }