| @@ 673-720 (lines=48) @@ | ||
| 670 | * |
|
| 671 | * @return \Cake\Network\Response |
|
| 672 | */ |
|
| 673 | public function go($messageId = null) |
|
| 674 | { |
|
| 675 | $this->loadModel('ConversationsMessages'); |
|
| 676 | ||
| 677 | $message = $this->ConversationsMessages |
|
| 678 | ->find() |
|
| 679 | ->contain([ |
|
| 680 | 'Conversations' |
|
| 681 | ]) |
|
| 682 | ->where([ |
|
| 683 | 'ConversationsMessages.id' => $messageId |
|
| 684 | ]) |
|
| 685 | ->first(); |
|
| 686 | ||
| 687 | if (is_null($message)) { |
|
| 688 | $this->Flash->error(__d('conversations', "This message doesn't exist or has been deleted.")); |
|
| 689 | ||
| 690 | return $this->redirect(['controller' => 'conversations', 'action' => 'index']); |
|
| 691 | } |
|
| 692 | ||
| 693 | $message->toArray(); |
|
| 694 | ||
| 695 | //Count the number of messages before this message. |
|
| 696 | $messagesBefore = $this->ConversationsMessages |
|
| 697 | ->find() |
|
| 698 | ->where([ |
|
| 699 | 'ConversationsMessages.conversation_id' => $message->conversation_id, |
|
| 700 | 'ConversationsMessages.created <' => $message->created |
|
| 701 | ]) |
|
| 702 | ->count(); |
|
| 703 | ||
| 704 | //Get the number of messages per page. |
|
| 705 | $messagesPerPage = Configure::read('Conversations.messages_per_page'); |
|
| 706 | ||
| 707 | //Calculate the page. |
|
| 708 | $page = ceil($messagesBefore / $messagesPerPage); |
|
| 709 | ||
| 710 | $page = ($page > 1) ? $page : 1; |
|
| 711 | ||
| 712 | //Redirect the user. |
|
| 713 | return $this->redirect([ |
|
| 714 | '_name' => 'conversations-view', |
|
| 715 | 'slug' => $message->conversation->title, |
|
| 716 | 'id' => $message->conversation->id, |
|
| 717 | '?' => ['page' => $page], |
|
| 718 | '#' => 'message-' . $messageId |
|
| 719 | ]); |
|
| 720 | } |
|
| 721 | ||
| 722 | /** |
|
| 723 | * Function to kick an user from a conversation. |
|
| @@ 359-406 (lines=48) @@ | ||
| 356 | * |
|
| 357 | * @return \Cake\Network\Response |
|
| 358 | */ |
|
| 359 | public function go($commentId = null) |
|
| 360 | { |
|
| 361 | $this->loadModel('BlogArticlesComments'); |
|
| 362 | ||
| 363 | $comment = $this->BlogArticlesComments |
|
| 364 | ->find() |
|
| 365 | ->contain([ |
|
| 366 | 'BlogArticles' |
|
| 367 | ]) |
|
| 368 | ->where([ |
|
| 369 | 'BlogArticlesComments.id' => $commentId |
|
| 370 | ]) |
|
| 371 | ->first(); |
|
| 372 | ||
| 373 | if (is_null($comment)) { |
|
| 374 | $this->Flash->error(__("This comment doesn't exist or has been deleted.")); |
|
| 375 | ||
| 376 | return $this->redirect(['action' => 'index']); |
|
| 377 | } |
|
| 378 | ||
| 379 | $comment->toArray(); |
|
| 380 | ||
| 381 | //Count the number of message before this message. |
|
| 382 | $messagesBefore = $this->BlogArticlesComments |
|
| 383 | ->find() |
|
| 384 | ->where([ |
|
| 385 | 'BlogArticlesComments.article_id' => $comment->article_id, |
|
| 386 | 'BlogArticlesComments.created <' => $comment->created |
|
| 387 | ]) |
|
| 388 | ->count(); |
|
| 389 | ||
| 390 | //Get the number of messages per page. |
|
| 391 | $messagesPerPage = Configure::read('Blog.comment_per_page'); |
|
| 392 | ||
| 393 | //Calculate the page. |
|
| 394 | $page = floor($messagesBefore / $messagesPerPage) + 1; |
|
| 395 | ||
| 396 | $page = ($page > 1) ? $page : 1; |
|
| 397 | ||
| 398 | //Redirect the user. |
|
| 399 | return $this->redirect([ |
|
| 400 | '_name' => 'blog-article', |
|
| 401 | 'slug' => $comment->blog_article->title, |
|
| 402 | 'id' => $comment->blog_article->id, |
|
| 403 | '?' => ['page' => $page], |
|
| 404 | '#' => 'comment-' . $commentId |
|
| 405 | ]); |
|
| 406 | } |
|
| 407 | ||
| 408 | /** |
|
| 409 | * Get all articles by a date formatted to "m-Y". |
|