my_students.php 3.1 KB

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