Use session/course entity in legacy pages

pull/3844/head
Julio Montoya 5 years ago
parent 3fcb32724f
commit 0cc51b8437
  1. 43
      public/main/inc/lib/sessionmanager.lib.php
  2. 39
      public/main/mySpace/course.php
  3. 45
      public/main/session/resume_session.php

@ -4762,24 +4762,18 @@ class SessionManager
return $row[0]; return $row[0];
} }
/** public static function cantEditSession(Session $session, bool $checkSession = true): bool
* @param int $id
* @param bool $checkSession
*
* @return bool
*/
public static function cantEditSession($id, $checkSession = true)
{ {
if (!self::allowToManageSessions()) { if (!self::allowToManageSessions()) {
return false; return false;
} }
if (api_is_platform_admin() && self::allowed($id)) { if (api_is_platform_admin() && self::allowed($session)) {
return true; return true;
} }
if ($checkSession) { if ($checkSession) {
if (self::allowed($id)) { if (self::allowed($session)) {
return true; return true;
} }
@ -4792,14 +4786,11 @@ class SessionManager
/** /**
* Protect a session to be edited. * Protect a session to be edited.
* *
* @param int $id
* @param bool $checkSession
*
* @return mixed | bool true if pass the check, api_not_allowed otherwise * @return mixed | bool true if pass the check, api_not_allowed otherwise
*/ */
public static function protectSession($id, $checkSession = true) public static function protectSession(Session $session, bool $checkSession = true)
{ {
if (!self::cantEditSession($id, $checkSession)) { if (!self::cantEditSession($session, $checkSession)) {
api_not_allowed(true); api_not_allowed(true);
} }
} }
@ -4815,7 +4806,7 @@ class SessionManager
$setting = api_get_setting('allow_teachers_to_create_sessions'); $setting = api_get_setting('allow_teachers_to_create_sessions');
if (api_is_teacher() && 'true' == $setting) { if (api_is_teacher() && 'true' === $setting) {
return true; return true;
} }
@ -9599,19 +9590,8 @@ class SessionManager
} }
} }
/** private static function allowed(Session $session): bool
* @param int $id
*
* @return bool
*/
private static function allowed($id)
{ {
$sessionInfo = self::fetch($id);
if (empty($sessionInfo)) {
return false;
}
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
return true; return true;
} }
@ -9619,17 +9599,18 @@ class SessionManager
$userId = api_get_user_id(); $userId = api_get_user_id();
if (api_is_session_admin() && if (api_is_session_admin() &&
'true' != api_get_setting('allow_session_admins_to_manage_all_sessions') 'true' !== api_get_setting('allow_session_admins_to_manage_all_sessions')
) { ) {
if ($sessionInfo['session_admin_id'] != $userId) {
if ($userId !== $session->getSessionAdmin()->getId()) {
return false; return false;
} }
} }
if (api_is_teacher() && if (api_is_teacher() &&
'true' == api_get_setting('allow_teachers_to_create_sessions') 'true' === api_get_setting('allow_teachers_to_create_sessions')
) { ) {
if ($sessionInfo['id_coach'] != $userId) { if ($userId !== $session->getGeneralCoach()->getId()) {
return false; return false;
} }
} }

