Exemplo n.º 1
0
 /**
  * Show all answers for this post id
  * @param int $postId
  * @return string
  * @throws NativeException
  * @return string
  */
 public function actionShowwallanswers($postId)
 {
     // check input post id num
     if (!Obj::isLikeInt($postId) || $postId < 1) {
         throw new NativeException('Wrong input data');
     }
     // try to find this post
     $object = WallPost::find($postId);
     if ($object === null || $object === false) {
         throw new NativeException('Wrong input data');
     }
     $result = $object->getAnswer()->orderBy('id', 'DESC')->take(200)->get();
     $response = [];
     foreach ($result as $answer) {
         // get user object and profile
         $user = $answer->getUser();
         $profile = $user->getProfile();
         // check if user exist
         if ($user === null || $user->id < 1) {
             continue;
         }
         // generate response array
         $response[] = ['answer_id' => $answer->id, 'user_id' => $answer->user_id, 'user_nick' => $profile->getNickname(), 'user_avatar' => $profile->getAvatarUrl('small'), 'answer_message' => $answer->message, 'answer_date' => Date::humanize($answer->created_at)];
     }
     return json_encode(['status' => 1, 'data' => $response]);
 }
Exemplo n.º 2
0
 /**
  * Allow post owners and targets delete
  * @param int $postId
  * @return string
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws ForbiddenException
  * @throws NotFoundException
  */
 public function actionWalldelete($postId)
 {
     // is user auth?
     if (!App::$User->isAuth()) {
         throw new ForbiddenException();
     }
     // is postId is integer?
     if (!Obj::isLikeInt($postId) || $postId < 1) {
         throw new NotFoundException();
     }
     // try to find the wall post
     $wallPost = WallPost::find($postId);
     if (null === $wallPost || false === $wallPost) {
         throw new NotFoundException();
     }
     // get user and check if he can delete this post
     $user = App::$User->identity();
     if ($wallPost->sender_id !== $user->id && $wallPost->target_id !== $user->id) {
         throw new ForbiddenException();
     }
     // check if submit sended
     $wallModel = new FormWallPostDelete($wallPost);
     if ($wallModel->send() && $wallModel->validate()) {
         $wallModel->make();
         $this->response->redirect('profile/show/' . $wallPost->target_id);
     }
     return $this->view->render('wall_delete', ['post' => $wallPost, 'model' => $wallModel]);
 }