From bfdf62f0f2dfa1ad4c23d3cbfb6bbaf3b74dee97 Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 18 Jan 2017 10:27:12 +0100 Subject: [PATCH] Add settings show_prerequisite_as_blocked see BT#12162 --- main/install/configuration.dist.php | 4 ++ main/lp/learnpath.class.php | 64 +++++++++++++++++++---------- main/lp/learnpathList.class.php | 3 +- main/lp/lp_list.php | 41 ++++++++++++++---- 4 files changed, 80 insertions(+), 32 deletions(-) diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 92c6363bd5..084294c02d 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -263,4 +263,8 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE; //$_configuration['add_all_files_in_lp_export'] = false; // Send exercise student score to manager in email notification //$_configuration['send_score_in_exam_notification_mail_to_manager'] = false; +// Show blocked LPs by prerequisite to students +//$_configuration['show_prerequisite_as_blocked'] = false; + + diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 5946ceeb24..1952c0b22e 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -2282,6 +2282,32 @@ class learnpath return $output; } + /** + * @param int $lpId + * @param array $courseInfo + * @return bool + * + */ + public static function isBlockedByPrerequisite($student_id, $prerequisite, $courseInfo, $sessionId) + { + $isBlocked = false; + + if (!empty($prerequisite)) { + $progress = self::getProgress( + $prerequisite, + $student_id, + $courseInfo['real_id'], + $sessionId + ); + $progress = intval($progress); + if ($progress < 100) { + $isBlocked = true; + } + } + + return $isBlocked; + } + /** * Checks if the learning path is visible for student after the progress * of its prerequisite is completed, considering the time availability and @@ -2306,12 +2332,6 @@ class learnpath $sessionId = api_get_session_id(); } - $tbl_learnpath = Database::get_course_table(TABLE_LP_MAIN); - // Get current prerequisite - $sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on - FROM $tbl_learnpath - WHERE c_id = ".$courseInfo['real_id']." AND id = $lp_id"; - $itemInfo = api_get_item_property_info( $courseInfo['real_id'], TOOL_LEARNPATH, @@ -2324,25 +2344,29 @@ class learnpath return false; } + // @todo remove this query and load the row info as a parameter + $tbl_learnpath = Database::get_course_table(TABLE_LP_MAIN); + // Get current prerequisite + $sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on + FROM $tbl_learnpath + WHERE c_id = ".$courseInfo['real_id']." AND id = $lp_id"; + $rs = Database::query($sql); $now = time(); if (Database::num_rows($rs) > 0) { $row = Database::fetch_array($rs, 'ASSOC'); - $prerequisite = $row['prerequisite']; $is_visible = true; - if (!empty($prerequisite)) { - $progress = self::getProgress( - $prerequisite, - $student_id, - $courseInfo['real_id'], - $sessionId - ); - $progress = intval($progress); - if ($progress < 100) { - $is_visible = false; - } + $isBlocked = self::isBlockedByPrerequisite( + $student_id, + $prerequisite, + $courseInfo, + $sessionId + ); + + if ($isBlocked) { + $is_visible = false; } // Also check the time availability of the LP @@ -2350,7 +2374,6 @@ class learnpath // Adding visibility restrictions if (!empty($row['publicated_on'])) { if ($now < api_strtotime($row['publicated_on'], 'UTC')) { - //api_not_allowed(); $is_visible = false; } } @@ -2361,14 +2384,12 @@ class learnpath $_custom['lps_hidden_when_no_start_date'] ) { if (empty($row['publicated_on'])) { - //api_not_allowed(); $is_visible = false; } } if (!empty($row['expired_on'])) { if ($now > api_strtotime($row['expired_on'], 'UTC')) { - //api_not_allowed(); $is_visible = false; } } @@ -2396,7 +2417,6 @@ class learnpath if (!empty($userGroups)) { foreach ($userGroups as $groupInfo) { $groupId = $groupInfo['iid']; - $userVisibility = api_get_item_visibility( $courseInfo, 'learnpath', diff --git a/main/lp/learnpathList.class.php b/main/lp/learnpathList.class.php index 65268f6115..ad989f366a 100755 --- a/main/lp/learnpathList.class.php +++ b/main/lp/learnpathList.class.php @@ -171,7 +171,8 @@ class LearnpathList 'expired_on' => $row->getExpiredOn() ? $row->getExpiredOn()->format('Y-m-d H:i:s') : null, //'category_id' => $row['category_id'], 'subscribe_users' => $row->getSubscribeUsers(), - 'lp_old_id' => $row->getId() + 'lp_old_id' => $row->getId(), + 'prerequisite' => $row->getPrerequisite() ); $names[$row->getName()] = $row->getIid(); } diff --git a/main/lp/lp_list.php b/main/lp/lp_list.php index a3fcf41b07..52a25076ca 100755 --- a/main/lp/lp_list.php +++ b/main/lp/lp_list.php @@ -63,7 +63,7 @@ $introductionSection = Display::return_introduction_section( ); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); - +$courseInfo = api_get_course_info(); $message = ''; $actions = ''; @@ -161,6 +161,7 @@ foreach ($categories as $item) { continue; } + $showBlockedPrerequisite = api_get_configuration_value('show_prerequisite_as_blocked'); $listData = []; if (!empty($flat_list)) { @@ -182,8 +183,18 @@ foreach ($categories as $item) { continue; } + $lpVisibility = learnpath::is_lp_visible_for_student($id, $userId); + $isBlocked = learnpath::isBlockedByPrerequisite( + $userId, + $details['prerequisite'], + $courseInfo, + api_get_session_id() + ); + // Check if the learnpath is visible for student. - if (!$is_allowed_to_edit && !learnpath::is_lp_visible_for_student($id, $userId)) { + if (!$is_allowed_to_edit && $lpVisibility == false && + ($isBlocked && $showBlockedPrerequisite == false) + ) { continue; } @@ -198,7 +209,7 @@ foreach ($categories as $item) { $time_limits = false; } - //Checking if expired_on is ON + // Checking if expired_on is ON if ($details['expired_on'] != '') { $time_limits = true; } @@ -255,8 +266,7 @@ foreach ($categories as $item) { if ($is_allowed_to_edit) { $url_start_lp .= '&isStudentView=true'; - $studentVisibility = learnpath::is_lp_visible_for_student($id, $userId); - $dsp_desc = ''.$details['lp_maker'].' '.($studentVisibility ? '' : ' - ('.get_lang('LPNotVisibleToStudent').')'); + $dsp_desc = ''.$details['lp_maker'].' '.($lpVisibility ? '' : ' - ('.get_lang('LPNotVisibleToStudent').')'); $extra = '
'.$dsp_desc.'
'; } @@ -282,6 +292,22 @@ foreach ($categories as $item) { ); } + // Students can see the lp but is inactive + if (!$is_allowed_to_edit && $lpVisibility == false && $showBlockedPrerequisite == true) { + $my_title = Display::tag( + 'font', + $name, + array('class' => 'text-muted') + ); + $icon_learnpath = Display::return_icon( + 'learnpath_na.png', + get_lang('LPName'), + '', + ICON_SIZE_SMALL + ); + $url_start_lp = '#'; + } + $dsp_desc = ''; $dsp_export = ''; $dsp_build = ''; @@ -291,7 +317,6 @@ foreach ($categories as $item) { $dsp_default_view = ''; $dsp_debug = ''; $dsp_order = ''; - $progress = 0; if (!api_is_invitee()) { @@ -820,9 +845,7 @@ $templateName = $template->get_template('learnpath/list.tpl'); $content = $template->fetch($templateName); $template->assign('content', $content); $template->display_one_col_template(); - -$course_info = api_get_course_info(); -learnpath::generate_learning_path_folder($course_info); +learnpath::generate_learning_path_folder($courseInfo); // Deleting the objects Session::erase('oLP');