post.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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('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 && !empty($post->getParent())) {
  39. $qb = $em->createQueryBuilder();
  40. $criteria = Criteria::create();
  41. if ($showPrivate == false) {
  42. $criteria->andWhere(Criteria::expr()->eq('private', false));
  43. }
  44. $criteria->andWhere(Criteria::expr()->eq('parent', $post->getParent()));
  45. $criteria->andWhere(Criteria::expr()->neq('id', $post->getId()));
  46. $qb
  47. ->select('p')
  48. ->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p')
  49. ->addCriteria($criteria)
  50. ->orderBy('p.createdAt', 'desc')
  51. ;
  52. $query = $qb->getQuery();
  53. $relatedPosts = $query->getResult();
  54. }
  55. $tpl = new Template($plugin->get_lang('plugin_title'));
  56. $tpl->assign('post', $post);
  57. $tpl->assign('related_posts', $relatedPosts);
  58. $url = api_get_path(WEB_PLUGIN_PATH).'/studentfollowup/post.php?student_id='.$studentId;
  59. $tpl->assign('post_url', $url);
  60. $tpl->assign(
  61. 'back_link',
  62. Display::url(
  63. Display::return_icon('back.png'),
  64. api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?student_id='.$studentId
  65. )
  66. );
  67. $tpl->assign('information_icon', Display::return_icon('info.png'));
  68. $content = $tpl->fetch('/'.$plugin->get_name().'/view/post.html.twig');
  69. // Assign into content
  70. $tpl->assign('content', $content);
  71. // Display
  72. $tpl->display_one_col_template();