Use course id instead of course code, use course/session entity

Use repositories to get exercises/student publications.
pull/3844/head
Julio Montoya 5 years ago
parent ac5fd9244f
commit 346910d1a8
  1. 4
      public/main/admin/dashboard_add_users_to_user.php
  2. 6
      public/main/auth/my_progress.php
  3. 3
      public/main/dropbox/dropbox_functions.inc.php
  4. 2
      public/main/exercise/exercise_show.php
  5. 2
      public/main/exercise/recalculate_all.php
  6. 10
      public/main/group/group.php
  7. 11
      public/main/group/group_overview.php
  8. 5
      public/main/inc/ajax/announcement.ajax.php
  9. 16
      public/main/inc/ajax/course.ajax.php
  10. 4
      public/main/inc/ajax/group.ajax.php
  11. 13
      public/main/inc/ajax/model.ajax.php
  12. 1
      public/main/inc/lib/add_course.lib.inc.php
  13. 52
      public/main/inc/lib/agenda.lib.php
  14. 70
      public/main/inc/lib/api.lib.php
  15. 92
      public/main/inc/lib/exercise.lib.php
  16. 51
      public/main/inc/lib/groupmanager.lib.php
  17. 4
      public/main/inc/lib/internationalization.lib.php
  18. 260
      public/main/inc/lib/myspace.lib.php
  19. 13
      public/main/inc/lib/redirect.class.php
  20. 28
      public/main/inc/lib/sessionmanager.lib.php
  21. 959
      public/main/inc/lib/tracking.lib.php
  22. 3
      public/main/lp/lp_report.php
  23. 15
      public/main/mySpace/company_reports.php
  24. 14
      public/main/mySpace/company_reports_resumed.php
  25. 9
      public/main/mySpace/course.php
  26. 48
      public/main/mySpace/myStudents.php
  27. 15
      public/main/mySpace/question_stats_global.php
  28. 15
      public/main/mySpace/question_stats_global_detail.php
  29. 2
      public/main/mySpace/session_admin_teachers.php
  30. 2
      public/main/mySpace/teachers.php
  31. 2
      public/main/session/index.php
  32. 75
      public/main/tracking/courseLog.php
  33. 47
      public/main/tracking/course_log_tools.php
  34. 24
      public/main/tracking/exams.php
  35. 2
      public/plugin/azure_active_directory/src/callback.php

@ -34,9 +34,7 @@ $user_id = isset($_GET['user']) ? (int) $_GET['user'] : 0;
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_anonymous = api_get_anonymous_id(); $user_anonymous = api_get_anonymous_id();
$current_user_id = api_get_user_id(); $current_user_id = api_get_user_id();
$userStatus = $user_info['status'];
$userStatus = api_get_user_status($user_id);
$firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null; $firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null;
// setting the name of the tool // setting the name of the tool

