From c4bf06013554b85ef82e1a4fb0ef2e9d2d79267a Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 24 Sep 2021 01:28:53 -0500 Subject: [PATCH] Session: Restore resume session page for user --- public/main/user/resume_session.php | 193 ++++++++-------------------- 1 file changed, 51 insertions(+), 142 deletions(-) diff --git a/public/main/user/resume_session.php b/public/main/user/resume_session.php index 546efb6e90..e6bb637ac8 100644 --- a/public/main/user/resume_session.php +++ b/public/main/user/resume_session.php @@ -6,7 +6,10 @@ * @author Bart Mollet, Julio Montoya lot of fixes */ +use Chamilo\CoreBundle\Component\Utils\NameConvention; use Chamilo\CoreBundle\Entity\Session; +use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser; +use Chamilo\CoreBundle\Framework\Container; $cidReset = true; require_once __DIR__.'/../inc/global.inc.php'; @@ -31,41 +34,9 @@ if ('true' === $allowTutors) { $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $sql = 'SELECT - name, - nbr_courses, - nbr_users, - nbr_classes, - DATE_FORMAT(access_start_date,"%d-%m-%Y") as access_start_date, - DATE_FORMAT(access_end_date,"%d-%m-%Y") as access_end_date, - lastname, - firstname, - username, - session_admin_id, - coach_access_start_date, - coach_access_end_date, - session_category_id, - visibility - FROM '.$tbl_session.' - LEFT JOIN '.$tbl_user.' - ON id_coach = user_id - WHERE '.$tbl_session.'.id='.$id_session; + $nameConvention = Container::$container->get(NameConvention::class); - $rs = Database::query($sql); - $session = Database::store_result($rs); - $session = $session[0]; - - $sql = 'SELECT name - FROM '.$tbl_session_category.' - WHERE id = '.intval($session['session_category_id']); - $rs = Database::query($sql); - $session_category = ''; - - if (Database::num_rows($rs) > 0) { - $rows_session_category = Database::store_result($rs); - $rows_session_category = $rows_session_category[0]; - $session_category = $rows_session_category['name']; - } + $session = api_get_session_entity($id_session); $action = isset($_GET['action']) ? $_GET['action'] : null; @@ -130,74 +101,50 @@ if ('true' === $allowTutors) { Display::return_icon( 'session.png', get_lang('Session') - ).' '.$session['name'] + ).' '.$session->getName() ); echo Display::page_subheader(get_lang('General properties').$url); ?> - - - - - - - - - - - + - - - - - + getCategory()) { ?> - - + + + + + getDuration()) { ?> + + + + + + + + + + + + + + + getNbrCourses()) { echo ' - + '; } else { // select the courses - $sql = "SELECT c.id, code,title,visual_code, nbr_users - FROM $tbl_course c,$tbl_session_rel_course sc - WHERE c.id = sc.c_id - AND session_id='$id_session' - ORDER BY title"; - $result = Database::query($sql); - $courses = Database::store_result($result); - foreach ($courses as $course) { - // Select the number of users - $sql = "SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru - WHERE - srcru.user_id = sru.user_id AND - srcru.session_id = sru.session_id AND - srcru.c_id = '".Database::escape_string($course['id'])."'AND - sru.relation_type = ".Session::STUDENT." AND - srcru.session_id = '".intval($id_session)."'"; - - $rs = Database::query($sql); - $course['nbr_users'] = Database::result($rs, 0, 0); - - // Get coachs of the courses in session + foreach ($session->getCourses() as $sessionRelCourse) { + $course = $sessionRelCourse->getCourse(); - $sql = "SELECT user.lastname,user.firstname,user.username - FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user - WHERE - session_rcru.user_id = user.id AND - session_rcru.session_id = '".intval($id_session)."' AND - session_rcru.c_id ='".Database::escape_string($course['id'])."' AND - session_rcru.status = ".Session::COURSE_COACH; - $rs = Database::query($sql); - - $coachs = []; - if (Database::num_rows($rs) > 0) { - while ($info_coach = Database::fetch_array($rs)) { - $coachs[] = api_get_person_name( - $info_coach['firstname'], - $info_coach['lastname'] - ).' ('.$info_coach['username'].')'; - } - } else { - $coach = get_lang('none'); - } + $coachSubscriptionList = $session->getSessionRelCourseRelUsersByStatus($course, Session::COURSE_COACH) + ->map( + fn(SessionRelCourseRelUser $sessionCourseUser) => $nameConvention->getPersonName($sessionCourseUser->getUser()) + ); - if (count($coachs) > 0) { - $coach = implode('
', $coachs); - } else { - $coach = get_lang('none'); - } + $courseLink = Display::url( + $course->getTitle().' ('.$course->getVisualCode().')', + api_get_course_url($course->getId(), $session->getId()) + ); + $coaches = $coachSubscriptionList ? implode('
', $coachSubscriptionList->getValues()) : get_lang('None'); + $nbrUsers = $sessionRelCourse->getNbrUsers(); - $orig_param = '&origin=resume_session'; - //hide_course_breadcrumb the parameter has been added to hide the - // name of the course, that appeared in the default $interbreadcrumb echo ' - - - - + + + '; } } ?> @@ -309,7 +218,7 @@ if ('true' === $allowTutors) { getNbrUsers()) { echo '';
:
: : - getGeneralCoaches() as $generalCoach) { + echo $nameConvention->getPersonName($generalCoach).'
'; } - echo $session['access_start_date'].' '.$session['access_end_date']; - } ?> -
- : - - + ?>
- : - - - getCategory()->getName(); ?>
getDuration().' '.get_lang('Days'); ?>
: - +
'.get_lang('No course for this session').''.get_lang('No course for this session').'
'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session), ''.$coach.''.$course['nbr_users'].''.$courseLink.''.$coaches.''.$nbrUsers.'
'.get_lang('No Users for this session').'