예제 #1
0
파일: Post.php 프로젝트: Penton/MoBlog
 public function insertTags($tags, $beforeCount = true, $afterCount = true)
 {
     if (!is_array($tags)) {
         return false;
     }
     $this->deleteTags($beforeCount);
     //先删除标签
     //插入新标签
     $tagIds = Tag::scanTags($tags);
     if ($tagIds) {
         foreach ($tagIds as $v) {
             $model = new Relationship();
             $model->cid = $this->cid;
             $model->mid = $v;
             $model->insert(false);
             if ($afterCount) {
                 //更新标签文章数
                 Tag::updateAllCounters(['count' => 1], ['mid' => $v]);
             }
         }
     }
     return true;
 }
예제 #2
0
파일: Content.php 프로젝트: luobenyu/blog-1
 public function saveCategory($categoryId)
 {
     //如果已经有分类且和新分类一致,则跳过
     if ($this->category && $this->category->id == $categoryId) {
         return true;
     }
     $relationship = new Relationship();
     //如果有分类,则查询久分类,然后分类的内容统计-1
     if ($this->category && ($oldCategory = $relationship->find()->where(['content_id' => $this->id, 'meta_id' => $this->category->id])->one())) {
         Meta::updateAllCounters(['content_total' => -1], ['id' => $this->category->id]);
         $oldCategory->delete();
     }
     $relationship->content_id = $this->id;
     $relationship->meta_id = $categoryId;
     if ($relationship->insert()) {
         //如果更新了分类,在新分类的内容数量+1,并且返回更新的条数
         return Meta::updateAllCounters(['content_total' => 1], ['id' => $categoryId]);
     }
     return false;
 }