diff --git a/config/packages/validator.yaml b/config/packages/validator.yaml index 3fcd3f82e1..a695e1a62a 100644 --- a/config/packages/validator.yaml +++ b/config/packages/validator.yaml @@ -1,4 +1,3 @@ framework: validation: email_validation_mode: html5 - diff --git a/public/main/exercise/exercise.class.php b/public/main/exercise/exercise.class.php index 259d086cf4..681b1d09e1 100644 --- a/public/main/exercise/exercise.class.php +++ b/public/main/exercise/exercise.class.php @@ -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; diff --git a/public/main/exercise/question_pool.php b/public/main/exercise/question_pool.php index 7b29135884..4067b036c0 100644 --- a/public/main/exercise/question_pool.php +++ b/public/main/exercise/question_pool.php @@ -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 '
'; -if (isset($fromExercise) && $fromExercise > 0) { - echo ''. - Display::return_icon('back.png', get_lang('Go back to the questions list'), '', ICON_SIZE_MEDIUM).''; - $titleAdd = get_lang('Add question to test'); -} else { - echo ''. - Display::return_icon('back.png', get_lang('BackToTestsList'), '', ICON_SIZE_MEDIUM).''; - echo "". - Display::return_icon('add_question.gif', get_lang('New question'), '', ICON_SIZE_MEDIUM).''; - $titleAdd = get_lang('Manage all questions'); -} -echo '
'; - -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 ''; -?> -
-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 '
'; +if (isset($fromExercise) && $fromExercise > 0) { + echo ''. + Display::return_icon('back.png', get_lang('Go back to the questions list'), '', ICON_SIZE_MEDIUM).''; +} else { + echo ''. + Display::return_icon('back.png', get_lang('BackToTestsList'), '', ICON_SIZE_MEDIUM).''; + echo "". + Display::return_icon('add_question.gif', get_lang('New question'), '', ICON_SIZE_MEDIUM).''; +} +echo '
'; + +if ('' != $displayMessage) { + echo Display::return_message($displayMessage, 'confirm'); +} + +echo $form->display(); + +echo ''; +?> +
+'; echo ''; @@ -1077,9 +1082,7 @@ foreach ($data as $rows) { } $row++; } - $table->display(); - echo ''; $html = '
'; @@ -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 .= '
  • 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; diff --git a/public/main/inc/lib/usergroup.lib.php b/public/main/inc/lib/usergroup.lib.php index 64755d57e1..8ff069ee9d 100644 --- a/public/main/inc/lib/usergroup.lib.php +++ b/public/main/inc/lib/usergroup.lib.php @@ -2856,7 +2856,6 @@ class UserGroup extends Model $direction = 'ASC'; } - $from = (int) $from; $sql .= " LIMIT $from, $number_of_items"; $res = Database::query($sql); diff --git a/src/CoreBundle/EventSubscriber/PaginationSubscriber.php b/src/CoreBundle/EventSubscriber/PaginationSubscriber.php new file mode 100644 index 0000000000..141396378c --- /dev/null +++ b/src/CoreBundle/EventSubscriber/PaginationSubscriber.php @@ -0,0 +1,43 @@ +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] + ]; + } +}