From ea4a55a9ac1fad3cb2bf9e754cac77b402747ed8 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Sun, 28 Feb 2021 12:24:12 +0100 Subject: [PATCH] Minor - Fix 1.11.x CRUD --- public/main/exercise/answer.class.php | 16 ++++---- public/main/exercise/exercise.class.php | 12 +++--- public/main/exercise/question.class.php | 53 +++++++++++++------------ public/main/inc/lib/thematic.lib.php | 1 + public/main/survey/survey.lib.php | 2 +- src/CoreBundle/Entity/ResourceLink.php | 2 +- src/CourseBundle/Entity/CAttendance.php | 2 +- 7 files changed, 45 insertions(+), 43 deletions(-) diff --git a/public/main/exercise/answer.class.php b/public/main/exercise/answer.class.php index 1f94a7ff25..976b6fac17 100644 --- a/public/main/exercise/answer.class.php +++ b/public/main/exercise/answer.class.php @@ -668,7 +668,7 @@ class Answer $quizAnswer ->setAnswer($answer) ->setComment($comment) - ->setCorrect($correct) + ->setCorrect((int) $correct) ->setPonderation($weighting) ->setPosition($position) ->setDestination($destination) @@ -700,13 +700,13 @@ class Answer for ($i = 1; $i <= $this->new_nbrAnswers; $i++) { $answer = $this->new_answer[$i]; - $correct = isset($this->new_correct[$i]) ? $this->new_correct[$i] : ''; - $comment = isset($this->new_comment[$i]) ? $this->new_comment[$i] : ''; - $weighting = isset($this->new_weighting[$i]) ? $this->new_weighting[$i] : ''; - $position = isset($this->new_position[$i]) ? $this->new_position[$i] : ''; - $hotspot_coordinates = isset($this->new_hotspot_coordinates[$i]) ? $this->new_hotspot_coordinates[$i] : ''; - $hotspot_type = isset($this->new_hotspot_type[$i]) ? $this->new_hotspot_type[$i] : ''; - $destination = isset($this->new_destination[$i]) ? $this->new_destination[$i] : ''; + $correct = isset($this->new_correct[$i]) ? (int) $this->new_correct[$i] : null; + $comment = isset($this->new_comment[$i]) ? $this->new_comment[$i] : null; + $weighting = isset($this->new_weighting[$i]) ? $this->new_weighting[$i] : null; + $position = isset($this->new_position[$i]) ? $this->new_position[$i] : null; + $hotspot_coordinates = isset($this->new_hotspot_coordinates[$i]) ? $this->new_hotspot_coordinates[$i] : null; + $hotspot_type = isset($this->new_hotspot_type[$i]) ? $this->new_hotspot_type[$i] : null; + $destination = isset($this->new_destination[$i]) ? $this->new_destination[$i] : null; //$autoId = $this->selectAutoId($i); $iid = isset($this->iid[$i]) ? $this->iid[$i] : 0; diff --git a/public/main/exercise/exercise.class.php b/public/main/exercise/exercise.class.php index 6c0a2d3cf1..64ce7a5530 100644 --- a/public/main/exercise/exercise.class.php +++ b/public/main/exercise/exercise.class.php @@ -1573,8 +1573,8 @@ class Exercise $description = $this->description; $sound = $this->sound; $type = $this->type; - $attempts = isset($this->attempts) ? $this->attempts : 0; - $feedback_type = isset($this->feedback_type) ? $this->feedback_type : 0; + $attempts = isset($this->attempts) ? (int) $this->attempts : 0; + $feedback_type = isset($this->feedback_type) ? (int) $this->feedback_type : 0; $random = $this->random; $random_answers = $this->random_answers; $active = $this->active; @@ -1624,9 +1624,9 @@ class Exercise ->setDescription($description) ->setSound($sound) ->setType($type) - ->setRandom($random) - ->setRandomAnswers($random_answers) - ->setActive($active) + ->setRandom((int) $random) + ->setRandomAnswers((bool) $random_answers) + ->setActive((bool) $active) ->setResultsDisabled($results_disabled) ->setMaxAttempt($attempts) ->setFeedbackType($feedback_type) @@ -1638,7 +1638,7 @@ class Exercise ->setPassPercentage($pass_percentage) ->setSaveCorrectAnswers($saveCorrectAnswers) ->setPropagateNeg($propagate_neg) - ->setHideQuestionTitle($this->getHideQuestionTitle()) + ->setHideQuestionTitle(1 === (int) $this->getHideQuestionTitle()) ->setQuestionSelectionType($this->getQuestionSelectionType()); $allow = api_get_configuration_value('allow_exercise_categories'); diff --git a/public/main/exercise/question.class.php b/public/main/exercise/question.class.php index 8018d8a8e7..1aff861ee2 100644 --- a/public/main/exercise/question.class.php +++ b/public/main/exercise/question.class.php @@ -552,32 +552,33 @@ abstract class Question if (!empty($id)) { /** @var CQuizQuestion $question */ $question = $questionRepo->find($id); - $question - ->setQuestion($this->question) - ->setDescription($this->description) - ->setPonderation($this->weighting) - ->setPosition($this->position) - ->setType($this->type) - ->setExtra($this->extra) - ->setLevel($this->level) - ->setFeedback($this->feedback) - ; - - if (!empty($categoryId)) { - $category = $questionCategoryRepo->find($categoryId); - $question->updateCategory($category); - } + if ($question) { + $question + ->setQuestion($this->question) + ->setDescription($this->description) + ->setPonderation($this->weighting) + ->setPosition($this->position) + ->setType($this->type) + ->setExtra($this->extra) + ->setLevel((int) $this->level) + ->setFeedback($this->feedback); + + if (!empty($categoryId)) { + $category = $questionCategoryRepo->find($categoryId); + $question->updateCategory($category); + } - $em->persist($question); - $em->flush(); + $em->persist($question); + $em->flush(); - Event::addEvent( - LOG_QUESTION_UPDATED, - LOG_QUESTION_ID, - $this->iid - ); - if ('true' === api_get_setting('search_enabled')) { - $this->search_engine_edit($exerciseId); + Event::addEvent( + LOG_QUESTION_UPDATED, + LOG_QUESTION_ID, + $this->iid + ); + if ('true' === api_get_setting('search_enabled')) { + $this->search_engine_edit($exerciseId); + } } } else { // Creates a new question @@ -604,7 +605,7 @@ abstract class Question ->setPosition($position) ->setType($this->type) ->setExtra($this->extra) - ->setLevel($this->level) + ->setLevel((int)$this->level) ->setFeedback($this->feedback) //->setParent($exerciseEntity) ->setParent($courseEntity) @@ -1170,7 +1171,7 @@ abstract class Question public static function getInstance($type) { if (null !== $type) { - list($fileName, $className) = self::get_question_type($type); + [$fileName, $className] = self::get_question_type($type); if (!empty($fileName)) { if (class_exists($className)) { return new $className(); diff --git a/public/main/inc/lib/thematic.lib.php b/public/main/inc/lib/thematic.lib.php index 82c0e1b532..fef07dfd9d 100644 --- a/public/main/inc/lib/thematic.lib.php +++ b/public/main/inc/lib/thematic.lib.php @@ -593,6 +593,7 @@ class Thematic $duration ) { $em = Database::getManager(); + $duration = (int) $duration; if (null === $advance) { $advance = new CThematicAdvance(); diff --git a/public/main/survey/survey.lib.php b/public/main/survey/survey.lib.php index 8cf9dec12d..84649467ba 100644 --- a/public/main/survey/survey.lib.php +++ b/public/main/survey/survey.lib.php @@ -353,7 +353,7 @@ class SurveyManager ->setCode(self::generateSurveyCode($values['survey_code'])) ->setTitle($values['survey_title']) ->setSubtitle($values['survey_title']) - ->setAuthor($_user['user_id']) + //->setAuthor($_user['user_id']) ->setLang($values['survey_language']) ->setAvailFrom($from) ->setAvailTill($until) diff --git a/src/CoreBundle/Entity/ResourceLink.php b/src/CoreBundle/Entity/ResourceLink.php index 1c69463310..46f46e3a11 100644 --- a/src/CoreBundle/Entity/ResourceLink.php +++ b/src/CoreBundle/Entity/ResourceLink.php @@ -56,7 +56,7 @@ class ResourceLink * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User") * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true) */ - protected ?User $user; + protected ?User $user = null; /** * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroup") diff --git a/src/CourseBundle/Entity/CAttendance.php b/src/CourseBundle/Entity/CAttendance.php index 806b12a36e..112a56d212 100644 --- a/src/CourseBundle/Entity/CAttendance.php +++ b/src/CourseBundle/Entity/CAttendance.php @@ -70,7 +70,7 @@ class CAttendance extends AbstractResource implements ResourceInterface protected int $locked; /** - * @var ArrayCollection|CAttendanceCalendar[] + * @var Collection|CAttendanceCalendar[] * * @ORM\OneToMany( * targetEntity="CAttendanceCalendar", mappedBy="attendance", cascade={"persist", "remove"}, orphanRemoval=true