Add deprecation for unused files, remove unused code, fix arguments

Use course entity
pull/3844/head
Julio Montoya 5 years ago
parent 86d9809ca6
commit ea0e05e446
  1. 18
      public/main/coursecopy/import_backup.php
  2. 3
      public/main/document/download_scorm.php
  3. 5
      public/main/exercise/exercise.class.php
  4. 13
      public/main/glossary/glossary_ajax_request.php
  5. 1
      public/main/inc/lib/api.lib.php
  6. 6
      public/main/inc/lib/webservices/Rest.php
  7. 2
      public/main/lp/download.php
  8. 84
      public/main/lp/learnpath.class.php
  9. 2
      public/main/lp/learnpathList.class.php
  10. 3
      public/main/lp/lp_controller.php
  11. 2
      public/main/lp/lp_impress.php
  12. 10
      public/main/lp/lp_list.php
  13. 8
      public/main/lp/lp_view.php
  14. 19
      public/main/mySpace/teachers.php
  15. 12
      src/CoreBundle/Controller/SessionController.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 '<a class="btn btn-default" href="'.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php">'.
echo '<a class="btn btn-default" href="'.api_get_course_url(api_get_course_id()).'">'.
get_lang('Course home').'</a>';
} else {
if (!$error) {
echo Display::return_message(get_lang('There are no resources in backup file'), 'warning');
echo '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('Try again').'</a>';
echo '<a
class="btn btn-default"
href="import_backup.php?'.api_get_cidreq().'">'.get_lang('Try again').'</a>';
} 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 '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('Try again').'</a>';
echo Display::return_message(
get_lang(
'The app/cache/ directory, used by this tool, is not writeable. Please contact your platform administrator.'
),
'error'
);
echo '<a
class="btn btn-default"
href="import_backup.php?'.api_get_cidreq().'">'.get_lang('Try again').'</a>';
} else {
if ('' == $filename) {
echo Display::return_message(get_lang('Select a backup file'), 'error');

@ -1,6 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
// @deprecated
exit;
use ChamiloSession as Session;
/**

@ -6551,7 +6551,8 @@ class Exercise
return [];
}
$link = $exercise->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,

@ -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');

@ -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()) {

@ -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;

@ -1,5 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
// @deprecated
exit;
use ChamiloSession as Session;

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
@ -2076,24 +2077,24 @@ class learnpath
}
/**
* @param int $studentId
* @param int $prerequisite
* @param array $courseInfo
* @param int $sessionId
* @param int $studentId
* @param int $prerequisite
* @param Course $course
* @param int $sessionId
*
* @return bool
*/
public static function isBlockedByPrerequisite(
$studentId,
$prerequisite,
$courseInfo,
Course $course,
$sessionId
) {
if (empty($courseInfo)) {
if (null === $course) {
return false;
}
$courseId = $courseInfo['real_id'];
$courseId = $course->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;

@ -129,7 +129,7 @@ class LearnpathList
$lpVisibility = learnpath::is_lp_visible_for_student(
$lp,
$user_id,
$courseInfo
$course
);
if (false === $lpVisibility) {
continue;

@ -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();
}
}

@ -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();
}

@ -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) {

@ -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)

@ -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) {

@ -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(),

Loading…
Cancel
Save