hrm_courses.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\CourseRelUser;
  4. use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
  5. use Chamilo\CoreBundle\Entity\Course;
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. api_block_anonymous_users(true);
  8. $isHrm = api_is_drh();
  9. if (!$isHrm) {
  10. api_not_allowed(true);
  11. }
  12. function formatCourseInfo(Course $course, $sessionId = 0, $showCourseCode = false)
  13. {
  14. $sysCoursePath = api_get_path(SYS_COURSE_PATH).$course->getDirectory();
  15. $webCoursePath = api_get_path(WEB_COURSE_PATH).$course->getDirectory();
  16. return [
  17. 'visibility' => $course->getVisibility(),
  18. 'link' => api_get_course_url($course->getCode(), $sessionId),
  19. 'category' => $course->getCategoryCode(),
  20. 'title' => $course->getTitle(),
  21. 'title_cut' => $course->getTitle(),
  22. 'code_course' => $showCourseCode ? $course->getCode() : null,
  23. 'image' => file_exists($sysCoursePath.'/course-pic.png')
  24. ? $webCoursePath.'/course-pic.png'
  25. : Display::return_icon(
  26. 'session_default.png',
  27. null,
  28. null,
  29. null,
  30. null,
  31. true
  32. ),
  33. 'teachers' => api_get_setting('display_teacher_in_courselist') === 'true'
  34. ? $teachers = CourseManager::getTeachersFromCourse($course->getId(), true)
  35. : []
  36. ];
  37. }
  38. $showCourseCode = api_get_configuration_value('display_coursecode_in_courselist') === 'true';
  39. $hrm = api_get_user_entity(api_get_user_id());
  40. $assignedUsers = UserManager::get_users_followed_by_drh($hrm->getId());
  41. $users = [];
  42. $courseController = new IndexManager('');
  43. foreach ($assignedUsers as $assignedUserId => $assignedUserInfo) {
  44. $assignedUser = api_get_user_entity($assignedUserId);
  45. if (!$assignedUser) {
  46. continue;
  47. }
  48. $userInfo = [
  49. 'username' => $assignedUser->getUsername(),
  50. 'complete_name' => $assignedUser->getCompleteName(),
  51. 'picture_url' => UserManager::getUserPicture($assignedUserId),
  52. 'course_list' => $courseController->returnCoursesAndSessions($assignedUserId)['html']
  53. ];
  54. $users[$assignedUser->getId()] = $userInfo;
  55. }
  56. $toolName = get_lang('HrmAssignedUsersCourseList');
  57. $view = new Template($toolName);
  58. $view->assign('users', $users);
  59. $content = $view->fetch(
  60. $view->get_template('auth/hrm_courses.tpl')
  61. );
  62. $view->assign('header', $toolName);
  63. $view->assign('content', $content);
  64. $view->display_one_col_template();