Exemplo n.º 1
0
 public static function edit(BlogForm $blogform)
 {
     $uid = \Yii::$app->user->getId();
     $blog = Blog::findOne(['id' => $blogform->id, 'uid' => $uid]);
     $blog->title = htmlspecialchars($blogform->title);
     $blog->content = htmlspecialchars($blogform->content);
     if ($blog->tags != $blogform->tags) {
         $updateTags = true;
     }
     /*
     		if ($blogform->status == self::STATUS_PUBLISH && $blog->status != self::STATUS_PUBLISH) {
     			$countInc = true;
     		}
     		if ($blogform->status != self::STATUS_PUBLISH && $blog->status == self::STATUS_PUBLISH) {
     			$countDec = true;
     		}
     */
     $analyse = self::analyse($blogform->content);
     if (!$blogform->description) {
         $blog->description = $analyse['description'];
     } else {
         $blog->description = $blogform->description;
     }
     //$blog->image = $blogform->image ? $blogform->image : $analyse['image'];
     $blog->image = $analyse['image'];
     $blog->thumb = $analyse['thumb'];
     $blog->tags = $blogform->tags;
     $blog->cid = $blogform->cid;
     $blog->status = $blogform->status ? $blogform->status : self::STATUS_PUBLISH;
     $blog->is_private = is_numeric($blogform->is_private) ? $blogform->is_private : 0;
     $blog->allow_review = is_numeric($blogform->allow_review) ? $blogform->allow_review : 1;
     $blog->uptime = time();
     $res = $blog->save();
     if ($res) {
         if (isset($updateTags) && $updateTags) {
             Tags::removeByBlogId($id);
             Tags::add($blog->tags, $id);
         }
         return true;
     }
     return false;
 }