Exemplo n.º 1
0
 public function actionIndex($slug)
 {
     $query = Vidmage::find()->joinWith('vidmageTags.tag')->where(['tag.name' => $slug])->orderBy(['id' => SORT_DESC]);
     $vidmages = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $tag = Tag::findOne(['name' => $slug]);
     return $this->render('index', compact('vidmages', 'tag'));
 }
Exemplo n.º 2
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         $tag = Tag::findOne($this->tag_id);
         $tag->recount--;
         $tag->save();
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 public function saveGroup()
 {
     $cleanUrl = preg_replace("/[^a-zA-Z0-9\\/_|+ -]/", '', $this->name);
     $cleanUrl = strtolower(trim($cleanUrl, '-'));
     $cleanUrl = preg_replace("/[\\/_|+ -]+/", '-', $cleanUrl);
     $this->url = $cleanUrl;
     $urlExists = Group::findOne(['url' => $cleanUrl]);
     if ($urlExists) {
         if ($this->isNewRecord) {
             $lastGroup = Group::find()->orderBy(['id' => SORT_DESC])->one();
             $this->url = $lastGroup->id++ . '-' . $this->url;
         } else {
             if ($urlExists->id !== $this->id) {
                 $this->url = $this->id . '-' . $this->url;
             }
         }
     }
     if (!$this->save()) {
         return false;
     }
     $tags = explode(',', str_replace(['[', ']', '\''], ['', '', ''], $this->tag));
     foreach ($tags as $tag) {
         $newTag = Tag::findOne(['name' => strtolower($tag)]);
         if (!$newTag) {
             $newTag = new Tag();
             $newTag->name = strtolower($tag);
             if ($newTag->save()) {
                 $tagToGroup = new TagToGroup();
                 $tagToGroup->tag_id = $newTag->id;
                 $tagToGroup->group_id = $this->id;
                 $tagToGroup->save();
             }
         } else {
             $tagToGroup = new TagToGroup();
             $tagToGroup->tag_id = $newTag->id;
             $tagToGroup->group_id = $this->id;
             $tagToGroup->save();
         }
     }
     $userToGroup = new UserToGroup();
     $userToGroup->user_id = Yii::$app->user->getIdentity()->id;
     $userToGroup->group_id = $this->id;
     $userToGroup->can_edit = 1;
     $userToGroup->group_admin = 1;
     if ($userToGroup->save()) {
         return true;
     }
     return false;
 }
Exemplo n.º 4
0
 public function actionDelete($id)
 {
     $model = Tag::findOne(['id' => $id, 'store_id' => Yii::$app->user->identity->store_id]);
     if ($model) {
         if ($model->delete()) {
             Yii::$app->session->setFlash('success', '成功删除标签“' . $model->name . '”。');
         } else {
             Yii::$app->session->setFlash('danger', '标签删除失败。');
         }
     }
     if (Yii::$app->request->referrer) {
         return $this->redirect(Yii::$app->request->referrer);
     } else {
         return $this->redirect(['index']);
     }
 }
Exemplo n.º 5
0
 /**
  * Finds the Tag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Tag::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 6
0
 /**
  * @return array Array of Tag
  */
 public function getTags()
 {
     $tagging = Tagging::find()->where(['taggable_id' => $this->id, 'taggable_type' => Tagging::TAGGABLE_VIDEO])->asArray()->all();
     $tags = [];
     foreach ($tagging as $data) {
         $tags[] = Tag::findOne($data['tag_id']);
     }
     return $tags;
 }
Exemplo n.º 7
0
 /**
  * 新建文章
  * @return bool
  * @throws Exception
  */
 public function saveArticle()
 {
     if (!$this->validate()) {
         return false;
     }
     if (!$this->tag) {
         return $this->save();
     }
     $res = $this->save();
     try {
         $tags = explode(';', $this->tag);
         foreach ($tags as $v) {
             if (!$v) {
                 continue;
             }
             $tag = Tag::findOne(['name' => $v]);
             if (!$tag) {
                 $tag = new Tag();
                 $tag->name = $v;
                 $tag->article_count = 0;
                 $res = $tag->save();
                 $id = $tag->id;
             } else {
                 $id = $tag->id;
             }
             $article_tag = new ArticleTag();
             $article_tag->article_id = $this->id;
             $article_tag->tag_id = $id;
             $article_tag->save();
             //更前标签的文章数量
             $tag->article_count++;
             $tag->save(false);
         }
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     return $res;
 }