post.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Doctrine\Common\Collections\Criteria;
  4. use Chamilo\PluginBundle\Entity\StudentFollowUp\CarePost;
  5. require_once __DIR__.'/../../main/inc/global.inc.php';
  6. $plugin = StudentFollowUpPlugin::create();
  7. $currentUserId = api_get_user_id();
  8. $studentId = isset($_GET['student_id']) ? (int) $_GET['student_id'] : api_get_user_id();
  9. $postId = isset($_GET['post_id']) ? (int) $_GET['post_id'] : 1;
  10. if (empty($studentId)) {
  11. api_not_allowed(true);
  12. }
  13. $permissions = StudentFollowUpPlugin::getPermissions($studentId, $currentUserId);
  14. $isAllow = $permissions['is_allow'];
  15. $showPrivate = $permissions['show_private'];
  16. if ($isAllow === false) {
  17. api_not_allowed(true);
  18. }
  19. $em = Database::getManager();
  20. $qb = $em->createQueryBuilder();
  21. $criteria = Criteria::create();
  22. $criteria->where(Criteria::expr()->eq('user', $studentId));
  23. if ($showPrivate == false) {
  24. $criteria->andWhere(Criteria::expr()->eq('private', false));
  25. }
  26. $criteria->andWhere(Criteria::expr()->eq('id', $postId));
  27. $qb
  28. ->select('distinct p')
  29. ->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p')
  30. ->addCriteria($criteria)
  31. ->setMaxResults(1)
  32. ;
  33. $query = $qb->getQuery();
  34. /** @var CarePost $post */
  35. $post = $query->getOneOrNullResult();
  36. // Get related posts (post with same parent)
  37. $relatedPosts = [];
  38. if ($post) {
  39. $qb = $em->createQueryBuilder();
  40. $criteria = Criteria::create();
  41. if (!empty($post->getParent())) {
  42. $criteria->where(Criteria::expr()->in('parent', [$post->getParent()->getId(), $post->getId()]));
  43. } else {
  44. $criteria->where(Criteria::expr()->eq('parent', $post->getId()));
  45. }
  46. if ($showPrivate == false) {
  47. $criteria->andWhere(Criteria::expr()->eq('private', false));
  48. }
  49. $criteria->orWhere(Criteria::expr()->eq('id', $post->getId()));
  50. $qb
  51. ->select('p')
  52. ->distinct()
  53. ->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p')
  54. ->addCriteria($criteria)
  55. ->orderBy('p.createdAt', 'desc')
  56. ;
  57. $query = $qb->getQuery();
  58. $relatedPosts = $query->getResult();
  59. }
  60. //var_dump($post->getTitle());
  61. $tpl = new Template($plugin->get_lang('plugin_title'));
  62. $tpl->assign('post', $post);
  63. $tpl->assign('related_posts', $relatedPosts);
  64. $url = api_get_path(WEB_PLUGIN_PATH).'/studentfollowup/post.php?student_id='.$studentId;
  65. $tpl->assign('post_url', $url);
  66. $tpl->assign(
  67. 'back_link',
  68. Display::url(
  69. Display::return_icon('back.png'),
  70. api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?student_id='.$studentId
  71. )
  72. );
  73. $tpl->assign('information_icon', Display::return_icon('info.png'));
  74. $tpl->assign('student_info', api_get_user_info($studentId));
  75. $tpl->assign('care_title', $plugin->get_lang('CareDetailView'));
  76. $content = $tpl->fetch('/'.$plugin->get_name().'/view/post.html.twig');
  77. // Assign into content
  78. $tpl->assign('content', $content);
  79. // Display
  80. $tpl->display_one_col_template();