my_students.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. //$key = api_replace_dangerous_char($key);
  56. if (empty($key)) {
  57. continue;
  58. }
  59. $qb
  60. ->andWhere('u.firstname LIKE :keyword OR u.lastname LIKE :keyword OR u.username LIKE :keyword')
  61. ->setParameter('keyword', "%$key%")
  62. ;
  63. }
  64. } else {
  65. $qb
  66. ->andWhere('u.firstname LIKE :keyword OR u.lastname LIKE :keyword OR u.username LIKE :keyword')
  67. ->setParameter('keyword', "%$keyword%")
  68. ;
  69. }
  70. }
  71. $query = $qb->getQuery();
  72. $items = new Paginator($query, $fetchJoinCollection = true);
  73. $totalItems = count($items);
  74. $pagesCount = ceil($totalItems / $pageSize);
  75. }
  76. $pagination = '';
  77. $url = api_get_self().'?';
  78. if ($totalItems > 1) {
  79. $pagination .= '<ul class="pagination">';
  80. for ($i = 0; $i < $pagesCount; $i++) {
  81. $newPage = $i + 1;
  82. if ($currentPage == $newPage) {
  83. $pagination .= '<li class="active"><a href="'.$url.'&page='.$newPage.'">'.$newPage.'</a></li>';
  84. } else {
  85. $pagination .= '<li><a href="'.$url.'&page='.$newPage.'">'.$newPage.'</a></li>';
  86. }
  87. }
  88. $pagination .= '</ul>';
  89. }
  90. // Create a search-box
  91. $form = new FormValidator('search_simple', 'get', null, null, null, 'inline');
  92. $form->addText(
  93. 'keyword',
  94. get_lang('Search'),
  95. false,
  96. array(
  97. 'aria-label' => get_lang("SearchUsers")
  98. )
  99. );
  100. $form->addButtonSearch(get_lang('Search'));
  101. $tpl = new Template($plugin->get_lang('plugin_title'));
  102. $tpl->assign('users', $items);
  103. $tpl->assign('form', $form->returnForm());
  104. $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?';
  105. $tpl->assign('post_url', $url);
  106. $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?';
  107. $tpl->assign('my_students_url', $url);
  108. $tpl->assign('pagination', $pagination);
  109. $tpl->assign('care_title', $plugin->get_lang('CareDetailView'));
  110. $content = $tpl->fetch('/'.$plugin->get_name().'/view/my_students.html.twig');
  111. // Assign into content
  112. $tpl->assign('content', $content);
  113. // Display
  114. $tpl->display_one_col_template();