my_students.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Doctrine\Common\Collections\Criteria;
  4. use Doctrine\ORM\Tools\Pagination\Paginator;
  5. require_once __DIR__.'/../../main/inc/global.inc.php';
  6. api_block_anonymous_users();
  7. $plugin = StudentFollowUpPlugin::create();
  8. $currentUserId = api_get_user_id();
  9. $currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
  10. $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
  11. $totalItems = 0;
  12. $items = [];
  13. $showPrivate = false;
  14. $pageSize = StudentFollowUpPlugin::getPageSize();
  15. $firstResults = $pageSize * ($currentPage - 1);
  16. $userList = [];
  17. if (!api_is_platform_admin()) {
  18. $status = COURSEMANAGER;
  19. if (api_is_drh()) {
  20. $status = DRH;
  21. }
  22. $userList = StudentFollowUpPlugin::getUsers(
  23. $status,
  24. $currentUserId,
  25. $firstResults,
  26. $pageSize
  27. );
  28. }
  29. if (!empty($userList) || api_is_platform_admin()) {
  30. $em = Database::getManager();
  31. $qb = $em->createQueryBuilder();
  32. $criteria = Criteria::create();
  33. if (!api_is_platform_admin()) {
  34. $criteria->where(Criteria::expr()->in('user', $userList));
  35. }
  36. if ($showPrivate == false) {
  37. $criteria->andWhere(Criteria::expr()->eq('private', false));
  38. }
  39. $qb
  40. ->select('p')
  41. ->distinct()
  42. ->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p')
  43. ->join('p.user', 'u')
  44. ->addCriteria($criteria)
  45. ->setFirstResult($firstResults)
  46. ->setMaxResults($pageSize)
  47. ->groupBy('p.user')
  48. ->orderBy('p.createdAt', 'desc')
  49. ;
  50. if (!empty($keyword)) {
  51. $keyword = explode(' ', $keyword);
  52. if (is_array($keyword)) {
  53. foreach ($keyword as $key) {
  54. $key = trim($key);
  55. if (empty($key)) {
  56. continue;
  57. }
  58. $qb
  59. ->andWhere('u.firstname LIKE :keyword OR u.lastname LIKE :keyword OR u.username LIKE :keyword')
  60. ->setParameter('keyword', "%$key%")
  61. ;
  62. }
  63. } else {
  64. $qb
  65. ->andWhere('u.firstname LIKE :keyword OR u.lastname LIKE :keyword OR u.username LIKE :keyword')
  66. ->setParameter('keyword', "%$keyword%")
  67. ;
  68. }
  69. }
  70. $query = $qb->getQuery();
  71. $items = new Paginator($query);
  72. $totalItems = $items->count();
  73. $pagesCount = ceil($totalItems / $pageSize);
  74. }
  75. $pagination = '';
  76. $url = api_get_self().'?';
  77. if ($totalItems > 1) {
  78. $pagination .= '<ul class="pagination">';
  79. for ($i = 0; $i < $pagesCount; $i++) {
  80. $newPage = $i + 1;
  81. if ($currentPage == $newPage) {
  82. $pagination .= '<li class="active"><a href="'.$url.'page='.$newPage.'">'.$newPage.'</a></li>';
  83. } else {
  84. $pagination .= '<li><a href="'.$url.'page='.$newPage.'">'.$newPage.'</a></li>';
  85. }
  86. }
  87. $pagination .= '</ul>';
  88. }
  89. // Create a search-box
  90. $form = new FormValidator('search_simple', 'get', null, null, null, 'inline');
  91. $form->addText(
  92. 'keyword',
  93. get_lang('Search'),
  94. false,
  95. [
  96. 'aria-label' => get_lang("SearchUsers"),
  97. ]
  98. );
  99. $form->addButtonSearch(get_lang('Search'));
  100. $tpl = new Template($plugin->get_lang('plugin_title'));
  101. $tpl->assign('users', $items);
  102. $tpl->assign('form', $form->returnForm());
  103. $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?';
  104. $tpl->assign('post_url', $url);
  105. $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?';
  106. $tpl->assign('my_students_url', $url);
  107. $tpl->assign('pagination', $pagination);
  108. $tpl->assign('care_title', $plugin->get_lang('CareDetailView'));
  109. $content = $tpl->fetch('/'.$plugin->get_name().'/view/my_students.html.twig');
  110. // Assign into content
  111. $tpl->assign('content', $content);
  112. // Display
  113. $tpl->display_one_col_template();