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