Fix php warning, fix question pagination

pull/3768/head
Julio Montoya 5 years ago
parent 386c731a8f
commit eccb1a40ab
  1. 1
      config/packages/validator.yaml
  2. 2
      public/main/exercise/exercise.class.php
  3. 107
      public/main/exercise/question_pool.php
  4. 54
      public/main/inc/ajax/exercise.ajax.php
  5. 1
      public/main/inc/lib/usergroup.lib.php
  6. 43
      src/CoreBundle/EventSubscriber/PaginationSubscriber.php

@ -1,4 +1,3 @@
framework:
validation:
email_validation_mode: html5

@ -183,7 +183,7 @@ class Exercise
// if the exercise has been found
if ($object = Database::fetch_object($result)) {
$this->id = $this->iId = $object->iid;
$this->id = $this->iId = (int) $object->iid;
$this->exercise = $object->title;
$this->name = $object->title;
$this->title = $object->title;

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\ExtraField as ExtraFieldEntity;
use Chamilo\CoreBundle\Framework\Container;
use ChamiloSession as Session;
use Knp\Component\Pager\Paginator;
@ -294,27 +295,6 @@ if (isset($_REQUEST['action'])) {
}
}
Display::display_header($nameTools, 'Exercise');
// Menu
echo '<div class="actions">';
if (isset($fromExercise) && $fromExercise > 0) {
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.
Display::return_icon('back.png', get_lang('Go back to the questions list'), '', ICON_SIZE_MEDIUM).'</a>';
$titleAdd = get_lang('Add question to test');
} else {
echo '<a href="exercise.php?'.api_get_cidreq().'">'.
Display::return_icon('back.png', get_lang('BackToTestsList'), '', ICON_SIZE_MEDIUM).'</a>';
echo "<a href='admin.php?exerciseId=0'>".
Display::return_icon('add_question.gif', get_lang('New question'), '', ICON_SIZE_MEDIUM).'</a>';
$titleAdd = get_lang('Manage all questions');
}
echo '</div>';
if ('' != $displayMessage) {
echo Display::return_message($displayMessage, 'confirm');
}
// Form
$sessionList = SessionManager::get_sessions_by_user(api_get_user_id(), api_is_platform_admin());
$session_select_list = ['-1' => get_lang('Select')];
@ -449,7 +429,6 @@ if (!empty($_course)) {
// Answer type list
$form = new FormValidator('question_pool', 'GET', $url);
$form->addHeader($nameTools.' - '.$titleAdd);
$form->addHidden('fromExercise', $fromExercise);
$form
->addSelect(
@ -514,14 +493,13 @@ $jsForExtraFields = $extraField->addElements($form, 0, [], true);
$form->addButtonFilter(get_lang('Filter'), 'name');
echo $form->display();
if (isset($fromExercise) && $fromExercise > 0) {
$titleAdd = get_lang('Add question to test');
} else {
$titleAdd = get_lang('Manage all questions');
}
echo '<script>$(function () {
'.$jsForExtraFields['jquery_ready_content'].'
})</script>';
?>
<div class="clear"></div>
<?php
$form->addHeader($nameTools.' - '.$titleAdd);
/**
* @return array
@ -880,12 +858,28 @@ if (empty($length)) {
$start = ($page - 1) * $length;
$paginator = new Paginator();
$pagination = $paginator->paginate([]);
$mainQuestionList = getQuestions(
false,
$start,
$length,
$exerciseId,
$courseCategoryId,
$selected_course,
$session_id,
$exerciseLevel,
$answerType,
$questionId,
$description,
$fromExercise,
$formValues
);
$paginator = new Paginator(Container::$container->get('event_dispatcher'));
$pagination = $paginator->paginate($mainQuestionList, $page, $length);
$pagination->setTotalItemCount($nbrQuestions);
$pagination->setItemNumberPerPage($length);
$pagination->setCurrentPageNumber($page);
$pagination->renderer = function ($data) use ($url) {
$render = '';
if ($data['pageCount'] > 1) {
@ -903,22 +897,6 @@ $pagination->renderer = function ($data) use ($url) {
return $render;
};
$mainQuestionList = getQuestions(
false,
$start,
$length,
$exerciseId,
$courseCategoryId,
$selected_course,
$session_id,
$exerciseLevel,
$answerType,
$questionId,
$description,
$fromExercise,
$formValues
);
// build the line of the array to display questions
// Actions are different if you launch the question_pool page
// They are different too if you have displayed questions from your course
@ -1045,8 +1023,35 @@ $headers = [
$actionLabel,
];
echo $pagination;
Display::display_header($nameTools, 'Exercise');
// Menu
echo '<div class="actions">';
if (isset($fromExercise) && $fromExercise > 0) {
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.
Display::return_icon('back.png', get_lang('Go back to the questions list'), '', ICON_SIZE_MEDIUM).'</a>';
} else {
echo '<a href="exercise.php?'.api_get_cidreq().'">'.
Display::return_icon('back.png', get_lang('BackToTestsList'), '', ICON_SIZE_MEDIUM).'</a>';
echo "<a href='admin.php?exerciseId=0'>".
Display::return_icon('add_question.gif', get_lang('New question'), '', ICON_SIZE_MEDIUM).'</a>';
}
echo '</div>';
if ('' != $displayMessage) {
echo Display::return_message($displayMessage, 'confirm');
}
echo $form->display();
echo '<script>$(function () {
'.$jsForExtraFields['jquery_ready_content'].'
})</script>';
?>
<div class="clear"></div>
<?php
echo $pagination;
$tableId = 'question_pool_id';
echo '<form id="'.$tableId.'" method="get" action="'.$url.'">';
echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
@ -1077,9 +1082,7 @@ foreach ($data as $rows) {
}
$row++;
}
$table->display();
echo '</form>';
$html = '<div class="btn-toolbar">';
@ -1108,7 +1111,7 @@ if ($selected_course == api_get_course_int_id()) {
$actions = ['reuse' => get_lang('Re-use in current testQuestion')];
}
foreach ($actions as $action => &$label) {
foreach ($actions as $action => $label) {
$html .= '<li>
<a
data-action ="'.$action.'"

@ -2,13 +2,13 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation;
use Chamilo\CoreBundle\Entity\TrackEExercises;
use Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation;
use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php';
$current_course_tool = TOOL_QUIZ;
$debug = false;
$debug = true;
api_protect_course_script(true);
$action = $_REQUEST['a'];
$course_id = api_get_course_int_id();
@ -39,7 +39,6 @@ switch ($action) {
echo json_encode($data);
break;
case 'update_duration':
if (Session::read('login_as')) {
if ($debug) {
error_log("User is 'login as' don't update duration time.");
@ -68,8 +67,8 @@ switch ($action) {
$onlyUpdateValue = 10;
$em = Database::getManager();
/** @var \Chamilo\CoreBundle\Entity\TrackEExercises $attempt */
$attempt = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->find($exeId);
/** @var TrackEExercises $attempt */
$attempt = $em->getRepository(TrackEExercises::class)->find($exeId);
if (empty($attempt)) {
if ($debug) {
@ -90,14 +89,14 @@ switch ($action) {
exit;
}
if ($exerciseInSession->id != $exerciseId) {
if ($exerciseInSession->iId !== $exerciseId) {
if ($debug) {
error_log("Cannot update, exercise are different.");
error_log('Cannot update, exercise are different.');
}
exit;
}
if ('incomplete' != $attempt->getStatus()) {
if ('incomplete' !== $attempt->getStatus()) {
if ($debug) {
error_log('Cannot update exercise is already completed.');
}
@ -125,20 +124,22 @@ switch ($action) {
$duration = (int) $duration;
if (!empty($duration)) {
if ($debug) {
error_log("Exe_id: #".$exeId);
error_log('Exe_id: #'.$exeId);
error_log("Key: $key");
error_log("Exercise to update: #$exerciseId of user: #$userId");
error_log("Duration time found in DB before update: $durationFromObject");
error_log("Current spent time $sessionTime before an update");
error_log("Accumulate duration to save in DB: $duration");
error_log("End date (UTC) before update: ".$attempt->getExeDate()->format('Y-m-d H:i:s'));
error_log("End date (UTC) to be save in DB: ".$nowObject->format('Y-m-d H:i:s'));
error_log('End date (UTC) before update: '.$attempt->getExeDate()->format('Y-m-d H:i:s'));
error_log('End date (UTC) to be save in DB: '.$nowObject->format('Y-m-d H:i:s'));
}
$attempt
->setExeDuration($duration)
->setExeDate($nowObject);
$em->persist($attempt);
$em->flush();
echo 1;
}
} else {
if ($debug) {
@ -288,7 +289,7 @@ switch ($action) {
$timeInfo = api_convert_and_format_date(
$row['start_date'],
DATE_TIME_FORMAT_LONG
).' ['.($h > 0 ? $h.':' : '').sprintf("%02d", $m).':'.sprintf("%02d", $s).']';
).' ['.($h > 0 ? $h.':' : '').sprintf('%02d', $m).':'.sprintf('%02d', $s).']';
} else {
$timeInfo = api_convert_and_format_date(
$row['start_date'],
@ -303,7 +304,7 @@ switch ($action) {
round($row['score'] * 100).'%',
];
$response->rows[$i]['cell'] = $array;
$i++;
++$i;
}
}
echo json_encode($response);
@ -327,7 +328,7 @@ switch ($action) {
'c_id' => $course_id,
]
);
$counter++;
++$counter;
}
echo Display::return_message(get_lang('Saved..'), 'confirmation');
}
@ -357,7 +358,7 @@ switch ($action) {
]
)
;
$counter++;
++$counter;
}
echo Display::return_message(get_lang('Saved..'), 'confirmation');
}
@ -420,10 +421,10 @@ switch ($action) {
if ($debug) {
error_log("exe_id = $exeId");
error_log("type = $type");
error_log("choice = ".print_r($choice, 1)." ");
error_log("hot_spot_coordinates = ".print_r($hot_spot_coordinates, 1));
error_log("remind_list = ".print_r($remind_list, 1));
error_log("--------------------------------");
error_log('choice = '.print_r($choice, 1).' ');
error_log('hot_spot_coordinates = '.print_r($hot_spot_coordinates, 1));
error_log('remind_list = '.print_r($remind_list, 1));
error_log('--------------------------------');
}
// Exercise information.
@ -439,10 +440,10 @@ switch ($action) {
echo 'error';
if ($debug) {
if (empty($question_list)) {
error_log("question_list is empty");
error_log('question_list is empty');
}
if (empty($objExercise)) {
error_log("objExercise is empty");
error_log('objExercise is empty');
}
}
exit;
@ -555,7 +556,6 @@ switch ($action) {
$my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null;
// Creates a temporary Question object
$objQuestionTmp = Question::read($my_question_id, $objExercise->course);
@ -774,7 +774,7 @@ switch ($action) {
// Destruction of the Question object
unset($objQuestionTmp);
if ($debug) {
error_log("---------- end question ------------");
error_log('---------- end question ------------');
}
}
if ($debug) {
@ -800,15 +800,15 @@ switch ($action) {
if (ONE_PER_PAGE == $objExercise->type) {
if ($debug) {
error_log("result: one_per_page");
error_log(" ------ end ajax call ------- ");
error_log('result: one_per_page');
error_log(' ------ end ajax call ------- ');
}
echo 'one_per_page';
exit;
}
if ($debug) {
error_log("result: ok");
error_log(" ------ end ajax call ------- ");
error_log('result: ok');
error_log(' ------ end ajax call ------- ');
}
echo 'ok';
break;

@ -2856,7 +2856,6 @@ class UserGroup extends Model
$direction = 'ASC';
}
$from = (int) $from;
$sql .= " LIMIT $from, $number_of_items";
$res = Database::query($sql);

@ -0,0 +1,43 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\EventSubscriber;
use Knp\Component\Pager\Event\ItemsEvent;
use Knp\Component\Pager\Event\PaginationEvent;
use Knp\Component\Pager\Pagination\SlidingPagination;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PaginationSubscriber implements EventSubscriberInterface
{
protected $defaultLocale;
protected $parameterBag;
protected $settingsManager;
public function items(ItemsEvent $event)
{
if (is_array($event->target)) {
$event->items = $event->target;
$event->count = count($event->target);
$event->stopPropagation();
}
}
public function pagination(PaginationEvent $event)
{
if (is_array($event->target)) {
$event->setPagination(new SlidingPagination);
}
$event->stopPropagation();
}
public static function getSubscribedEvents()
{
return [
'knp_pager.items' => ['items', 1/*increased priority to override any internal*/],
'knp_pager.pagination' => ['pagination', 0]
];
}
}
Loading…
Cancel
Save