示例#1
0
 public function testSetTags()
 {
     $tagGroup = new TagGroup();
     $tagGroup->setTags(array('tag1', 'tag2', 'tag3'));
     $tagGroup->save();
     $this->assertEquals(array('tag1', 'tag2', 'tag3'), Tag::statement()->where('? IN (?)', Tag::columns()->id, new Raw(TagGroup::findByPrimaryKey($tagGroup->id)->tagIds))->query()->fetchAll(null, Tag::columns()->text));
 }
示例#2
0
 public function run(Log $log = null)
 {
     /** @var \Yaoi\Database\Definition\Table[] $tables */
     $tables = array(Symbol::table(), Run::table(), RelatedStat::table(), SymbolStat::table(), Project::table(), Tag::table(), Aggregate::table(), ReportAggregate::table(), TagGroup::table());
     if (null === $log) {
         $log = Log::nil();
     }
     foreach ($tables as $table) {
         $table->migration()->setLog($log)->apply();
     }
 }
示例#3
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;
 }