From 3351d26d509d82243b87724cfd92e242bafe36ef Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 21 Apr 2021 18:29:05 -0500 Subject: [PATCH] Add student_follow_page_add_LP_invisible_checkbox conf setting - refs BT#18671 Prepend a column in student LPs table to display a checkbox to select the LP category and its LPs. Requires DB changes: INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, default_value, field_order, visible_to_self, visible_to_others, changeable, filter, created_at) VALUES (20, 13, 'invisible', 'Invisible', '', 0, 1, 0, 0, 0, NOW()); --- main/inc/ajax/student_follow_page.ajax.php | 29 +++++++++ main/inc/lib/StudentFollowPage.php | 69 +++++++++++++++++++--- main/install/configuration.dist.php | 6 ++ main/lp/learnpath.class.php | 14 +++++ main/lp/learnpathList.class.php | 1 + main/mySpace/myStudents.php | 26 ++++++++ 6 files changed, 137 insertions(+), 8 deletions(-) diff --git a/main/inc/ajax/student_follow_page.ajax.php b/main/inc/ajax/student_follow_page.ajax.php index c920d04a1c..3ce0b27814 100644 --- a/main/inc/ajax/student_follow_page.ajax.php +++ b/main/inc/ajax/student_follow_page.ajax.php @@ -20,6 +20,12 @@ switch ($httpRequest->get('a')) { $httpRequest->query->getInt('lp_view') ); break; + case 'views_invisible': + processViewsInvisible( + $httpRequest->request->get('chkb_view') ?: [], + $httpRequest->request->getBoolean('state') + ); + break; } function displayForm(int $lpViewId) @@ -105,3 +111,26 @@ function displayForm(int $lpViewId) }) })"; } + +function processViewsInvisible(array $lpViewsIds, bool $state) +{ + $lpViewsIds = array_map('intval', $lpViewsIds); + $lpViewsIds = array_filter($lpViewsIds); + + if (empty($lpViewsIds)) { + return; + } + + foreach ($lpViewsIds as $lpViewId) { + $extraFieldValue = new ExtraFieldValue('lp_view'); + $extraFieldValue->save( + [ + 'variable' => StudentFollowPage::VARIABLE_INVISIBLE, + 'item_id' => $lpViewId, + 'comment' => json_encode(['user' => api_get_user_id(), 'datetime' => api_get_utc_datetime()]), + 'value' => !$state, + ] + ); + } + +} diff --git a/main/inc/lib/StudentFollowPage.php b/main/inc/lib/StudentFollowPage.php index 95a76ad9f2..6e79a811be 100644 --- a/main/inc/lib/StudentFollowPage.php +++ b/main/inc/lib/StudentFollowPage.php @@ -10,6 +10,7 @@ use Chamilo\CourseBundle\Entity\CItemProperty; class StudentFollowPage { const VARIABLE_ACQUISITION = 'acquisition'; + const VARIABLE_INVISIBLE = 'invisible'; public static function getLpSubscription( array $lpInfo, @@ -61,14 +62,7 @@ class StudentFollowPage int $courseId, int $sessionId = 0 ): string { - $tblLpView = Database::get_course_table(TABLE_LP_VIEW); - - $sessionCondition = api_get_session_condition($sessionId); - - $sql = "SELECT iid FROM $tblLpView - WHERE c_id = $courseId AND lp_id = {$lpInfo['iid']} AND user_id = $studentId $sessionCondition - ORDER BY view_count DESC"; - $lpView = Database::fetch_assoc(Database::query($sql)); + $lpView = learnpath::findLastView($lpInfo['iid'], $studentId, $courseId, $sessionId); if (empty($lpView)) { return '-'; @@ -120,4 +114,63 @@ class StudentFollowPage return '
'.$return.'
'; } + + public static function getLpVisibleScript() + { + $url = api_get_path(WEB_AJAX_PATH).'student_follow_page.ajax.php?'.http_build_query(['a' => 'views_invisible']); + + return ""; + } + + public static function getLpVisibleField(array $lpInfo, int $studentId, int $courseId, int $sessionId = 0) + { + $lpView = learnpath::findLastView($lpInfo['iid'], $studentId, $courseId, $sessionId); + + if (empty($lpView)) { + return '-'; + } + + $attrs = []; + + $extraFieldValue = new ExtraFieldValue('lp_view'); + $value = $extraFieldValue->get_values_by_handler_and_field_variable($lpView['iid'], self::VARIABLE_INVISIBLE); + + if (empty($value) || empty($value['value'])) { + $attrs['checked'] = 'checked'; + } + + return Display::input('checkbox', 'chkb_view[]', $lpView['iid'], $attrs); + } } diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index cc3a5735dc..ba0c734747 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -393,6 +393,12 @@ INSERT INTO extra_field_options (field_id, option_value, display_text, priority, */ //$_configuration['student_follow_page_add_LP_acquisition_info'] = false; +// Prepend a column in student LPs table to display a checkbox to select the LP category and its LPs. Requires DB changes: +/* +INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, default_value, field_order, visible_to_self, visible_to_others, changeable, filter, created_at) VALUES +(20, 13, 'invisible', 'Invisible', '', 0, 1, 0, 0, 0, NOW()); +*/ +//$_configuration['student_follow_page_add_LP_invisible_checkbox'] = false; // Hide session link of course_block on index/userportal //$_configuration['remove_session_url']= false ; // Allow foldable block for session list in session category on My courses tab diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 94ee3e4618..86ed66d18d 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -14310,4 +14310,18 @@ EOD; $author->setOptions($options); } } + + public static function findLastView(int $lpId, int $studentId, int $courseId, int $sessionId = 0) + { + $tblLpView = Database::get_course_table(TABLE_LP_VIEW); + + $sessionCondition = api_get_session_condition($sessionId); + + $sql = "SELECT iid FROM $tblLpView + WHERE c_id = $courseId AND lp_id = $lpId AND user_id = $studentId $sessionCondition + ORDER BY view_count DESC"; + $result = Database::query($sql); + + return Database::fetch_assoc($result); + } } diff --git a/main/lp/learnpathList.class.php b/main/lp/learnpathList.class.php index 9c732d8216..5ebca07bd9 100755 --- a/main/lp/learnpathList.class.php +++ b/main/lp/learnpathList.class.php @@ -203,6 +203,7 @@ class LearnpathList 'lp_old_id' => $row->getId(), 'iid' => $row->getIid(), 'prerequisite' => $row->getPrerequisite(), + 'category_id' => $row->getCategoryId(), ]; $names[$row->getName()] = $row->getIid(); } diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index caf22e6565..250a77d9e4 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -1353,6 +1353,17 @@ if (empty($details)) { } } + if (true === api_get_configuration_value('student_follow_page_add_LP_invisible_checkbox')) { + echo StudentFollowPage::getLpVisibleScript(); + + $chkb = Display::input('checkbox', 'chkb_category[]', ''); + + $columnHeaders = array_merge( + ['student_follow_page_add_LP_invisible_checkbox' => $chkb], + $columnHeaders + ); + } + if (true === api_get_configuration_value('student_follow_page_add_LP_subscription_info')) { $columnHeaders['student_follow_page_add_LP_subscription_info'] = get_lang('Unlock'); } @@ -1372,6 +1383,8 @@ if (empty($details)) { ); } + unset($columnHeadersToExport['student_follow_page_add_LP_invisible_checkbox']); + $hookLpTracking = HookMyStudentsLpTracking::create(); if ($hookLpTracking) { $hookHeaders = $hookLpTracking->notifyTrackingHeader(); @@ -1544,6 +1557,19 @@ if (empty($details)) { echo ''; $contentToExport = []; + + if (in_array('student_follow_page_add_LP_invisible_checkbox', $columnHeadersKeys)) { + echo Display::tag( + 'td', + StudentFollowPage::getLpVisibleField( + $learnpath, + $student_id, + $courseInfo['real_id'], + $sessionId + ) + ); + } + if (in_array('lp', $columnHeadersKeys)) { $contentToExport[] = api_html_entity_decode( stripslashes($lp_name),