@ -36,8 +36,8 @@ if ($pluginCalendar) {
$user_id = api_get_user_id(); $user_id = api_get_user_id();
$courseUserList = CourseManager::get_courses_list_by_user_id($user_id); $courseUserList = CourseManager::get_courses_list_by_user_id($user_id);
$dates = $issues = ''; $dates = $issues = '';
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0; $sessionId = isset($_GET['sid']) ? (int) $_GET['sid'] : 0;
$courseCode = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : null; $courseId = isset($_GET['cid']) ? (int) $_GET['cid'] : 0;
if (!empty($courseUserList)) { if (!empty($courseUserList)) {
$items = MySpace::get_connections_from_course_list( $items = MySpace::get_connections_from_course_list(
@ -78,7 +78,7 @@ if (!empty($courseUserList)) {
} }
$content = Tracking::show_user_progress($user_id, $sessionId); $content = Tracking::show_user_progress($user_id, $sessionId);
$content .= Tracking::show_course_detail($user_id, $courseCode, $sessionId); $content .= Tracking::show_course_detail($user_id, $courseId, $sessionId);
if (!empty($dates)) { if (!empty($dates)) {
if (!empty($content)) { if (!empty($content)) {

@ -509,6 +509,7 @@ function display_addcategory_form($category_name = '', $id = 0, $action = '')
function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = 0) function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = 0)
{ {
$course_info = api_get_course_info(); $course_info = api_get_course_info();
$course = api_get_course_entity();
$_user = api_get_user_info(); $_user = api_get_user_info();
$is_courseAdmin = api_is_course_admin(); $is_courseAdmin = api_is_course_admin();
$is_courseTutor = api_is_course_tutor(); $is_courseTutor = api_is_course_tutor();
@ -687,7 +688,7 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id =
if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin) if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin)
&& 'true' == $allowGroups || 'true' === $allowStudentToStudent && 'true' == $allowGroups || 'true' === $allowStudentToStudent
) { ) {
$complete_group_list_for_dropbox = GroupManager::get_group_list(null, $course_info); $complete_group_list_for_dropbox = GroupManager::get_group_list(null, $course);
if (count($complete_group_list_for_dropbox) > 0) { if (count($complete_group_list_for_dropbox) > 0) {
foreach ($complete_group_list_for_dropbox as $current_group) { foreach ($complete_group_list_for_dropbox as $current_group) {

@ -1078,7 +1078,7 @@ if ('student_progress' == $origin) {
} elseif ('myprogress' == $origin) { } elseif ('myprogress' == $origin) {
?> ?>
<button type="button" class="save" <button type="button" class="save"
onclick="top.location.href='../auth/my_progress.php?course=<?php echo api_get_course_id(); ?>'" onclick="top.location.href='../auth/my_progress.php?cid=<?php echo api_get_course_int_id(); ?>'"
value="<?php echo get_lang('Quit test'); ?>"> value="<?php echo get_lang('Quit test'); ?>">
<?php echo get_lang('Quit test'); ?> <?php echo get_lang('Quit test'); ?>
</button> </button>

@ -31,7 +31,7 @@ $result = ExerciseLib::get_exam_results_data(
$exerciseId, $exerciseId,
'', '',
false, false,
null, api_get_course_int_id(),
false, false,
false, false,
[], [],

@ -239,13 +239,15 @@ if ('true' === api_get_setting('allow_group_categories')) {
'title' => get_lang('Default groups'), 'title' => get_lang('Default groups'),
]; ];
$categories = array_merge([$defaultCategory], $categories); $categories = array_merge([$defaultCategory], $categories);
$course = api_get_course_entity();
foreach ($categories as $index => $category) { foreach ($categories as $index => $category) {
$categoryId = $category['iid']; $categoryId = $category['iid'];
$groupList = GroupManager::get_group_list($categoryId, [], $groupList = GroupManager::get_group_list(
null, $categoryId,
$course,
null,
null, null,
false, false,
null, null,
true true
); );

@ -21,8 +21,7 @@ $current_course_tool = TOOL_GROUP;
api_protect_course_script(true); api_protect_course_script(true);
$nameTools = get_lang('Groups overview'); $nameTools = get_lang('Groups overview');
$courseId = api_get_course_int_id(); $course = api_get_course_entity();
$courseInfo = api_get_course_info();
$groupId = isset($_GET['id']) ? (int) $_GET['id'] : 0; $groupId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$keyword = $_GET['keyword'] ?? ''; $keyword = $_GET['keyword'] ?? '';
@ -80,10 +79,10 @@ if (isset($_GET['action'])) {
break; break;
case 'export_pdf': case 'export_pdf':
$content = GroupManager::getOverview($courseInfo, $keyword); $content = GroupManager::getOverview($course, $keyword);
$pdf = new PDF(); $pdf = new PDF();
$extra = '<div style="text-align:center"><h2>'.get_lang('Groups list').'</h2></div>'; $extra = '<div style="text-align:center"><h2>'.get_lang('Groups list').'</h2></div>';
$extra .= '<strong>'.get_lang('Course').': </strong>'.$courseInfo['title'].' ('.$courseInfo['code'].')'; $extra .= '<strong>'.get_lang('Course').': </strong>'.$course->getTitle().' ('.$course->getCode().')';
$content = $extra.$content; $content = $extra.$content;
$pdf->content_to_pdf($content, null, null, api_get_course_id()); $pdf->content_to_pdf($content, null, null, api_get_course_id());
@ -112,7 +111,7 @@ if (isset($_GET['action'])) {
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')]; $interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
$origin = api_get_origin(); $origin = api_get_origin();
if ('learnpath' != $origin) { if ('learnpath' !== $origin) {
// So we are not in learnpath tool // So we are not in learnpath tool
if (!api_is_allowed_in_course()) { if (!api_is_allowed_in_course()) {
api_not_allowed(true); api_not_allowed(true);
@ -157,7 +156,7 @@ Display::return_icon('user.png', get_lang('Go to').' '.get_lang('Users'), '', IC
// Action links // Action links
echo Display::toolbarAction('actions', [$actions, GroupManager::getSearchForm()]); echo Display::toolbarAction('actions', [$actions, GroupManager::getSearchForm()]);
echo GroupManager::getOverview($courseInfo, $keyword); echo GroupManager::getOverview($course, $keyword);
if ('learnpath' !== $origin) { if ('learnpath' !== $origin) {
Display::display_footer(); Display::display_footer();

@ -6,10 +6,11 @@ use Chamilo\CoreBundle\Framework\Container;
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $action = $_REQUEST['a'] ?? null;
$isAllowedToEdit = api_is_allowed_to_edit(); $isAllowedToEdit = api_is_allowed_to_edit();
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
$course = api_get_course_entity();
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
$courseCode = api_get_course_id(); $courseCode = api_get_course_id();
$groupId = api_get_group_id(); $groupId = api_get_group_id();
@ -78,7 +79,7 @@ switch ($action) {
$previewUsers[] = $student['user_id']; $previewUsers[] = $student['user_id'];
} }
$groupList = GroupManager::get_group_list(null, $courseInfo, null, $sessionId); $groupList = GroupManager::get_group_list(null, $course, null, $sessionId);
foreach ($groupList as $group) { foreach ($groupList as $group) {
$previewGroups[] = $group['iid']; $previewGroups[] = $group['iid'];
} }

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi; use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuiz;
/** /**
* Responses to AJAX calls. * Responses to AJAX calls.
@ -310,16 +312,22 @@ switch ($action) {
break; break;
case 'search_exercise_by_course': case 'search_exercise_by_course':
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$course = api_get_course_info_by_id($_GET['course_id']); $course = api_get_course_entity($_GET['course_id']);
$session_id = (!empty($_GET['session_id'])) ? (int) $_GET['session_id'] : 0; $session_id = !empty($_GET['session_id']) ? $_GET['session_id'] : 0;
$exercises = ExerciseLib::get_all_exercises( $session = api_get_session_entity($session_id);
$qb = Container::getQuizRepository()->findAllByCourse($course, $session, $_GET['q'], 2, false);
/** @var CQuiz[] $exercises */
$exercises = $qb->getQuery()->getResult();
/*$exercises = ExerciseLib::get_all_exercises(
$course, $course,
$session_id, $session_id,
false, false,
$_GET['q'], $_GET['q'],
true, true,
3 3
); );*/
foreach ($exercises as $exercise) { foreach ($exercises as $exercise) {
$data[] = ['id' => $exercise->getIid(), 'text' => html_entity_decode($exercise->getTitle())]; $data[] = ['id' => $exercise->getIid(), 'text' => html_entity_decode($exercise->getTitle())];

@ -4,13 +4,13 @@
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; $action = $_REQUEST['a'] ?? '';
$isAllowedToEdit = api_is_allowed_to_edit(); $isAllowedToEdit = api_is_allowed_to_edit();
switch ($action) { switch ($action) {
case 'search': case 'search':
if ($isAllowedToEdit) { if ($isAllowedToEdit) {
$groups = GroupManager::get_group_list(null, api_get_course_info(), null, 0, false, $_REQUEST['q']); $groups = GroupManager::get_group_list(null, api_get_course_entity(), null, 0, false, $_REQUEST['q']);
$list = []; $list = [];
foreach ($groups as $group) { foreach ($groups as $group) {
$list[] = [ $list[] = [

@ -654,7 +654,8 @@ switch ($action) {
$count = ExerciseLib::get_count_exam_results( $count = ExerciseLib::get_count_exam_results(
$exercise_id, $exercise_id,
$whereCondition $whereCondition,
api_get_course_int_id()
); );
break; break;
case 'get_exercise_results_report': case 'get_exercise_results_report':
@ -687,7 +688,7 @@ switch ($action) {
$count = ExerciseLib::get_count_exam_results( $count = ExerciseLib::get_count_exam_results(
$exerciseId, $exerciseId,
$whereCondition, $whereCondition,
$courseInfo['code'], $courseInfo['real_id'],
true true
); );
break; break;
@ -1519,7 +1520,9 @@ switch ($action) {
$sidx, $sidx,
$sord, $sord,
$exercise_id, $exercise_id,
$whereCondition $whereCondition,
false,
api_get_course_int_id()
); );
break; break;
case 'get_exercise_results_report': case 'get_exercise_results_report':
@ -1579,7 +1582,7 @@ switch ($action) {
if (!empty($categoryList)) { if (!empty($categoryList)) {
foreach ($categoryList as $categoryInfo) { foreach ($categoryList as $categoryInfo) {
$label = 'category_'.$categoryInfo['id']; $label = 'category_'.$categoryInfo['id'];
if ('excel' == $operation) { if ('excel' === $operation) {
$columns[] = $label.'_score_percentage'; $columns[] = $label.'_score_percentage';
$columns[] = $label.'_only_score'; $columns[] = $label.'_only_score';
$columns[] = $label.'_total'; $columns[] = $label.'_total';
@ -1610,7 +1613,7 @@ switch ($action) {
$exerciseId, $exerciseId,
$whereCondition, $whereCondition,
false, false,
$courseInfo['code'], $courseInfo['real_id'],
true, true,
true, true,
$extraFieldsToAdd, $extraFieldsToAdd,

@ -756,7 +756,6 @@ class AddCourse
$course = new Course(); $course = new Course();
$course $course
->setCode($code) ->setCode($code)
->setDirectory($directory)
->setCourseLanguage($course_language) ->setCourseLanguage($course_language)
->setTitle($title) ->setTitle($title)
->setDescription(get_lang('Course Description')) ->setDescription(get_lang('Course Description'))

@ -8,7 +8,7 @@ use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CCalendarEvent; use Chamilo\CourseBundle\Entity\CCalendarEvent;
use Chamilo\CourseBundle\Entity\CCalendarEventAttachment; use Chamilo\CourseBundle\Entity\CCalendarEventAttachment;
use Chamilo\CourseBundle\Entity\CGroup; use Chamilo\CourseBundle\Entity\CGroup;
use Doctrine\DBAL\Types\Types; use Chamilo\CoreBundle\Entity\Course;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
/** /**
@ -954,7 +954,7 @@ class Agenda
$this->getPlatformEvents($start, $end); $this->getPlatformEvents($start, $end);
break; break;
case 'course': case 'course':
$courseInfo = api_get_course_info_by_id($courseId); $course = api_get_course_entity($courseId);
// Session coach can see all events inside a session. // Session coach can see all events inside a session.
if (api_is_coach()) { if (api_is_coach()) {
@ -962,7 +962,7 @@ class Agenda
$this->getCourseEvents( $this->getCourseEvents(
$start, $start,
$end, $end,
$courseInfo, $course,
$groupId, $groupId,
$this->sessionId, $this->sessionId,
$user_id $user_id
@ -980,7 +980,7 @@ class Agenda
$this->getCourseEvents( $this->getCourseEvents(
$start, $start,
$end, $end,
$courseInfo, $course,
$groupId, $groupId,
$this->sessionId, $this->sessionId,
$user_id $user_id
@ -1056,13 +1056,11 @@ class Agenda
if (!empty($my_courses)) { if (!empty($my_courses)) {
foreach ($my_courses as $course_item) { foreach ($my_courses as $course_item) {
$courseInfo = api_get_course_info_by_id( $course = api_get_course_entity($course_item['real_id']);
$course_item['real_id']
);
$this->getCourseEvents( $this->getCourseEvents(
$start, $start,
$end, $end,
$courseInfo, $course,
0, 0,
$my_session_id $my_session_id
); );
@ -1073,15 +1071,13 @@ class Agenda
if (!empty($my_course_list) && false == $sessionFilterActive) { if (!empty($my_course_list) && false == $sessionFilterActive) {
foreach ($my_course_list as $courseInfoItem) { foreach ($my_course_list as $courseInfoItem) {
$courseInfo = api_get_course_info_by_id( $course = api_get_course_entity($courseInfoItem['real_id']);
$courseInfoItem['real_id']
);
if (isset($courseId) && !empty($courseId)) { if (isset($courseId) && !empty($courseId)) {
if ($courseInfo['real_id'] == $courseId) { if ($course->getId() == $courseId) {
$this->getCourseEvents( $this->getCourseEvents(
$start, $start,
$end, $end,
$courseInfo, $course,
0, 0,
0, 0,
$user_id $user_id
@ -1091,7 +1087,7 @@ class Agenda
$this->getCourseEvents( $this->getCourseEvents(
$start, $start,
$end, $end,
$courseInfo, $course,
0, 0,
0, 0,
$user_id $user_id
@ -1399,6 +1395,7 @@ class Agenda
if (!empty($courses)) { if (!empty($courses)) {
foreach ($courses as $course) { foreach ($courses as $course) {
$course = api_get_course_entity($course['real_id']);
$this->getCourseEvents( $this->getCourseEvents(
$start, $start,
$end, $end,
@ -1415,7 +1412,7 @@ class Agenda
/** /**
* @param int $start * @param int $start
* @param int $end * @param int $end
* @param array $courseInfo * @param Course $course
* @param int $groupId * @param int $groupId
* @param int $sessionId * @param int $sessionId
* @param int $user_id * @param int $user_id
@ -1426,7 +1423,7 @@ class Agenda
public function getCourseEvents( public function getCourseEvents(
$start, $start,
$end, $end,
$courseInfo, Course $course,
$groupId = 0, $groupId = 0,
$sessionId = 0, $sessionId = 0,
$user_id = 0, $user_id = 0,
@ -1438,23 +1435,18 @@ class Agenda
$start = !empty($start) ? api_get_utc_datetime($start) : null; $start = !empty($start) ? api_get_utc_datetime($start) : null;
$end = !empty($end) ? api_get_utc_datetime($end) : null; $end = !empty($end) ? api_get_utc_datetime($end) : null;
if (empty($courseInfo)) { if (null === $course) {
return [];
}
$courseId = $courseInfo['real_id'];
if (empty($courseId)) {
return []; return [];
} }
$courseId = $course->getId();
$userId = api_get_user_id(); $userId = api_get_user_id();
$sessionId = (int) $sessionId; $sessionId = (int) $sessionId;
$user_id = (int) $user_id; $user_id = (int) $user_id;
$groupList = GroupManager::get_group_list( $groupList = GroupManager::get_group_list(
null, null,
$courseInfo, $course,
null, null,
$sessionId $sessionId
); );
@ -1462,10 +1454,7 @@ class Agenda
if (api_is_platform_admin() || api_is_allowed_to_edit()) { if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$isAllowToEdit = true; $isAllowToEdit = true;
} else { } else {
$isAllowToEdit = CourseManager::isCourseTeacher( $isAllowToEdit = CourseManager::isCourseTeacher($userId, $courseId);
$userId,
$courseId
);
} }
$isAllowToEditByHrm = false; $isAllowToEditByHrm = false;
@ -1494,9 +1483,8 @@ class Agenda
} }
$repo = Container::getCalendarEventRepository(); $repo = Container::getCalendarEventRepository();
$courseEntity = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId); $session = api_get_session_entity($sessionId);
$qb = $repo->getResourcesByCourseOnly($courseEntity, $courseEntity->getResourceNode()); $qb = $repo->getResourcesByCourseOnly($course, $course->getResourceNode());
$userCondition = ''; $userCondition = '';
if ($isAllowToEdit) { if ($isAllowToEdit) {
@ -1685,7 +1673,7 @@ class Agenda
}*/ }*/
$event['session_name'] = $sessionInfo['name'] ?? ''; $event['session_name'] = $sessionInfo['name'] ?? '';
$event['course_name'] = $courseInfo['title'] ?? ''; $event['course_name'] = $course->getTitle();
/*if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { /*if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
$event['borderColor'] = $event['backgroundColor'] = $this->event_group_color; $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color;
@ -1799,7 +1787,7 @@ class Agenda
}*/ }*/
$event['sent_to'] = implode('<br />', $sentTo); $event['sent_to'] = implode('<br />', $sentTo);
$event['description'] = $row->getContent(); $event['description'] = $row->getContent();
$event['visibility'] = $row->isVisible($courseEntity, $session) ? 1 : 0; $event['visibility'] = $row->isVisible($course, $session) ? 1 : 0;
$event['real_id'] = $eventId; $event['real_id'] = $eventId;
$event['allDay'] = $row->getAllDay(); $event['allDay'] = $row->getAllDay();
$event['parent_event_id'] = $row->getParentEvent() ? $row->getParentEvent()->getIid() : null; $event['parent_event_id'] = $row->getParentEvent() ? $row->getParentEvent()->getIid() : null;

@ -1033,7 +1033,7 @@ function api_protect_course_script($print_headers = false, $allow_session_admins
} }
//If password is set and user is not registered to the course then the course is not visible //If password is set and user is not registered to the course then the course is not visible
if (false == $isAllowedInCourse && if (false === $isAllowedInCourse &&
isset($course_info['registration_code']) && isset($course_info['registration_code']) &&
!empty($course_info['registration_code']) !empty($course_info['registration_code'])
) { ) {
@ -2416,7 +2416,7 @@ function api_format_course_array(Course $course = null)
$courseData['code'] = $courseData['sysCode'] = $course->getCode(); $courseData['code'] = $courseData['sysCode'] = $course->getCode();
$courseData['name'] = $courseData['title'] = $course->getTitle(); $courseData['name'] = $courseData['title'] = $course->getTitle();
$courseData['official_code'] = $courseData['visual_code'] = $course->getVisualCode(); $courseData['official_code'] = $courseData['visual_code'] = $course->getVisualCode();
$courseData['path'] = $courseData['directory'] = $course->getDirectory(); // Use as key in path. //$courseData['path'] = $courseData['directory'] = $course->getDirectory(); // Use as key in path.
$courseData['creation_date'] = $course->getCreationDate()->format('Y-m-d H:i:s'); $courseData['creation_date'] = $course->getCreationDate()->format('Y-m-d H:i:s');
$courseData['titular'] = $course->getTutorName(); $courseData['titular'] = $course->getTutorName();
$courseData['language'] = $courseData['course_language'] = $course->getCourseLanguage(); $courseData['language'] = $courseData['course_language'] = $course->getCourseLanguage();
@ -2631,27 +2631,27 @@ function get_status_from_code($status_code)
{ {
switch ($status_code) { switch ($status_code) {
case STUDENT: case STUDENT:
return get_lang('Student', ''); return get_lang('Student');
case COURSEMANAGER: case COURSEMANAGER:
return get_lang('Teacher', ''); return get_lang('Teacher');
case SESSIONADMIN: case SESSIONADMIN:
return get_lang('SessionsAdmin', ''); return get_lang('SessionsAdmin');
case DRH: case DRH:
return get_lang('Drh', ''); return get_lang('Drh');
case ANONYMOUS: case ANONYMOUS:
return get_lang('Anonymous', ''); return get_lang('Anonymous');
case PLATFORM_ADMIN: case PLATFORM_ADMIN:
return get_lang('Administrator', ''); return get_lang('Administrator');
case SESSION_COURSE_COACH: case SESSION_COURSE_COACH:
return get_lang('SessionCourseCoach', ''); return get_lang('SessionCourseCoach');
case SESSION_GENERAL_COACH: case SESSION_GENERAL_COACH:
return get_lang('SessionGeneralCoach', ''); return get_lang('SessionGeneralCoach');
case COURSE_TUTOR: case COURSE_TUTOR:
return get_lang('CourseAssistant', ''); return get_lang('CourseAssistant');
case STUDENT_BOSS: case STUDENT_BOSS:
return get_lang('StudentBoss', ''); return get_lang('StudentBoss');
case INVITEE: case INVITEE:
return get_lang('Invitee', ''); return get_lang('Invitee');
} }
} }
@ -3398,38 +3398,6 @@ function api_is_invitee()
return isset($user['status']) && INVITEE == $user['status']; return isset($user['status']) && INVITEE == $user['status'];
} }
/**
* This function checks whether a session is assigned into a category.
*
* @param int - session id
* @param string - category name
*
* @return bool - true if is found, otherwise false
*/
function api_is_session_in_category($session_id, $category_name)
{
$session_id = (int) $session_id;
$category_name = Database::escape_string($category_name);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$sql = "SELECT 1
FROM $tbl_session
WHERE $session_id IN (
SELECT s.id FROM $tbl_session s, $tbl_session_category sc
WHERE
s.session_category_id = sc.id AND
sc.name LIKE '%$category_name'
)";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
return true;
} else {
return false;
}
}
/** /**
* Displays the title of a tool. * Displays the title of a tool.
* Normal use: parameter is a string: * Normal use: parameter is a string:
@ -3855,18 +3823,6 @@ function api_is_allowed($tool, $action, $task_id = 0)
*/ */
function api_is_anonymous($user_id = null, $db_check = false) function api_is_anonymous($user_id = null, $db_check = false)
{ {
/*if ($db_check) {
if (!isset($user_id)) {
$user_id = api_get_user_id();
}
$info = api_get_user_info($user_id);
if (6 == $info['status'] || 0 == $user_id || empty($info)) {
return true;
}
}*/
return !Container::getAuthorizationChecker()->isGranted('IS_AUTHENTICATED_FULLY'); return !Container::getAuthorizationChecker()->isGranted('IS_AUTHENTICATED_FULLY');
} }

@ -1866,12 +1866,12 @@ HOTSPOT;
* *
* @param int $exerciseId * @param int $exerciseId
* @param array $conditions * @param array $conditions
* @param string $courseCode * @param int $courseId
* @param bool $showSession * @param bool $showSession
* *
* @return array * @return array
*/ */
public static function get_count_exam_results($exerciseId, $conditions, $courseCode = '', $showSession = false) public static function get_count_exam_results($exerciseId, $conditions, $courseId, $showSession = false)
{ {
$count = self::get_exam_results_data( $count = self::get_exam_results_data(
null, null,
@ -1881,7 +1881,7 @@ HOTSPOT;
$exerciseId, $exerciseId,
$conditions, $conditions,
true, true,
$courseCode, $courseId,
$showSession $showSession
); );
@ -1900,7 +1900,7 @@ HOTSPOT;
* @param int $exercise_id * @param int $exercise_id
* @param null $extra_where_conditions * @param null $extra_where_conditions
* @param bool $get_count * @param bool $get_count
* @param string $courseCode * @param int $courseId
* @param bool $showSessionField * @param bool $showSessionField
* @param bool $showExerciseCategories * @param bool $showExerciseCategories
* @param array $userExtraFieldsToAdd * @param array $userExtraFieldsToAdd
@ -1918,7 +1918,7 @@ HOTSPOT;
$exercise_id, $exercise_id,
$extra_where_conditions = null, $extra_where_conditions = null,
$get_count = false, $get_count = false,
$courseCode = null, $courseId = null,
$showSessionField = false, $showSessionField = false,
$showExerciseCategories = false, $showExerciseCategories = false,
$userExtraFieldsToAdd = [], $userExtraFieldsToAdd = [],
@ -1928,16 +1928,12 @@ HOTSPOT;
) { ) {
//@todo replace all this globals //@todo replace all this globals
global $filter; global $filter;
$courseCode = empty($courseCode) ? api_get_course_id() : $courseCode; $courseId = (int) $courseId;
$courseInfo = api_get_course_info($courseCode); $course = api_get_course_entity($courseId);
if (null === $course) {
if (empty($courseInfo)) {
return []; return [];
} }
//$documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
$course_id = $courseInfo['real_id'];
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$exercise_id = (int) $exercise_id; $exercise_id = (int) $exercise_id;
@ -1974,7 +1970,7 @@ HOTSPOT;
LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr
ON (ttte.exe_id = tr.exe_id) ON (ttte.exe_id = tr.exe_id)
WHERE WHERE
c_id = $course_id AND c_id = $courseId AND
exe_exo_id = $exercise_id exe_exo_id = $exercise_id
$sessionCondition $sessionCondition
)"; )";
@ -1997,9 +1993,9 @@ HOTSPOT;
g.id as group_id g.id as group_id
FROM $TBL_USER u FROM $TBL_USER u
INNER JOIN $TBL_GROUP_REL_USER gru INNER JOIN $TBL_GROUP_REL_USER gru
ON (gru.user_id = u.id AND gru.c_id= $course_id ) ON (gru.user_id = u.id AND gru.c_id= $courseId )
INNER JOIN $TBL_GROUP g INNER JOIN $TBL_GROUP g
ON (gru.group_id = g.id AND g.c_id= $course_id ) ON (gru.group_id = g.id AND g.c_id= $courseId )
)"; )";
} }
@ -2060,9 +2056,9 @@ HOTSPOT;
g.iid as group_id g.iid as group_id
FROM $TBL_USER u FROM $TBL_USER u
LEFT OUTER JOIN $TBL_GROUP_REL_USER gru LEFT OUTER JOIN $TBL_GROUP_REL_USER gru
ON (gru.user_id = u.id AND gru.c_id= $course_id ) ON (gru.user_id = u.id AND gru.c_id= $courseId )
LEFT OUTER JOIN $TBL_GROUP g LEFT OUTER JOIN $TBL_GROUP g
ON (gru.group_id = g.id AND g.c_id = $course_id ) ON (gru.group_id = g.id AND g.c_id = $courseId )
)"; )";
} }
@ -2079,7 +2075,7 @@ HOTSPOT;
} }
$sqlFromOption = " , $TBL_GROUP_REL_USER AS gru "; $sqlFromOption = " , $TBL_GROUP_REL_USER AS gru ";
$sqlWhereOption = " AND gru.c_id = $course_id AND gru.user_id = user.id "; $sqlWhereOption = " AND gru.c_id = $courseId AND gru.user_id = user.id ";
$first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname"; $first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname";
if ($get_count) { if ($get_count) {
@ -2118,7 +2114,7 @@ HOTSPOT;
INNER JOIN $sql_inner_join_tbl_user AS user INNER JOIN $sql_inner_join_tbl_user AS user
ON (user.user_id = exe_user_id) ON (user.user_id = exe_user_id)
WHERE WHERE
te.c_id = $course_id $session_id_and AND te.c_id = $courseId $session_id_and AND
ce.active <> -1 ce.active <> -1
$exercise_where $exercise_where
$extra_where_conditions $extra_where_conditions
@ -2136,7 +2132,7 @@ HOTSPOT;
return $rowx[0]; return $rowx[0];
} }
$teacher_list = CourseManager::get_teacher_list_from_course_code($courseCode); $teacher_list = CourseManager::get_teacher_list_from_course_code($course->getCode());
$teacher_id_list = []; $teacher_id_list = [];
if (!empty($teacher_list)) { if (!empty($teacher_list)) {
foreach ($teacher_list as $teacher) { foreach ($teacher_list as $teacher) {
@ -2172,7 +2168,7 @@ HOTSPOT;
$results[] = $rowx; $results[] = $rowx;
} }
$group_list = GroupManager::get_group_list(null, $courseInfo); $group_list = GroupManager::get_group_list(null, $course);
$clean_group_list = []; $clean_group_list = [];
if (!empty($group_list)) { if (!empty($group_list)) {
foreach ($group_list as $group) { foreach ($group_list as $group) {
@ -2187,7 +2183,7 @@ HOTSPOT;
if (is_array($results)) { if (is_array($results)) {
$users_array_id = []; $users_array_id = [];
$from_gradebook = false; $from_gradebook = false;
if (isset($_GET['gradebook']) && 'view' == $_GET['gradebook']) { if (isset($_GET['gradebook']) && 'view' === $_GET['gradebook']) {
$from_gradebook = true; $from_gradebook = true;
} }
$sizeof = count($results); $sizeof = count($results);
@ -2200,7 +2196,7 @@ HOTSPOT;
// Looping results // Looping results
for ($i = 0; $i < $sizeof; $i++) { for ($i = 0; $i < $sizeof; $i++) {
$revised = $results[$i]['revised']; $revised = $results[$i]['revised'];
if ('incomplete' == $results[$i]['completion_status']) { if ('incomplete' === $results[$i]['completion_status']) {
// If the exercise was incomplete, we need to determine // If the exercise was incomplete, we need to determine
// if it is still into the time allowed, or if its // if it is still into the time allowed, or if its
// allowed time has expired and it can be closed // allowed time has expired and it can be closed
@ -2244,7 +2240,8 @@ HOTSPOT;
} }
$lp_name = null; $lp_name = null;
if ($lp_obj) { if ($lp_obj) {
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$results[$i]['orig_lp_id']; $url = api_get_path(WEB_CODE_PATH).
'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$results[$i]['orig_lp_id'];
$lp_name = Display::url( $lp_name = Display::url(
$lp_obj['lp_name'], $lp_obj['lp_name'],
$url, $url,
@ -2469,7 +2466,7 @@ HOTSPOT;
} }
} }
$objExercise = new Exercise($course_id); $objExercise = new Exercise($courseId);
if ($showExerciseCategories) { if ($showExerciseCategories) {
// Getting attempt info // Getting attempt info
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId); $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
@ -3065,30 +3062,9 @@ EOT;
return []; return [];
} }
/*$activeFilter = 0;
if (2 !== $active) {
$activeFilter = (int) $active;
}*/
/*$now = api_get_utc_datetime();
$timeConditions = '';
if ($check_publication_dates) {
// Start and end are set
$timeConditions = " AND ((start_time <> '' AND start_time < '$now' AND end_time <> '' AND end_time > '$now' ) OR ";
// only start is set
$timeConditions .= " (start_time <> '' AND start_time < '$now' AND end_time is NULL) OR ";
// only end is set
$timeConditions .= " (start_time IS NULL AND end_time <> '' AND end_time > '$now') OR ";
// nothing is set
$timeConditions .= ' (start_time IS NULL AND end_time IS NULL)) ';
}
$needle_where = !empty($search) ? " AND title LIKE '?' " : '';
$needle = !empty($search) ? "%".$search."%" : '';*/
$repo = Container::getQuizRepository(); $repo = Container::getQuizRepository();
return $repo->findQuizzes($course, $session, (string) $search, $active); return $repo->findAllByCourse($course, $session, (string) $search, $active);
// Show courses by active status // Show courses by active status
/*if (true == $search_all_sessions) { /*if (true == $search_all_sessions) {
@ -3602,28 +3578,6 @@ EOT;
return $avg_score; return $avg_score;
} }
/**
* @param string $course_code
* @param int $session_id
*
* @return CQuiz
*/
public static function get_exercises_to_be_taken($course_code, $session_id)
{
$course_info = api_get_course_info($course_code);
$exercises = self::get_all_exercises($course_info, $session_id);
$result = [];
$now = time() + 15 * 24 * 60 * 60;
foreach ($exercises as $exercise_item) {
$endTime = $exercise_item->getEndTime() ?: null;
if (null !== $endTime && $endTime->getTimestamp() < $now) {
$result[] = $exercise_item;
}
}
return $result;
}
/** /**
* Get student results (only in completed exercises) stats by question. * Get student results (only in completed exercises) stats by question.
* *

@ -92,59 +92,38 @@ class GroupManager
/** /**
* Get list of groups for current course. * Get list of groups for current course.
* *
* @param int $categoryId The id of the category from which the groups are * @param int $categoryId The id of the category from which the groups are
* requested * requested
* @param array $course_info Default is current course * @param Course $course Default is current course
* @param int $status group status * @param int $status group status
* @param int $sessionId * @param int $sessionId
* @param bool $getCount * @param bool $getCount
* @param bool $notInGroup Get groups not in a category * @param bool $notInGroup Get groups not in a category
* *
* @return array an array with all information about the groups * @return array an array with all information about the groups
*/ */
public static function get_group_list( public static function get_group_list(
$categoryId = null, $categoryId = null,
$course_info = [], $course = null,
$status = null, $status = null,
$sessionId = 0, $sessionId = 0,
$getCount = false, $getCount = false,
$filterByKeyword = '', $filterByKeyword = '',
$returnEntityList = false $returnEntityList = false
) { ) {
$course_info = empty($course_info) ? api_get_course_info() : $course_info; $course = $course ?? api_get_course_entity();
if (empty($course_info)) { if (null === $course) {
return []; return [];
} }
$sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId; $sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId;
$course_id = $course_info['real_id'];
$repo = Container::getGroupRepository(); $repo = Container::getGroupRepository();
$course = api_get_course_entity($course_id);
$session = api_get_session_entity($sessionId); $session = api_get_session_entity($sessionId);
//$group = api_get_group_entity(api_get_group_id()); $qb = $repo->findAllByCourse($course, $session, $filterByKeyword, $status);
$group = null;
$qb = $repo->getResourcesByCourse($course, $session, $group);
if (null === $categoryId) {
$qb
->andWhere('resource.category is NULL');
} else {
$qb
->andWhere('resource.category = :category')
->setParameter('category', $categoryId);
}
if (!empty($filterByKeyword)) {
$qb->andWhere($qb->expr()->like('resource.name', ':keyword'));
$qb->setParameter('keyword', "%$filterByKeyword%");
}
if ($getCount) { if ($getCount) {
$qb->select('count(resource)'); return $repo->getCount($qb);
return $qb->getQuery()->getSingleScalarResult();
} }
if ($returnEntityList) { if ($returnEntityList) {
@ -2851,12 +2830,12 @@ class GroupManager
} }
/** /**
* @param array $courseInfo * @param Course $course
* @param string $keyword * @param string $keyword
* *
* @return string * @return string
*/ */
public static function getOverview($courseInfo, $keyword = '') public static function getOverview(Course $course, $keyword = '')
{ {
$content = null; $content = null;
$categories = self::get_categories(); $categories = self::get_categories();
@ -2866,7 +2845,7 @@ class GroupManager
if ('true' === api_get_setting('allow_group_categories')) { if ('true' === api_get_setting('allow_group_categories')) {
$content .= '<h2>'.$category['title'].'</h2>'; $content .= '<h2>'.$category['title'].'</h2>';
} }
$groups = self::get_group_list($category['iid'], $courseInfo, null, 0, false, $keyword); $groups = self::get_group_list($category['iid'], $course, null, 0, false, $keyword);
$content .= '<ul>'; $content .= '<ul>';
if (!empty($groups)) { if (!empty($groups)) {
foreach ($groups as $group) { foreach ($groups as $group) {
@ -2878,7 +2857,7 @@ class GroupManager
} }
// Check groups with no categories. // Check groups with no categories.
$groups = self::get_group_list(null, api_get_course_info(), null, api_get_session_id(), false, true); $groups = self::get_group_list(null, $course, null, api_get_session_id(), false, true);
if (!empty($groups)) { if (!empty($groups)) {
$content .= '<h2>'.get_lang('NoCategorySelected').'</h2>'; $content .= '<h2>'.get_lang('NoCategorySelected').'</h2>';
$content .= '<ul>'; $content .= '<ul>';

@ -760,10 +760,6 @@ function api_get_person_name(
switch ($format) { switch ($format) {
case PERSON_NAME_COMMON_CONVENTION: case PERSON_NAME_COMMON_CONVENTION:
$valid[$format][$language] = _api_get_person_name_convention($language, 'format'); $valid[$format][$language] = _api_get_person_name_convention($language, 'format');
$usernameOrderFromDatabase = api_get_setting('user_name_order');
if (isset($usernameOrderFromDatabase) && !empty($usernameOrderFromDatabase)) {
$valid[$format][$language] = $usernameOrderFromDatabase;
}
break; break;
case PERSON_NAME_WESTERN_ORDER: case PERSON_NAME_WESTERN_ORDER:
$valid[$format][$language] = '%t %f %l'; $valid[$format][$language] = '%t %f %l';

@ -1,6 +1,8 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use ChamiloSession as Session; use ChamiloSession as Session;
use CpChart\Cache as pCache; use CpChart\Cache as pCache;
use CpChart\Data as pData; use CpChart\Data as pData;
@ -117,7 +119,7 @@ class MySpace
'', '',
ICON_SIZE_MEDIUM ICON_SIZE_MEDIUM
), ),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php" api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
); );
$menuItems[] = Display::url( $menuItems[] = Display::url(
Display::return_icon( Display::return_icon(
@ -294,38 +296,32 @@ class MySpace
/** /**
* Creates a small table in the last column of the table with the user overview. * Creates a small table in the last column of the table with the user overview.
* *
* @param int $user_id the id of the user
*
* @return array List course * @return array List course
*/ */
public static function returnCourseTracking($user_id) public static function returnCourseTracking(User $user)
{ {
$user_id = (int) $user_id; $userId = $user->getId();
if (empty($user_id)) {
return [];
}
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
// getting all the courses of the user // getting all the courses of the user
$sql = "SELECT * FROM $tbl_course_user $sql = "SELECT * FROM $tbl_course_user
WHERE WHERE
user_id = $user_id AND user_id = $userId AND
relation_type <> ".COURSE_RELATION_TYPE_RRHH; relation_type <> ".COURSE_RELATION_TYPE_RRHH;
$result = Database::query($sql); $result = Database::query($sql);
$list = []; $list = [];
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$courseInfo = api_get_course_info_by_id($row['c_id']); $course = api_get_course_entity($row['c_id']);
$courseId = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
if (empty($courseInfo)) { if (null === $course) {
continue; continue;
} }
$avg_score = Tracking::get_avg_student_score($user_id, $courseCode); $courseId = $course->getId();
$courseCode = $course->getCode();
$avg_score = Tracking::get_avg_student_score($userId, $courseCode);
if (is_numeric($avg_score)) { if (is_numeric($avg_score)) {
$avg_score = round($avg_score, 2); $avg_score = round($avg_score, 2);
} else { } else {
@ -333,29 +329,34 @@ class MySpace
} }
// Student exercises results (obtained score, maximum score, number of exercises answered, score percentage) // Student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
$exercisesResults = self::exercises_results($user_id, $courseCode); $exercisesResults = self::exercises_results($userId, $courseCode);
$resultToString = ''; $resultToString = '';
if (!is_null($exercisesResults['percentage'])) { if (!is_null($exercisesResults['percentage'])) {
$resultToString = $exercisesResults['score_obtained'].'/'.$exercisesResults['score_possible'].' ( '.$exercisesResults['percentage'].'% )'; $resultToString =
$exercisesResults['score_obtained'].'/'.$exercisesResults['score_possible'].
' ( '.$exercisesResults['percentage'].'% )';
} }
$item = [ $item = [
'code' => $courseInfo['code'], 'code' => $courseCode,
'real_id' => $courseInfo['real_id'], 'real_id' => $courseId,
'title' => $courseInfo['title'], 'title' => $course->getTitle(),
'category' => '', 'category' => '',
//'category' => $courseInfo['categoryName'], // @todo show categories instead of 1 category //'category' => $courseInfo['categoryName'], // @todo show categories instead of 1 category
'image_small' => $courseInfo['course_image'], //'image_small' => $courseInfo['course_image'],
'image_large' => $courseInfo['course_image_large'], //'image_large' => $courseInfo['course_image_large'],
'time_spent' => api_time_to_hms(Tracking::get_time_spent_on_the_course($user_id, $courseId)), 'time_spent' => api_time_to_hms(Tracking::get_time_spent_on_the_course($userId, $courseId)),
'student_progress' => round(Tracking::get_avg_student_progress($user_id, $courseCode)), 'student_progress' => round(Tracking::get_avg_student_progress($userId, $courseCode)),
'student_score' => $avg_score, 'student_score' => $avg_score,
'student_message' => Tracking::count_student_messages($user_id, $courseCode), 'student_message' => Container::getForumPostRepository()->countUserForumPosts($user, $course),
'student_assignments' => Tracking::count_student_assignments($user_id, $courseCode), 'student_assignments' => Container::getStudentPublicationRepository()->countUserPublications($user, $course),
'student_exercises' => $resultToString, 'student_exercises' => $resultToString,
'questions_answered' => $exercisesResults['questions_answered'], 'questions_answered' => $exercisesResults['questions_answered'],
'last_connection' => Tracking::get_last_connection_date_on_the_course($user_id, $courseInfo), 'last_connection' => Tracking::get_last_connection_date_on_the_course(
$user_id,
['real_id' => $courseId]
),
]; ];
$list[] = $item; $list[] = $item;
} }
@ -374,26 +375,25 @@ class MySpace
* *
* @since April 2019 * @since April 2019
*/ */
public static function returnTrackingUserOverviewFilter($user_id) public static function returnTrackingUserOverviewFilter($userId)
{ {
$tpl = new Template('', false, false, false, false, false, false); $tpl = new Template('', false, false, false, false, false, false);
$userInfo = api_get_user_info($user_id); $user = api_get_user_entity($userId);
$url = Container::getIllustrationRepository()->getIllustrationUrl($user);
$avatar = UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_SMALL);
$user = [ $item = [
'id' => $user_id, 'id' => $user->getId(),
'code_user' => $userInfo['official_code'], 'code_user' => $user->getOfficialCode(),
'complete_name' => $userInfo['complete_name'], 'complete_name' => UserManager::formatUserFullName($user),
'username' => $userInfo['username'], 'username' => $user->getUsername(),
'course' => self::returnCourseTracking($user_id), 'course' => self::returnCourseTracking($user),
'avatar' => $avatar, 'avatar' => $url,
]; ];
$tpl->assign('item', $user); $tpl->assign('item', $item);
$templateName = $tpl->get_template('my_space/partials/tracking_user_overview.tpl'); $templateName = $tpl->get_template('my_space/partials/tracking_user_overview.tpl');
$content = $tpl->fetch($templateName);
return $content; return $tpl->fetch($templateName);
} }
/** /**
@ -1512,8 +1512,8 @@ class MySpace
$list = []; $list = [];
foreach ($courses as $course) { foreach ($courses as $course) {
$list[] = [ $list[] = [
'0' => $course['code'], '0' => $course['real_id'],
'col0' => $course['code'], 'col0' => $course['real_id'],
]; ];
} }
@ -1531,24 +1531,14 @@ class MySpace
*/ */
public static function course_tracking_filter($course_code, $url_params, $row) public static function course_tracking_filter($course_code, $url_params, $row)
{ {
$course_code = $row[0]; $courseId = $row[0];
$courseInfo = api_get_course_info($course_code); $course = api_get_course_entity($courseId);
$courseId = $courseInfo['real_id']; $courseCode = $course->getCode();
$tpl = new Template('', false, false, false, false, false, false); $tpl = new Template('', false, false, false, false, false, false);
$data = null; $data = null;
// database table definition
$tbl_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
// getting all the courses of the user
$sql = "SELECT *
FROM $tbl_user AS u
INNER JOIN $tbl_course_rel_user AS cu
ON cu.user_id = u.user_id
WHERE cu.c_id = '".$courseId."'";
$result = Database::query($sql);
$time_spent = 0; $time_spent = 0;
$progress = 0; $progress = 0;
$nb_progress_lp = 0; $nb_progress_lp = 0;
@ -1560,15 +1550,22 @@ class MySpace
$total_score_obtained = 0; $total_score_obtained = 0;
$total_score_possible = 0; $total_score_possible = 0;
$total_questions_answered = 0; $total_questions_answered = 0;
while ($row = Database::fetch_object($result)) {
$courseId = $course->getId();
$courseCode = $course->getCode();
$courseRelUsers = $course->getUsers();
foreach ($courseRelUsers as $courseRelUser) {
$user = $courseRelUser->getUser();
$userId = $user->getId();
// get time spent in the course and session // get time spent in the course and session
$time_spent += Tracking::get_time_spent_on_the_course( $time_spent += Tracking::get_time_spent_on_the_course(
$row->user_id, $userId,
$courseInfo['real_id'] $courseId
); );
$progress_tmp = Tracking::get_avg_student_progress( $progress_tmp = Tracking::get_avg_student_progress(
$row->user_id, $userId,
$course_code, $courseCode,
[], [],
null, null,
true true
@ -1576,8 +1573,8 @@ class MySpace
$progress += $progress_tmp[0]; $progress += $progress_tmp[0];
$nb_progress_lp += $progress_tmp[1]; $nb_progress_lp += $progress_tmp[1];
$score_tmp = Tracking::get_avg_student_score( $score_tmp = Tracking::get_avg_student_score(
$row->user_id, $userId,
$course_code, $courseCode,
[], [],
null, null,
true true
@ -1586,17 +1583,12 @@ class MySpace
$score += $score_tmp[0]; $score += $score_tmp[0];
$nb_score_lp += $score_tmp[1]; $nb_score_lp += $score_tmp[1];
} }
$nb_messages += Tracking::count_student_messages( $nb_messages += Container::getForumPostRepository($user, $course);
$row->user_id, $nb_assignments += Container::getStudentPublicationRepository($user, $course);
$course_code
);
$nb_assignments += Tracking::count_student_assignments(
$row->user_id,
$course_code
);
$last_login_date_tmp = Tracking::get_last_connection_date_on_the_course( $last_login_date_tmp = Tracking::get_last_connection_date_on_the_course(
$row->user_id, $userId,
$courseInfo, ['real_id' => $courseId],
null, null,
false false
); );
@ -1612,7 +1604,7 @@ class MySpace
} }
} }
$exercise_results_tmp = self::exercises_results($row->user_id, $course_code); $exercise_results_tmp = self::exercises_results($userId, $courseCode);
$total_score_obtained += $exercise_results_tmp['score_obtained']; $total_score_obtained += $exercise_results_tmp['score_obtained'];
$total_score_possible += $exercise_results_tmp['score_possible']; $total_score_possible += $exercise_results_tmp['score_possible'];
$total_questions_answered += $exercise_results_tmp['questions_answered']; $total_questions_answered += $exercise_results_tmp['questions_answered'];
@ -1648,13 +1640,13 @@ class MySpace
} }
$data = [ $data = [
'course_code' => $course_code, 'course_code' => $courseCode,
'id' => $courseId, 'id' => $courseId,
'image' => $courseInfo['course_image_large'], //'image' => $courseInfo['course_image_large'],
'image_small' => $courseInfo['course_image'], //'image_small' => $courseInfo['course_image'],
'title' => $courseInfo['title'], 'title' => $course->getTitle(),
'url' => $courseInfo['course_public_url'], //'url' => $courseInfo['course_public_url'],
'category' => $courseInfo['categoryName'], //'category' => $courseInfo['categoryName'],
'time_spent' => api_time_to_hms($time_spent), 'time_spent' => api_time_to_hms($time_spent),
'avg_progress' => $avg_progress, 'avg_progress' => $avg_progress,
'avg_score' => $avg_score, 'avg_score' => $avg_score,
@ -1667,9 +1659,8 @@ class MySpace
$tpl->assign('data', $data); $tpl->assign('data', $data);
$layout = $tpl->get_template('my_space/partials/tracking_course_overview.tpl'); $layout = $tpl->get_template('my_space/partials/tracking_course_overview.tpl');
$content = $tpl->fetch($layout);
return $content; return $tpl->fetch($layout);
} }
/** /**
@ -1725,21 +1716,15 @@ class MySpace
// the other lines (the data) // the other lines (the data)
foreach ($course_data as $key => $course) { foreach ($course_data as $key => $course) {
$course_code = $course[0]; $courseId = $course[0];
$courseInfo = api_get_course_info($course_code); $course = api_get_course_entity($courseId);
$course_title = $courseInfo['title']; $courseCode = $course->getCode();
$courseId = $courseInfo['real_id']; $course_title = $course->getTitle();
$csv_row = []; $csv_row = [];
$csv_row[] = $course_title; $csv_row[] = $course_title;
// getting all the courses of the session
$sql = "SELECT *
FROM $tbl_user AS u
INNER JOIN $tbl_course_rel_user AS cu
ON cu.user_id = u.user_id
WHERE cu.c_id = '".$courseId."'";
$result = Database::query($sql);
$time_spent = 0; $time_spent = 0;
$progress = 0; $progress = 0;
$nb_progress_lp = 0; $nb_progress_lp = 0;
@ -1751,15 +1736,20 @@ class MySpace
$total_score_obtained = 0; $total_score_obtained = 0;
$total_score_possible = 0; $total_score_possible = 0;
$total_questions_answered = 0; $total_questions_answered = 0;
while ($row = Database::fetch_object($result)) {
$courseRelUsers = $course->getUsers();
foreach ($courseRelUsers as $courseRelUser) {
$user = $courseRelUser->getUser();
$userId = $user->getId();
// get time spent in the course and session // get time spent in the course and session
$time_spent += Tracking::get_time_spent_on_the_course( $time_spent += Tracking::get_time_spent_on_the_course(
$row->user_id, $userId,
$courseId $courseId
); );
$progress_tmp = Tracking::get_avg_student_progress( $progress_tmp = Tracking::get_avg_student_progress(
$row->user_id, $userId,
$course_code, $courseCode,
[], [],
null, null,
true true
@ -1767,8 +1757,8 @@ class MySpace
$progress += $progress_tmp[0]; $progress += $progress_tmp[0];
$nb_progress_lp += $progress_tmp[1]; $nb_progress_lp += $progress_tmp[1];
$score_tmp = Tracking::get_avg_student_score( $score_tmp = Tracking::get_avg_student_score(
$row->user_id, $userId,
$course_code, $courseCode,
[], [],
null, null,
true true
@ -1777,18 +1767,12 @@ class MySpace
$score += $score_tmp[0]; $score += $score_tmp[0];
$nb_score_lp += $score_tmp[1]; $nb_score_lp += $score_tmp[1];
} }
$nb_messages += Tracking::count_student_messages( $nb_messages += Container::getForumPostRepository()->countUserForumPosts($user, $course);
$row->user_id, $nb_assignments += Container::getStudentPublicationRepository()->countUserPublications($user, $course);
$course_code
);
$nb_assignments += Tracking::count_student_assignments(
$row->user_id,
$course_code
);
$last_login_date_tmp = Tracking::get_last_connection_date_on_the_course( $last_login_date_tmp = Tracking::get_last_connection_date_on_the_course(
$row->user_id, $userId,
$courseInfo, ['real_id' => $courseId],
null, null,
false false
); );
@ -1803,7 +1787,7 @@ class MySpace
} }
} }
$exercise_results_tmp = self::exercises_results($row->user_id, $course_code); $exercise_results_tmp = self::exercises_results($userId, $courseCode);
$total_score_obtained += $exercise_results_tmp['score_obtained']; $total_score_obtained += $exercise_results_tmp['score_obtained'];
$total_score_possible += $exercise_results_tmp['score_possible']; $total_score_possible += $exercise_results_tmp['score_possible'];
$total_questions_answered += $exercise_results_tmp['questions_answered']; $total_questions_answered += $exercise_results_tmp['questions_answered'];
@ -1967,28 +1951,25 @@ class MySpace
*/ */
public static function session_tracking_filter($session_id, $url_params, $row) public static function session_tracking_filter($session_id, $url_params, $row)
{ {
$session_id = $row[0]; $sessionId = $row[0];
$url = api_get_url_entity();
$session = api_get_session_entity($sessionId);
// the table header // the table header
$return = '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">'; $return = '<table
class="data_table"
style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
// database table definition
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$sessionRelCourses = $session->getCourses();
// getting all the courses of the user foreach ($sessionRelCourses as $sessionRelCourse) {
$sql = "SELECT * FROM $tbl_course AS c $course = $sessionRelCourse->getCourse();
INNER JOIN $tbl_session_rel_course AS sc $courseId = $course->getId();
ON sc.c_id = c.id $courseCode = $course->getCode();
WHERE sc.session_id = '".$session_id."'";
$result = Database::query($sql);
while ($row = Database::fetch_object($result)) {
$courseId = $row->c_id;
$courseInfo = api_get_course_info_by_id($courseId);
$return .= '<tr>'; $return .= '<tr>';
// course code $return .= '<td>'.$course->getTitle().'</td>';
$return .= ' <td width="157px" >'.$row->title.'</td>'; //$users = Container::getSessionRepository()->getUsersByCourse($session, $course, $url);
// get the users in the course // get the users in the course
$sql = "SELECT u.user_id $sql = "SELECT u.user_id
FROM $tbl_user AS u FROM $tbl_user AS u
@ -2008,21 +1989,32 @@ class MySpace
$total_score_possible = 0; $total_score_possible = 0;
$total_questions_answered = 0; $total_questions_answered = 0;
while ($row_user = Database::fetch_object($result_users)) { while ($row_user = Database::fetch_object($result_users)) {
$user = api_get_user_entity($row_user->user_id);
// get time spent in the course and session // get time spent in the course and session
$time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $courseId, $session_id); $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $courseId, $session_id);
$progress_tmp = Tracking::get_avg_student_progress($row_user->user_id, $row->code, [], $session_id, true); $progress_tmp = Tracking::get_avg_student_progress(
$row_user->user_id,
$courseCode,
[],
$session_id,
true
);
$progress += $progress_tmp[0]; $progress += $progress_tmp[0];
$nb_progress_lp += $progress_tmp[1]; $nb_progress_lp += $progress_tmp[1];
$score_tmp = Tracking::get_avg_student_score($row_user->user_id, $row->code, [], $session_id, true); $score_tmp = Tracking::get_avg_student_score($row_user->user_id, $courseCode, [], $session_id, true);
if (is_array($score_tmp)) { if (is_array($score_tmp)) {
$score += $score_tmp[0]; $score += $score_tmp[0];
$nb_score_lp += $score_tmp[1]; $nb_score_lp += $score_tmp[1];
} }
$nb_messages += Tracking::count_student_messages($row_user->user_id, $row->code, $session_id); $nb_messages += Container::getForumPostRepository()->countUserForumPosts($user, $course, $session);
$nb_assignments += Tracking::count_student_assignments($row_user->user_id, $row->code, $session_id); $nb_assignments += Container::getStudentPublicationRepository()->countUserPublications(
$user,
$course,
$session
);
$last_login_date_tmp = Tracking::get_last_connection_date_on_the_course( $last_login_date_tmp = Tracking::get_last_connection_date_on_the_course(
$row_user->user_id, $row_user->user_id,
$courseInfo, ['real_id' => $courseId],
$session_id, $session_id,
false false
); );
@ -2991,7 +2983,7 @@ class MySpace
$sql_select = "SELECT COUNT(user_id) as nbUsers FROM $tbl_session_rel_course_rel_user $sql_select = "SELECT COUNT(user_id) as nbUsers FROM $tbl_session_rel_course_rel_user
WHERE session_id='$id_session' AND c_id='$enreg_course'"; WHERE session_id='$id_session' AND c_id='$enreg_course'";
$rs = Database::query($sql_select); $rs = Database::query($sql_select);
list($nbr_users) = Database::fetch_array($rs); [$nbr_users] = Database::fetch_array($rs);
$sql_update = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users
WHERE session_id='$id_session' AND c_id='$enreg_course'"; WHERE session_id='$id_session' AND c_id='$enreg_course'";
Database::query($sql_update); Database::query($sql_update);

@ -51,7 +51,7 @@ class Redirect
* @param bool Whether the user just logged in (in this case, use page_after_login rules) * @param bool Whether the user just logged in (in this case, use page_after_login rules)
* @param int The user_id, if defined. Otherwise just send to where the page_after_login setting says * @param int The user_id, if defined. Otherwise just send to where the page_after_login setting says
*/ */
public static function session_request_uri($logging_in = false, $user_id = null) public static function session_request_uri($logging_in = false, $userInfo = null)
{ {
$no_redirection = isset($_SESSION['noredirection']) ? $_SESSION['noredirection'] : false; $no_redirection = isset($_SESSION['noredirection']) ? $_SESSION['noredirection'] : false;
@ -75,17 +75,18 @@ class Redirect
} elseif ($logging_in || } elseif ($logging_in ||
(isset($_REQUEST['sso_referer']) && !empty($_REQUEST['sso_referer'])) (isset($_REQUEST['sso_referer']) && !empty($_REQUEST['sso_referer']))
) { ) {
if (isset($user_id)) { if (isset($userInfo) && !empty($userInfo)) {
$userId = $userInfo['user_id'];
$allow = api_get_configuration_value('plugin_redirection_enabled'); $allow = api_get_configuration_value('plugin_redirection_enabled');
if ($allow) { if ($allow) {
$allow = api_get_configuration_value('plugin_redirection_enabled'); $allow = api_get_configuration_value('plugin_redirection_enabled');
if ($allow) { if ($allow) {
RedirectionPlugin::redirectUser($user_id); RedirectionPlugin::redirectUser($userId);
} }
} }
// Make sure we use the appropriate role redirection in case one has been defined // Make sure we use the appropriate role redirection in case one has been defined
$user_status = api_get_user_status($user_id); $user_status = $userInfo['status'];
switch ($user_status) { switch ($user_status) {
case COURSEMANAGER: case COURSEMANAGER:
$redir = api_get_setting('teacher_page_after_login'); $redir = api_get_setting('teacher_page_after_login');
@ -122,12 +123,12 @@ class Redirect
// if multiple URLs are enabled, make sure he's admin of the // if multiple URLs are enabled, make sure he's admin of the
// current URL before redirecting // current URL before redirecting
$url = api_get_current_access_url_id(); $url = api_get_current_access_url_id();
if (api_is_platform_admin_by_id($user_id, $url)) { if (api_is_platform_admin_by_id($userId, $url)) {
self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php');
} }
} else { } else {
// if no multiple URL, then it's enough to be platform admin // if no multiple URL, then it's enough to be platform admin
if (api_is_platform_admin_by_id($user_id)) { if (api_is_platform_admin_by_id($userId)) {
self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php');
} }
} }

@ -1132,18 +1132,19 @@ class SessionManager
$arrLesson[$row['session_id']]['lessons_total']++; $arrLesson[$row['session_id']]['lessons_total']++;
} }
} }
$session = api_get_session_entity($sessionId);
$qb = Container::getQuizRepository()->findAllByCourse($course, $session, null, 2);
$exercises = $qb->getQuery()->getResult();
$exercises_total = count($exercises);
/** /*$exercises = ExerciseLib::get_all_exercises(
* Exercises.
*/
$exercises = ExerciseLib::get_all_exercises(
$course, $course,
$sessionId, $sessionId,
false, false,
'', '',
$getAllSessions $getAllSessions
); );
$exercises_total = count($exercises); $exercises_total = count($exercises);*/
/** /**
* Assignments. * Assignments.
@ -1246,7 +1247,8 @@ class SessionManager
} }
//Lessons //Lessons
//TODO: Lessons done and left is calculated by progress per item in lesson, maybe we should calculate it only per completed lesson? //TODO: Lessons done and left is calculated by progress per item in lesson,
// maybe we should calculate it only per completed lesson?
$lessons_progress = Tracking::get_avg_student_progress( $lessons_progress = Tracking::get_avg_student_progress(
$user['user_id'], $user['user_id'],
$course['code'], $course['code'],
@ -1271,7 +1273,11 @@ class SessionManager
$exercises_left = $exercises_total - $exercises_done; $exercises_left = $exercises_total - $exercises_done;
//Assignments //Assignments
$assignments_done = Tracking::count_student_assignments($user['user_id'], $course['code'], $user['id_session']); $assignments_done = Container::getStudentPublicationRepository()->countUserPublications(
$user['user_id'],
$course['code'],
$user['id_session']
);
$assignments_left = $assignments_total - $assignments_done; $assignments_left = $assignments_total - $assignments_done;
if (!empty($assignments_total)) { if (!empty($assignments_total)) {
$assignments_progress = round((($assignments_done * 100) / $assignments_total), 2); $assignments_progress = round((($assignments_done * 100) / $assignments_total), 2);
@ -1673,11 +1679,8 @@ class SessionManager
} else { } else {
$sessionInfo = self::get_session_by_name($name); $sessionInfo = self::get_session_by_name($name);
$exists = false; $exists = false;
if (!empty($sessionInfo) && $sessionInfo['id'] !== $id) {
if (!empty($sessionInfo)) { $exists = true;
if ($sessionInfo['id'] != $id) {
$exists = true;
}
} }
if ($exists) { if ($exists) {
@ -1687,7 +1690,6 @@ class SessionManager
return false; return false;
} else { } else {
/** @var Session $sessionEntity */
$sessionEntity = api_get_session_entity($id); $sessionEntity = api_get_session_entity($id);
$sessionEntity $sessionEntity
->setName($name) ->setName($name)

File diff suppressed because it is too large Load Diff

@ -18,6 +18,7 @@ if (!$isAllowedToEdit) {
} }
$lpTable = Database::get_course_table(TABLE_LP_MAIN); $lpTable = Database::get_course_table(TABLE_LP_MAIN);
$course = api_get_course_entity();
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
@ -157,7 +158,7 @@ $lpInfo = Database::select(
'first' 'first'
); );
$groups = GroupManager::get_group_list(null, $courseInfo, null, $sessionId); $groups = GroupManager::get_group_list(null, $course, null, $sessionId);
$label = get_lang('Groups'); $label = get_lang('Groups');
$classes = []; $classes = [];
if ($allowUserGroups) { if ($allowUserGroups) {

@ -227,35 +227,34 @@ $actions = null;
if (api_is_student_boss()) { if (api_is_student_boss()) {
$actions .= Display::url( $actions .= Display::url(
Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM), Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php" api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
); );
$actions .= Display::url( $actions .= Display::url(
Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM), Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."mySpace/student.php" api_get_path(WEB_CODE_PATH).'mySpace/student.php'
); );
$actions .= Display::url( $actions .= Display::url(
Display::return_icon("statistics.png", get_lang("Corporate report"), [], ICON_SIZE_MEDIUM), Display::return_icon('statistics.png', get_lang('Corporate report'), [], ICON_SIZE_MEDIUM),
"#" "#"
); );
$actions .= Display::url( $actions .= Display::url(
Display::return_icon( Display::return_icon(
"certificate_list.png", 'certificate_list.png',
get_lang("GradebookSeeListOfLearnersCertificates"), get_lang('GradebookSeeListOfLearnersCertificates'),
[], [],
ICON_SIZE_MEDIUM ICON_SIZE_MEDIUM
), ),
api_get_path(WEB_CODE_PATH)."gradebook/certificate_report.php" api_get_path(WEB_CODE_PATH).'gradebook/certificate_report.php'
); );
} }
$content = '<div class="actions">'; $content = '<div class="actions">';
if (!empty($actions)) { if (!empty($actions)) {
$content .= $actions; $content .= $actions;
} }
$content .= Display::url( $content .= Display::url(
get_lang("Corporate reportResumed"), get_lang("Corporate reportResumed"),
api_get_path(WEB_CODE_PATH)."mySpace/company_reports_resumed.php", api_get_path(WEB_CODE_PATH).'mySpace/company_reports_resumed.php',
[ [
'class' => 'btn btn-success', 'class' => 'btn btn-success',
] ]

@ -86,24 +86,24 @@ $actions = null;
if (api_is_student_boss()) { if (api_is_student_boss()) {
$actions .= Display::url( $actions .= Display::url(
Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM), Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php" api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
); );
$actions .= Display::url( $actions .= Display::url(
Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM), Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."mySpace/student.php" api_get_path(WEB_CODE_PATH).'mySpace/student.php'
); );
$actions .= Display::url( $actions .= Display::url(
Display::return_icon("statistics.png", get_lang("Corporate report"), [], ICON_SIZE_MEDIUM), Display::return_icon('statistics.png', get_lang('Corporate report'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."mySpace/company_reports.php" api_get_path(WEB_CODE_PATH).'mySpace/company_reports.php'
); );
$actions .= Display::url( $actions .= Display::url(
Display::return_icon( Display::return_icon(
"certificate_list.png", 'certificate_list.png',
get_lang("GradebookSeeListOfLearnersCertificates"), get_lang('GradebookSeeListOfLearnersCertificates'),
[], [],
ICON_SIZE_MEDIUM ICON_SIZE_MEDIUM
), ),
api_get_path(WEB_CODE_PATH)."gradebook/certificate_report.php" api_get_path(WEB_CODE_PATH).'gradebook/certificate_report.php'
); );
} }

@ -86,11 +86,11 @@ if (api_is_platform_admin(true, true)) {
if (!api_is_session_admin()) { if (!api_is_session_admin()) {
$menu_items[] = Display::url( $menu_items[] = Display::url(
Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM), Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php" api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
); );
$menu_items[] = Display::url( $menu_items[] = Display::url(
Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM), Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM),
"index.php?view=drh_students&amp;display=yourstudents" 'index.php?view=drh_students&display=yourstudents'
); );
$menu_items[] = Display::url( $menu_items[] = Display::url(
Display::return_icon('teacher.png', get_lang('Teachers'), [], ICON_SIZE_MEDIUM), Display::return_icon('teacher.png', get_lang('Teachers'), [], ICON_SIZE_MEDIUM),
@ -114,7 +114,8 @@ if (api_is_platform_admin(true, true)) {
api_get_path(WEB_CODE_PATH).'mySpace/question_stats_global_detail.php' api_get_path(WEB_CODE_PATH).'mySpace/question_stats_global_detail.php'
); );
if (api_can_login_as($user_id)) { if (api_can_login_as($user_id)) {
$link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.Security::get_existing_token().'">'. $link = '<a
href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.Security::get_existing_token().'">'.
Display::return_icon('login_as.png', get_lang('Login as'), null, ICON_SIZE_MEDIUM).'</a>&nbsp;&nbsp;'; Display::return_icon('login_as.png', get_lang('Login as'), null, ICON_SIZE_MEDIUM).'</a>&nbsp;&nbsp;';
$menu_items[] = $link; $menu_items[] = $link;
} }
@ -143,7 +144,7 @@ if (api_is_platform_admin(true, true)) {
if ($showImportIcon) { if ($showImportIcon) {
echo "<div align=\"right\">"; echo "<div align=\"right\">";
echo '<a href="user_import.php?id_session='.$sessionId.'&action=export&amp;type=xml">'. echo '<a href="user_import.php?id_session='.$sessionId.'&action=export&type=xml">'.
Display::return_icon('excel.gif', get_lang('Import users list')).'&nbsp;'.get_lang('Import users list').'</a>'; Display::return_icon('excel.gif', get_lang('Import users list')).'&nbsp;'.get_lang('Import users list').'</a>';
echo "</div><br />"; echo "</div><br />";
} }

@ -15,9 +15,8 @@ require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users(); api_block_anonymous_users();
//$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_PUBLIC_PATH).'assets/jquery.easy-pie-chart/dist/jquery.easypiechart.js"></script>';
$htmlHeadXtra[] = null; $htmlHeadXtra[] = null;
$export = isset($_GET['export']) ? $_GET['export'] : false; $export = $_GET['export'] ?? false;
$sessionId = isset($_GET['sid']) ? (int) $_GET['sid'] : 0; $sessionId = isset($_GET['sid']) ? (int) $_GET['sid'] : 0;
$origin = api_get_origin(); $origin = api_get_origin();
$courseId = isset($_GET['cid']) ? (int) $_GET['cid'] : ''; $courseId = isset($_GET['cid']) ? (int) $_GET['cid'] : '';
@ -129,7 +128,7 @@ if (!empty($details)) {
} else { } else {
if ('resume_session' === $origin) { if ('resume_session' === $origin) {
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => "../session/session_list.php", 'url' => '../session/session_list.php',
'name' => get_lang('Session list'), 'name' => get_lang('Session list'),
]; ];
$interbreadcrumb[] = [ $interbreadcrumb[] = [
@ -210,15 +209,15 @@ if (!empty($details)) {
// Database Table Definitions // Database Table Definitions
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$action = isset($_GET['action']) ? $_GET['action'] : ''; $action = $_GET['action'] ?? '';
switch ($action) { switch ($action) {
case 'add_work_time': case 'add_work_time':
if (false === $workingTimeEdit) { if (false === $workingTimeEdit) {
api_not_allowed(true); api_not_allowed(true);
} }
$workingTime = isset($_GET['time']) ? $_GET['time'] : ''; $workingTime = $_GET['time'] ?? '';
$workId = isset($_GET['work_id']) ? $_GET['work_id'] : ''; $workId = $_GET['work_id'] ?? '';
Event::eventAddVirtualCourseTime($courseInfo['real_id'], $studentId, $sessionId, $workingTime, $workId); Event::eventAddVirtualCourseTime($courseInfo['real_id'], $studentId, $sessionId, $workingTime, $workId);
Display::addFlash(Display::return_message(get_lang('Updated'))); Display::addFlash(Display::return_message(get_lang('Updated')));
@ -228,8 +227,8 @@ switch ($action) {
if (false === $workingTimeEdit) { if (false === $workingTimeEdit) {
api_not_allowed(true); api_not_allowed(true);
} }
$workingTime = isset($_GET['time']) ? $_GET['time'] : ''; $workingTime = $_GET['time'] ?? '';
$workId = isset($_GET['work_id']) ? $_GET['work_id'] : ''; $workId = $_GET['work_id'] ?? '';
Event::eventRemoveVirtualCourseTime($courseInfo['real_id'], $studentId, $sessionId, $workingTime, $workId); Event::eventRemoveVirtualCourseTime($courseInfo['real_id'], $studentId, $sessionId, $workingTime, $workId);
Display::addFlash(Display::return_message(get_lang('Updated'))); Display::addFlash(Display::return_message(get_lang('Updated')));
@ -461,8 +460,8 @@ switch ($action) {
break; break;
case 'send_message': case 'send_message':
if (true === $allowMessages) { if (true === $allowMessages) {
$subject = isset($_POST['subject']) ? $_POST['subject'] : ''; $subject = $_POST['subject'] ?? '';
$message = isset($_POST['message']) ? $_POST['message'] : ''; $message = $_POST['message'] ?? '';
$userInfo = api_get_user_info($studentId); $userInfo = api_get_user_info($studentId);
if (!empty($subject) && !empty($message)) { if (!empty($subject) && !empty($message)) {
@ -574,7 +573,6 @@ switch ($action) {
} }
$courses_in_session = []; $courses_in_session = [];
// See #4676 // See #4676
$drh_can_access_all_courses = false; $drh_can_access_all_courses = false;
if (api_is_drh() || api_is_platform_admin() || api_is_student_boss() || api_is_session_admin()) { if (api_is_drh() || api_is_platform_admin() || api_is_student_boss() || api_is_session_admin()) {
@ -650,10 +648,7 @@ while ($row = Database::fetch_array($rs, 'ASSOC')) {
} }
} }
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), $courseInfo);
api_get_user_id(),
$courseInfo
);
if (api_is_drh() && !api_is_platform_admin()) { if (api_is_drh() && !api_is_platform_admin()) {
if (!empty($studentId)) { if (!empty($studentId)) {
@ -1078,8 +1073,6 @@ if (isset($_GET['action']) && 'all_attendance' === $_GET['action']) {
} }
echo '</tbody> echo '</tbody>
</table></div>'; </table></div>';
/** Display dates */
/*Display all attendances */
Display::display_footer(); Display::display_footer();
exit(); exit();
} }
@ -1874,16 +1867,13 @@ if (empty($details)) {
$result_exercices = Database::query($sql); $result_exercices = Database::query($sql);
$i = 0;*/ $i = 0;*/
$repo = Container::getQuizRepository();
$course = api_get_course_entity($courseInfo['real_id']); $course = api_get_course_entity($courseInfo['real_id']);
$session = api_get_session_entity($sessionId); $session = api_get_session_entity($sessionId);
// 2. Get query builder from repo. $repo = Container::getQuizRepository();
$qb = $repo->getResourcesByCourse($course, $session); $qb = $repo->findAllByCourse($course, $session, null, 2, false);
$qb->andWhere('resource.active = 1 OR resource.active = 0');
$exerciseList = $qb->getQuery()->getResult(); $exerciseList = $qb->getQuery()->getResult();
if ($exerciseList) { if ($exerciseList) {
//while ($exercices = Database::fetch_array($result_exercices)) {
/** @var CQuiz $exercise */ /** @var CQuiz $exercise */
foreach ($exerciseList as $exercise) { foreach ($exerciseList as $exercise) {
$exercise_id = (int) $exercise->getIid(); $exercise_id = (int) $exercise->getIid();
@ -1928,10 +1918,8 @@ if (empty($details)) {
if ($i % 2) { if ($i % 2) {
$css_class = 'row_odd'; $css_class = 'row_odd';
} }
$exerciseTitle = Exercise::get_formated_title_variable($exercise->getTitle());
echo '<tr class="'.$css_class.'"><td>'.Exercise::get_formated_title_variable( echo '<tr class="'.$css_class.'"><td>'.$exerciseTitle.'</td>';
$exercise->getTitle()
).'</td>';
echo '<td>'; echo '<td>';
if (!empty($lp_name)) { if (!empty($lp_name)) {
@ -2121,9 +2109,8 @@ if (empty($details)) {
echo '<td class="text-center"><a href="'.$url.'">('.$documentNumber.')</a></td>'; echo '<td class="text-center"><a href="'.$url.'">('.$documentNumber.')</a></td>';
$qualification = !empty($results['qualification']) ? $results['qualification'] : '-'; $qualification = !empty($results['qualification']) ? $results['qualification'] : '-';
echo '<td class="text-center">'.$qualification.'</td>'; echo '<td class="text-center">'.$qualification.'</td>';
echo '<td class="text-center">'.api_convert_and_format_date( echo '<td class="text-center">'.
$results['sent_date_from_db'] api_convert_and_format_date($results['sent_date_from_db']).' '.$results['expiry_note'].'</td>';
).' '.$results['expiry_note'].'</td>';
$assignment = get_work_assignment_by_id($work->iid, $courseInfo['real_id']); $assignment = get_work_assignment_by_id($work->iid, $courseInfo['real_id']);
echo '<td class="text-center">'; echo '<td class="text-center">';
@ -2169,7 +2156,6 @@ if (empty($details)) {
'; ';
$csv_content[] = []; $csv_content[] = [];
$csv_content[] = [ $csv_content[] = [
get_lang('OTI (Online Training Interaction) settings report'), get_lang('OTI (Online Training Interaction) settings report'),
]; ];
@ -2198,7 +2184,7 @@ if (empty($details)) {
get_lang('Latest chat connection'), get_lang('Latest chat connection'),
$chat_last_connection, $chat_last_connection,
]; ];
} //end details }
if (true === $allowMessages) { if (true === $allowMessages) {
// Messages // Messages

@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuiz;
$cidReset = true; $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_TRACKING; $this_section = SECTION_TRACKING;
@ -24,15 +27,19 @@ $exerciseList = [];
$selectedExercises = []; $selectedExercises = [];
if (!empty($courseIdList)) { if (!empty($courseIdList)) {
foreach ($courseIdList as $courseId) { foreach ($courseIdList as $courseId) {
$courseInfo = api_get_course_info_by_id($courseId); $course = api_get_course_entity($courseId);
$courseExerciseList = ExerciseLib::get_all_exercises( /*$courseExerciseList = ExerciseLib::get_all_exercises(
$courseInfo, $courseInfo,
0, 0,
false, false,
null, null,
false, false,
3 3
); );*/
$qb = Container::getQuizRepository()->findAllByCourse($course, null, null, 2, false);
/** @var CQuiz[] $courseExerciseList */
$courseExerciseList = $qb->getQuery()->getResult();
if (!empty($courseExerciseList)) { if (!empty($courseExerciseList)) {
foreach ($courseExerciseList as $exercise) { foreach ($courseExerciseList as $exercise) {
@ -43,7 +50,7 @@ if (!empty($courseIdList)) {
} }
$exerciseList += array_column($courseExerciseList, 'title', 'iid'); $exerciseList += array_column($courseExerciseList, 'title', 'iid');
} }
$courseOptions[$courseId] = $courseInfo['name']; $courseOptions[$courseId] = $course->getTitle();
} }
} }

@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuiz;
$cidReset = true; $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_TRACKING; $this_section = SECTION_TRACKING;
@ -24,15 +27,19 @@ $exerciseList = [];
$selectedExercises = []; $selectedExercises = [];
if (!empty($courseIdList)) { if (!empty($courseIdList)) {
foreach ($courseIdList as $courseId) { foreach ($courseIdList as $courseId) {
$courseInfo = api_get_course_info_by_id($courseId); $course = api_get_course_entity($courseId);
$courseExerciseList = ExerciseLib::get_all_exercises( /*$courseExerciseList = ExerciseLib::get_all_exercises(
$courseInfo, $courseInfo,
0, 0,
false, false,
null, null,
false, false,
3 3
); );*/
$qb = Container::getQuizRepository()->findAllByCourse($course, null, null, 2, false);
/** @var CQuiz[] $courseExerciseList */
$courseExerciseList = $qb->getQuery()->getResult();
if (!empty($courseExerciseList)) { if (!empty($courseExerciseList)) {
foreach ($courseExerciseList as $exercise) { foreach ($courseExerciseList as $exercise) {
@ -43,7 +50,7 @@ if (!empty($courseIdList)) {
} }
$exerciseList += array_column($courseExerciseList, 'title', 'iid'); $exerciseList += array_column($courseExerciseList, 'title', 'iid');
} }
$courseOptions[$courseId] = $courseInfo['name']; $courseOptions[$courseId] = $course->getTitle();
} }
} }

@ -181,7 +181,7 @@ if (api_is_drh()) {
$menu_items = [ $menu_items = [
Display::url( Display::url(
Display::return_icon('statistics.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), Display::return_icon('statistics.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php" api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
), ),
Display::url(Display::return_icon('user.png', get_lang('Students'), [], ICON_SIZE_MEDIUM), 'student.php'), Display::url(Display::return_icon('user.png', get_lang('Students'), [], ICON_SIZE_MEDIUM), 'student.php'),
Display::url( Display::url(

@ -193,7 +193,7 @@ if (api_is_drh()) {
$menu_items = [ $menu_items = [
Display::url( Display::url(
Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM), Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php" api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
), ),
Display::url(Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM), 'student.php'), Display::url(Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM), 'student.php'),
Display::url( Display::url(

@ -631,7 +631,7 @@ if (!api_is_anonymous()) {
$reportingTab .= '<br />'; $reportingTab .= '<br />';
$reportingTab .= Tracking::show_course_detail( $reportingTab .= Tracking::show_course_detail(
api_get_user_id(), api_get_user_id(),
$courseCode, $course_id,
$session_id $session_id
); );
} }

@ -4,13 +4,14 @@
use Chamilo\CoreBundle\Component\Utils\ChamiloApi; use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuiz;
use ChamiloSession as Session; use ChamiloSession as Session;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_TRACKING; $current_course_tool = TOOL_TRACKING;
$courseInfo = api_get_course_info(); $course = api_get_course_entity();
if (empty($courseInfo)) { if (null === $course) {
api_not_allowed(true); api_not_allowed(true);
} }
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
@ -21,20 +22,19 @@ if (!$is_allowedToTrack) {
} }
//keep course_code form as it is loaded (global) by the table's get_user_data //keep course_code form as it is loaded (global) by the table's get_user_data
$courseCode = $courseInfo['code']; $courseCode = $course->getCode();
$courseId = $courseInfo['real_id']; $courseId = $course->getId();
// PERSON_NAME_DATA_EXPORT is buggy // PERSON_NAME_DATA_EXPORT is buggy
$sortByFirstName = api_sort_by_first_name(); $sortByFirstName = api_sort_by_first_name();
$from_myspace = false; $from_myspace = false;
$from = isset($_GET['from']) ? $_GET['from'] : null; $from = $_GET['from'] ?? null;
$origin = api_get_origin(); $origin = api_get_origin();
// Starting the output buffering when we are exporting the information. // Starting the output buffering when we are exporting the information.
$export_csv = isset($_GET['export']) && 'csv' === $_GET['export'] ? true : false; $export_csv = isset($_GET['export']) && 'csv' === $_GET['export'];
$htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js'); $htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js');
$htmlHeadXtra[] = ' ';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
if ('myspace' === $from) { if ('myspace' === $from) {
@ -50,8 +50,8 @@ if (api_is_drh()) {
$coursesFromSession = SessionManager::getAllCoursesFollowedByUser(api_get_user_id(), null); $coursesFromSession = SessionManager::getAllCoursesFollowedByUser(api_get_user_id(), null);
$coursesFromSessionCodeList = []; $coursesFromSessionCodeList = [];
if (!empty($coursesFromSession)) { if (!empty($coursesFromSession)) {
foreach ($coursesFromSession as $course) { foreach ($coursesFromSession as $courseItem) {
$coursesFromSessionCodeList[$course['code']] = $course['code']; $coursesFromSessionCodeList[$courseItem['code']] = $courseItem['code'];
} }
} }
@ -213,7 +213,8 @@ if (isset($_GET['users_tracking_per_page'])) {
$users_tracking_per_page = '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']); $users_tracking_per_page = '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']);
} }
$actionsRight .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$additionalParams.$users_tracking_per_page.'"> $actionsRight .= '<a
href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$additionalParams.$users_tracking_per_page.'">
'.Display::return_icon('export_csv.png', get_lang('CSV export'), '', ICON_SIZE_MEDIUM).'</a>'; '.Display::return_icon('export_csv.png', get_lang('CSV export'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsRight .= '</div>'; $actionsRight .= '</div>';
// Create a search-box. // Create a search-box.
@ -236,7 +237,7 @@ echo Display::toolbarAction(
[$actionsLeft, $form_search->returnForm(), $actionsRight] [$actionsLeft, $form_search->returnForm(), $actionsRight]
); );
$course_name = get_lang('Course').' '.$courseInfo['name']; $course_name = get_lang('Course').' '.$course->getTitle();
if ($sessionId) { if ($sessionId) {
$titleSession = Display::return_icon( $titleSession = Display::return_icon(
@ -257,11 +258,11 @@ if ($sessionId) {
get_lang('Course'), get_lang('Course'),
[], [],
ICON_SIZE_SMALL ICON_SIZE_SMALL
).' '.$courseInfo['name']; ).' '.$course->getTitle();
} }
$teacherList = CourseManager::getTeacherListFromCourseCodeToString( $teacherList = CourseManager::getTeacherListFromCourseCodeToString(
$courseInfo['code'], $courseCode,
',', ',',
true, true,
true true
@ -271,7 +272,7 @@ $coaches = null;
if (!empty($sessionId)) { if (!empty($sessionId)) {
$coaches = CourseManager::get_coachs_from_course_to_string( $coaches = CourseManager::get_coachs_from_course_to_string(
$sessionId, $sessionId,
$courseInfo['real_id'], $courseId,
',', ',',
true, true,
true true
@ -290,7 +291,7 @@ if (!empty($coaches)) {
$showReporting = false === api_get_configuration_value('hide_reporting_session_list'); $showReporting = false === api_get_configuration_value('hide_reporting_session_list');
if ($showReporting) { if ($showReporting) {
$sessionList = SessionManager::get_session_by_course($courseInfo['real_id']); $sessionList = SessionManager::get_session_by_course($courseId);
if (!empty($sessionList)) { if (!empty($sessionList)) {
$html .= Display::page_subheader2(get_lang('Session list')); $html .= Display::page_subheader2(get_lang('Session list'));
$icon = Display::return_icon( $icon = Display::return_icon(
@ -306,30 +307,30 @@ if ($showReporting) {
foreach ($sessionList as $session) { foreach ($sessionList as $session) {
if (!$isAdmin) { if (!$isAdmin) {
// Check session visibility // Check session visibility
$visibility = api_get_session_visibility($session['id'], api_get_course_int_id()); $visibility = api_get_session_visibility($session['id'], $courseId);
if (SESSION_INVISIBLE == $visibility) { if (SESSION_INVISIBLE == $visibility) {
continue; continue;
} }
// Check if is coach // Check if is coach
$isCoach = api_is_coach($session['id'], api_get_course_int_id()); $isCoach = api_is_coach($session['id'], $courseId);
if (!$isCoach) { if (!$isCoach) {
continue; continue;
} }
} }
$url = $urlWebCode.'mySpace/course.php?session_id='.$session['id'].'&cidReq='.$courseInfo['code']; $url = $urlWebCode.'mySpace/course.php?sid='.$session['id'].'&cid='.$courseId;
$html .= Display::tag('li', $icon.' '.Display::url($session['name'], $url)); $html .= Display::tag('li', $icon.' '.Display::url($session['name'], $url));
} }
$html .= '</ul>'; $html .= '</ul>';
} }
} }
$trackingColumn = isset($_GET['users_tracking_column']) ? $_GET['users_tracking_column'] : null; $trackingColumn = $_GET['users_tracking_column'] ?? null;
$trackingDirection = isset($_GET['users_tracking_direction']) ? $_GET['users_tracking_direction'] : null; $trackingDirection = $_GET['users_tracking_direction'] ?? null;
$hideReports = api_get_configuration_value('hide_course_report_graph'); $hideReports = api_get_configuration_value('hide_course_report_graph');
$conditions = []; $conditions = [];
$groupList = GroupManager::get_group_list(null, $courseInfo, 1, $sessionId); $groupList = GroupManager::get_group_list(null, $course, 1, $sessionId);
$class = new UserGroup(); $class = new UserGroup();
//$options['where'] = [' usergroup.course_id = ? ' => $courseId]; //$options['where'] = [' usergroup.course_id = ? ' => $courseId];
//$classes = $class->getUserGroupInCourse($options); //$classes = $class->getUserGroupInCourse($options);
@ -463,6 +464,7 @@ if ($nbStudents > 0) {
} }
if (false === $hideReports) { if (false === $hideReports) {
$conditions['course_id'] = $courseId;
$conditions['include_invited_users'] = false; $conditions['include_invited_users'] = false;
$usersTracking = TrackingCourseLog::get_user_data( $usersTracking = TrackingCourseLog::get_user_data(
null, null,
@ -582,7 +584,7 @@ if ($nbStudents > 0) {
$el->setSelected(7); $el->setSelected(7);
$form->addElement('hidden', 'action', 'add'); $form->addElement('hidden', 'action', 'add');
$form->addElement('hidden', 'remindallinactives', 'true'); $form->addElement('hidden', 'remindallinactives', 'true');
$form->addElement('hidden', 'cidReq', $courseInfo['code']); $form->addElement('hidden', 'cidReq', $course->getCode());
$form->addElement('hidden', 'id_session', api_get_session_id()); $form->addElement('hidden', 'id_session', api_get_session_id());
$form->addButtonSend(get_lang('Notify')); $form->addButtonSend(get_lang('Notify'));
@ -609,6 +611,7 @@ if ($nbStudents > 0) {
$table->total_number_of_items = $nbStudents; $table->total_number_of_items = $nbStudents;
} else { } else {
$conditions['include_invited_users'] = true; $conditions['include_invited_users'] = true;
$conditions['course_id'] = $courseId;
$table = new SortableTable( $table = new SortableTable(
'users_tracking', 'users_tracking',
['TrackingCourseLog', 'get_number_of_users'], ['TrackingCourseLog', 'get_number_of_users'],
@ -790,14 +793,20 @@ $groupTable->setHeaderContents(0, $column++, get_lang('AverageTrainingTime'));
$groupTable->setHeaderContents(0, $column++, get_lang('CourseProgress')); $groupTable->setHeaderContents(0, $column++, get_lang('CourseProgress'));
$groupTable->setHeaderContents(0, $column++, get_lang('ExerciseAverage')); $groupTable->setHeaderContents(0, $column++, get_lang('ExerciseAverage'));
$exerciseList = ExerciseLib::get_all_exercises( /*$exerciseList = ExerciseLib::get_all_exercises(
$courseInfo, $courseInfo,
$sessionId, $sessionId,
false, false,
null, null,
false, false,
3 3
); );*/
$session = api_get_session_entity($sessionId);
$qb = Container::getQuizRepository()->findAllByCourse($course, $session, null, 2, false);
/** @var CQuiz[] $exercises */
$exercises = $qb->getQuery()->getResult();
if (!empty($groupList)) { if (!empty($groupList)) {
$totalTime = null; $totalTime = null;
$totalLpProgress = null; $totalLpProgress = null;
@ -849,12 +858,12 @@ if (!empty($groupList)) {
$totalLpProgress += $totalGroupLpProgress; $totalLpProgress += $totalGroupLpProgress;
} }
if (!empty($exerciseList)) { if (!empty($exercises)) {
foreach ($exerciseList as $exerciseData) { foreach ($exercises as $exerciseData) {
foreach ($usersInGroup as $userId) { foreach ($usersInGroup as $userId) {
$results = Event::get_best_exercise_results_by_user( $results = Event::get_best_exercise_results_by_user(
$exerciseData->getIid(), $exerciseData->getIid(),
$courseInfo['real_id'], $courseId,
0, 0,
$userId $userId
); );
@ -873,7 +882,7 @@ if (!empty($groupList)) {
} }
} }
$bestScoreAverageNotInLP = round( $bestScoreAverageNotInLP = round(
$bestScoreAverageNotInLP / count($exerciseList) * 100 / $userInGroupCount, $bestScoreAverageNotInLP / count($exercises) * 100 / $userInGroupCount,
2 2
); );
@ -946,12 +955,12 @@ if (!empty($groupList)) {
} }
$totalBestScoreAverageNotInLP = 0; $totalBestScoreAverageNotInLP = 0;
$bestScoreAverageNotInLP = 0; $bestScoreAverageNotInLP = 0;
if (!empty($exerciseList)) { if (!empty($exercises)) {
foreach ($exerciseList as $exerciseData) { foreach ($exercises as $exerciseData) {
foreach ($studentIdList as $userId) { foreach ($studentIdList as $userId) {
$results = Event::get_best_exercise_results_by_user( $results = Event::get_best_exercise_results_by_user(
$exerciseData['iid'], $exerciseData->getIid(),
$courseInfo['real_id'], $courseId,
$sessionId, $sessionId,
$userId $userId
); );
@ -972,7 +981,7 @@ if (!empty($groupList)) {
} }
if (!empty($nbStudents)) { if (!empty($nbStudents)) {
$bestScoreAverageNotInLP = round( $bestScoreAverageNotInLP = round(
$bestScoreAverageNotInLP / count($exerciseList) * 100 / $nbStudents, $bestScoreAverageNotInLP / count($exercises) * 100 / $nbStudents,
2 2
).' %'; ).' %';
} }

@ -2,16 +2,20 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuiz;
use ChamiloSession as Session; use ChamiloSession as Session;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_TRACKING; $current_course_tool = TOOL_TRACKING;
$course_info = api_get_course_info(); $course = api_get_course_entity();
$groupId = api_get_group_id(); $groupId = api_get_group_id();
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$session = api_get_session_entity($session_id);
$from_myspace = false; $from_myspace = false;
$from = isset($_GET['from']) ? $_GET['from'] : null; $from = $_GET['from'] ?? null;
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
if ('myspace' === $from) { if ('myspace' === $from) {
@ -57,7 +61,7 @@ if ($export_csv) {
$csv_content = []; $csv_content = [];
// Breadcrumbs. // Breadcrumbs.
if (isset($_GET['origin']) && 'resume_session' == $_GET['origin']) { if (isset($_GET['origin']) && 'resume_session' === $_GET['origin']) {
$interbreadcrumb[] = ['url' => '../admin/index.php', 'name' => get_lang('Administration')]; $interbreadcrumb[] = ['url' => '../admin/index.php', 'name' => get_lang('Administration')];
$interbreadcrumb[] = ['url' => '../session/session_list.php', 'name' => get_lang('Session list')]; $interbreadcrumb[] = ['url' => '../session/session_list.php', 'name' => get_lang('Session list')];
$interbreadcrumb[] = [ $interbreadcrumb[] = [
@ -66,7 +70,7 @@ if (isset($_GET['origin']) && 'resume_session' == $_GET['origin']) {
]; ];
} }
$view = isset($_REQUEST['view']) ? $_REQUEST['view'] : ''; $view = $_REQUEST['view'] ?? '';
$nameTools = get_lang('Reporting'); $nameTools = get_lang('Reporting');
// Display the header. // Display the header.
@ -75,7 +79,7 @@ Display::display_header($nameTools, 'Tracking');
// getting all the students of the course // getting all the students of the course
if (empty($session_id)) { if (empty($session_id)) {
// Registered students in a course outside session. // Registered students in a course outside session.
$a_students = CourseManager:: get_student_list_from_course_code( $a_students = CourseManager::get_student_list_from_course_code(
api_get_course_id(), api_get_course_id(),
false, false,
0, 0,
@ -86,7 +90,7 @@ if (empty($session_id)) {
); );
} else { } else {
// Registered students in session. // Registered students in session.
$a_students = CourseManager:: get_student_list_from_course_code( $a_students = CourseManager::get_student_list_from_course_code(
api_get_course_id(), api_get_course_id(),
true, true,
api_get_session_id() api_get_session_id()
@ -114,7 +118,7 @@ $course_code = api_get_course_id();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
if ($lpReporting) { if ($lpReporting) {
$list = new LearnpathList(null, $course_info, $session_id); $list = new LearnpathList(null, ['real_id' => $course->getId(), 'code' => $course->getCode()], $session_id);
$flat_list = $list->get_flat_list(); $flat_list = $list->get_flat_list();
if (count($flat_list) > 0) { if (count($flat_list) > 0) {
@ -181,10 +185,6 @@ if ($exerciseReporting) {
).' '.get_lang('Tests score') ).' '.get_lang('Tests score')
); );
echo '<table class="data_table">'; echo '<table class="data_table">';
$course_id = api_get_course_int_id();
$sql = "SELECT iid, title FROM $TABLEQUIZ
WHERE c_id = $course_id AND active <> -1 AND session_id = $session_id";
$rs = Database::query($sql);
if ($export_csv) { if ($export_csv) {
$temp = [get_lang('Progress in courses'), '']; $temp = [get_lang('Progress in courses'), ''];
@ -192,17 +192,28 @@ if ($exerciseReporting) {
$csv_content[] = $temp; $csv_content[] = $temp;
} }
$course_path_params = '&cidReq='.$course_code.'&id_session='.$session_id; $course_path_params = '&cid='.$course_id.'&sid='.$session_id;
/*$course_id = api_get_course_int_id();
$sql = "SELECT iid, title FROM $TABLEQUIZ
WHERE c_id = $course_id AND active <> -1 AND session_id = $session_id";
$rs = Database::query($sql);*/
$session = api_get_session_entity($session_id);
$qb = Container::getQuizRepository()->findAllByCourse($course, $session, null, 2, false);
/** @var CQuiz[] $exercises */
$exercises = $qb->getQuery()->getResult();
if (Database::num_rows($rs) > 0) { if (!empty($exercises)) {
while ($quiz = Database::fetch_array($rs)) { foreach ($exercises as $exercise) {
$exerciseId = $exercise->getIid();
$quiz_avg_score = 0; $quiz_avg_score = 0;
if ($studentCount > 0) { if ($studentCount > 0) {
foreach ($student_ids as $student_id) { foreach ($student_ids as $student_id) {
$avg_student_score = Tracking::get_avg_student_exercise_score( $avg_student_score = Tracking::get_avg_student_exercise_score(
$student_id, $student_id,
$course_code, $course_code,
$quiz['iid'], $exerciseId,
$session_id $session_id
); );
$quiz_avg_score += $avg_student_score; $quiz_avg_score += $avg_student_score;
@ -210,16 +221,16 @@ if ($exerciseReporting) {
} }
$studentCount = (0 == $studentCount || is_null($studentCount) || '' == $studentCount) ? 1 : $studentCount; $studentCount = (0 == $studentCount || is_null($studentCount) || '' == $studentCount) ? 1 : $studentCount;
$quiz_avg_score = round(($quiz_avg_score / $studentCount), 2).'%'; $quiz_avg_score = round(($quiz_avg_score / $studentCount), 2).'%';
$url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?exerciseId='.$quiz['iid'].$course_path_params; $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?exerciseId='.$exerciseId.$course_path_params;
echo '<tr><td>'; echo '<tr><td>';
echo Display::url( echo Display::url(
$quiz['title'], $exercise->getTitle(),
$url $url
); );
echo '</td><td align="right">'.$quiz_avg_score.'</td></tr>'; echo '</td><td align="right">'.$quiz_avg_score.'</td></tr>';
if ($export_csv) { if ($export_csv) {
$temp = [$quiz['title'], $quiz_avg_score]; $temp = [$exercise->getTitle(), $quiz_avg_score];
$csv_content[] = $temp; $csv_content[] = $temp;
} }
} }

@ -32,11 +32,10 @@ $courseList = [];
if ($global) { if ($global) {
$temp = CourseManager::get_courses_list(); $temp = CourseManager::get_courses_list();
foreach ($temp as $tempCourse) { foreach ($temp as $tempCourse) {
$courseInfo = api_get_course_info($tempCourse['code']); $courseList[] = api_get_course_entity($tempCourse['real_id']);
$courseList[] = $courseInfo;
} }
} else { } else {
$courseList = [api_get_course_info()]; $courseList = [api_get_course_entity()];
} }
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
@ -157,9 +156,10 @@ if ($global) {
$export_array_global = $export_array = []; $export_array_global = $export_array = [];
$s_css_class = null; $s_css_class = null;
if (!empty($courseList) && is_array($courseList)) { if (!empty($courseList)) {
foreach ($courseList as $courseInfo) { foreach ($courseList as $course) {
$sessionList = SessionManager::get_session_by_course($courseInfo['real_id']); $courseId = $course->getId();
$sessionList = SessionManager::get_session_by_course($courseId);
$newSessionList = []; $newSessionList = [];
if (!empty($sessionList)) { if (!empty($sessionList)) {
@ -168,9 +168,8 @@ if (!empty($courseList) && is_array($courseList)) {
} }
} }
$courseId = $courseInfo['real_id'];
if ($global) { if ($global) {
// @todo use CQuizRepository
$sql = "SELECT count(iid) as count $sql = "SELECT count(iid) as count
FROM $quizTable AS quiz FROM $quizTable AS quiz
WHERE c_id = $courseId AND active = 1 AND (session_id = 0 OR session_id IS NULL)"; WHERE c_id = $courseId AND active = 1 AND (session_id = 0 OR session_id IS NULL)";
@ -184,7 +183,6 @@ if (!empty($courseList) && is_array($courseList)) {
$result = Database::query($sql); $result = Database::query($sql);
$countExercises = Database::store_result($result); $countExercises = Database::store_result($result);
$exerciseSessionCount = $countExercises[0]['count']; $exerciseSessionCount = $countExercises[0]['count'];
$exerciseCount = $exerciseCount + $exerciseCount * count($newSessionList) + $exerciseSessionCount; $exerciseCount = $exerciseCount + $exerciseCount * count($newSessionList) + $exerciseSessionCount;
// Add course and session list. // Add course and session list.
@ -193,7 +191,7 @@ if (!empty($courseList) && is_array($courseList)) {
} }
$html .= "<tr> $html .= "<tr>
<td rowspan=$exerciseCount>"; <td rowspan=$exerciseCount>";
$html .= $courseInfo['title']; $html .= $course->getTitle();
$html .= "</td>"; $html .= "</td>";
} }
@ -206,9 +204,9 @@ if (!empty($courseList) && is_array($courseList)) {
// Getting the exam list. // Getting the exam list.
if ($global) { if ($global) {
$sql = "SELECT quiz.title, iid, session_id $sql = "SELECT quiz.title, iid, session_id
FROM $quizTable AS quiz FROM $quizTable AS quiz
WHERE c_id = $courseId AND active = 1 WHERE c_id = $courseId AND active = 1
ORDER BY session_id, quiz.title ASC"; ORDER BY session_id, quiz.title ASC";
} else { } else {
//$sessionCondition = api_get_session_condition($sessionId, true, false); //$sessionCondition = api_get_session_condition($sessionId, true, false);
if (!empty($exerciseId)) { if (!empty($exerciseId)) {

@ -104,4 +104,4 @@ $_user['uidReset'] = true;
ChamiloSession::write('_user', $_user); ChamiloSession::write('_user', $_user);
ChamiloSession::write('_user_auth_source', 'azure_active_directory'); ChamiloSession::write('_user_auth_source', 'azure_active_directory');
Redirect::session_request_uri(true, $userInfo['user_id']); Redirect::session_request_uri(true, $userInfo);

Loading…
Cancel
Save