diff --git a/public/main/admin/dashboard_add_users_to_user.php b/public/main/admin/dashboard_add_users_to_user.php index 1fd3f453c1..6703a4591c 100644 --- a/public/main/admin/dashboard_add_users_to_user.php +++ b/public/main/admin/dashboard_add_users_to_user.php @@ -109,12 +109,12 @@ function search_users($needle, $type = 'multiple') $order_clause "; } else { - $sql = "SELECT user_id, username, lastname, firstname + $sql = "SELECT id as user_id, username, lastname, firstname FROM $tbl_user user WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND status NOT IN(".DRH.', '.SESSIONADMIN.', '.STUDENT_BOSS.") AND - user_id NOT IN ($user_anonymous, $current_user_id, $user_id) + id NOT IN ($user_anonymous, $current_user_id, $user_id) $without_assigned_users $order_clause "; @@ -397,20 +397,20 @@ if (api_is_multiple_url_enabled()) { $sql = "SELECT user.id as user_id, username, lastname, firstname FROM $tbl_user user LEFT JOIN $tbl_access_url_rel_user au - ON (au.user_id = user.user_id) + ON (au.user_id = user.id) WHERE $without_assigned_users - user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND + user.id NOT IN ($user_anonymous, $current_user_id, $user_id) AND status NOT IN(".DRH.', '.SESSIONADMIN.', '.ANONYMOUS.") $search_user AND access_url_id = ".api_get_current_access_url_id()." $sqlConditions ORDER BY firstname"; } else { - $sql = "SELECT user_id, username, lastname, firstname + $sql = "SELECT id as user_id, username, lastname, firstname FROM $tbl_user user WHERE $without_assigned_users - user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND + id NOT IN ($user_anonymous, $current_user_id, $user_id) AND status NOT IN(".DRH.', '.SESSIONADMIN.', '.ANONYMOUS.") $search_user $sqlConditions diff --git a/public/main/admin/user_list.php b/public/main/admin/user_list.php index 97500935e9..2d5733f07c 100644 --- a/public/main/admin/user_list.php +++ b/public/main/admin/user_list.php @@ -597,9 +597,9 @@ function modify_filter($user_id, $url_params, $row) if (api_is_platform_admin()) { if (!$user_is_anonymous) { $result .= ''. - Display::return_icon('info2.png', get_lang('Informationrmation')).'  '; + Display::return_icon('info2.png', get_lang('Information')).'  '; } else { - $result .= Display::return_icon('info2_na.png', get_lang('Informationrmation')).'  '; + $result .= Display::return_icon('info2_na.png', get_lang('Information')).'  '; } } diff --git a/public/main/admin/user_list_consent.php b/public/main/admin/user_list_consent.php index d31daa49ab..8be9cb37f8 100644 --- a/public/main/admin/user_list_consent.php +++ b/public/main/admin/user_list_consent.php @@ -644,7 +644,7 @@ $toolbarActions = Display::toolbarAction( ); $noticeMessage = sprintf( - get_lang('InformationrmationRightToBeForgottenLinkX'), + get_lang("You can find more information about the user's right to be forgotten through the following page: %s"), 'https://gdpr-info.eu/art-17-gdpr/' ); $notice = Display::return_message($noticeMessage, 'normal', false); diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index a0b36b78d9..e315c2c5e8 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -2081,10 +2081,10 @@ function api_get_anonymous_id() if ($max >= 2) { $sql = "SELECT * FROM $table as TEL JOIN $tableU as U - ON U.user_id = TEL.login_user_id + ON U.id = TEL.login_user_id WHERE TEL.user_ip = '$ip' AND U.status = ".ANONYMOUS." - AND U.user_id != 2 "; + AND U.id != 2 "; $result = Database::query($sql); if (empty(Database::num_rows($result))) { @@ -2108,19 +2108,19 @@ function api_get_anonymous_id() } else { $row = Database::fetch_array($result, 'ASSOC'); - return $row['user_id']; + return $row['id']; } } $table = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT user_id + $sql = "SELECT id FROM $table WHERE status = ".ANONYMOUS." "; $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res, 'ASSOC'); - return $row['user_id']; + return $row['id']; } // No anonymous user was found. @@ -3088,7 +3088,7 @@ function api_get_user_status($user_id = null) $user_id = api_get_user_id(); } $table = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT status FROM $table WHERE user_id = $user_id "; + $sql = "SELECT status FROM $table WHERE id = $user_id "; $result = Database::query($sql); $status = null; if (Database::num_rows($result)) { @@ -5705,7 +5705,7 @@ function api_is_course_visible_for_user($userid = null, $cid = null) $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $sql = "SELECT status FROM $tbl_user - WHERE user_id = $userid + WHERE id = $userid LIMIT 1"; $result = Database::query($sql); diff --git a/public/main/inc/lib/attendance.lib.php b/public/main/inc/lib/attendance.lib.php index e7d0ec430a..d975a14fcb 100644 --- a/public/main/inc/lib/attendance.lib.php +++ b/public/main/inc/lib/attendance.lib.php @@ -25,13 +25,24 @@ class Attendance /** * Get attendance list only the id, name and attendance_qualify_max fields. * - * @param int $course_id course db name (optional) - * @param int $session_id session id (optional) + * @param int $courseId + * @param int $sessionId * * @return array attendances list */ - public function get_attendances_list($course_id = 0, $session_id = 0) + public function get_attendances_list($courseId = 0, $sessionId = 0) { + $repo = Container::getAttendanceRepository(); + + $course = api_get_course_entity($courseId); + $session = api_get_session_entity($sessionId); + + $qb = $repo->getResourcesByCourse($course, $session, null); + //$qb->select('resource'); + $qb->andWhere('resource.active = 1'); + + return $qb->getQuery()->getResult(); + $table = Database::get_course_table(TABLE_ATTENDANCE); $course_id = (int) $course_id; if (empty($course_id)) { diff --git a/public/main/inc/lib/course.lib.php b/public/main/inc/lib/course.lib.php index 07c35c6407..49db543187 100644 --- a/public/main/inc/lib/course.lib.php +++ b/public/main/inc/lib/course.lib.php @@ -6,6 +6,7 @@ use Chamilo\CoreBundle\Entity\AccessUrlRelSession; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField; use Chamilo\CoreBundle\Entity\SequenceResource; +use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Repository\CourseRepository; use Chamilo\CoreBundle\Repository\SequenceResourceRepository; @@ -1075,9 +1076,8 @@ class CourseManager 'c_id' => $courseId, 'visible' => $visible, ]; - $insertId = Database::insert($courseUserTable, $params); - return $insertId; + return Database::insert($courseUserTable, $params); } /** @@ -1145,24 +1145,38 @@ class CourseManager } /** - * @param int $user_id - * @param string $startsWith Optional + * @param int $userId + * @param string $keyword * * @return array an array with the course info of all the courses (real and virtual) * of which the current user is course admin */ - public static function get_course_list_of_user_as_course_admin($user_id, $startsWith = '') + public static function get_course_list_of_user_as_course_admin($userId, $keyword = '') { - if ($user_id != strval(intval($user_id))) { + $user = api_get_user_entity($userId); + + if (null === $user) { return []; } + $url = api_get_url_entity(); + $user = api_get_user_entity($userId); + + $repo = Container::getUserRepository(); + + return $repo->getCourses($user, $url, COURSEMANAGER, $keyword); + + // Definitions database tables and variables $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tblCourseCategory = Database::get_main_table(TABLE_MAIN_CATEGORY); - $user_id = intval($user_id); - $data = []; + $userId = (int) $userId; + + + if (empty($userId)) { + return []; + } $sql = "SELECT course.code, @@ -1173,9 +1187,10 @@ class CourseManager FROM $tbl_course_user as course_rel_user INNER JOIN $tbl_course as course ON course.id = course_rel_user.c_id - LEFT JOIN $tblCourseCategory ON course.category_id = $tblCourseCategory.id + LEFT JOIN $tblCourseCategory + ON course.category_id = $tblCourseCategory.id WHERE - course_rel_user.user_id = $user_id AND + course_rel_user.user_id = $userId AND course_rel_user.status = 1 "; @@ -1196,23 +1211,23 @@ class CourseManager ON (course_rel_url.c_id = course.id) WHERE access_url_id = $access_url_id AND - course_rel_user.user_id = $user_id AND + course_rel_user.user_id = $userId AND course_rel_user.status = 1 "; } } - if (!empty($startsWith)) { - $startsWith = Database::escape_string($startsWith); - - $sql .= " AND (course.title LIKE '$startsWith%' OR course.code LIKE '$startsWith%')"; + if (!empty($keyword)) { + $keyword = Database::escape_string($keyword); + $sql .= " AND (course.title LIKE '$keyword%' OR course.code LIKE '$keyword%')"; } $sql .= ' ORDER BY course.title'; - $result_nb_cours = Database::query($sql); - if (Database::num_rows($result_nb_cours) > 0) { - while ($row = Database::fetch_array($result_nb_cours, 'ASSOC')) { + $query = Database::query($sql); + $data = []; + if (Database::num_rows($query) > 0) { + while ($row = Database::fetch_array($query, 'ASSOC')) { $data[$row['id']] = $row; } } @@ -1258,7 +1273,7 @@ class CourseManager /** * Check if user is subscribed inside a course. * - * @param int $user_id + * @param int $userId * @param string $course_code , if this parameter is null, it'll check for all courses * @param bool $in_a_session True for checking inside sessions too, by default is not checked * @param int $session_id @@ -1266,12 +1281,12 @@ class CourseManager * @return bool $session_id true if the user is registered in the course, false otherwise */ public static function is_user_subscribed_in_course( - $user_id, + $userId, $course_code = null, $in_a_session = false, $session_id = 0 ) { - $user_id = (int) $user_id; + $userId = (int) $userId; $session_id = (int) $session_id; if (api_get_configuration_value('catalog_course_subscription_in_user_s_session')) { @@ -1283,7 +1298,7 @@ class CourseManager return false; } - $user = api_get_user_entity($user_id); + $user = api_get_user_entity($userId); if (is_null($user)) { return false; } @@ -1312,7 +1327,7 @@ class CourseManager $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." WHERE - user_id = $user_id AND + user_id = $userId AND relation_type<>".COURSE_RELATION_TYPE_RRHH." $condition_course "; @@ -1330,21 +1345,21 @@ class CourseManager $tableSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $sql = "SELECT 1 FROM $tableSessionCourseUser - WHERE user_id = $user_id AND session_id = $session_id $condition_course"; + WHERE user_id = $userId AND session_id = $session_id $condition_course"; if (Database::num_rows(Database::query($sql)) > 0) { return true; } $sql = "SELECT 1 FROM $tableSessionCourseUser - WHERE user_id = $user_id AND session_id = $session_id AND status = 2 $condition_course"; + WHERE user_id = $userId AND session_id = $session_id AND status = 2 $condition_course"; if (Database::num_rows(Database::query($sql)) > 0) { return true; } $sql = 'SELECT 1 FROM '.Database::get_main_table(TABLE_MAIN_SESSION). - " WHERE id = $session_id AND id_coach = $user_id"; + " WHERE id = $session_id AND id_coach = $userId"; if (Database::num_rows(Database::query($sql)) > 0) { return true; @@ -1356,14 +1371,14 @@ class CourseManager /** * Is the user a teacher in the given course? * - * @param int $user_id , the id (int) of the user + * @param int $userId , the id (int) of the user * @param string $course_code , the course code * * @return bool if the user is a teacher in the course, false otherwise */ - public static function is_course_teacher($user_id, $course_code) + public static function is_course_teacher($userId, $course_code) { - if ($user_id != strval(intval($user_id))) { + if ($userId != strval(intval($userId))) { return false; } @@ -1373,7 +1388,7 @@ class CourseManager } $courseId = $courseInfo['real_id']; $sql = "SELECT status FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." - WHERE c_id = $courseId AND user_id = $user_id "; + WHERE c_id = $courseId AND user_id = $userId "; $result = Database::query($sql); if (Database::num_rows($result) > 0) { diff --git a/public/main/inc/lib/tracking.lib.php b/public/main/inc/lib/tracking.lib.php index 14f1a91379..621786af5e 100644 --- a/public/main/inc/lib/tracking.lib.php +++ b/public/main/inc/lib/tracking.lib.php @@ -2605,7 +2605,7 @@ class Tracking } $resultLP = Database::select( - 'id', + 'iid', $lPTable, ['where' => $lpConditions] ); @@ -2773,13 +2773,13 @@ class Tracking // Check the real number of LPs corresponding to the filter in the // database (and if no list was given, get them all) if (empty($session_id)) { - $sql = "SELECT DISTINCT(id), use_max_score + $sql = "SELECT DISTINCT(iid), use_max_score FROM $lp_table WHERE c_id = $course_id AND (session_id = 0 OR session_id IS NULL) $condition_lp "; } else { - $sql = "SELECT DISTINCT(id), use_max_score + $sql = "SELECT DISTINCT(iid), use_max_score FROM $lp_table WHERE c_id = $course_id $condition_lp "; } @@ -6499,9 +6499,9 @@ class Tracking } // Now fill users data - $sqlUsers = "SELECT user_id, username, lastname, firstname + $sqlUsers = "SELECT id as user_id, username, lastname, firstname FROM $tuser - WHERE user_id IN (".implode(',', $userIds).")"; + WHERE id IN (".implode(',', $userIds).")"; $resUsers = Database::query($sqlUsers); while ($rowUser = Database::fetch_assoc($resUsers)) { $users[$rowUser['user_id']] = $rowUser; diff --git a/public/main/mySpace/myStudents.php b/public/main/mySpace/myStudents.php index c3c9d1147e..1ae8b871fe 100644 --- a/public/main/mySpace/myStudents.php +++ b/public/main/mySpace/myStudents.php @@ -25,23 +25,24 @@ $courseCode = ''; if ($courseInfo) { $courseCode = $courseInfo['code']; } -$student_id = isset($_GET['student']) ? (int) $_GET['student'] : 0; +$studentId = isset($_GET['student']) ? (int) $_GET['student'] : 0; + +if (empty($studentId)) { + api_not_allowed(true); +} + $coachId = isset($_GET['id_coach']) ? (int) $_GET['id_coach'] : 0; $details = isset($_GET['details']) ? Security::remove_XSS($_GET['details']) : ''; -$currentUrl = api_get_self().'?student='.$student_id.'&course='.$courseCode.'&id_session='.$sessionId +$currentUrl = api_get_self().'?student='.$studentId.'&course='.$courseCode.'&id_session='.$sessionId .'&origin='.$origin.'&details='.$details; $allowMessages = api_get_configuration_value('private_messages_about_user'); $workingTime = api_get_configuration_value('considered_working_time'); $workingTimeEdit = api_get_configuration_value('allow_working_time_edition'); -if (empty($student_id)) { - api_not_allowed(true); -} - // user info -$user_info = api_get_user_info($student_id); +$userInfo = api_get_user_info($studentId); -if (empty($user_info)) { +if (empty($userInfo)) { api_not_allowed(true); } @@ -149,7 +150,7 @@ if (!empty($details)) { 'name' => get_lang('Learners of trainer'), ]; $interbreadcrumb[] = [ - 'url' => 'myStudents.php?student='.$student_id.'&id_coach='.$coachId, + 'url' => 'myStudents.php?student='.$studentId.'&id_coach='.$coachId, 'name' => get_lang('Learner details'), ]; } else { @@ -158,7 +159,7 @@ if (!empty($details)) { 'name' => get_lang('My learners'), ]; $interbreadcrumb[] = [ - 'url' => 'myStudents.php?student='.$student_id, + 'url' => 'myStudents.php?student='.$studentId, 'name' => get_lang('Learner details'), ]; } @@ -182,7 +183,7 @@ if (!empty($details)) { $this_section = SECTION_TRACKING; $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Reporting')]; $interbreadcrumb[] = ['url' => 'teachers.php', 'name' => get_lang('Trainers')]; - $nameTools = $user_info['complete_name']; + $nameTools = $userInfo['complete_name']; } else { $interbreadcrumb[] = [ 'url' => api_is_student_boss() ? '#' : 'index.php', @@ -221,7 +222,7 @@ switch ($action) { } $workingTime = isset($_GET['time']) ? $_GET['time'] : ''; $workId = isset($_GET['work_id']) ? $_GET['work_id'] : ''; - Event::eventAddVirtualCourseTime($courseInfo['real_id'], $student_id, $sessionId, $workingTime, $workId); + Event::eventAddVirtualCourseTime($courseInfo['real_id'], $studentId, $sessionId, $workingTime, $workId); Display::addFlash(Display::return_message(get_lang('Updated'))); header('Location: '.$currentUrl); @@ -232,7 +233,7 @@ switch ($action) { } $workingTime = isset($_GET['time']) ? $_GET['time'] : ''; $workId = isset($_GET['work_id']) ? $_GET['work_id'] : ''; - Event::eventRemoveVirtualCourseTime($courseInfo['real_id'], $student_id, $sessionId, $workingTime, $workId); + Event::eventRemoveVirtualCourseTime($courseInfo['real_id'], $studentId, $sessionId, $workingTime, $workId); Display::addFlash(Display::return_message(get_lang('Updated'))); @@ -254,7 +255,7 @@ switch ($action) { $progressPerCourse = []; foreach ($courses as $course) { $courseId = $course['c_id']; - $courseTimeSpent = Tracking::get_time_spent_on_the_course($student_id, $courseId, $sessionToExport); + $courseTimeSpent = Tracking::get_time_spent_on_the_course($studentId, $courseId, $sessionToExport); $timeSpentPerCourse[$courseId] = $courseTimeSpent; $timeSpent += $courseTimeSpent; $sql = "SELECT DISTINCT count(course_access_id) as count @@ -262,11 +263,11 @@ switch ($action) { WHERE c_id = $courseId AND session_id = $sessionToExport AND - user_id = $student_id"; + user_id = $studentId"; $result = Database::query($sql); $row = Database::fetch_array($result); $numberVisits += $row['count']; - $courseProgress = Tracking::get_avg_student_progress($student_id, $course['code'], [], $sessionToExport); + $courseProgress = Tracking::get_avg_student_progress($studentId, $course['code'], [], $sessionToExport); $progressPerCourse[$courseId] = $courseProgress; $progress += $courseProgress; } @@ -274,8 +275,8 @@ switch ($action) { $average = round($progress / count($courses), 1); $average = empty($average) ? '0%' : $average.'%'; - $first = Tracking::get_first_connection_date($student_id); - $last = Tracking::get_last_connection_date($student_id); + $first = Tracking::get_first_connection_date($studentId); + $last = Tracking::get_last_connection_date($studentId); $table = new HTML_Table(['class' => 'data_table']); $column = 0; @@ -328,7 +329,7 @@ switch ($action) { $courseCodeItem = $courseInfoItem['code']; $isSubscribed = CourseManager::is_user_subscribed_in_course( - $student_id, + $studentId, $courseCodeItem, true, $sId @@ -342,7 +343,7 @@ switch ($action) { $totalProgress += $progress; $bestScore = Tracking::get_avg_student_score( - $student_id, + $studentId, $courseCodeItem, [], $sId, @@ -391,7 +392,7 @@ switch ($action) { $tpl = new Template('', false, false, false, true, false, false); $tpl->assign('title', get_lang('Attestation of attendance')); $tpl->assign('session_title', $sessionInfo['name']); - $tpl->assign('student', $user_info['complete_name']); + $tpl->assign('student', $userInfo['complete_name']); $tpl->assign('table_progress', $table->toHtml()); $tpl->assign('subtitle', sprintf( get_lang('In session %s, you had the following results'), @@ -405,7 +406,7 @@ switch ($action) { 'session_info' => $sessionInfo, 'course_info' => '', 'pdf_date' => '', - 'student_info' => $user_info, + 'student_info' => $userInfo, 'show_grade_generated_date' => true, 'show_real_course_teachers' => false, 'show_teacher_as_myself' => false, @@ -444,7 +445,7 @@ switch ($action) { $title .= '_'.$sessionInfo['name']; } - $fileName = 'report'.$title.'_'.$user_info['complete_name']; + $fileName = 'report'.$title.'_'.$userInfo['complete_name']; switch ($export) { case 'csv': Export::arrayToCsv($dataToExport, $fileName); @@ -465,27 +466,27 @@ switch ($action) { if (!empty($subject) && !empty($message)) { $currentUserInfo = api_get_user_info(); MessageManager::sendMessageAboutUser( - $user_info, + $userInfo, $currentUserInfo, $subject, $message ); // Send also message to all student bosses - $bossList = UserManager::getStudentBossList($student_id); + $bossList = UserManager::getStudentBossList($studentId); if (!empty($bossList)) { - $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id; + $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$studentId; $link = Display::url($url, $url); foreach ($bossList as $boss) { MessageManager::send_message_simple( $boss['boss_id'], - sprintf(get_lang('Follow up message about student %s'), $user_info['complete_name']), + sprintf(get_lang('Follow up message about student %s'), $userInfo['complete_name']), sprintf( get_lang('Hi,

'), $currentUserInfo['complete_name'], - $user_info['complete_name'], + $userInfo['complete_name'], $link ) ); @@ -505,35 +506,35 @@ switch ($action) { // Delete old certificate $myCertificate = GradebookUtils::get_certificate_by_user_id( 0, - $student_id + $studentId ); if ($myCertificate) { - $certificate = new Certificate($myCertificate['id'], $student_id); + $certificate = new Certificate($myCertificate['id'], $studentId); $certificate->delete(true); } // Create new one - $certificate = new Certificate(0, $student_id); + $certificate = new Certificate(0, $studentId); $certificate->generatePdfFromCustomCertificate(); exit; break; case 'send_legal': - $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $student_id); + $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $studentId); if ($isBoss || api_is_platform_admin()) { $subject = get_lang('Legal conditions'); $content = sprintf( get_lang('Hello,
Your tutor sent you your terms and conditions. You can sign it following this URL: %s'), api_get_path(WEB_PATH) ); - MessageManager::send_message_simple($student_id, $subject, $content); + MessageManager::send_message_simple($studentId, $subject, $content); Display::addFlash(Display::return_message(get_lang('Sent'))); } break; case 'delete_legal': - $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $student_id); + $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $studentId); if ($isBoss || api_is_platform_admin()) { $extraFieldValue = new ExtraFieldValue('user'); $value = $extraFieldValue->get_values_by_handler_and_field_variable( - $student_id, + $studentId, 'legal_accept' ); $result = $extraFieldValue->delete($value['id']); @@ -547,12 +548,12 @@ switch ($action) { $check = true; if (!empty($lp_id) && - !empty($student_id) && + !empty($studentId) && api_is_allowed_to_edit() && Security::check_token('get') ) { Event::delete_student_lp_events( - $student_id, + $studentId, $lp_id, $courseInfo, $sessionId @@ -611,7 +612,7 @@ $sql = "SELECT c_id FROM $tbl_course_user WHERE relation_type <> ".COURSE_RELATION_TYPE_RRHH." AND - user_id = ".$student_id; + user_id = ".$studentId; $rs = Database::query($sql); while ($row = Database::fetch_array($rs)) { @@ -627,7 +628,7 @@ while ($row = Database::fetch_array($rs)) { // Get the list of sessions where the user is subscribed as student $sql = 'SELECT session_id, c_id FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).' - WHERE user_id='.$student_id; + WHERE user_id='.$studentId; $rs = Database::query($sql); $tmp_sessions = []; while ($row = Database::fetch_array($rs, 'ASSOC')) { @@ -651,12 +652,12 @@ $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( ); if (api_is_drh() && !api_is_platform_admin()) { - if (!empty($student_id)) { + if (!empty($studentId)) { if (api_drh_can_access_all_session_content()) { } else { if (!$isDrhOfCourse) { if (api_is_drh() && - !UserManager::is_user_followed_by_drh($student_id, api_get_user_id()) + !UserManager::is_user_followed_by_drh($studentId, api_get_user_id()) ) { api_not_allowed(true); } @@ -691,40 +692,40 @@ echo ''. +if (!empty($userInfo['email'])) { + $send_mail = ''. Display::return_icon('mail_send.png', get_lang('Send message mail'), '', ICON_SIZE_MEDIUM).''; } else { $send_mail = Display::return_icon('mail_send_na.png', get_lang('Send message mail'), '', ICON_SIZE_MEDIUM); } echo $send_mail; -if (!empty($student_id) && !empty($courseCode)) { +if (!empty($studentId) && !empty($courseCode)) { // Only show link to connection details if course and student were defined in the URL - echo '' .Display::return_icon('statistics.png', get_lang('Access details'), '', ICON_SIZE_MEDIUM) .''; } $notebookTeacherEnable = 'true' === api_get_plugin_setting('notebookteacher', 'enable_plugin_notebookteacher'); -if ($notebookTeacherEnable && !empty($student_id) && !empty($course_code)) { +if ($notebookTeacherEnable && !empty($studentId) && !empty($course_code)) { // link notebookteacher - $optionsLink = 'student_id='.$student_id.'&origin='.$origin.'&cidReq='.$courseCode.'&id_session='.$sessionId; + $optionsLink = 'student_id='.$studentId.'&origin='.$origin.'&cidReq='.$courseCode.'&id_session='.$sessionId; echo '' .Display::return_icon('notebookteacher.png', get_lang('Notebook'), '', ICON_SIZE_MEDIUM) .''; } -if (api_can_login_as($student_id)) { - echo '' .Display::return_icon('login_as.png', get_lang('Login as'), null, ICON_SIZE_MEDIUM).'  '; } -if (Skill::isAllowed($student_id, false)) { +if (Skill::isAllowed($studentId, false)) { echo Display::url( Display::return_icon( 'skill-badges.png', @@ -732,11 +733,11 @@ if (Skill::isAllowed($student_id, false)) { null, ICON_SIZE_MEDIUM ), - api_get_path(WEB_CODE_PATH).'badge/assign.php?'.http_build_query(['user' => $student_id]) + api_get_path(WEB_CODE_PATH).'badge/assign.php?'.http_build_query(['user' => $studentId]) ); } -if (Skill::isAllowed($student_id, false)) { +if (Skill::isAllowed($studentId, false)) { echo Display::url( Display::return_icon( 'attendance.png', @@ -744,12 +745,12 @@ if (Skill::isAllowed($student_id, false)) { null, ICON_SIZE_MEDIUM ), - api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?action=all_attendance&student='.$student_id + api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?action=all_attendance&student='.$studentId ); } $permissions = StudentFollowUpPlugin::getPermissions( - $student_id, + $studentId, api_get_user_id() ); @@ -762,14 +763,14 @@ if ($isAllow) { null, ICON_SIZE_MEDIUM ), - api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?student_id='.$student_id + api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?student_id='.$studentId ); } echo ''; // is the user online ? $online = get_lang('No'); -if (user_is_online($student_id)) { +if (user_is_online($studentId)) { $online = get_lang('Yes'); } @@ -777,10 +778,10 @@ if (user_is_online($student_id)) { $avg_student_progress = $avg_student_score = 0; if (empty($sessionId)) { - $isSubscribedToCourse = CourseManager::is_user_subscribed_in_course($user_info['user_id'], $courseCode); + $isSubscribedToCourse = CourseManager::is_user_subscribed_in_course($studentId, $courseCode); } else { $isSubscribedToCourse = CourseManager::is_user_subscribed_in_course( - $user_info['user_id'], + $studentId, $courseCode, true, $sessionId @@ -789,7 +790,7 @@ if (empty($sessionId)) { if ($isSubscribedToCourse) { $avg_student_progress = Tracking::get_avg_student_progress( - $user_info['user_id'], + $studentId, $courseCode, [], $sessionId @@ -797,7 +798,7 @@ if ($isSubscribedToCourse) { // the score inside the Reporting table $avg_student_score = Tracking::get_avg_student_score( - $user_info['user_id'], + $studentId, $courseCode, [], $sessionId @@ -809,7 +810,7 @@ $time_spent_on_the_course = 0; if (!empty($courseInfo)) { $time_spent_on_the_course = api_time_to_hms( Tracking::get_time_spent_on_the_course( - $user_info['user_id'], + $studentId, $courseInfo['real_id'], $sessionId ) @@ -817,13 +818,13 @@ if (!empty($courseInfo)) { } // get information about connections on the platform by student -$first_connection_date = Tracking::get_first_connection_date($user_info['user_id']); +$first_connection_date = Tracking::get_first_connection_date($studentId); if ('' == $first_connection_date) { $first_connection_date = get_lang('No connection'); } $last_connection_date = Tracking::get_last_connection_date( - $user_info['user_id'], + $studentId, true ); if ('' == $last_connection_date) { @@ -840,9 +841,9 @@ $csv_content[] = [ get_lang('Tel'), ]; $csv_content[] = [ - $user_info['complete_name'], - $user_info['email'], - $user_info['phone'], + $userInfo['complete_name'], + $userInfo['email'], + $userInfo['phone'], ]; $csv_content[] = []; @@ -869,30 +870,18 @@ $csv_content[] = [ $coachs_name = ''; $session_name = ''; -$userPicture = UserManager::getUserPicture($user_info['user_id'], USER_IMAGE_SIZE_BIG); +$userPicture = UserManager::getUserPicture($studentId, USER_IMAGE_SIZE_BIG); $userGroupManager = new UserGroup(); $userGroups = $userGroupManager->getNameListByUser( - $user_info['user_id'], + $studentId, UserGroup::NORMAL_CLASS ); -$userInfo = [ - 'id' => $user_info['user_id'], - 'complete_name' => $user_info['complete_name'], - 'complete_name_link' => $user_info['complete_name_with_message_link'], - 'phone' => $user_info['phone'], - 'code' => $user_info['official_code'], - 'username' => $user_info['username'], - 'registration_date' => $user_info['registration_date'], - 'email' => $user_info['email'], - 'has_certificates' => $user_info['has_certificates'], - 'last_login' => $user_info['last_login'], - 'profile_url' => $user_info['profile_url'], - 'groups' => $userGroupManager, - 'avatar' => $userPicture, - 'online' => $online, -]; +$userInfo['complete_name_link'] = $userInfo['complete_name_with_message_link']; +$userInfo['groups'] = $userGroupManager; +$userInfo['avatar'] = $userPicture; +$userInfo['online'] = $online; if (!empty($courseCode)) { $userInfo['url_access'] = Display::url( @@ -900,7 +889,7 @@ if (!empty($courseCode)) { 'access_details.php?' .http_build_query( [ - 'student' => $student_id, + 'student' => $studentId, 'course' => $courseCode, 'origin' => $origin, 'cidReq' => $courseCode, @@ -914,7 +903,7 @@ if (!empty($courseCode)) { // Display timezone if the user selected one and if the admin allows the use of user's timezone $timezone = null; $timezone_user = UserManager::get_extra_user_data_by_field( - $user_info['user_id'], + $studentId, 'timezone' ); $use_users_timezone = api_get_setting('use_users_timezone', 'timezones'); @@ -942,13 +931,13 @@ if ('true' === $details) { $icon = ''; $timeLegalAccept = ''; $btn = ''; - +$userInfo['legal'] = ''; if ('true' === api_get_setting('allow_terms_conditions')) { - $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $student_id); + $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $studentId); if ($isBoss || api_is_platform_admin()) { $extraFieldValue = new ExtraFieldValue('user'); $value = $extraFieldValue->get_values_by_handler_and_field_variable( - $student_id, + $studentId, 'legal_accept' ); $icon = Display::return_icon('accept_na.png'); @@ -959,14 +948,14 @@ if ('true' === api_get_setting('allow_terms_conditions')) { $icon = Display::return_icon('accept.png'); $btn = Display::url( get_lang('Delete legal agreement'), - api_get_self().'?action=delete_legal&student='.$student_id.'&course='.$course_code, + api_get_self().'?action=delete_legal&student='.$studentId.'&course='.$course_code, ['class' => 'btn btn-danger'] ); $timeLegalAccept = api_get_local_time($legalTime); } else { $btn = Display::url( get_lang('Send message legal agreement'), - api_get_self().'?action=send_legal&student='.$student_id.'&course='.$course_code, + api_get_self().'?action=send_legal&student='.$studentId.'&course='.$course_code, ['class' => 'btn btn-primary'] ); $timeLegalAccept = get_lang('Not Registered'); @@ -1010,9 +999,9 @@ if (isset($_GET['action']) and 'all_attendance' == $_GET['action']) { $defaults['startDate'] = $startDateText; $defaults['endDate'] = $endDateText; $form = new FormValidator('all_attendance_list', 'GET', - 'myStudents.php?action=all_attendance&student='.$student_id.'&startDate='.$defaults['startDate'].'&endDate='.$defaults['endDate'].'&&'.api_get_cidreq(), + 'myStudents.php?action=all_attendance&student='.$studentId.'&startDate='.$defaults['startDate'].'&endDate='.$defaults['endDate'].'&&'.api_get_cidreq(), ''); - $form->addElement('html', ''); + $form->addElement('html', ''); $form->addElement('html', ''); $form->addDateTimePicker('startDate', [ @@ -1031,7 +1020,7 @@ if (isset($_GET['action']) and 'all_attendance' == $_GET['action']) { $form->display(); /** Display dates */ $attendance = new Attendance(); - $data = $attendance->getCoursesWithAttendance($student_id, $startDate, $endDate); + $data = $attendance->getCoursesWithAttendance($studentId, $startDate, $endDate); // 'attendance from %s to %s' $title = sprintf(get_lang('AttendanceFromXToY'), $startDateText, $endDateText); @@ -1072,7 +1061,7 @@ if (isset($_GET['action']) and 'all_attendance' == $_GET['action']) { ' .'' + .$studentId.'">' .$attendanceWork['courseTitle']." $printSession ".' @@ -1100,12 +1089,12 @@ $tpl = new Template( ); if (!empty($courseInfo)) { - $nb_assignments = Tracking::count_student_assignments($student_id, $courseCode, $sessionId); - $messages = Tracking::count_student_messages($student_id, $courseCode, $sessionId); - $links = Tracking::count_student_visited_links($student_id, $courseInfo['real_id'], $sessionId); - $chat_last_connection = Tracking::chat_last_connection($student_id, $courseInfo['real_id'], $sessionId); - $documents = Tracking::count_student_downloaded_documents($student_id, $courseInfo['real_id'], $sessionId); - $uploaded_documents = Tracking::count_student_uploaded_documents($student_id, $courseCode, $sessionId); + $nb_assignments = Tracking::count_student_assignments($studentId, $courseCode, $sessionId); + $messages = Tracking::count_student_messages($studentId, $courseCode, $sessionId); + $links = Tracking::count_student_visited_links($studentId, $courseInfo['real_id'], $sessionId); + $chat_last_connection = Tracking::chat_last_connection($studentId, $courseInfo['real_id'], $sessionId); + $documents = Tracking::count_student_downloaded_documents($studentId, $courseInfo['real_id'], $sessionId); + $uploaded_documents = Tracking::count_student_uploaded_documents($studentId, $courseCode, $sessionId); $tpl->assign('title', $courseInfo['title']); $userInfo['tools'] = [ @@ -1115,9 +1104,9 @@ if (!empty($courseInfo)) { 'chat_connection' => $chat_last_connection, 'documents' => $documents, 'upload_documents' => $uploaded_documents, - 'course_first_access' => Tracking::get_first_connection_date_on_the_course($student_id, $courseInfo['real_id'], $sessionId), - 'course_last_access' => Tracking::get_last_connection_date_on_the_course($student_id, $courseInfo, $sessionId), - 'count_access_dates' => Tracking::getNumberOfCourseAccessDates($student_id, $courseInfo['real_id'], $sessionId), + 'course_first_access' => Tracking::get_first_connection_date_on_the_course($studentId, $courseInfo['real_id'], $sessionId), + 'course_last_access' => Tracking::get_last_connection_date_on_the_course($studentId, $courseInfo, $sessionId), + 'count_access_dates' => Tracking::getNumberOfCourseAccessDates($studentId, $courseInfo['real_id'], $sessionId), ]; } else { $details = false; @@ -1134,7 +1123,7 @@ $allowAll = api_get_configuration_value('allow_teacher_access_student_skills'); if ($allowAll) { // Show all skills echo Tracking::displayUserSkills( - $user_info['user_id'], + $studentId, 0, 0, true @@ -1142,7 +1131,7 @@ if ($allowAll) { } else { // Default behaviour - Show all skills depending the course and session id echo Tracking::displayUserSkills( - $user_info['user_id'], + $studentId, $courseInfo ? $courseInfo['real_id'] : 0, $sessionId ); @@ -1254,12 +1243,12 @@ if (empty($details)) { if (empty($session_info)) { $isSubscribed = CourseManager::is_user_subscribed_in_course( - $student_id, + $studentId, $courseCodeItem ); } else { $isSubscribed = CourseManager::is_user_subscribed_in_course( - $student_id, + $studentId, $courseCodeItem, true, $sId @@ -1268,7 +1257,7 @@ if (empty($details)) { if ($isSubscribed) { $timeInSeconds = Tracking::get_time_spent_on_the_course( - $user_info['user_id'], + $studentId, $courseId, $sId ); @@ -1277,7 +1266,7 @@ if (empty($details)) { // get average of faults in attendances by student $results_faults_avg = $attendance->get_faults_average_by_course( - $student_id, + $studentId, $courseCodeItem, $sId ); @@ -1287,7 +1276,7 @@ if (empty($details)) { if (api_is_drh()) { $attendances_faults_avg = '' + .$studentId.'">' .$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' (' .$results_faults_avg['porcent'].'%)'; } else { @@ -1312,9 +1301,9 @@ if (empty($details)) { $scoretotal = []; if (isset($cats) && isset($cats[0])) { if (!empty($sId)) { - $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem, $sId); + $scoretotal = $cats[0]->calc_score($studentId, null, $courseCodeItem, $sId); } else { - $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem); + $scoretotal = $cats[0]->calc_score($studentId, null, $courseCodeItem); } } @@ -1330,7 +1319,7 @@ if (empty($details)) { } $progress = Tracking::get_avg_student_progress( - $user_info['user_id'], + $studentId, $courseCodeItem, [], $sId @@ -1339,7 +1328,7 @@ if (empty($details)) { $totalProgress += $progress; $score = Tracking::get_avg_student_score( - $user_info['user_id'], + $studentId, $courseCodeItem, [], $sId @@ -1375,12 +1364,12 @@ if (empty($details)) { '.$scoretotal_display.''; if (!empty($coachId)) { - echo '' .Display::return_icon('2rightarrow.png', get_lang('Details')).''; } else { - echo '' .Display::return_icon('2rightarrow.png', get_lang('Details')).''; } @@ -1483,10 +1472,10 @@ if (empty($details)) { $timeCourse = null; if (Tracking::minimumTimeAvailable($sessionId, $courseInfo['real_id'])) { - $timeCourse = Tracking::getCalculateTime($student_id, $courseInfo['real_id'], $sessionId); + $timeCourse = Tracking::getCalculateTime($studentId, $courseInfo['real_id'], $sessionId); } - if (INVITEE != $user_info['status']) { + if (INVITEE != $userInfo['status']) { $csv_content[] = []; $csv_content[] = [str_replace(' ', '', strip_tags($userInfo['complete_name']))]; $trackingColumns = api_get_configuration_value('tracking_columns'); @@ -1581,7 +1570,7 @@ if (empty($details)) { // Get progress in lp $progress = Tracking::get_avg_student_progress( - $student_id, + $studentId, $course_code, [$lp_id], $sessionId @@ -1599,7 +1588,7 @@ if (empty($details)) { $total_time = isset($lpTime[$lp_id]) ? (int) $lpTime[$lp_id] : 0; } else { $total_time = Tracking::get_time_spent_in_lp( - $student_id, + $studentId, $courseCode, [$lp_id], $sessionId @@ -1612,7 +1601,7 @@ if (empty($details)) { // Get last connection time in lp $start_time = Tracking::get_last_connection_time_in_lp( - $student_id, + $studentId, $courseCode, $lp_id, $sessionId @@ -1630,7 +1619,7 @@ if (empty($details)) { // Quiz in lp $score = Tracking::get_avg_student_score( - $student_id, + $studentId, $courseCode, [$lp_id], $sessionId @@ -1638,7 +1627,7 @@ if (empty($details)) { // Latest exercise results in a LP $score_latest = Tracking::get_avg_student_score( - $student_id, + $studentId, $courseCode, [$lp_id], $sessionId, @@ -1647,7 +1636,7 @@ if (empty($details)) { ); $bestScore = Tracking::get_avg_student_score( - $student_id, + $studentId, $courseCode, [$lp_id], $sessionId, @@ -1719,7 +1708,7 @@ if (empty($details)) { } if ($hookLpTracking) { - $hookContents = $hookLpTracking->notifyTrackingContent($lp_id, $student_id); + $hookContents = $hookLpTracking->notifyTrackingContent($lp_id, $studentId); foreach ($hookContents as $hookContent) { $contentToExport[] = strip_tags($hookContent['value']); @@ -1738,7 +1727,7 @@ if (empty($details)) { $link = Display::url( Display::return_icon('2rightarrow.png', get_lang('Details')), $codePath.'mySpace/lp_tracking.php?cid='.$courseInfo['real_id'].'&course='.$course_code.$from.'&origin='.$origin - .'&lp_id='.$lp_id.'&student_id='.$user_info['user_id'].'&sid='.$sessionId + .'&lp_id='.$lp_id.'&student_id='.$studentId.'&sid='.$sessionId ); echo Display::tag('td', $link); } @@ -1748,7 +1737,7 @@ if (empty($details)) { if (true === $any_result) { $url = 'myStudents.php?action=reset_lp&sec_token='.$token.'&cid='.$courseInfo['real_id'].'&course=' .$course_code.'&details='.$details.'&origin='.$origin.'&lp_id='.$lp_id.'&student=' - .$user_info['user_id'].'&details=true&sid='.$sessionId; + .$studentId.'&details=true&sid='.$sessionId; echo Display::url( Display::return_icon('clean.png', get_lang('Clean')), $url, @@ -1770,7 +1759,7 @@ if (empty($details)) { } } - if (INVITEE != $user_info['status']) { + if (INVITEE != $userInfo['status']) { echo '
@@ -1844,7 +1833,7 @@ if (empty($details)) { while ($exercices = Database::fetch_array($result_exercices)) { $exercise_id = (int) $exercices['id']; $count_attempts = Tracking::count_student_exercise_attempts( - $student_id, + $studentId, $courseInfo['real_id'], $exercise_id, 0, @@ -1853,7 +1842,7 @@ if (empty($details)) { 2 ); $score_percentage = Tracking::get_avg_student_exercise_score( - $student_id, + $studentId, $courseCode, $exercise_id, $sessionId, @@ -1863,12 +1852,12 @@ if (empty($details)) { $lp_name = '-'; $hookContents = $hookQuizTracking - ? $hookQuizTracking->notifyTrackingContent($exercise_id, $student_id) + ? $hookQuizTracking->notifyTrackingContent($exercise_id, $studentId) : []; if (!isset($score_percentage) && $count_attempts > 0) { $scores_lp = Tracking::get_avg_student_exercise_score( - $student_id, + $studentId, $courseCode, $exercise_id, $sessionId, @@ -1911,7 +1900,7 @@ if (empty($details)) { $sql = 'SELECT exe_id FROM '.$tbl_stats_exercices.' WHERE exe_exo_id = "'.$exercise_id.'" AND - exe_user_id ="'.$student_id.'" AND + exe_user_id ="'.$studentId.'" AND c_id = '.$courseInfo['real_id'].' AND session_id = "'.$sessionId.'" AND status = "" @@ -1926,7 +1915,7 @@ if (empty($details)) { $qualifyLink = '&action=qualify'; } $attemptLink = '../exercise/exercise_show.php?id='.$id_last_attempt.'&cidReq='.$courseCode - .'&id_session='.$sessionId.'&session_id='.$sessionId.'&student='.$student_id.'&origin=' + .'&id_session='.$sessionId.'&session_id='.$sessionId.'&student='.$studentId.'&origin=' .(empty($origin) ? 'tracking' : $origin).$qualifyLink; echo Display::url( Display::return_icon('quiz.png', get_lang('Test')), @@ -1939,7 +1928,7 @@ if (empty($details)) { echo '
'; if ($count_attempts > 0) { $all_attempt_url = "../exercise/exercise_report.php?id=$exercise_id&" - ."cidReq=$courseCode&filter_by_user=$student_id&id_session=$sessionId"; + ."cidReq=$courseCode&filter_by_user=$studentId&id_session=$sessionId"; echo Display::url( Display::return_icon( 'test_results.png', @@ -2002,7 +1991,7 @@ if (empty($details)) { [], ICON_SIZE_SMALL ); - if (in_array($student_id, $user_list)) { + if (in_array($studentId, $user_list)) { $survey_done = Display::return_icon( "accept.png", get_lang('Answered'), @@ -2040,7 +2029,7 @@ if (empty($details)) { } } - $userWorks = getWorkPerUser($student_id, $courseInfo['real_id'], $sessionId); + $userWorks = getWorkPerUser($studentId, $courseInfo['real_id'], $sessionId); echo '
@@ -2151,7 +2140,7 @@ if (empty($details)) { if (true === $allowMessages) { // Messages echo Display::page_subheader2(get_lang('Messages')); - echo MessageManager::getMessagesAboutUserToString($user_info); + echo MessageManager::getMessagesAboutUserToString($userInfo); echo Display::url( get_lang('New message'), 'javascript: void(0);', @@ -2177,7 +2166,7 @@ if (true === $allowMessages) { $allow = api_get_configuration_value('allow_user_message_tracking'); if ($allow && (api_is_drh() || api_is_platform_admin())) { - $users = MessageManager::getUsersThatHadConversationWithUser($student_id); + $users = MessageManager::getUsersThatHadConversationWithUser($studentId); echo Display::page_subheader2(get_lang('MessageReporting')); $table = new HTML_Table(['class' => 'table']); @@ -2194,7 +2183,7 @@ if ($allow && (api_is_drh() || api_is_platform_admin())) { $row++; foreach ($users as $userFollowed) { $followedUserId = $userFollowed['user_id']; - $url = api_get_path(WEB_CODE_PATH).'tracking/messages.php?from_user='.$student_id.'&to_user='.$followedUserId; + $url = api_get_path(WEB_CODE_PATH).'tracking/messages.php?from_user='.$studentId.'&to_user='.$followedUserId; $link = Display::url( $userFollowed['complete_name'], $url @@ -2206,7 +2195,7 @@ if ($allow && (api_is_drh() || api_is_platform_admin())) { } if ($pluginCalendar) { - echo $plugin->getUserStatsPanel($student_id, $courses_in_session); + echo $plugin->getUserStatsPanel($studentId, $courses_in_session); } if ($export) { diff --git a/public/main/template/default/my_space/user_details.html.twig b/public/main/template/default/my_space/user_details.html.twig index 0b8e841d41..f95c39f5fb 100644 --- a/public/main/template/default/my_space/user_details.html.twig +++ b/public/main/template/default/my_space/user_details.html.twig @@ -1,7 +1,7 @@ {% import '@ChamiloCore/Macros/box.html.twig' as display %} {% autoescape false %} -{% if title %} +{% if title is defined %}

{{ title }}

{% endif %} diff --git a/src/CoreBundle/Entity/Course.php b/src/CoreBundle/Entity/Course.php index 47a99878ff..e4fecd5ce5 100644 --- a/src/CoreBundle/Entity/Course.php +++ b/src/CoreBundle/Entity/Course.php @@ -117,6 +117,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith /** * @var ArrayCollection|AccessUrlRelCourse[] + * * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true) */ protected $urls; diff --git a/src/CoreBundle/Entity/CourseRelUser.php b/src/CoreBundle/Entity/CourseRelUser.php index 8170c3f4d3..646264ce40 100644 --- a/src/CoreBundle/Entity/CourseRelUser.php +++ b/src/CoreBundle/Entity/CourseRelUser.php @@ -61,13 +61,15 @@ class CourseRelUser /** * @var int + * * @Groups({"user:read", "course:read"}) * @ORM\Column(name="relation_type", type="integer", nullable=false, unique=false) */ protected $relationType; /** - * @var bool + * @var int + * * @Groups({"user:read"}) * @ORM\Column(name="status", type="integer", nullable=false, unique=false) */ @@ -177,10 +179,8 @@ class CourseRelUser /** * Set status. - * - * @param bool $status */ - public function setStatus($status): self + public function setStatus(int $status): self { $this->status = $status; @@ -189,10 +189,8 @@ class CourseRelUser /** * Get status. - * - * @return bool */ - public function getStatus() + public function getStatus(): int { return $this->status; } @@ -219,18 +217,12 @@ class CourseRelUser return $this->sort; } - /** - * @return bool - */ - public function isTutor() + public function isTutor(): bool { return $this->tutor; } - /** - * @param bool $tutor - */ - public function setTutor($tutor) + public function setTutor(bool $tutor): self { $this->tutor = $tutor; @@ -241,10 +233,8 @@ class CourseRelUser * Set userCourseCat. * * @param int $userCourseCat - * - * @return CourseRelUser */ - public function setUserCourseCat($userCourseCat) + public function setUserCourseCat($userCourseCat): self { $this->userCourseCat = $userCourseCat; @@ -265,10 +255,8 @@ class CourseRelUser * Set legalAgreement. * * @param int $legalAgreement - * - * @return CourseRelUser */ - public function setLegalAgreement($legalAgreement) + public function setLegalAgreement($legalAgreement): self { $this->legalAgreement = $legalAgreement; @@ -287,10 +275,8 @@ class CourseRelUser /** * Get relation_type list. - * - * @return array */ - public static function getRelationTypeList() + public static function getRelationTypeList(): array { return [ '0' => '', @@ -300,10 +286,8 @@ class CourseRelUser /** * Get status list. - * - * @return array */ - public static function getStatusList() + public static function getStatusList(): array { return [ User::COURSE_MANAGER => 'Teacher', diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index 28e4cfa8a4..002857e412 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -10,6 +10,7 @@ use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; +use Chamilo\CourseBundle\Entity\CGroupRelUser; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; @@ -269,12 +270,16 @@ class User implements UserInterface, EquatableInterface protected $passwordRequestedAt; /** + * @var CourseRelUser[]|ArrayCollection + * * @ApiSubresource() * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true) */ protected $courses; /** + * @var UsergroupRelUser[]|ArrayCollection + * * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user") */ protected $classes; @@ -328,6 +333,8 @@ class User implements UserInterface, EquatableInterface protected $curriculumItems; /** + * @var AccessUrlRelUser[]|ArrayCollection + * * @ORM\OneToMany( * targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser", * mappedBy="user", @@ -394,6 +401,8 @@ class User implements UserInterface, EquatableInterface protected $gradeBookCategories; /** + * @var Session[]|ArrayCollection + * * @ORM\OneToMany( * targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser", * mappedBy="user", @@ -404,7 +413,7 @@ class User implements UserInterface, EquatableInterface protected $sessions; /** - * @var Collection + * @var CGroupRelUser[]|ArrayCollection * * @ORM\OneToMany( * targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser", @@ -713,12 +722,14 @@ class User implements UserInterface, EquatableInterface /** * @param ArrayCollection $courses */ - public function setCourses($courses) + public function setCourses($courses): self { $this->courses = $courses; + + return $this; } - public function getCourses(): Collection + public function getCourses() { return $this->courses; } @@ -794,10 +805,6 @@ class User implements UserInterface, EquatableInterface $this->portals->add($portal); } - /** - * @param $value - * @param (mixed|string|string[])[] $value - */ public function setPortals(array $value) { $this->portals = $value; @@ -811,37 +818,26 @@ class User implements UserInterface, EquatableInterface return $this->curriculumItems; } - /** - * @param $items - * - * @return $this - */ - public function setCurriculumItems(array $items) + public function setCurriculumItems(array $items): self { $this->curriculumItems = $items; return $this; } - /** - * @return bool - */ - public function getIsActive() + public function getIsActive(): bool { - return 1 == $this->active; + return true === $this->active; } - /** - * @return bool - */ - public function isActive() + public function isActive(): bool { return $this->getIsActive(); } public function isEnabled() { - return 1 == $this->getActive(); + return $this->isActive(); } /** @@ -1455,7 +1451,7 @@ class User implements UserInterface, EquatableInterface return $this->setUsername($slug); } - public function setUsername($username) + public function setUsername($username): self { $this->username = $username; @@ -1469,7 +1465,7 @@ class User implements UserInterface, EquatableInterface return $this; } - public function setEmailCanonical($emailCanonical) + public function setEmailCanonical($emailCanonical): self { $this->emailCanonical = $emailCanonical; @@ -1480,10 +1476,8 @@ class User implements UserInterface, EquatableInterface * Set lastLogin. * * @param \DateTime $lastLogin - * - * @return User */ - public function setLastLogin(\DateTime $lastLogin = null) + public function setLastLogin(\DateTime $lastLogin = null): self { $this->lastLogin = $lastLogin; @@ -1510,13 +1504,7 @@ class User implements UserInterface, EquatableInterface return $this->sessionCourseSubscriptions; } - /** - * @param $value - * @param string[][] $value - * - * @return $this - */ - public function setSessionCourseSubscriptions(array $value) + public function setSessionCourseSubscriptions(array $value): self { $this->sessionCourseSubscriptions = $value; @@ -1533,10 +1521,8 @@ class User implements UserInterface, EquatableInterface /** * @param string $confirmationToken - * - * @return User */ - public function setConfirmationToken($confirmationToken) + public function setConfirmationToken($confirmationToken): self { $this->confirmationToken = $confirmationToken; @@ -1567,7 +1553,7 @@ class User implements UserInterface, EquatableInterface return $this->plainPassword; } - public function setPlainPassword(string $password) + public function setPlainPassword(string $password): self { $this->plainPassword = $password; @@ -1600,17 +1586,15 @@ class User implements UserInterface, EquatableInterface /** * Sets the credentials expiration date. - * - * @return User */ - public function setCredentialsExpireAt(\DateTime $date = null) + public function setCredentialsExpireAt(\DateTime $date = null): self { $this->credentialsExpireAt = $date; return $this; } - public function addGroup($group) + public function addGroup($group): self { if (!$this->getGroups()->contains($group)) { $this->getGroups()->add($group); @@ -1623,10 +1607,8 @@ class User implements UserInterface, EquatableInterface * Sets the user groups. * * @param array $groups - * - * @return User */ - public function setGroups($groups) + public function setGroups($groups): self { foreach ($groups as $group) { $this->addGroup($group); @@ -1635,10 +1617,7 @@ class User implements UserInterface, EquatableInterface return $this; } - /** - * @return string - */ - public function getFullname() + public function getFullname(): string { return sprintf('%s %s', $this->getFirstname(), $this->getLastname()); } @@ -1648,10 +1627,7 @@ class User implements UserInterface, EquatableInterface return $this->groups; } - /** - * @return array - */ - public function getGroupNames() + public function getGroupNames(): array { $names = []; foreach ($this->getGroups() as $group) { @@ -1663,15 +1639,13 @@ class User implements UserInterface, EquatableInterface /** * @param string $name - * - * @return bool */ - public function hasGroup($name) + public function hasGroup($name): bool { return in_array($name, $this->getGroupNames()); } - public function removeGroup($group) + public function removeGroup($group): self { if ($this->getGroups()->contains($group)) { $this->getGroups()->removeElement($group); @@ -1682,10 +1656,8 @@ class User implements UserInterface, EquatableInterface /** * @param string $role - * - * @return $this */ - public function addRole($role) + public function addRole($role): self { $role = strtoupper($role); if ($role === static::ROLE_DEFAULT) { @@ -1760,10 +1732,8 @@ class User implements UserInterface, EquatableInterface /** * @param bool $boolean - * - * @return User */ - public function setCredentialsExpired($boolean) + public function setCredentialsExpired($boolean): self { $this->credentialsExpired = $boolean; @@ -1772,10 +1742,8 @@ class User implements UserInterface, EquatableInterface /** * @param $boolean - * - * @return $this */ - public function setEnabled($boolean) + public function setEnabled($boolean): self { $this->enabled = (bool) $boolean; @@ -1794,20 +1762,15 @@ class User implements UserInterface, EquatableInterface * Sets this user to expired. * * @param bool $boolean - * - * @return User */ - public function setExpired($boolean) + public function setExpired($boolean): self { $this->expired = (bool) $boolean; return $this; } - /** - * @return User - */ - public function setExpiresAt(\DateTime $date) + public function setExpiresAt(\DateTime $date): self { $this->expiresAt = $date; @@ -1821,20 +1784,15 @@ class User implements UserInterface, EquatableInterface /** * @param $boolean - * - * @return $this */ - public function setLocked($boolean) + public function setLocked($boolean): self { $this->locked = $boolean; return $this; } - /** - * @return $this - */ - public function setRoles(array $roles) + public function setRoles(array $roles): self { $this->roles = []; @@ -1856,12 +1814,9 @@ class User implements UserInterface, EquatableInterface } /** - * @param $value * @param string[] $value - * - * @return $this */ - public function setAchievedSkills(array $value) + public function setAchievedSkills(array $value): self { $this->achievedSkills = $value; @@ -1872,10 +1827,8 @@ class User implements UserInterface, EquatableInterface * Check if the user has the skill. * * @param Skill $skill The skill - * - * @return bool */ - public function hasSkill(Skill $skill) + public function hasSkill(Skill $skill): bool { $achievedSkills = $this->getAchievedSkills(); @@ -1896,10 +1849,7 @@ class User implements UserInterface, EquatableInterface return $this->profileCompleted; } - /** - * @return User - */ - public function setProfileCompleted($profileCompleted) + public function setProfileCompleted($profileCompleted): self { $this->profileCompleted = $profileCompleted; @@ -1908,10 +1858,8 @@ class User implements UserInterface, EquatableInterface /** * Sets the AccessUrl for the current user in memory. - * - * @return $this */ - public function setCurrentUrl(AccessUrl $url) + public function setCurrentUrl(AccessUrl $url): self { $urlList = $this->getPortals(); /** @var AccessUrlRelUser $item */ @@ -1948,10 +1896,8 @@ class User implements UserInterface, EquatableInterface * Get sessionAsGeneralCoach. * * @param ArrayCollection $value - * - * @return $this */ - public function setSessionAsGeneralCoach($value) + public function setSessionAsGeneralCoach($value): self { $this->sessionAsGeneralCoach = $value; @@ -1966,7 +1912,7 @@ class User implements UserInterface, EquatableInterface /** * @return User */ - public function setCommentedUserSkills(array $commentedUserSkills) + public function setCommentedUserSkills(array $commentedUserSkills): self { $this->commentedUserSkills = $commentedUserSkills; @@ -2190,10 +2136,8 @@ class User implements UserInterface, EquatableInterface /** * @param \DateTime $dateOfBirth - * - * @return User */ - public function setDateOfBirth($dateOfBirth) + public function setDateOfBirth($dateOfBirth): self { $this->dateOfBirth = $dateOfBirth; diff --git a/src/CoreBundle/Repository/CourseRepository.php b/src/CoreBundle/Repository/CourseRepository.php index 2e9255d006..ed3b5d235c 100644 --- a/src/CoreBundle/Repository/CourseRepository.php +++ b/src/CoreBundle/Repository/CourseRepository.php @@ -4,9 +4,11 @@ namespace Chamilo\CoreBundle\Repository; +use Chamilo\CoreBundle\Entity\AccessUrl; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\ResourceNode; use Chamilo\CoreBundle\Entity\Session; +use Chamilo\CoreBundle\Entity\User; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Query\Expr\Join; @@ -55,12 +57,7 @@ class CourseRepository extends ResourceRepository $em->flush(); } - /** - * @param string $code - * - * @return Course - */ - public function findOneByCode($code) + public function findOneByCode(string $code): ?Course { return $this->findOneBy(['code' => $code]); } @@ -68,7 +65,7 @@ class CourseRepository extends ResourceRepository /** * Get all users that are registered in the course. No matter the status. * - * @return \Doctrine\ORM\QueryBuilder + * @return QueryBuilder */ public function getSubscribedUsers(Course $course) { @@ -81,7 +78,7 @@ class CourseRepository extends ResourceRepository // Selecting courses for users. $queryBuilder->innerJoin('c.users', 'subscriptions'); $queryBuilder->innerJoin( - 'ChamiloCoreBundle:User', + User::class, 'user', Join::WITH, 'subscriptions.user = user.id' @@ -185,4 +182,29 @@ class CourseRepository extends ResourceRepository return $courseList; } + + /** + * Get course user relationship based in the course_rel_user table. + * + * @return array + */ + public function getCoursesByUser(User $user, AccessUrl $url) + { + $qb = $this->repository->createQueryBuilder('course'); + + $qb + ->innerJoin('user.courses', 'courseRelUser') + ->innerJoin('courseRelUser.course', 'course') + ->innerJoin('course.urls', 'accessUrlRelCourse') + ->innerJoin('accessUrlRelCourse.url', 'url') + ->where('user = :user') + ->andWhere('url = :url') + ->setParameters(['user' => $user, 'url' => $url]) + ->addSelect('courseRelUser') + ; + + $query = $qb->getQuery(); + + return $query->getResult(); + } } diff --git a/src/CoreBundle/Repository/UserRepository.php b/src/CoreBundle/Repository/UserRepository.php index 6b099089a9..41d0def40d 100644 --- a/src/CoreBundle/Repository/UserRepository.php +++ b/src/CoreBundle/Repository/UserRepository.php @@ -77,7 +77,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface, $this->encoder = $encoder; } - public function loadUserByUsername($username) + public function loadUserByUsername($username): ?User { return $this->findBy(['username' => $username]); } @@ -252,38 +252,47 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface, /** * Get course user relationship based in the course_rel_user table. * - * @return array + * @return Course[] */ - /*public function getCourses(User $user) + public function getCourses(User $user, AccessUrl $url, int $status, $keyword = '') { - $queryBuilder = $this->createQueryBuilder('user'); - - // Selecting course info. - $queryBuilder->select('c'); - - // Loading User. - //$qb->from('Chamilo\CoreBundle\Entity\User', 'u'); - - // Selecting course - $queryBuilder->innerJoin('Chamilo\CoreBundle\Entity\Course', 'c'); - - //@todo check app settings - //$qb->add('orderBy', 'u.lastname ASC'); + $qb = $this->repository->createQueryBuilder('user'); - $wherePart = $queryBuilder->expr()->andx(); + $qb + ->select('DISTINCT course') + //->addSelect('user.courses') + ->innerJoin( + CourseRelUser::class, + 'courseRelUser', + Join::WITH, + 'user = courseRelUser.user' + ) + ->innerJoin('courseRelUser.course', 'course') + ->innerJoin('course.urls', 'accessUrlRelCourse') + ->innerJoin('accessUrlRelCourse.url', 'url') + ->where('user = :user') + ->andWhere('url = :url') + ->andWhere('courseRelUser.status = :status') + ->setParameters(['user' => $user, 'url' => $url, 'status' => $status]) + ->addSelect('courseRelUser'); + + if (!empty($keyword)) { + $qb + ->andWhere('course.title like = :keyword') + ->setParameter('keyword', $keyword); + } - // Get only users subscribed to this course - $wherePart->add($queryBuilder->expr()->eq('user.userId', $user->getUserId())); + $qb->add('orderBy', 'course.title DESC'); - $queryBuilder->where($wherePart); - $query = $queryBuilder->getQuery(); + $query = $qb->getQuery(); - return $query->execute(); + return $query->getResult(); } + /* public function getTeachers() { - $queryBuilder = $this->createQueryBuilder('u'); + $queryBuilder = $this->repository->createQueryBuilder('u'); // Selecting course info. $queryBuilder @@ -298,7 +307,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface, /*public function getUsers($group) { - $queryBuilder = $this->createQueryBuilder('u'); + $queryBuilder = $this->repository->createQueryBuilder('u'); // Selecting course info. $queryBuilder diff --git a/src/CoreBundle/Resources/views/Macros/box.html.twig b/src/CoreBundle/Resources/views/Macros/box.html.twig index d249733de8..212b91152b 100644 --- a/src/CoreBundle/Resources/views/Macros/box.html.twig +++ b/src/CoreBundle/Resources/views/Macros/box.html.twig @@ -460,9 +460,9 @@ {% endif %} - {% if user.created %} -
{{ user.created }}
- {% endif %} +{# {% if user.created %}#} +{#
{{ user.created }}
#} +{# {% endif %}#} {# {% if user.url_access or user.legal.url_send %}#} {#
#}