Ejemplo n.º 1
0
 public function editPost($editPost)
 {
     $editPost['title'] = $this->title;
     $editPost['content'] = $this->content;
     $editPost['permit'] = $this->permit[0];
     if ($this->upload()) {
         $editPost['image'] = $this->thumbnail;
     }
     if ($this->date == "") {
         $editPost['create_at'] = date("Y-m-d");
     } else {
         $editPost['create_at'] = $this->date;
     }
     $editPost['user_id'] = $this->user_id;
     $editPost->save();
     PostProtected::deleteAll(['post_id' => $editPost['id']]);
     if ($editPost['permit'] == 2) {
         foreach ($this->reader as $userId) {
             $newPostProtected = new PostProtected();
             $newPostProtected['create_at'] = $editPost['create_at'];
             $newPostProtected['post_id'] = $editPost['id'];
             $newPostProtected['user_id'] = $userId;
             $newPostProtected->save();
         }
     }
 }
Ejemplo n.º 2
0
 public function actionDeletePost()
 {
     $selection = (array) Yii::$app->request->post('selection');
     foreach ($selection as $id) {
         Post::deleteAll(['id' => $id]);
         Like::deleteAll(['post_id' => $id]);
         Comment::deleteAll(['post_id' => $id]);
         PostTag::deleteAll(['post_id' => $id]);
         PostNotification::deleteAll(['post_id' => $id]);
         PostProtected::deleteAll(['post_id' => $id]);
     }
     return $this->render('post-manage');
 }
Ejemplo n.º 3
0
 public function actionDelete()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect(Url::to(['/site/login']));
     }
     if (isset($_POST['id'])) {
         $id = $_POST['id'];
         Post::findOne(['id' => $id])->delete();
         Like::deleteAll(['post_id' => $id]);
         Comment::deleteAll(['post_id' => $id]);
         PostTag::deleteAll(['post_id' => $id]);
         PostNotification::deleteAll(['post_id' => $id]);
         PostProtected::deleteAll(['post_id' => $id]);
     }
 }