示例#1
0
 public function setTags(array $tagTexts)
 {
     $tagCols = Tag::columns();
     $tagIdsToAdd = array();
     $tagIdsByText = Tag::statement()->where('? IN (?)', $tagCols->text, $tagTexts)->query()->fetchAll($tagCols->text, $tagCols->id);
     foreach ($tagTexts as $tagText) {
         if (!isset($tagIdsByText[$tagText])) {
             $tagIdsToAdd[$tagText] = null;
         }
     }
     foreach ($tagIdsToAdd as $tagText => $tagId) {
         $newTag = new Tag();
         $newTag->text = $tagText;
         $newTag->save();
         $tagIdsByText[$tagText] = $newTag->id;
     }
     asort($tagIdsByText);
     /**
      * @todo consider helper crc32 index here
      */
     $this->tagIds = implode(',', $tagIdsByText);
     return $this;
 }