Exemple #1
0
 public function actionEdit($post_id = 0)
 {
     $post_id = (int) $post_id;
     if ($post_id != 0) {
         $post = BlogPost::model()->findByPk($post_id);
         if (!$post) {
             throw new CHttpException(404, "Поста не существует. Возможно, его удалили");
         }
         if ($post->user_id != Yii::app()->user->id and !Yii::app()->user->can("blog_moderate")) {
             throw new CHttpException(403, "Вы можете редактировать только собственные посты");
         }
         if ($post->book_id != 0) {
             $this->redirect("/book/{$post->book_id}/blog/{$post->id}/edit");
         }
     } else {
         $post = new BlogPost();
         $post->user_id = Yii::app()->user->id;
         $post->topics = (int) $_GET["topic"];
     }
     if (isset($_POST["BlogPost"])) {
         $post->attributes = $_POST["BlogPost"];
         $post->lastcomment = date("Y-m-d H:i:s");
         if ($post->save()) {
             $post->setTrack();
             $this->redirect($post->url);
         }
     }
     $this->render("edit", array("post" => $post));
 }
 public function actionEdit($book_id, $post_id = 0)
 {
     $this->loadBook($book_id);
     $post_id = (int) $post_id;
     if (!$this->book->can("blog_r") || !$this->book->can("blog_w")) {
         throw new CHttpException(403, "Вы не можете писать и редактировать посты в блоге этого перевода. " . $this->book->getWhoCanDoIt("blog_w"));
     }
     if ($post_id != 0) {
         $post = BlogPost::model()->findByPk($post_id);
         if (!$post) {
             throw new CHttpException(404, "Поста не существует. Возможно, его удалили.");
         }
         if ($post->user_id != Yii::app()->user->id and !Yii::app()->user->can("blog_moderate")) {
             throw new CHttpException(403, "Вы можете редактировать только собственные посты.");
         }
         if ($post->book_id == 0) {
             $this->redirect("/blog/{$post->id}/edit");
         }
         if ($post->book_id != $this->book->id) {
             $this->redirect("/book/{$post->book_id}/blog/{$post->id}/edit");
         }
         if ($post->isAnnounce) {
             throw new CHttpException(404, "Поста не существует. Возможно, его удалили.");
         }
     } else {
         $post = new BlogPost();
         $post->user_id = Yii::app()->user->id;
         $post->book_id = $this->book->id;
         $post->topics = isset($_GET["topic"]) ? (int) $_GET["topic"] : 3;
     }
     $post->book = $this->book;
     if (isset($_POST["BlogPost"])) {
         $post->attributes = $_POST["BlogPost"];
         if ($post->save()) {
             // Добавляем пост в мои обсуждения
             $post->setTrack();
             $this->redirect($post->url);
         }
     }
     $this->render("//blog/edit", array("post" => $post));
 }