@ -1,8 +1,8 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/**
* Courses reporting. use Chamilo\CoreBundle\Framework\Container;
*/
ob_start(); ob_start();
$cidReset = true; $cidReset = true;
@ -275,8 +275,9 @@ function get_courses($from, $limit, $column, $direction)
$session = api_get_session_entity($sessionId); $session = api_get_session_entity($sessionId);
foreach ($courses as $data) { foreach ($courses as $data) {
$courseCode = $data['code']; $courseCode = $data['code'];
$courseId = $data['real_id'];
$courseInfo = api_get_course_info($courseCode); $courseInfo = api_get_course_info($courseCode);
$course = api_get_course_entity($courseCode['real_id']); $course = api_get_course_entity($courseId);
if (empty($sessionId)) { if (empty($sessionId)) {
$userList = CourseManager::get_user_list_from_course_code($data['code']); $userList = CourseManager::get_user_list_from_course_code($data['code']);
@ -307,11 +308,18 @@ function get_courses($from, $limit, $column, $direction)
if (count($userIdList) > 0) { if (count($userIdList) > 0) {
$countStudents = count($userIdList); $countStudents = count($userIdList);
// tracking data // tracking data
$avgProgressInCourse = Tracking :: get_avg_student_progress($userIdList, $courseCode, [], $sessionId); $avgProgressInCourse = Tracking::get_avg_student_progress($userIdList, $courseCode, [], $sessionId);
$avgScoreInCourse = Tracking :: get_avg_student_score($userIdList, $courseCode, [], $sessionId); $avgScoreInCourse = Tracking::get_avg_student_score($userIdList, $courseCode, [], $sessionId);
$avgTimeSpentInCourse = Tracking :: get_time_spent_on_the_course($userIdList, $courseInfo['real_id'], $sessionId); $avgTimeSpentInCourse = Tracking::get_time_spent_on_the_course(
$messagesInCourse = Tracking :: count_student_messages($userIdList, $courseCode, $sessionId); $userIdList,
$assignmentsInCourse = Tracking :: count_student_assignments($userIdList, $courseCode, $sessionId); $courseInfo['real_id'],
$sessionId
);
$messagesInCourse = Container::getForumPostRepository()->countCourseForumPosts($course, $session);
$assignmentsInCourse = Container::getStudentPublicationRepository()->countCoursePublications(
$course,
$session
);
$avgTimeSpentInCourse = api_time_to_hms($avgTimeSpentInCourse / $countStudents); $avgTimeSpentInCourse = api_time_to_hms($avgTimeSpentInCourse / $countStudents);
$avgProgressInCourse = round($avgProgressInCourse / $countStudents, 2); $avgProgressInCourse = round($avgProgressInCourse / $countStudents, 2);
@ -324,13 +332,16 @@ function get_courses($from, $limit, $column, $direction)
$tematic_advance = $thematic->get_total_average_of_thematic_advances($course, $session); $tematic_advance = $thematic->get_total_average_of_thematic_advances($course, $session);
$tematicAdvanceProgress = '-'; $tematicAdvanceProgress = '-';
if (!empty($tematic_advance)) { if (!empty($tematic_advance)) {
$tematicAdvanceProgress = '<a title="'.get_lang('Go to thematic advance').'" href="'.api_get_path(WEB_CODE_PATH).'course_progress/index.php?cidReq='.$courseCode.'&id_session='.$sessionId.'">'. $tematicAdvanceProgress = '<a
title="'.get_lang('Go to thematic advance').'"
href="'.api_get_path(WEB_CODE_PATH).'course_progress/index.php?cid='.$courseId.'&sid='.$sessionId.'">'.
$tematic_advance.'%</a>'; $tematic_advance.'%</a>';
} }
$courseIcon = '<a href="'.api_get_path(WEB_CODE_PATH).'tracking/courseLog.php?cidReq='.$courseCode.'&id_session='.$sessionId.'"> $courseIcon = '<a
'.Display::return_icon('2rightarrow.png', get_lang('Details')).' href="'.api_get_path(WEB_CODE_PATH).'tracking/courseLog.php?cid='.$courseId.'&sid='.$sessionId.'">
</a>'; '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
</a>';
$title = Display::url( $title = Display::url(
$data['title'], $data['title'],
$courseInfo['course_public_url'].'?id_session='.$sessionId $courseInfo['course_public_url'].'?id_session='.$sessionId
@ -338,7 +349,7 @@ function get_courses($from, $limit, $column, $direction)
$attendanceLink = Display::url( $attendanceLink = Display::url(
Display::return_icon('attendance_list.png', get_lang('Attendance'), [], ICON_SIZE_MEDIUM), Display::return_icon('attendance_list.png', get_lang('Attendance'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'attendance/index.php?cidReq='.$courseCode.'&id_session='.$sessionId.'&action=calendar_logins' api_get_path(WEB_CODE_PATH).'attendance/index.php?cid='.$courseId.'&sid='.$sessionId.'&action=calendar_logins'
); );
$courseList[] = [ $courseList[] = [

@ -2,7 +2,6 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Promotion;
use Chamilo\CoreBundle\Entity\SequenceResource; use Chamilo\CoreBundle\Entity\SequenceResource;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionRelCourse; use Chamilo\CoreBundle\Entity\SessionRelCourse;
@ -24,9 +23,10 @@ if (empty($sessionId)) {
api_not_allowed(true); api_not_allowed(true);
} }
SessionManager::protectSession($sessionId); $session = api_get_session_entity($sessionId);
$codePath = api_get_path(WEB_CODE_PATH); SessionManager::protectSession($session);
$codePath = api_get_path(WEB_CODE_PATH);
$tool_name = get_lang('Session overview'); $tool_name = get_lang('Session overview');
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => 'session_list.php', 'url' => 'session_list.php',
@ -47,11 +47,9 @@ $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); $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$em = Database::getManager(); $em = Database::getManager();
$sessionInfo = api_get_session_info($sessionId);
$session = api_get_session_entity($sessionId);
$sessionCategory = $session->getCategory(); $sessionCategory = $session->getCategory();
$action = isset($_GET['action']) ? $_GET['action'] : null; $action = $_GET['action'] ?? null;
$url_id = api_get_current_access_url_id(); $url_id = api_get_current_access_url_id();
switch ($action) { switch ($action) {
@ -130,7 +128,6 @@ $url = Display::url(
); );
$sessionTitle = Display::page_subheader(get_lang('General properties').$url); $sessionTitle = Display::page_subheader(get_lang('General properties').$url);
$generalCoach = api_get_user_info($sessionInfo['id_coach']);
$sessionField = new ExtraField('session'); $sessionField = new ExtraField('session');
$extraFieldData = $sessionField->getDataAndFormattedValues($sessionId); $extraFieldData = $sessionField->getDataAndFormattedValues($sessionId);
@ -298,10 +295,11 @@ if (!empty($userList)) {
$table = new HTML_Table( $table = new HTML_Table(
['class' => 'table table-bordered', 'id' => 'session-user-list'] ['class' => 'table table-bordered', 'id' => 'session-user-list']
); );
$table->setHeaderContents(0, 0, get_lang('User')); $table->setHeaderContents(0, 0, '#');
$table->setHeaderContents(0, 1, get_lang('Status')); $table->setHeaderContents(0, 1, get_lang('User'));
$table->setHeaderContents(0, 2, get_lang('Registration date')); $table->setHeaderContents(0, 2, get_lang('Status'));
$table->setHeaderContents(0, 3, get_lang('Detail')); $table->setHeaderContents(0, 3, get_lang('Registration date'));
$table->setHeaderContents(0, 4, get_lang('Detail'));
$row = 1; $row = 1;
foreach ($userList as $user) { foreach ($userList as $user) {
@ -348,8 +346,6 @@ if (!empty($userList)) {
$editUrl $editUrl
); );
}*/ }*/
$table->setCellContents($row, 0, $userLink);
$link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl; $link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;
switch ($user['relation_type']) { switch ($user['relation_type']) {
case 1: case 1:
@ -365,9 +361,11 @@ if (!empty($userList)) {
$registered = !empty($user['registered_at']) ? Display::dateToStringAgoAndLongDate($user['registered_at']) : ''; $registered = !empty($user['registered_at']) ? Display::dateToStringAgoAndLongDate($user['registered_at']) : '';
$table->setCellContents($row, 1, $status); $table->setCellContents($row, 0, $row);
$table->setCellContents($row, 2, $registered); $table->setCellContents($row, 1, $userLink);
$table->setCellContents($row, 3, $link); $table->setCellContents($row, 2, $status);
$table->setCellContents($row, 3, $registered);
$table->setCellContents($row, 4, $link);
$row++; $row++;
} }
$userListToShow .= $table->toHtml(); $userListToShow .= $table->toHtml();
@ -391,25 +389,18 @@ if (!empty($requirementAndDependencies['dependencies'])) {
$dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link')); $dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link'));
} }
$promotion = null; $promotion = $session->getPromotion();
if (!empty($sessionInfo['promotion_id'])) {
$promotion = $em->getRepository(Promotion::class);
$promotion = $promotion->find($sessionInfo['promotion_id']);
}
$programmedAnnouncement = new ScheduledAnnouncement(); $programmedAnnouncement = new ScheduledAnnouncement();
$programmedAnnouncement = $programmedAnnouncement->allowed(); $programmedAnnouncement = $programmedAnnouncement->allowed();
$tpl = new Template($tool_name); $tpl = new Template($tool_name);
$tpl->assign('session_header', $sessionHeader); $tpl->assign('session_header', $sessionHeader);
$tpl->assign('title', $sessionTitle); $tpl->assign('title', $sessionTitle);
$tpl->assign('general_coach', $generalCoach); $tpl->assign('session', $session);
$tpl->assign('session_admin', api_get_user_info($session->getSessionAdmin()->getId()));
$tpl->assign('session', $sessionInfo);
$tpl->assign('programmed_announcement', $programmedAnnouncement); $tpl->assign('programmed_announcement', $programmedAnnouncement);
$tpl->assign('session_category', is_null($sessionCategory) ? null : $sessionCategory->getName()); $tpl->assign('session_category', is_null($sessionCategory) ? null : $sessionCategory->getName());
$tpl->assign('session_dates', SessionManager::parseSessionDates($sessionInfo, true)); //$tpl->assign('session_dates', SessionManager::parseSessionDates($sessionInfo, true));
$tpl->assign('session_visibility', SessionManager::getSessionVisibility($sessionInfo)); //$tpl->assign('session_visibility', SessionManager::getSessionVisibility($sessionInfo));
$tpl->assign('promotion', $promotion); $tpl->assign('promotion', $promotion);
$tpl->assign('url_list', $urlList); $tpl->assign('url_list', $urlList);
$tpl->assign('extra_fields', $extraFieldData); $tpl->assign('extra_fields', $extraFieldData);

Loading…
Cancel
Save