Improve speed when editing a question (dont parse question list)

Format code

BT#15329
pull/2865/head
Julio 7 years ago
parent a1a8c94f56
commit 3e000d0365
  1. 6
      main/admin/questions.php
  2. 31
      main/exercise/admin.php
  3. 2
      main/exercise/answer.class.php

@ -3,6 +3,8 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CQuizQuestion; use Chamilo\CourseBundle\Entity\CQuizQuestion;
use Knp\Component\Pager\Paginator;
use Doctrine\Common\Collections\Criteria;
/** /**
* @package chamilo.admin * @package chamilo.admin
@ -38,7 +40,7 @@ if ($formSent) {
$em = Database::getManager(); $em = Database::getManager();
$repo = $em->getRepository('ChamiloCourseBundle:CQuizQuestion'); $repo = $em->getRepository('ChamiloCourseBundle:CQuizQuestion');
$criteria = new \Doctrine\Common\Collections\Criteria(); $criteria = new Criteria();
if (!empty($id)) { if (!empty($id)) {
$criteria->where($criteria->expr()->eq('iid', $id)); $criteria->where($criteria->expr()->eq('iid', $id));
} }
@ -65,7 +67,7 @@ if ($formSent) {
$questionCount = count($questions); $questionCount = count($questions);
$paginator = new Knp\Component\Pager\Paginator(); $paginator = new Paginator();
$pagination = $paginator->paginate($questions, $page, $length); $pagination = $paginator->paginate($questions, $page, $length);
$pagination->setItemNumberPerPage($length); $pagination->setItemNumberPerPage($length);
$pagination->setCurrentPageNumber($page); $pagination->setCurrentPageNumber($page);

@ -62,9 +62,7 @@ if (!$is_allowedToEdit) {
api_not_allowed(true); api_not_allowed(true);
} }
if (empty($exerciseId)) { $exerciseId = isset($_GET['exerciseId']) ? (int) $_GET['exerciseId'] : '0';
$exerciseId = isset($_GET['exerciseId']) ? intval($_GET['exerciseId']) : '0';
}
/* stripslashes POST data */ /* stripslashes POST data */
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@ -81,11 +79,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
} }
$newQuestion = isset($_GET['newQuestion']) ? $_GET['newQuestion'] : 0; $newQuestion = isset($_GET['newQuestion']) ? $_GET['newQuestion'] : 0;
$modifyAnswers = isset($_GET['modifyAnswers']) ? $_GET['modifyAnswers'] : 0;
if (empty($modifyAnswers)) {
$modifyAnswers = isset($_GET['modifyAnswers']) ? $_GET['modifyAnswers'] : 0;
}
$editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : 0; $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : 0;
if (empty($modifyQuestion)) { if (empty($modifyQuestion)) {
@ -169,7 +163,12 @@ if (!is_object($objExercise)) {
// creation of a new exercise if wrong or not specified exercise ID // creation of a new exercise if wrong or not specified exercise ID
if ($exerciseId) { if ($exerciseId) {
$objExercise->read($exerciseId, $showPagination > 0 ? false : true); $parseQuestionList = $showPagination > 0 ? false : true;
if ($editQuestion) {
$parseQuestionList = false;
$showPagination = true;
}
$objExercise->read($exerciseId, $parseQuestionList);
} }
// saves the object into the session // saves the object into the session
Session::write('objExercise', $objExercise); Session::write('objExercise', $objExercise);
@ -285,21 +284,21 @@ if (api_is_in_gradebook()) {
$interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')]; $interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')];
if (isset($_GET['newQuestion']) || isset($_GET['editQuestion'])) { if (isset($_GET['newQuestion']) || isset($_GET['editQuestion'])) {
$interbreadcrumb[] = [ $interbreadcrumb[] = [
"url" => "admin.php?exerciseId=".$objExercise->id.'&'.api_get_cidreq(), 'url' => "admin.php?exerciseId=".$objExercise->id.'&'.api_get_cidreq(),
"name" => $objExercise->selectTitle(true), 'name' => $objExercise->selectTitle(true),
]; ];
} else { } else {
$interbreadcrumb[] = [ $interbreadcrumb[] = [
"url" => "#", 'url' => '#',
"name" => $objExercise->selectTitle(true), 'name' => $objExercise->selectTitle(true),
]; ];
} }
// shows a link to go back to the question pool // shows a link to go back to the question pool
if (!$exerciseId && $nameTools != get_lang('ExerciseManagement')) { if (!$exerciseId && $nameTools != get_lang('ExerciseManagement')) {
$interbreadcrumb[] = [ $interbreadcrumb[] = [
"url" => api_get_path(WEB_CODE_PATH)."exercise/question_pool.php?fromExercise=$fromExercise&".api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH)."exercise/question_pool.php?fromExercise=$fromExercise&".api_get_cidreq(),
"name" => get_lang('QuestionPool'), 'name' => get_lang('QuestionPool'),
]; ];
} }
@ -370,7 +369,6 @@ if ($inATest) {
if ($objExercise->added_in_lp()) { if ($objExercise->added_in_lp()) {
echo Display::return_message(get_lang('AddedToLPCannotBeAccessed'), 'warning'); echo Display::return_message(get_lang('AddedToLPCannotBeAccessed'), 'warning');
} }
if ($editQuestion && $objQuestion->existsInAnotherExercises()) { if ($editQuestion && $objQuestion->existsInAnotherExercises()) {
echo Display::return_message( echo Display::return_message(
Display::returnFontAwesomeIcon('exclamation-triangle"') Display::returnFontAwesomeIcon('exclamation-triangle"')
@ -416,7 +414,6 @@ if ($newQuestion || $editQuestion) {
$objExercise->edit_exercise_in_lp = true; $objExercise->edit_exercise_in_lp = true;
require 'question_admin.inc.php'; require 'question_admin.inc.php';
} }
if ($editQuestion) { if ($editQuestion) {
// Question preview if teacher clicked the "switch to student" // Question preview if teacher clicked the "switch to student"
if ($studentViewActive && $is_allowedToEdit) { if ($studentViewActive && $is_allowedToEdit) {

@ -80,7 +80,7 @@ class Answer
// fills arrays // fills arrays
$objExercise = new Exercise($this->course_id); $objExercise = new Exercise($this->course_id);
$exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null; $exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
$objExercise->read($exerciseId); $objExercise->read($exerciseId, false);
} else { } else {
$objExercise = $exercise; $objExercise = $exercise;
} }

Loading…
Cancel
Save