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());
pull/3859/head
Angel Fernando Quiroz Campos 5 years ago
parent a67f006d4a
commit 3351d26d50
  1. 29
      main/inc/ajax/student_follow_page.ajax.php
  2. 69
      main/inc/lib/StudentFollowPage.php
  3. 6
      main/install/configuration.dist.php
  4. 14
      main/lp/learnpath.class.php
  5. 1
      main/lp/learnpathList.class.php
  6. 26
      main/mySpace/myStudents.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)
})
})</script>";
}
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,
]
);
}
}

@ -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 '<div id="acquisition-'.$lpView['iid'].'">'.$return.'</div>';
}
public static function getLpVisibleScript()
{
$url = api_get_path(WEB_AJAX_PATH).'student_follow_page.ajax.php?'.http_build_query(['a' => 'views_invisible']);
return "<script>$(function () {
var chkbView = $('[name=\"chkb_view[]\"]');
function doRequest(element, state) {
element.prop('disabled', true);
var views = $.makeArray(element).map(function (input) { return input.value; });
return $.post('$url', { 'chkb_view[]': views, 'state': state }, function () { element.prop('disabled', false); });
}
$('[name=\"chkb_category[]\"]').on('change', function () {
var checked = this.checked;
var chkbs = $(this).parents('table').find('td :checkbox').each(function () { this.checked = checked; });
doRequest(chkbs, checked);
}).prop('checked', true);
chkbView.on('change', function () {
doRequest($(this), this.checked);
$(this).parents('table').find('th :checkbox').prop(
'checked',
$.makeArray($(this).parents('table').find('td :checkbox'))
.map(function (input) { return input.checked; })
.reduce(function (acc, cur) { return acc && cur; })
);
}).each(function () {
if (!this.checked) {
$(this).parents('table').find('th :checkbox').prop('checked', false);
}
});
});</script>";
}
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);
}
}

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

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

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

@ -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 '<tr class="'.$css_class.'">';
$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),

Loading…
Cancel
Save