my_students.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. use Doctrine\Common\Collections\Criteria;
  3. use Doctrine\ORM\Tools\Pagination\Paginator;
  4. require_once __DIR__.'/../../main/inc/global.inc.php';
  5. api_block_anonymous_users();
  6. $plugin = StudentFollowUpPlugin::create();
  7. $currentUserId = api_get_user_id();
  8. $currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
  9. $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
  10. $totalItems = 0;
  11. $items = [];
  12. $showPrivate = false;
  13. $pageSize = StudentFollowUpPlugin::getPageSize();
  14. $firstResults = $pageSize * ($currentPage - 1);
  15. $userList = [];
  16. if (!api_is_platform_admin()) {
  17. $status = COURSEMANAGER;
  18. if (api_is_drh()) {
  19. $status = DRH;
  20. }
  21. $userList = StudentFollowUpPlugin::getUsers(
  22. $status,
  23. $currentUserId,
  24. $firstResults,
  25. $pageSize
  26. );
  27. }
  28. if (!empty($userList) || api_is_platform_admin()) {
  29. $em = Database::getManager();
  30. $qb = $em->createQueryBuilder();
  31. $criteria = Criteria::create();
  32. if (!api_is_platform_admin()) {
  33. $criteria->where(Criteria::expr()->in('user', $userList));
  34. }
  35. if ($showPrivate == false) {
  36. $criteria->andWhere(Criteria::expr()->eq('private', false));
  37. }
  38. $qb
  39. ->select('p')
  40. ->distinct()
  41. ->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p')
  42. ->join('p.user', 'u')
  43. ->addCriteria($criteria)
  44. ->setFirstResult($firstResults)
  45. ->setMaxResults($pageSize)
  46. ->groupBy('p.user')
  47. ->orderBy('p.createdAt', 'desc')
  48. ;
  49. if (!empty($keyword)) {
  50. $keyword = explode(' ', $keyword);
  51. if (is_array($keyword)) {
  52. foreach ($keyword as $key) {
  53. $key = trim($key);
  54. //$key = api_replace_dangerous_char($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, $fetchJoinCollection = true);
  72. $totalItems = count($items);
  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. array(
  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();