From ea0e05e4461b7900548f42d4e18d44b0405ab5bf Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 11 Mar 2021 15:35:31 +0100 Subject: [PATCH] Add deprecation for unused files, remove unused code, fix arguments Use course entity --- public/main/coursecopy/import_backup.php | 18 ++-- public/main/document/download_scorm.php | 3 + public/main/exercise/exercise.class.php | 5 +- .../main/glossary/glossary_ajax_request.php | 13 +-- public/main/inc/lib/api.lib.php | 1 + public/main/inc/lib/webservices/Rest.php | 6 +- public/main/lp/download.php | 2 + public/main/lp/learnpath.class.php | 84 ++++++++----------- public/main/lp/learnpathList.class.php | 2 +- public/main/lp/lp_controller.php | 3 +- public/main/lp/lp_impress.php | 2 +- public/main/lp/lp_list.php | 10 +-- public/main/lp/lp_view.php | 8 +- public/main/mySpace/teachers.php | 19 ++--- .../Controller/SessionController.php | 12 +-- 15 files changed, 88 insertions(+), 100 deletions(-) diff --git a/public/main/coursecopy/import_backup.php b/public/main/coursecopy/import_backup.php index edfcabf784..5ade16b67c 100644 --- a/public/main/coursecopy/import_backup.php +++ b/public/main/coursecopy/import_backup.php @@ -78,21 +78,29 @@ if (Security::check_token('post') && ('course_select_form' === $action || 'full_ $course = CourseArchiver::readCourse($filename, $delete_file); } } - if (!$error && is_object($course) && $course->has_resources()) { $cr = new CourseRestorer($course); $cr->set_file_option($_POST['same_file_name_option']); $cr->restore(); echo Display::return_message(get_lang('Import finished')); - echo ''. + echo ''. get_lang('Course home').''; } else { if (!$error) { echo Display::return_message(get_lang('There are no resources in backup file'), 'warning'); - echo ''.get_lang('Try again').''; + echo ''.get_lang('Try again').''; } elseif (false === $filename) { - echo Display::return_message(get_lang('The app/cache/ directory, used by this tool, is not writeable. Please contact your platform administrator.'), 'error'); - echo ''.get_lang('Try again').''; + echo Display::return_message( + get_lang( + 'The app/cache/ directory, used by this tool, is not writeable. Please contact your platform administrator.' + ), + 'error' + ); + echo ''.get_lang('Try again').''; } else { if ('' == $filename) { echo Display::return_message(get_lang('Select a backup file'), 'error'); diff --git a/public/main/document/download_scorm.php b/public/main/document/download_scorm.php index 37023632d3..e6ed7bd7c9 100644 --- a/public/main/document/download_scorm.php +++ b/public/main/document/download_scorm.php @@ -1,6 +1,9 @@ getFirstResourceLinkFromCourseSession(api_get_course_entity($this->course_id)); + $course = api_get_course_entity($this->course_id); + $link = $exercise->getFirstResourceLinkFromCourseSession($course); if ($link->isDraft()) { $this->active = 0; @@ -6575,7 +6576,7 @@ class Exercise $lp = Container::getLpRepository()->find($lpId); // 2.1 LP is loaded if ($lp && 0 == $this->active && - !learnpath::is_lp_visible_for_student($lp, api_get_user_id()) + !learnpath::is_lp_visible_for_student($lp, api_get_user_id(), $course) ) { return [ 'value' => false, diff --git a/public/main/glossary/glossary_ajax_request.php b/public/main/glossary/glossary_ajax_request.php index 14211405c9..34a98a4dfd 100644 --- a/public/main/glossary/glossary_ajax_request.php +++ b/public/main/glossary/glossary_ajax_request.php @@ -16,15 +16,16 @@ api_protect_course_script(true); $charset = api_get_system_encoding(); // Replace image path -$path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path(); -$path_image_search = '../..'.api_get_path(REL_COURSE_PATH).api_get_course_path(); +// @todo redo the image path replace +/*$path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path(); +$path_image_search = '../..'.api_get_path(REL_COURSE_PATH).api_get_course_path();*/ $glossaryId = isset($_REQUEST['glossary_id']) ? (int) $_REQUEST['glossary_id'] : 0; $description = get_lang('No results found'); if (!empty($glossaryId)) { $description = GlossaryManager::get_glossary_term_by_glossary_id($glossaryId); - $description = str_replace($path_image_search, $path_image, $description); -} elseif (isset($_REQUEST['glossary_data']) && 'true' == $_REQUEST['glossary_data']) { + //$description = str_replace($path_image_search, $path_image, $description); +} elseif (isset($_REQUEST['glossary_data']) && 'true' === $_REQUEST['glossary_data']) { // get_glossary_terms $glossary_data = GlossaryManager::get_glossary_terms(); $glossary_all_data = []; @@ -38,11 +39,11 @@ if (!empty($glossaryId)) { $glossaryInfo = GlossaryManager::get_glossary_term_by_glossary_name($_REQUEST['glossary_name']); if (!empty($glossaryInfo)) { - $description = str_replace( + /*$description = str_replace( $path_image_search, $path_image, $glossaryInfo['description'] - ); + );*/ if (null === $description || 0 == strlen(trim($description))) { $description = get_lang('No results found'); diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index a0442e9dc2..1d299962fd 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -7234,6 +7234,7 @@ function api_can_login_as($loginAsUserId, $userId = null) } $userInfo = api_get_user_info($loginAsUserId); + $isDrh = function () use ($loginAsUserId) { if (api_is_drh()) { if (api_drh_can_access_all_session_content()) { diff --git a/public/main/inc/lib/webservices/Rest.php b/public/main/inc/lib/webservices/Rest.php index a796e7d1ed..c73fd58402 100644 --- a/public/main/inc/lib/webservices/Rest.php +++ b/public/main/inc/lib/webservices/Rest.php @@ -823,13 +823,11 @@ class Rest extends WebService $categoriesTempList = learnpath::getCategories($this->course->getId()); $categoryNone = new CLpCategory(); - $categoryNone->setId(0); $categoryNone->setName(get_lang('WithOutCategory')); $categoryNone->setPosition(0); $categories = array_merge([$categoryNone], $categoriesTempList); $categoryData = []; - /** @var CLpCategory $category */ foreach ($categories as $category) { $learnPathList = new LearnpathList( @@ -838,7 +836,7 @@ class Rest extends WebService $sessionId, null, false, - $category->getId() + $category->getIid() ); $flatLpList = $learnPathList->get_flat_list(); @@ -857,7 +855,7 @@ class Rest extends WebService if (!learnpath::is_lp_visible_for_student( $lpId, $this->user->getId(), - api_get_course_info($this->course->getCode()), + $this->course, $sessionId )) { continue; diff --git a/public/main/lp/download.php b/public/main/lp/download.php index a9921ad593..3ab11640d6 100644 --- a/public/main/lp/download.php +++ b/public/main/lp/download.php @@ -1,5 +1,7 @@ getId(); $allow = api_get_configuration_value('allow_teachers_to_access_blocked_lp_by_prerequisite'); if ($allow) { @@ -2157,23 +2158,12 @@ class learnpath * Checks if the learning path is visible for student after the progress * of its prerequisite is completed, considering the time availability and * the LP visibility. - * - * @param int $student_id - * @param array $courseInfo - * @param int $sessionId - * - * @return bool */ - public static function is_lp_visible_for_student( - CLp $lp, - $student_id, - $courseInfo = [], - $sessionId = 0 - ) { - $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo; + public static function is_lp_visible_for_student(CLp $lp, $student_id, Course $course, $sessionId = 0): bool + { $sessionId = (int) $sessionId; - if (empty($courseInfo)) { + if (null === $course) { return false; } @@ -2181,7 +2171,7 @@ class learnpath $sessionId = api_get_session_id(); } - $courseId = $courseInfo['real_id']; + $courseId = $course->getId(); /*$itemInfo = api_get_item_property_info( $courseId, @@ -2190,38 +2180,28 @@ class learnpath $sessionId );*/ - $visibility = $lp->isVisible($courseInfo['entity'], api_get_session_entity($sessionId)); + $visibility = $lp->isVisible($course, api_get_session_entity($sessionId)); // If the item was deleted. if (false === $visibility) { return false; } - $lp_id = $lp->getIid(); - // @todo remove this query and load the row info as a parameter - $table = Database::get_course_table(TABLE_LP_MAIN); - // Get current prerequisite - $sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on, category_id - FROM $table - WHERE iid = $lp_id"; - $rs = Database::query($sql); $now = time(); - if (Database::num_rows($rs) > 0) { - $row = Database::fetch_array($rs, 'ASSOC'); + if ($lp->hasCategory()) { + $category = $lp->getCategory(); - if (!empty($row['category_id'])) { - $category = Container::getLpCategoryRepository()->find($row['category_id']); - if (false === self::categoryIsVisibleForStudent($category, api_get_user_entity($student_id))) { - return false; - } + if (false === self::categoryIsVisibleForStudent($category, api_get_user_entity($student_id))) { + return false; } - $prerequisite = $row['prerequisite']; + + $prerequisite = $lp->getPrerequisite(); $is_visible = true; $isBlocked = self::isBlockedByPrerequisite( $student_id, $prerequisite, - $courseInfo, + $course, $sessionId ); @@ -2232,8 +2212,8 @@ class learnpath // Also check the time availability of the LP if ($is_visible) { // Adding visibility restrictions - if (!empty($row['publicated_on'])) { - if ($now < api_strtotime($row['publicated_on'], 'UTC')) { + if (null !== $lp->getPublicatedOn()) { + if ($now < $lp->getPublicatedOn()->getTimestamp()) { $is_visible = false; } } @@ -2242,13 +2222,13 @@ class learnpath if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date'] ) { - if (empty($row['publicated_on'])) { + if (null !== $lp->getPublicatedOn()) { $is_visible = false; } } - if (!empty($row['expired_on'])) { - if ($now > api_strtotime($row['expired_on'], 'UTC')) { + if (null !== $lp->getExpiredOn()) { + if ($now > $lp->getExpiredOn()->getTimestamp()) { $is_visible = false; } } @@ -2258,20 +2238,22 @@ class learnpath $subscriptionSettings = self::getSubscriptionSettings(); // Check if the subscription users/group to a LP is ON - if (isset($row['subscribe_users']) && 1 == $row['subscribe_users'] && + if (1 == $lp->getSubscribeUsers() && true === $subscriptionSettings['allow_add_users_to_lp'] ) { // Try group $is_visible = false; // Checking only the user visibility - $userVisibility = api_get_item_visibility( + // @todo fix visibility + $userVisibility = 1; + /*$userVisibility = api_get_item_visibility( $courseInfo, 'learnpath', $row['id'], $sessionId, $student_id, 'LearnpathSubscription' - ); + );*/ if (1 == $userVisibility) { $is_visible = true; @@ -2280,7 +2262,9 @@ class learnpath if (!empty($userGroups)) { foreach ($userGroups as $groupInfo) { $groupId = $groupInfo['iid']; - $userVisibility = api_get_item_visibility( + // @todo fix visibility. + $userVisibility = 1; + /*$userVisibility = api_get_item_visibility( $courseInfo, 'learnpath', $row['id'], @@ -2288,7 +2272,7 @@ class learnpath null, 'LearnpathSubscription', $groupId - ); + );*/ if (1 == $userVisibility) { $is_visible = true; diff --git a/public/main/lp/learnpathList.class.php b/public/main/lp/learnpathList.class.php index 8b333b3f76..aedead4b25 100644 --- a/public/main/lp/learnpathList.class.php +++ b/public/main/lp/learnpathList.class.php @@ -129,7 +129,7 @@ class LearnpathList $lpVisibility = learnpath::is_lp_visible_for_student( $lp, $user_id, - $courseInfo + $course ); if (false === $lpVisibility) { continue; diff --git a/public/main/lp/lp_controller.php b/public/main/lp/lp_controller.php index e0950f3474..b54a04c1d0 100644 --- a/public/main/lp/lp_controller.php +++ b/public/main/lp/lp_controller.php @@ -28,6 +28,7 @@ $current_course_tool = TOOL_LEARNPATH; $course_id = api_get_course_int_id(); $lpRepo = Container::getLpRepository(); $courseInfo = api_get_course_info(); +$course = api_get_course_entity(); $glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools'); $showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']); @@ -911,7 +912,7 @@ switch ($action) { // Teachers can export to PDF if (!$is_allowed_to_edit) { - if (!learnpath::is_lp_visible_for_student($oLP->getEntity(), api_get_user_id(), $courseInfo)) { + if (!learnpath::is_lp_visible_for_student($oLP->getEntity(), api_get_user_id(), $course)) { api_not_allowed(); } } diff --git a/public/main/lp/lp_impress.php b/public/main/lp/lp_impress.php index 1c81fd023b..1f1013f189 100644 --- a/public/main/lp/lp_impress.php +++ b/public/main/lp/lp_impress.php @@ -16,7 +16,7 @@ $lp_id = intval($_GET['lp_id']); // Check if the learning path is visible for student - (LP requisites) if (!api_is_allowed_to_edit(null, true) && - !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id(), api_get_course_info()) + !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id(), api_get_course_entity()) ) { api_not_allowed(); } diff --git a/public/main/lp/lp_list.php b/public/main/lp/lp_list.php index 212d9b53cc..e8f93a93e8 100644 --- a/public/main/lp/lp_list.php +++ b/public/main/lp/lp_list.php @@ -49,8 +49,8 @@ $courseId = api_get_course_int_id(); $sessionId = api_get_session_id(); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $courseInfo = api_get_course_info(); -$courseEntity = api_get_course_entity($courseId); -$sessionEntity = api_get_session_entity($sessionId); +$course = api_get_course_entity($courseId); +$session = api_get_session_entity($sessionId); $subscriptionSettings = learnpath::getSubscriptionSettings(); $introduction = ''; @@ -218,7 +218,7 @@ foreach ($categories as $category) { $categoryId = $category->getIid(); $visibility = true; if (null !== $categoryId) { - $visibility = $category->isVisible($courseEntity, $sessionEntity); + $visibility = $category->isVisible($course, $session); } if (0 !== $categoryId && true == $subscriptionSettings['allow_add_users_to_lp_category']) { // "Without category" has id = 0 @@ -284,14 +284,14 @@ foreach ($categories as $category) { continue; } - $lpVisibility = learnpath::is_lp_visible_for_student($details['entity'], $userId, $courseInfo); + $lpVisibility = learnpath::is_lp_visible_for_student($details['entity'], $userId, $course); // Check if the learnpath is visible for student. if (!$is_allowed_to_edit) { $isBlocked = learnpath::isBlockedByPrerequisite( $userId, $details['prerequisite'], - $courseInfo, + $course, $sessionId ); if (false === $lpVisibility && $isBlocked && false === $showBlockedPrerequisite) { diff --git a/public/main/lp/lp_view.php b/public/main/lp/lp_view.php index ff27c77f17..a54f45cad8 100644 --- a/public/main/lp/lp_view.php +++ b/public/main/lp/lp_view.php @@ -31,8 +31,8 @@ $sessionId = api_get_session_id(); $course_code = api_get_course_id(); $course_id = api_get_course_int_id(); $user_id = api_get_user_id(); -$courseEntity = api_get_course_entity($course_id); -$sessionEntity = api_get_session_entity($sessionId); +$course = api_get_course_entity($course_id); +$session = api_get_session_entity($sessionId); /** @var learnpath $lp */ //$oLP = Session::read('oLP'); @@ -42,14 +42,14 @@ $lp = $lp; // Check if the learning path is visible for student - (LP requisites) if (!api_is_platform_admin()) { if (!api_is_allowed_to_edit(null, true, false, false) && - !learnpath::is_lp_visible_for_student($lp, api_get_user_id()) + !learnpath::is_lp_visible_for_student($lp, api_get_user_id(), $course) ) { api_not_allowed(true); } } // Checking visibility (eye icon) -$visibility = $lp->isVisible($courseEntity, $sessionEntity); +$visibility = $lp->isVisible($course, $session); if (false === $visibility && !api_is_allowed_to_edit(false, true, false, false) diff --git a/public/main/mySpace/teachers.php b/public/main/mySpace/teachers.php index 3853021a7a..943455ec03 100644 --- a/public/main/mySpace/teachers.php +++ b/public/main/mySpace/teachers.php @@ -17,21 +17,21 @@ if (!$allowToTrack) { api_not_allowed(true); } -$export_csv = isset($_GET['export']) && 'csv' == $_GET['export'] ? true : false; +$export_csv = isset($_GET['export']) && 'csv' === $_GET['export'] ? true : false; $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null; -$active = isset($_GET['active']) ? intval($_GET['active']) : 1; -$sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null; +$active = isset($_GET['active']) ? (int) $_GET['active'] : 1; +$sleepingDays = isset($_GET['sleeping_days']) ? (int) $_GET['sleeping_days'] : null; $nameTools = get_lang('Trainers'); $this_section = SECTION_TRACKING; -$interbreadcrumb[] = ["url" => "index.php", "name" => get_lang('Reporting')]; +$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Reporting')]; -if (isset($_GET["user_id"]) && "" != $_GET["user_id"] && !isset($_GET["type"])) { - $interbreadcrumb[] = ["url" => "teachers.php", "name" => get_lang('Trainers')]; +if (isset($_GET['user_id']) && '' != $_GET['user_id'] && !isset($_GET['type'])) { + $interbreadcrumb[] = ['url' => 'teachers.php', 'name' => get_lang('Trainers')]; } -if (isset($_GET["user_id"]) && "" != $_GET["user_id"] && isset($_GET["type"]) && "coach" == $_GET["type"]) { - $interbreadcrumb[] = ["url" => "coaches.php", "name" => get_lang('Coaches')]; +if (isset($_GET['user_id']) && '' != $_GET['user_id'] && isset($_GET['type']) && 'coach' == $_GET['type']) { + $interbreadcrumb[] = ['url' => 'coaches.php', 'name' => get_lang('Coaches')]; } function get_count_users() @@ -61,7 +61,7 @@ function get_users($from, $limit, $column, $direction) { $active = isset($_GET['active']) ? $_GET['active'] : 1; $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null; - $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null; + $sleepingDays = isset($_GET['sleeping_days']) ? (int) $_GET['sleeping_days'] : null; $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0; $lastConnectionDate = null; @@ -109,7 +109,6 @@ function get_users($from, $limit, $column, $direction) $keyword ); } - $all_datas = []; $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php'; foreach ($students as $student_data) { diff --git a/src/CoreBundle/Controller/SessionController.php b/src/CoreBundle/Controller/SessionController.php index c99e2d3bc3..a1096e346c 100644 --- a/src/CoreBundle/Controller/SessionController.php +++ b/src/CoreBundle/Controller/SessionController.php @@ -174,17 +174,7 @@ class SessionController extends AbstractController ]; } - $sessionDates = SessionManager::parseSessionDates( - [ - 'display_start_date' => $session->getDisplayStartDate(), - 'display_end_date' => $session->getDisplayEndDate(), - 'access_start_date' => $session->getAccessStartDate(), - 'access_end_date' => $session->getAccessEndDate(), - 'coach_access_start_date' => $session->getCoachAccessStartDate(), - 'coach_access_end_date' => $session->getCoachAccessEndDate(), - ], - true - ); + $sessionDates = SessionManager::parseSessionDates($session, true); /*$sessionRequirements = $sequenceResourceRepo->getRequirements( $session->getId(),