Plugin: ExerciseFocused: Allow save level in log - refs BT#20900

pull/4900/head
Angel Fernando Quiroz Campos 2 years ago committed by Angel Fernando Quiroz Campos
parent 466775f891
commit 3a8a5648fa
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 22
      plugin/exercisefocused/index.php
  2. 21
      plugin/exercisefocused/src/Controller/LogController.php
  3. 19
      plugin/exercisefocused/src/Entity/Log.php
  4. 16
      plugin/exercisefocused/templates/script.html.twig

@ -15,16 +15,20 @@ if ($renderRegion) {
$_template['show_region'] = true;
$em = Database::getManager();
$logRepository = $em->getRepository(Log::class);
$existingExeId = (int) ChamiloSession::read('exe_id');
$trackingExercise = null;
if ($existingExeId) {
$trackingExercise = $em->find(TrackEExercises::class, $existingExeId);
}
$_template['sec_token'] = Security::get_token('exercisefocused');
if ('true' === $plugin->get(ExerciseFocusedPlugin::SETTING_ENABLE_OUTFOCUSED_LIMIT)) {
$existingExeId = (int) ChamiloSession::read('exe_id');
if ($existingExeId) {
$trackingExercise = $em->find(TrackEExercises::class, $existingExeId);
$logRepository = $em->getRepository(Log::class);
if ($trackingExercise) {
$countOutfocused = $logRepository->countByActionInExe($trackingExercise, Log::TYPE_OUTFOCUSED);
} else {
$countOutfocused = 0;
@ -33,4 +37,12 @@ if ($renderRegion) {
$_template['count_outfocused'] = $countOutfocused;
$_template['remaining_outfocused'] = (int) $plugin->get(ExerciseFocusedPlugin::SETTING_OUTFOCUSED_LIMIT) - $countOutfocused;
}
if ($trackingExercise) {
$exercise = new Exercise($trackingExercise->getCId());
if ($exercise->read($trackingExercise->getExeExoId())) {
$_template['exercise_type'] = (int) $exercise->selectType();
}
}
}

@ -5,6 +5,7 @@
namespace Chamilo\PluginBundle\ExerciseFocused\Controller;
use Chamilo\CoreBundle\Entity\TrackEExercises;
use Chamilo\CourseBundle\Entity\CQuizQuestion;
use Chamilo\PluginBundle\ExerciseFocused\Entity\Log;
use ChamiloSession;
use Exception;
@ -37,6 +38,8 @@ class LogController extends BaseController
}
$action = $this->request->query->get('action');
$levelId = $this->request->query->getInt('level_id');
$exeId = (int) ChamiloSession::read('exe_id');
if (!in_array($action, self::VALID_ACTIONS)) {
@ -49,10 +52,26 @@ class LogController extends BaseController
throw new Exception('no exercise attempt');
}
$objExercise = new Exercise($trackingExercise->getCId());
$objExercise->read($trackingExercise->getExeExoId());
$level = 0;
if (ONE_PER_PAGE == $objExercise->selectType()) {
$question = $this->em->find(CQuizQuestion::class, $levelId);
if (!$question) {
throw new Exception('Invalid level');
}
$level = $question->getIid();
}
$log = new Log();
$log
->setAction($action)
->setExe($trackingExercise);
->setExe($trackingExercise)
->setLevel($level);
$this->em->persist($log);
$this->em->flush();

@ -42,6 +42,13 @@ class Log
*/
private $exe;
/**
* @var int
*
* @ORM\Column(name="level", type="integer")
*/
private $level;
/**
* @var string
*
@ -66,6 +73,18 @@ class Log
return $this;
}
public function getLevel(): int
{
return $this->level;
}
public function setLevel(int $level): self
{
$this->level = $level;
return $this;
}
public function getAction(): string
{
return $this->action;

@ -4,6 +4,9 @@
{% set enable_outfocused_limit = 'true' == exercisefocused.plugin_info.obj.get('enable_outfocused_limit') %}
{% set outfocused_limit = exercisefocused.plugin_info.obj.get('outfocused_limit') %}
{% set ALL_ON_ONE_PAGE = exercisefocused.exercise_type == 1 %}
{% set ONE_PER_PAGE = exercisefocused.exercise_type == 2 %}
<script>
$(function () {
var $exerciseFocused = $("#exercisefocused-block").appendTo('body');
@ -16,6 +19,8 @@
.addClass('exercisefocused-backdrop text-danger')
.attr('data-alert', '{{ 'AlertBeforeLeaving'|get_plugin_lang('ExerciseFocusedPlugin') }}');
var $btnSaveNow = $('button[name="save_now"]');
$backdrop.appendTo('body');
var secToken = "{{ exercisefocused.sec_token }}";
@ -62,11 +67,18 @@
{% endif %}
function sendAction(action, callback) {
{% if ALL_ON_ONE_PAGE %}
var levelId = 0;
{% elseif ONE_PER_PAGE %}
var levelId = $btnSaveNow.data('question') || -1;
{% endif %}
$.ajax({
url: "{{ _p.web_plugin }}exercisefocused/pages/log.php",
data: {
action: action,
exercisefocused_sec_token: secToken,
level_id: levelId
},
success: function (response) {
if (!response) {
@ -104,9 +116,9 @@
sendAction('outfocused');
remainingTime = {{ time_limit }};
{% if enable_time_limit %}
remainingTime = {{ time_limit }};
updateCountdown();
countdownInterval = window.setInterval(updateCountdown, 1000);

Loading…
Cancel
Save