コード例 #1
0
ファイル: Tags.php プロジェクト: albertborsos/yii2-tagger
 public static function matchLabelWithID($labels)
 {
     $tagsWithIDs = [];
     foreach ($labels as $label) {
         $foundTag = Tags::findOne(['label' => $label]);
         if (!is_null($foundTag)) {
             //létezik ilyen cimke
             $tagsWithIDs[$foundTag->id] = $label;
         } else {
             //még nincs ilyen cimke -> mentjük
             if (trim($label) !== '') {
                 $tag = new Tags();
                 $tag->label = $label;
                 $tag->status = 'a';
                 $tag->save();
                 // már van ID-nk
                 $tagsWithIDs[$tag->id] = $label;
             }
         }
     }
     return $tagsWithIDs;
 }