Beispiel #1
0
 public function linkTag($item, $tags, $type)
 {
     $tagsLink = new TagsLink();
     $tagsLink->deleteAll(['link_type_id' => $type, 'link_id' => $item]);
     // wrap tags
     if (!is_array($tags)) {
         $tags[] = $tags;
     }
     foreach ($tags as $ind => $val) {
         $tagsLink = new TagsLink();
         $tagsLink->link_type_id = $type;
         $tagsLink->link_id = $item;
         $tagsLink->tag_id = $val;
         try {
             $tagsLink->save();
         } catch (Exception $e) {
             dd($val);
             continue;
         }
         unset($tagsLink);
     }
 }
Beispiel #2
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (is_array($this->NavTags) and is_array($this->SystemTags)) {
         $tags = array_merge($this->NavTags, $this->SystemTags);
     } elseif (!is_array($this->NavTags)) {
         $tags = $this->SystemTags;
     } else {
         $tags = $this->NavTags;
     }
     $tagsLink = new TagsLink();
     $tagsLink->linkTag($this->id, $tags, 1);
 }