Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
chamilo-lms/main/inc/ajax/student_follow_page.ajax.php

136 lines
3.9 KiB

<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpView;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
require_once __DIR__.'/../global.inc.php';
api_protect_course_script(true);
$httpRequest = HttpRequest::createFromGlobals();
$isAllowedToEdit = api_is_allowed_to_edit();
switch ($httpRequest->get('a')) {
case 'form_adquisition':
displayForm(
$httpRequest->query->getInt('lp_view')
);
break;
case 'views_invisible':
processViewsInvisible(
$httpRequest->request->get('chkb_view') ?: [],
$httpRequest->request->getBoolean('state')
);
break;
}
function displayForm(int $lpViewId)
{
$em = Database::getManager();
$lpView = $em->find(CLpView::class, $lpViewId);
if (null === $lpView) {
return;
}
$lp = $em->find(CLp::class, $lpView->getLpId());
$extraField = new ExtraField('lp_view');
$field = $extraField->get_handler_field_info_by_field_variable(StudentFollowPage::VARIABLE_ACQUISITION);
$extraFieldValue = new ExtraFieldValue('lp_view');
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
$lpViewId,
StudentFollowPage::VARIABLE_ACQUISITION
);
$options = [];
foreach ($field['options'] as $option) {
$options[$option['option_value']] = $option['display_text'];
}
$frmId = 'frm_lp_acquisition_'.$lpView->getLpId();
$frmAction = api_get_self().'?'.http_build_query(['lp_view' => $lpViewId, 'a' => 'form_adquisition']);
$form = new FormValidator($frmId, 'post', $frmAction);
$form->addRadio(StudentFollowPage::VARIABLE_ACQUISITION, get_lang('Acquisition'), $options);
$form->addHidden('lp_view', $lpViewId);
$form->addButtonSave(get_lang('Save'));
if ($form->validate()) {
$values = $form->exportValues();
$extraFieldValue = new ExtraFieldValue('lp_view');
$extraFieldValue->save(
[
'variable' => StudentFollowPage::VARIABLE_ACQUISITION,
'item_id' => $lpViewId,
'comment' => json_encode(['user' => api_get_user_id(), 'datetime' => api_get_utc_datetime()]),
'value' => $values[StudentFollowPage::VARIABLE_ACQUISITION]
]
);
echo StudentFollowPage::getLpAcquisition(
[
'iid' => $lp->getIid(),
'lp_name' => $lp->getName(),
],
$lpView->getUserId(),
$lpView->getCId(),
$lpView->getSessionId()
);
exit;
}
if (!empty($value)) {
$form->setDefaults([StudentFollowPage::VARIABLE_ACQUISITION => $value['value']]);
}
echo $form->returnForm()
."<script>$(function () {
$('#$frmId').on('submit', function (e) {
e.preventDefault();
var self = $(this);
self.find(':submit').prop('disabled', true);
$.post(this.action, self.serialize()).done(function (response) {
$('#acquisition-$lpViewId').html(response);
$('#global-modal').modal('hide');
self.find(':submit').prop('disabled', false);
});
})
})</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,
]
);
}
}