Update exercise CRUD + add migrations

Rename CQuizCategory.php to CQuizRelQuestionCategory.php
pull/3844/head
Julio Montoya 5 years ago
parent 251179e2af
commit a63c7ffb4c
  1. 17
      public/main/exercise/MultipleAnswerTrueFalseDegreeCertainty.php
  2. 86
      public/main/exercise/TestCategory.php
  3. 55
      public/main/exercise/answer.class.php
  4. 71
      public/main/exercise/exercise.class.php
  5. 11
      public/main/exercise/exercise_global_report.php
  6. 41
      public/main/exercise/exercise_submit_modal.php
  7. 36
      public/main/exercise/question.class.php
  8. 60
      public/main/exercise/unique_answer.class.php
  9. 12
      public/main/inc/lib/events.lib.php
  10. 1
      src/CoreBundle/Entity/TrackEAttemptRecording.php
  11. 2
      src/CoreBundle/Migrations/Schema/V200/Version20.php
  12. 43
      src/CoreBundle/Migrations/Schema/V200/Version20170904145500.php
  13. 4
      src/CourseBundle/Entity/CExerciseCategory.php
  14. 50
      src/CourseBundle/Entity/CQuiz.php
  15. 122
      src/CourseBundle/Entity/CQuizAnswer.php
  16. 135
      src/CourseBundle/Entity/CQuizCategory.php
  17. 64
      src/CourseBundle/Entity/CQuizQuestion.php
  18. 47
      src/CourseBundle/Entity/CQuizQuestionCategory.php
  19. 72
      src/CourseBundle/Entity/CQuizRelQuestionCategory.php
  20. 16
      src/CourseBundle/Entity/CSurveyQuestion.php

@ -11,20 +11,17 @@ use ChamiloSession as Session;
*/ */
class MultipleAnswerTrueFalseDegreeCertainty extends Question class MultipleAnswerTrueFalseDegreeCertainty extends Question
{ {
const LEVEL_DARKGREEN = 1; public const LEVEL_DARKGREEN = 1;
const LEVEL_LIGHTGREEN = 2; public const LEVEL_LIGHTGREEN = 2;
const LEVEL_WHITE = 3; public const LEVEL_WHITE = 3;
const LEVEL_LIGHTRED = 4; public const LEVEL_LIGHTRED = 4;
const LEVEL_DARKRED = 5; public const LEVEL_DARKRED = 5;
public $typePicture = 'mccert.png'; public $typePicture = 'mccert.png';
public $explanationLangVar = 'Multiple answer true/false/degree of certainty'; public $explanationLangVar = 'Multiple answer true/false/degree of certainty';
public $optionsTitle; public $optionsTitle;
public $options; public $options;
/**
* Constructor.
*/
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -288,7 +285,9 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
if (empty($options)) { if (empty($options)) {
// If this is the first time that the question is created then change // If this is the first time that the question is created then change
// the default values from the form 1 and 2 by the correct "option id" registered // the default values from the form 1 and 2 by the correct "option id" registered
$goodAnswer = $sortedByPosition[$goodAnswer]['id']; if (!empty($goodAnswer)) {
$goodAnswer = $sortedByPosition[$goodAnswer]['iid'];
}
} }
$questionWeighting += $extraValues[0]; //By default 0 has the correct answers $questionWeighting += $extraValues[0]; //By default 0 has the correct answers
$objAnswer->createAnswer($answer, $goodAnswer, $comment, '', $i); $objAnswer->createAnswer($answer, $goodAnswer, $comment, '', $i);

@ -89,7 +89,6 @@ class TestCategory
$category = new CQuizQuestionCategory(); $category = new CQuizQuestionCategory();
$category $category
->setTitle($this->name) ->setTitle($this->name)
->setCourse($course)
->setDescription($this->description) ->setDescription($this->description)
->setParent($course) ->setParent($course)
->addCourseLink($course, api_get_session_entity()); ->addCourseLink($course, api_get_session_entity());
@ -181,46 +180,6 @@ class TestCategory
return $row['nb']; return $row['nb'];
} }
/**
* Return an array of all Category objects in the database
* If $field=="" Return an array of all category objects in the database
* Otherwise, return an array of all in_field value
* in the database (in_field = id or name or description).
*
* @param string $field
* @param int $courseId
*
* @return array
*/
public static function getCategoryListInfo($field = '', $courseId = 0)
{
$courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId;
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$categories = [];
if (empty($field)) {
$sql = "SELECT iid FROM $table
WHERE c_id = $courseId
ORDER BY title ASC";
$res = Database::query($sql);
while ($row = Database::fetch_array($res)) {
$category = new TestCategory();
$categories[] = $category->getCategory($row['iid'], $courseId);
}
} else {
$field = Database::escape_string($field);
$sql = "SELECT $field FROM $table
WHERE c_id = $courseId
ORDER BY $field ASC";
$res = Database::query($sql);
while ($row = Database::fetch_array($res)) {
$categories[] = $row[$field];
}
}
return $categories;
}
/** /**
* Return the TestCategory id for question with question_id = $questionId * Return the TestCategory id for question with question_id = $questionId
* In this version, a question has only 1 TestCategory. * In this version, a question has only 1 TestCategory.
@ -286,7 +245,7 @@ class TestCategory
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$sql = "SELECT title $sql = "SELECT title
FROM $table FROM $table
WHERE iid = $categoryId AND c_id = $courseId"; WHERE iid = $categoryId ";
$res = Database::query($sql); $res = Database::query($sql);
$data = Database::fetch_array($res); $data = Database::fetch_array($res);
$result = ''; $result = '';
@ -474,10 +433,10 @@ class TestCategory
if (empty($courseId)) { if (empty($courseId)) {
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
} }
$categories = self::getCategoryListInfo('', $courseId); $categories = self::getCategories($courseId);
$result = ['0' => get_lang('No category selected')]; $result = [0 => get_lang('No category selected')];
for ($i = 0; $i < count($categories); $i++) { foreach ($categories as $category) {
$result[$categories[$i]->id] = $categories[$i]->name; $result[$category->getIid()] = $category->getTitle();
} }
return $result; return $result;
@ -867,30 +826,6 @@ class TestCategory
return ''; return '';
} }
/**
* @param $primaryKeys
* @param $allPrimaryKeys
* @param \Symfony\Component\HttpFoundation\Session\Session $session
* @param $parameters
*/
public function deleteResource(
$primaryKeys,
$allPrimaryKeys,
Symfony\Component\HttpFoundation\Session\Session $session,
$parameters
) {
$repo = Container::getQuestionCategoryRepository();
$translator = Container::getTranslator();
foreach ($primaryKeys as $id) {
$category = $repo->find($id);
$repo->hardDelete($category);
}
Display::addFlash(Display::return_message($translator->trans('Deleted')));
header('Location:'.api_get_self().'?'.api_get_cidreq());
exit;
}
/** /**
* @param Exercise $exercise * @param Exercise $exercise
* @param int $courseId * @param int $courseId
@ -1105,14 +1040,11 @@ class TestCategory
*/ */
public static function categoryTitleExists($name, $courseId = 0) public static function categoryTitleExists($name, $courseId = 0)
{ {
$categories = self::getCategoryListInfo('title', $courseId); $repo = Container::getQuestionCategoryRepository();
foreach ($categories as $title) { $courseEntity = api_get_course_entity($courseId);
if ($title == $name) { $resource = $repo->findResourceByTitle($name, $courseEntity->getResourceNode(), $courseEntity);
return true;
}
}
return false; return null !== $resource;
} }
/** /**

@ -2,7 +2,9 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuizAnswer; use Chamilo\CourseBundle\Entity\CQuizAnswer;
use Chamilo\CourseBundle\Entity\CQuizQuestion;
/** /**
* Class Answer * Class Answer
@ -125,7 +127,6 @@ class Answer
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE WHERE
c_id = {$this->course_id} AND
question_id ='".$questionId."' question_id ='".$questionId."'
ORDER BY position"; ORDER BY position";
@ -150,33 +151,6 @@ class Answer
$this->nbrAnswers = $i - 1; $this->nbrAnswers = $i - 1;
} }
/**
* Get answers already added to question.
*
* @return array
*/
public function getAnswers()
{
$table = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId = $this->questionId;
$sql = "SELECT * FROM $table
WHERE c_id = {$this->course_id}
AND question_id = $questionId
ORDER BY position";
$result = Database::query($sql);
$answers = [];
// while a record is found
while ($answer = Database::fetch_assoc($result)) {
$answers[] = $answer;
}
return $answers;
}
/** /**
* @param int $id * @param int $id
* *
@ -328,7 +302,7 @@ class Answer
*/ */
public function selectAutoId($id) public function selectAutoId($id)
{ {
return isset($this->autoId[$id]) ? $this->autoId[$id] : 0; return isset($this->iid[$id]) ? (int) $this->iid[$id] : 0;
} }
/** /**
@ -395,7 +369,7 @@ class Answer
$table = Database::get_course_table(TABLE_QUIZ_ANSWER); $table = Database::get_course_table(TABLE_QUIZ_ANSWER);
$auto_id = (int) $auto_id; $auto_id = (int) $auto_id;
$sql = "SELECT iid, answer FROM $table $sql = "SELECT iid, answer FROM $table
WHERE c_id = {$this->course_id} AND iid='$auto_id'"; WHERE iid='$auto_id'";
$rs = Database::query($sql); $rs = Database::query($sql);
if (Database::num_rows($rs) > 0) { if (Database::num_rows($rs) > 0) {
@ -697,12 +671,16 @@ class Answer
$courseId = $this->course['real_id']; $courseId = $this->course['real_id'];
$answerList = []; $answerList = [];
$questionRepo = Container::getQuestionRepository();
/** @var CQuizQuestion $question */
$question = $questionRepo->find($questionId);
$questionType = $question->getType();
for ($i = 1; $i <= $this->new_nbrAnswers; $i++) { for ($i = 1; $i <= $this->new_nbrAnswers; $i++) {
$answer = $this->new_answer[$i]; $answer = (string) $this->new_answer[$i];
$correct = isset($this->new_correct[$i]) ? (int) $this->new_correct[$i] : null; $correct = isset($this->new_correct[$i]) ? (int) $this->new_correct[$i] : null;
$comment = isset($this->new_comment[$i]) ? $this->new_comment[$i] : null; $comment = isset($this->new_comment[$i]) ? $this->new_comment[$i] : null;
$weighting = isset($this->new_weighting[$i]) ? $this->new_weighting[$i] : null; $weighting = isset($this->new_weighting[$i]) ? (float) $this->new_weighting[$i] : null;
$position = isset($this->new_position[$i]) ? $this->new_position[$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_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; $hotspot_type = isset($this->new_hotspot_type[$i]) ? $this->new_hotspot_type[$i] : null;
@ -713,8 +691,7 @@ class Answer
if (!isset($this->position[$i])) { if (!isset($this->position[$i])) {
$quizAnswer = new CQuizAnswer(); $quizAnswer = new CQuizAnswer();
$quizAnswer $quizAnswer
->setCId($courseId) ->setQuestion($question)
->setQuestionId($questionId)
->setAnswer($answer) ->setAnswer($answer)
->setCorrect($correct) ->setCorrect($correct)
->setComment($comment) ->setComment($comment)
@ -730,11 +707,7 @@ class Answer
$iid = $quizAnswer->getIid(); $iid = $quizAnswer->getIid();
if ($iid) { if ($iid) {
$questionType = $this->getQuestionType(); if (in_array($questionType, [MATCHING, MATCHING_DRAGGABLE])) {
if (in_array(
$questionType,
[MATCHING, MATCHING_DRAGGABLE]
)) {
$answer = new self($this->questionId, $courseId, $this->exercise, false); $answer = new self($this->questionId, $courseId, $this->exercise, false);
$answer->read(); $answer->read();
$correctAnswerId = $answer->selectAnswerIdByPosition($correct); $correctAnswerId = $answer->selectAnswerIdByPosition($correct);
@ -771,8 +744,6 @@ class Answer
$answerList[$i] = $iid; $answerList[$i] = $iid;
} }
$questionType = $this->getQuestionType();
switch ($questionType) { switch ($questionType) {
case MATCHING_DRAGGABLE: case MATCHING_DRAGGABLE:
foreach ($this->new_correct as $value => $status) { foreach ($this->new_correct as $value => $status) {
@ -934,7 +905,6 @@ class Answer
$quizAnswer = new CQuizAnswer(); $quizAnswer = new CQuizAnswer();
$quizAnswer $quizAnswer
->setCId($courseId)
->setQuestionId($newQuestionId) ->setQuestionId($newQuestionId)
->setAnswer($answer['answer']) ->setAnswer($answer['answer'])
->setCorrect($answer['correct']) ->setCorrect($answer['correct'])
@ -982,7 +952,6 @@ class Answer
$quizAnswer = new CQuizAnswer(); $quizAnswer = new CQuizAnswer();
$quizAnswer $quizAnswer
->setCId($courseId)
->setQuestionId($newQuestionId) ->setQuestionId($newQuestionId)
->setAnswer($this->answer[$i]) ->setAnswer($this->answer[$i])
->setCorrect($correct) ->setCorrect($correct)

@ -7,10 +7,9 @@ use Chamilo\CoreBundle\Entity\GradebookLink;
use Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation; use Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation;
use Chamilo\CoreBundle\Entity\TrackEHotspot; use Chamilo\CoreBundle\Entity\TrackEHotspot;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
use Chamilo\CourseBundle\Entity\CExerciseCategory; use Chamilo\CourseBundle\Entity\CExerciseCategory;
use Chamilo\CourseBundle\Entity\CQuiz; use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CQuizCategory; use Chamilo\CourseBundle\Entity\CQuizRelQuestionCategory;
use ChamiloSession as Session; use ChamiloSession as Session;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
@ -140,7 +139,7 @@ class Exercise
$this->globalCategoryId = null; $this->globalCategoryId = null;
$this->notifications = []; $this->notifications = [];
$this->exerciseCategoryId = 0; $this->exerciseCategoryId = 0;
$this->pageResultConfiguration; $this->pageResultConfiguration = null;
$this->preventBackwards = 0; $this->preventBackwards = 0;
$this->hideComment = false; $this->hideComment = false;
$this->hideNoAnswer = false; $this->hideNoAnswer = false;
@ -986,7 +985,7 @@ class Exercise
if (!empty($questions_by_category)) { if (!empty($questions_by_category)) {
$newCategoryList = []; $newCategoryList = [];
$em = Database::getManager(); $em = Database::getManager();
$repo = $em->getRepository(CQuizCategory::class); $repo = $em->getRepository(CQuizRelQuestionCategory::class);
foreach ($questions_by_category as $categoryId => $questionList) { foreach ($questions_by_category as $categoryId => $questionList) {
$category = new TestCategory(); $category = new TestCategory();
@ -998,9 +997,9 @@ class Exercise
$categoryParentInfo = null; $categoryParentInfo = null;
// Parent is not set no loop here // Parent is not set no loop here
if (isset($cat['parent_id']) && !empty($cat['parent_id'])) { if (isset($cat['parent_id']) && !empty($cat['parent_id'])) {
/** @var CQuizCategory $categoryEntity */ /** @var CQuizRelQuestionCategory $categoryEntity */
if (!isset($parentsLoaded[$cat['parent_id']])) { if (!isset($parentsLoaded[$cat['parent_id']])) {
$categoryEntity = $em->find(CQuizCategory::class, $cat['parent_id']); $categoryEntity = $em->find(CQuizRelQuestionCategory::class, $cat['parent_id']);
$parentsLoaded[$cat['parent_id']] = $categoryEntity; $parentsLoaded[$cat['parent_id']] = $categoryEntity;
} else { } else {
$categoryEntity = $parentsLoaded[$cat['parent_id']]; $categoryEntity = $parentsLoaded[$cat['parent_id']];
@ -1012,7 +1011,7 @@ class Exercise
//$index = 1; //$index = 1;
} }
/** @var CQuizCategory $categoryParent */ /** @var CQuizRelQuestionCategory $categoryParent */
// @todo not implemented in 1.11.x // @todo not implemented in 1.11.x
/*foreach ($path as $categoryParent) { /*foreach ($path as $categoryParent) {
$visibility = $categoryParent->getVisibility(); $visibility = $categoryParent->getVisibility();
@ -1252,10 +1251,10 @@ class Exercise
$sql = "SELECT q.iid $sql = "SELECT q.iid
FROM $table e FROM $table e
INNER JOIN $tableQuestion q INNER JOIN $tableQuestion q
ON (e.question_id = q.iid AND e.c_id = q.c_id) ON (e.question_id = q.iid)
WHERE WHERE
q.type NOT IN ('$questionTypeToString') AND q.type NOT IN ('$questionTypeToString') AND
e.c_id = {$this->course_id} AND
e.quiz_id = ".$this->getId(); e.quiz_id = ".$this->getId();
$result = Database::query($sql); $result = Database::query($sql);
@ -1717,11 +1716,10 @@ class Exercise
$position = (int) $position; $position = (int) $position;
$questionId = (int) $questionId; $questionId = (int) $questionId;
$sql = "UPDATE $table SET $sql = "UPDATE $table SET
question_order ='".$position."' question_order = $position
WHERE WHERE
c_id = ".$this->course_id.' AND question_id = $questionId AND
question_id = '.$questionId.' AND quiz_id= ".$this->getId();
quiz_id='.$this->getId();
Database::query($sql); Database::query($sql);
} }
} }
@ -1824,7 +1822,7 @@ class Exercise
$table = Database::get_course_table(TABLE_QUIZ_TEST); $table = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "UPDATE $table SET active='-1' $sql = "UPDATE $table SET active='-1'
WHERE c_id = ".$this->course_id.' AND iid = '.$exerciseId; WHERE iid = $exerciseId";
Database::query($sql); Database::query($sql);
$repo->softDelete($exercise); $repo->softDelete($exercise);
@ -2098,23 +2096,16 @@ class Exercise
'checkbox', 'checkbox',
'hide_category_table', 'hide_category_table',
null, null,
get_lang('HideCategoryTable') get_lang('Hide category table')
), ),
$form->createElement( $form->createElement(
'checkbox', 'checkbox',
'hide_correct_answered_questions', 'hide_correct_answered_questions',
null, null,
get_lang('HideCorrectAnsweredQuestions') get_lang('Hide correct answered questions')
), ),
]; ];
$form->addGroup( $form->addGroup($group, null, get_lang('Results and feedback page configuration'));
$group,
null,
get_lang(
'Results and feedback and feedback and feedback and feedback and feedback and feedback page configuration'
)
);
$displayMatrix = 'none'; $displayMatrix = 'none';
$displayRandom = 'none'; $displayRandom = 'none';
$selectionType = $this->getQuestionSelectionType(); $selectionType = $this->getQuestionSelectionType();
@ -3636,7 +3627,7 @@ class Exercise
// Get answer list for matching // Get answer list for matching
$sql = "SELECT iid, answer $sql = "SELECT iid, answer
FROM $table_ans FROM $table_ans
WHERE c_id = $course_id AND question_id = $questionId"; WHERE question_id = $questionId";
$res_answer = Database::query($sql); $res_answer = Database::query($sql);
$answerMatching = []; $answerMatching = [];
@ -3651,7 +3642,7 @@ class Exercise
) { ) {
$sql = "SELECT * $sql = "SELECT *
FROM $table_ans FROM $table_ans
WHERE c_id = $course_id AND question_id = $questionId WHERE question_id = $questionId
ORDER BY position ORDER BY position
LIMIT 1"; LIMIT 1";
$result = Database::query($sql); $result = Database::query($sql);
@ -4445,7 +4436,6 @@ class Exercise
$sql = "SELECT iid, answer $sql = "SELECT iid, answer
FROM $table_ans FROM $table_ans
WHERE WHERE
c_id = $course_id AND
question_id = $questionId AND question_id = $questionId AND
correct = 0 correct = 0
"; ";
@ -4459,7 +4449,6 @@ class Exercise
$sql = "SELECT iid, answer, correct, ponderation $sql = "SELECT iid, answer, correct, ponderation
FROM $table_ans FROM $table_ans
WHERE WHERE
c_id = $course_id AND
question_id = $questionId AND question_id = $questionId AND
correct <> 0 correct <> 0
ORDER BY iid"; ORDER BY iid";
@ -7283,7 +7272,7 @@ class Exercise
$table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
if (!empty($this->getId())) { if (!empty($this->getId())) {
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE exercise_id = {$this->getId()} AND c_id = {$this->course_id} "; WHERE exercise_id = {$this->getId()} ";
$result = Database::query($sql); $result = Database::query($sql);
$list = []; $list = [];
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -7884,7 +7873,7 @@ class Exercise
$sql = "SELECT DISTINCT cat.* $sql = "SELECT DISTINCT cat.*
FROM $TBL_EXERCICE_QUESTION e FROM $TBL_EXERCICE_QUESTION e
INNER JOIN $TBL_QUESTIONS q INNER JOIN $TBL_QUESTIONS q
ON (e.question_id = q.iid AND e.c_id = q.c_id) ON (e.question_id = q.iid)
INNER JOIN $categoryRelTable catRel INNER JOIN $categoryRelTable catRel
ON (catRel.question_id = e.question_id) ON (catRel.question_id = e.question_id)
INNER JOIN $categoryTable cat INNER JOIN $categoryTable cat
@ -8331,7 +8320,8 @@ class Exercise
]; ];
$type = Type::getType('array'); $type = Type::getType('array');
$platform = Database::getManager()->getConnection()->getDatabasePlatform(); $platform = Database::getManager()->getConnection()->getDatabasePlatform();
$this->pageResultConfiguration = $type->convertToDatabaseValue($params, $platform); //$this->pageResultConfiguration = $type->convertToDatabaseValue($params, $platform);
$this->pageResultConfiguration = $params;
} }
} }
@ -8372,7 +8362,7 @@ class Exercise
$result = $this->getPageResultConfiguration(); $result = $this->getPageResultConfiguration();
if (!empty($result)) { if (!empty($result)) {
return isset($result[$attribute]) ? $result[$attribute] : null; return $result[$attribute] ?? null;
} }
return null; return null;
@ -8565,9 +8555,9 @@ class Exercise
$sql = "SELECT DISTINCT e.question_id $sql = "SELECT DISTINCT e.question_id
FROM $quizRelQuestion e FROM $quizRelQuestion e
INNER JOIN $question q INNER JOIN $question q
ON (e.question_id = q.iid AND e.c_id = q.c_id) ON (e.question_id = q.iid)
WHERE WHERE
e.c_id = {$this->course_id} AND
e.quiz_id = '".$this->getId()."' e.quiz_id = '".$this->getId()."'
ORDER BY question_order ORDER BY question_order
LIMIT $start, $length LIMIT $start, $length
@ -9010,7 +9000,7 @@ class Exercise
// Count number exercise - teacher // Count number exercise - teacher
$sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION $sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION
WHERE c_id = $courseId AND quiz_id = $exerciseId"; WHERE quiz_id = $exerciseId";
$sqlresult = Database::query($sql); $sqlresult = Database::query($sql);
$rowi = (int) Database::result($sqlresult, 0, 0); $rowi = (int) Database::result($sqlresult, 0, 0);
@ -10406,9 +10396,8 @@ class Exercise
$sql = "SELECT DISTINCT count(e.question_order) as count $sql = "SELECT DISTINCT count(e.question_order) as count
FROM $TBL_EXERCICE_QUESTION e FROM $TBL_EXERCICE_QUESTION e
INNER JOIN $TBL_QUESTIONS q INNER JOIN $TBL_QUESTIONS q
ON (e.question_id = q.iid AND e.c_id = q.c_id) ON (e.question_id = q.iid)
WHERE WHERE
e.c_id = {$this->course_id} AND
e.quiz_id = ".$this->getId(); e.quiz_id = ".$this->getId();
$result = Database::query($sql); $result = Database::query($sql);
@ -10419,9 +10408,9 @@ class Exercise
$sql = "SELECT DISTINCT e.question_id, e.question_order $sql = "SELECT DISTINCT e.question_id, e.question_order
FROM $TBL_EXERCICE_QUESTION e FROM $TBL_EXERCICE_QUESTION e
INNER JOIN $TBL_QUESTIONS q INNER JOIN $TBL_QUESTIONS q
ON (e.question_id = q.iid AND e.c_id = q.c_id) ON (e.question_id = q.iid)
WHERE WHERE
e.c_id = {$this->course_id} AND
e.quiz_id = '".$this->getId()."' e.quiz_id = '".$this->getId()."'
ORDER BY question_order"; ORDER BY question_order";
$result = Database::query($sql); $result = Database::query($sql);
@ -10825,7 +10814,7 @@ class Exercise
$resultDisabledGroup, $resultDisabledGroup,
null, null,
get_lang( get_lang(
'ShowResults and feedback and feedback and feedback and feedback and feedback and feedbackToStudents' 'Show score to learner'
) )
); );
} }
@ -10896,7 +10885,7 @@ class Exercise
'radio', 'radio',
'results_disabled', 'results_disabled',
null, null,
get_lang('ShowScoreEveryAttemptShowAnswersLastAttemptNoFeedback'), get_lang('Show the result to the learner: Show the score, the learner\'s choice and his feedback on each attempt, add the correct answer and his feedback when the chosen limit of attempts is reached.'),
RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK,
['id' => 'result_disabled_10'] ['id' => 'result_disabled_10']
); );

@ -15,7 +15,7 @@ $courseCode = api_get_course_id();
$data = []; $data = [];
$students = CourseManager::get_student_list_from_course_code($courseCode); $students = CourseManager::get_student_list_from_course_code($courseCode);
$categories = TestCategory::getCategoryListInfo('', $courseId); $categories = TestCategory::getCategories($courseId);
$table = Database::get_course_table(TABLE_QUIZ_TEST); $table = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "SELECT iid, title FROM $table $sql = "SELECT iid, title FROM $table
@ -32,12 +32,11 @@ $header[] = get_lang('LastName');
$header[] = get_lang('Email'); $header[] = get_lang('Email');
$header[] = get_lang('OfficialCode'); $header[] = get_lang('OfficialCode');
/** @var TestCategory $categoryInfo */
foreach ($categories as $categoryInfo) { foreach ($categories as $categoryInfo) {
$header[] = 'Aciertos: '.$categoryInfo->name; $header[] = 'Aciertos: '.$categoryInfo->getTitle();
$header[] = 'Errores: '.$categoryInfo->name; $header[] = 'Errores: '.$categoryInfo->getTitle();
$header[] = 'Omisiones: '.$categoryInfo->name; $header[] = 'Omisiones: '.$categoryInfo->getTitle();
$header[] = 'Puntos: '.$categoryInfo->name; $header[] = 'Puntos: '.$categoryInfo->getTitle();
} }
foreach ($exercises as $exerciseInfo) { foreach ($exercises as $exerciseInfo) {

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuizQuestion;
use ChamiloSession as Session; use ChamiloSession as Session;
/** /**
@ -39,18 +41,22 @@ $choiceValue = isset($_GET['choice']) ? $_GET['choice'] : '';
$hotSpot = isset($_GET['hotspot']) ? $_GET['hotspot'] : ''; $hotSpot = isset($_GET['hotspot']) ? $_GET['hotspot'] : '';
$tryAgain = isset($_GET['tryagain']) && 1 === (int) $_GET['tryagain']; $tryAgain = isset($_GET['tryagain']) && 1 === (int) $_GET['tryagain'];
$repo = Container::getQuestionRepository();
/** @var CQuizQuestion $question */
$question = $repo->find($questionId);
$allowTryAgain = false; $allowTryAgain = false;
if ($tryAgain) { if ($tryAgain) {
// Check if try again exists in this question, otherwise only allow one attempt BT#15827. // Check if try again exists in this question, otherwise only allow one attempt BT#15827.
$objQuestionTmp = Question::read($questionId); $answerType = $question->getType();
$answerType = $objQuestionTmp->selectType();
$showResult = false; $showResult = false;
$objAnswerTmp = new Answer($questionId, api_get_course_int_id()); //$objAnswerTmp = new Answer($questionId, api_get_course_int_id());
$answers = $objAnswerTmp->getAnswers(); $answers = $question->getAnswers();
if (!empty($answers)) { if (!empty($answers)) {
foreach ($answers as $answerData) { foreach ($answers as $answerData) {
if (isset($answerData['destination'])) { $destination = $answerData->getDestination();
$itemList = explode('@@', $answerData['destination']); if (!empty($destination)) {
$itemList = explode('@@', $destination);
if (isset($itemList[0]) && !empty($itemList[0])) { if (isset($itemList[0]) && !empty($itemList[0])) {
$allowTryAgain = true; $allowTryAgain = true;
break; break;
@ -102,7 +108,7 @@ function SendEx(num) {
} else { } else {
num -= 1; num -= 1;
window.location.href = "exercise_submit.php?'.api_get_cidreq().'&tryagain=1&exerciseId='.$exerciseId.'&num="+num+"&learnpath_item_id='.$learnpath_item_id.'&learnpath_id='.$learnpath_id.'"; window.location.href = "exercise_submit.php?'.api_get_cidreq().'&tryagain=1&exerciseId='.$exerciseId.'&num="+num+"&learnpath_item_id='.$learnpath_item_id.'&learnpath_id='.$learnpath_id.'";
} }
return false; return false;
} }
</script>'; </script>';
@ -148,18 +154,18 @@ if (empty($choiceValue) && empty($hotSpot) && $loaded) {
if (empty($choiceValue) && empty($hotSpot)) { if (empty($choiceValue) && empty($hotSpot)) {
echo "<script> echo "<script>
// this works for only radio buttons // this works for only radio buttons
var f = window.document.frm_exercise; var f = window.document.frm_exercise;
var choice_js = {answers: []}; var choice_js = {answers: []};
var hotspot = new Array(); var hotspot = new Array();
var hotspotcoord = new Array(); var hotspotcoord = new Array();
var counter = 0; var counter = 0;
for (var i = 0; i < f.elements.length; i++) { for (var i = 0; i < f.elements.length; i++) {
if (f.elements[i].type == 'radio' && f.elements[i].checked) { if (f.elements[i].type == 'radio' && f.elements[i].checked) {
choice_js.answers.push(f.elements[i].value); choice_js.answers.push(f.elements[i].value);
counter ++; counter ++;
} }
if (f.elements[i].type == 'checkbox' && f.elements[i].checked) { if (f.elements[i].type == 'checkbox' && f.elements[i].checked) {
choice_js.answers.push(f.elements[i].value); choice_js.answers.push(f.elements[i].value);
counter ++; counter ++;
@ -167,7 +173,7 @@ if (empty($choiceValue) && empty($hotSpot)) {
if (f.elements[i].type == 'hidden') { if (f.elements[i].type == 'hidden') {
var name = f.elements[i].name; var name = f.elements[i].name;
if (name.substr(0,7) == 'hotspot') { if (name.substr(0,7) == 'hotspot') {
hotspot.push(f.elements[i].value); hotspot.push(f.elements[i].value);
} }
@ -177,9 +183,9 @@ if (empty($choiceValue) && empty($hotSpot)) {
} }
} }
} }
var my_choice = $('*[name*=\"choice[".$questionId."]\"]').serialize(); var my_choice = $('*[name*=\"choice[".$questionId."]\"]').serialize();
var hotspot = $('*[name*=\"hotspot[".$questionId."]\"]').serialize(); var hotspot = $('*[name*=\"hotspot[".$questionId."]\"]').serialize();
"; ";
// IMPORTANT // IMPORTANT
@ -206,7 +212,7 @@ if (is_array($choice)) {
$exerciseResult = $choice; $exerciseResult = $choice;
} else { } else {
// gets the question ID from $choice. It is the key of the array // gets the question ID from $choice. It is the key of the array
list($key) = array_keys($choice); [$key] = array_keys($choice);
// if the user didn't already answer this question // if the user didn't already answer this question
if (!isset($exerciseResult[$key])) { if (!isset($exerciseResult[$key])) {
// stores the user answer into the array // stores the user answer into the array
@ -218,8 +224,7 @@ if (is_array($choice)) {
// the script "exercise_result.php" will take the variable $exerciseResult from the session // the script "exercise_result.php" will take the variable $exerciseResult from the session
Session::write('exerciseResult', $exerciseResult); Session::write('exerciseResult', $exerciseResult);
$objQuestionTmp = Question::read($questionId); $answerType = $question->getType();
$answerType = $objQuestionTmp->selectType();
$showResult = false; $showResult = false;
$objAnswerTmp = new Answer($questionId, api_get_course_int_id()); $objAnswerTmp = new Answer($questionId, api_get_course_int_id());

@ -195,9 +195,8 @@ abstract class Question
$sql = "SELECT DISTINCT q.quiz_id $sql = "SELECT DISTINCT q.quiz_id
FROM $TBL_EXERCISE_QUESTION q FROM $TBL_EXERCISE_QUESTION q
INNER JOIN $tblQuiz e INNER JOIN $tblQuiz e
ON e.c_id = q.c_id AND e.iid = q.quiz_id ON e.iid = q.quiz_id
WHERE WHERE
q.c_id = $course_id AND
q.question_id = $id AND q.question_id = $id AND
e.active >= 0"; e.active >= 0";
@ -587,18 +586,15 @@ abstract class Question
$TBL_EXERCISE_QUESTION as test_question $TBL_EXERCISE_QUESTION as test_question
WHERE WHERE
question.iid = test_question.question_id AND question.iid = test_question.question_id AND
test_question.quiz_id = ".$exerciseId." AND test_question.quiz_id = ".$exerciseId;
question.c_id = $c_id AND
test_question.c_id = $c_id ";
$result = Database::query($sql); $result = Database::query($sql);
$current_position = Database::result($result, 0, 0); $current_position = Database::result($result, 0, 0);
$this->updatePosition($current_position + 1); $this->updatePosition($current_position + 1);
$position = $this->position; $position = $this->position;
$exerciseEntity = $exerciseRepo->find($exerciseId); //$exerciseEntity = $exerciseRepo->find($exerciseId);
$question = new CQuizQuestion(); $question = new CQuizQuestion();
$question $question
->setCId($c_id)
->setQuestion($this->question) ->setQuestion($this->question)
->setDescription($this->description) ->setDescription($this->description)
->setPonderation($this->weighting) ->setPonderation($this->weighting)
@ -607,7 +603,6 @@ abstract class Question
->setExtra($this->extra) ->setExtra($this->extra)
->setLevel((int) $this->level) ->setLevel((int) $this->level)
->setFeedback($this->feedback) ->setFeedback($this->feedback)
//->setParent($exerciseEntity)
->setParent($courseEntity) ->setParent($courseEntity)
->addCourseLink( ->addCourseLink(
$courseEntity, $courseEntity,
@ -639,9 +634,7 @@ abstract class Question
if (HOT_SPOT == $type || HOT_SPOT_ORDER == $type) { if (HOT_SPOT == $type || HOT_SPOT_ORDER == $type) {
$quizAnswer = new CQuizAnswer(); $quizAnswer = new CQuizAnswer();
$quizAnswer $quizAnswer
->setCId($c_id) ->setQuestion($question)
->setQuestionId($this->id)
->setAnswer('')
->setPonderation(10) ->setPonderation(10)
->setPosition(1) ->setPosition(1)
->setHotspotCoordinates('0;0|0|0') ->setHotspotCoordinates('0;0|0|0')
@ -654,9 +647,7 @@ abstract class Question
if (HOT_SPOT_DELINEATION == $type) { if (HOT_SPOT_DELINEATION == $type) {
$quizAnswer = new CQuizAnswer(); $quizAnswer = new CQuizAnswer();
$quizAnswer $quizAnswer
->setCId($c_id) ->setQuestion($question)
->setQuestionId($this->id)
->setAnswer('')
->setPonderation(10) ->setPonderation(10)
->setPosition(1) ->setPosition(1)
->setHotspotCoordinates('0;0|0|0') ->setHotspotCoordinates('0;0|0|0')
@ -850,8 +841,8 @@ abstract class Question
$newExercise->read($exerciseId, false); $newExercise->read($exerciseId, false);
$count = $newExercise->getQuestionCount(); $count = $newExercise->getQuestionCount();
$count++; $count++;
$sql = "INSERT INTO $exerciseRelQuestionTable (c_id, question_id, quiz_id, question_order) $sql = "INSERT INTO $exerciseRelQuestionTable (question_id, quiz_id, question_order)
VALUES ({$this->course['real_id']}, ".$id.', '.$exerciseId.", '$count')"; VALUES (".$id.', '.$exerciseId.", '$count')";
Database::query($sql); Database::query($sql);
// we do not want to reindex if we had just saved adnd indexed the question // we do not want to reindex if we had just saved adnd indexed the question
@ -891,7 +882,6 @@ abstract class Question
$sql = "SELECT question_order $sql = "SELECT question_order
FROM $table FROM $table
WHERE WHERE
c_id = $courseId AND
question_id = $id AND question_id = $id AND
quiz_id = $exerciseId"; quiz_id = $exerciseId";
$res = Database::query($sql); $res = Database::query($sql);
@ -901,7 +891,6 @@ abstract class Question
$sql = "UPDATE $table $sql = "UPDATE $table
SET question_order = question_order-1 SET question_order = question_order-1
WHERE WHERE
c_id = $courseId AND
quiz_id = $exerciseId AND quiz_id = $exerciseId AND
question_order > ".$row['question_order']; question_order > ".$row['question_order'];
Database::query($sql); Database::query($sql);
@ -910,7 +899,6 @@ abstract class Question
$sql = "DELETE FROM $table $sql = "DELETE FROM $table
WHERE WHERE
c_id = $courseId AND
question_id = $id AND question_id = $id AND
quiz_id = $exerciseId"; quiz_id = $exerciseId";
Database::query($sql); Database::query($sql);
@ -954,7 +942,7 @@ abstract class Question
//update the question_order of each question to avoid inconsistencies //update the question_order of each question to avoid inconsistencies
$sql = "SELECT quiz_id, question_order $sql = "SELECT quiz_id, question_order
FROM $TBL_EXERCISE_QUESTION FROM $TBL_EXERCISE_QUESTION
WHERE c_id = $courseId AND question_id = ".$id; WHERE question_id = ".$id;
$res = Database::query($sql); $res = Database::query($sql);
if (Database::num_rows($res) > 0) { if (Database::num_rows($res) > 0) {
@ -963,7 +951,6 @@ abstract class Question
$sql = "UPDATE $TBL_EXERCISE_QUESTION $sql = "UPDATE $TBL_EXERCISE_QUESTION
SET question_order = question_order-1 SET question_order = question_order-1
WHERE WHERE
c_id = $courseId AND
quiz_id = ".(int) ($row['quiz_id']).' AND quiz_id = ".(int) ($row['quiz_id']).' AND
question_order > '.$row['question_order']; question_order > '.$row['question_order'];
Database::query($sql); Database::query($sql);
@ -972,21 +959,20 @@ abstract class Question
} }
$sql = "DELETE FROM $TBL_EXERCISE_QUESTION $sql = "DELETE FROM $TBL_EXERCISE_QUESTION
WHERE c_id = $courseId AND question_id = ".$id; WHERE question_id = ".$id;
Database::query($sql); Database::query($sql);
$sql = "DELETE FROM $TBL_QUESTIONS $sql = "DELETE FROM $TBL_QUESTIONS
WHERE c_id = $courseId AND iid = ".$id; WHERE iid = ".$id;
Database::query($sql); Database::query($sql);
$sql = "DELETE FROM $TBL_REPONSES $sql = "DELETE FROM $TBL_REPONSES
WHERE c_id = $courseId AND question_id = ".$id; WHERE question_id = ".$id;
Database::query($sql); Database::query($sql);
// remove the category of this question in the question_rel_category table // remove the category of this question in the question_rel_category table
$sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY $sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY
WHERE WHERE
c_id = $courseId AND
question_id = ".$id; question_id = ".$id;
Database::query($sql); Database::query($sql);

@ -459,64 +459,4 @@ class UniqueAnswer extends Question
return $header; return $header;
} }
/**
* Saves one answer to the database.
*
* @param int $id The ID of the answer (has to be calculated for this course)
* @param int $question_id The question ID (to which the answer is attached)
* @param string $title The text of the answer
* @param string $comment The feedback for the answer
* @param float $score The score you get when picking this answer
* @param int $correct Whether this answer is considered *the* correct one (this is the unique answer type)
*/
public function addAnswer(
$id,
$question_id,
$title,
$comment,
$score = 0.0,
$correct = 0
) {
$em = Database::getManager();
$tbl_quiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
$tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$course_id = api_get_course_int_id();
$question_id = (int) $question_id;
$score = (float) $score;
$correct = (int) $correct;
$title = Database::escape_string($title);
$comment = Database::escape_string($comment);
// Get the max position.
$sql = "SELECT max(position) as max_position
FROM $tbl_quiz_answer
WHERE
c_id = $course_id AND
question_id = $question_id";
$rs_max = Database::query($sql);
$row_max = Database::fetch_object($rs_max);
$position = $row_max->max_position + 1;
// Insert a new answer
$quizAnswer = new CQuizAnswer();
$quizAnswer
->setCId($course_id)
->setQuestionId($question_id)
->setAnswer($title)
->setCorrect($correct)
->setComment($comment)
->setPonderation($score)
->setPosition($position)
->setDestination('0@@0@@0@@0');
$em->persist($quizAnswer);
$em->flush();
if ($correct) {
$sql = "UPDATE $tbl_quiz_question
SET ponderation = (ponderation + $score)
WHERE c_id = $course_id AND id = ".$question_id;
Database::query($sql);
}
}
} }

@ -559,14 +559,14 @@ class Event
return false; return false;
} }
if (null === $answer) {
$answer = '';
}
if (null === $score) { if (null === $score) {
$score = 0; $score = 0;
} }
if (null != $answer) {
$answer = (int) $answer;
}
$attempt = [ $attempt = [
'user_id' => $user_id, 'user_id' => $user_id,
'question_id' => $question_id, 'question_id' => $question_id,
@ -619,8 +619,8 @@ class Event
->setExeId($attempt_id) ->setExeId($attempt_id)
->setQuestionId($question_id) ->setQuestionId($question_id)
->setAnswer($answer) ->setAnswer($answer)
->setMarks($score) ->setMarks((int) $score)
->setAuthor('') //->setAuthor('')
->setSessionId($session_id) ->setSessionId($session_id)
; ;
$em->persist($recording); $em->persist($recording);

@ -77,6 +77,7 @@ class TrackEAttemptRecording
$this->teacherComment = ''; $this->teacherComment = '';
$this->answer = null; $this->answer = null;
$this->sessionId = 0; $this->sessionId = 0;
$this->author = 0;
} }
/** /**

@ -52,7 +52,7 @@ class Version20 extends AbstractMigrationChamilo
$this->addSql('UPDATE user_friend_relation_type SET title = "No title" WHERE title IS NULL'); $this->addSql('UPDATE user_friend_relation_type SET title = "No title" WHERE title IS NULL');
$this->addSql('ALTER TABLE user_friend_relation_type CHANGE title title VARCHAR(20) NOT NULL'); $this->addSql('ALTER TABLE user_friend_relation_type CHANGE title title VARCHAR(20) NOT NULL');
$this->addSql('UPDATE settings_options SET variable = "No variable" WHERE variable IS NULL'); $this->addSql('UPDATE settings_options SET variable = "No variable name" WHERE variable IS NULL');
$this->addSql('ALTER TABLE settings_options CHANGE variable variable VARCHAR(190) NOT NULL'); $this->addSql('ALTER TABLE settings_options CHANGE variable variable VARCHAR(190) NOT NULL');
if ($schema->hasTable('mail_template')) { if ($schema->hasTable('mail_template')) {

@ -22,7 +22,7 @@ class Version20170904145500 extends AbstractMigrationChamilo
); );
$this->addSql('ALTER TABLE c_exercise_category ADD resource_node_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE c_exercise_category ADD resource_node_id INT DEFAULT NULL');
$this->addSql( $this->addSql(
'ALTER TABLE c_exercise_category ADD CONSTRAINT FK_B94C157E91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)' 'ALTER TABLE c_exercise_category ADD CONSTRAINT FK_B94C157E91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE'
); );
$this->addSql( $this->addSql(
'ALTER TABLE c_exercise_category ADD CONSTRAINT FK_B94C157E1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE' 'ALTER TABLE c_exercise_category ADD CONSTRAINT FK_B94C157E1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
@ -112,6 +112,11 @@ class Version20170904145500 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE c_quiz_answer DROP id'); $this->addSql('ALTER TABLE c_quiz_answer DROP id');
} }
$this->addSql('ALTER TABLE c_quiz_answer CHANGE question_id question_id INT DEFAULT NULL');
if (false === $table->hasForeignKey('FK_AEBC3EFF1E27F6BF')) {
$this->addSql('ALTER TABLE c_quiz_answer ADD CONSTRAINT FK_AEBC3EFF1E27F6BF FOREIGN KEY (question_id) REFERENCES c_quiz_question (iid) ON DELETE CASCADE');
}
// c_quiz_question. // c_quiz_question.
$table = $schema->getTable('c_quiz_question'); $table = $schema->getTable('c_quiz_question');
if (false === $table->hasColumn('resource_node_id')) { if (false === $table->hasColumn('resource_node_id')) {
@ -141,7 +146,7 @@ class Version20170904145500 extends AbstractMigrationChamilo
// c_quiz_question_category. // c_quiz_question_category.
$table = $schema->getTable('c_quiz_question_category'); $table = $schema->getTable('c_quiz_question_category');
if (false === $table->hasColumn('session_id')) { if (false === $table->hasColumn('session_id')) {
$this->addSql('ALTER TABLE c_quiz_question_category ADD session_id INT DEFAULT NULL'); /*$this->addSql('ALTER TABLE c_quiz_question_category ADD session_id INT DEFAULT NULL');
if (false === $table->hasIndex('IDX_1414369D613FECDF')) { if (false === $table->hasIndex('IDX_1414369D613FECDF')) {
$this->addSql('CREATE INDEX IDX_1414369D613FECDF ON c_quiz_question_category (session_id)'); $this->addSql('CREATE INDEX IDX_1414369D613FECDF ON c_quiz_question_category (session_id)');
} }
@ -149,15 +154,22 @@ class Version20170904145500 extends AbstractMigrationChamilo
$this->addSql( $this->addSql(
'ALTER TABLE c_quiz_question_category ADD CONSTRAINT FK_1414369D613FECDF FOREIGN KEY (session_id) REFERENCES session (id)' 'ALTER TABLE c_quiz_question_category ADD CONSTRAINT FK_1414369D613FECDF FOREIGN KEY (session_id) REFERENCES session (id)'
); );
} }*/
} }
$this->addSql('ALTER TABLE c_quiz_question_category CHANGE description description LONGTEXT DEFAULT NULL;'); $this->addSql('ALTER TABLE c_quiz_question_category CHANGE description description LONGTEXT DEFAULT NULL;');
if (false === $table->hasForeignKey('FK_1414369D91D79BD3')) { if ($table->hasIndex('IDX_1414369D613FECDF')) {
$this->addSql('DROP INDEX IDX_1414369D613FECDF ON c_quiz_question_category');
}
if ($table->hasIndex('course')) {
$this->addSql('DROP INDEX course ON c_quiz_question_category');
}
/*if (false === $table->hasForeignKey('FK_1414369D91D79BD3')) {
$this->addSql( $this->addSql(
'ALTER TABLE c_quiz_question_category ADD CONSTRAINT FK_1414369D91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE;' 'ALTER TABLE c_quiz_question_category ADD CONSTRAINT FK_1414369D91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE;'
); );
} }*/
$table = $schema->getTable('c_quiz_question_option'); $table = $schema->getTable('c_quiz_question_option');
if ($table->hasColumn('id')) { if ($table->hasColumn('id')) {
@ -166,6 +178,27 @@ class Version20170904145500 extends AbstractMigrationChamilo
$table = $schema->getTable('c_quiz_rel_question'); $table = $schema->getTable('c_quiz_rel_question');
$this->addSql('UPDATE c_quiz_rel_category SET count_questions = 0 WHERE count_questions IS NULL');
$this->addSql('ALTER TABLE c_quiz_rel_category CHANGE count_questions count_questions INT NOT NULL');
$this->addSql('ALTER TABLE c_quiz_rel_category CHANGE exercise_id exercise_id INT DEFAULT NULL');
if (!$table->hasForeignKey('FK_F8EC662312469DE2')) {
$this->addSql('ALTER TABLE c_quiz_rel_category ADD CONSTRAINT FK_F8EC662312469DE2 FOREIGN KEY (category_id) REFERENCES c_quiz_question_category (iid) ON DELETE CASCADE;');
}
if (!$table->hasIndex('IDX_F8EC662312469DE2')) {
$this->addSql('CREATE INDEX IDX_F8EC662312469DE2 ON c_quiz_rel_category (category_id)');
}
if (!$table->hasIndex('IDX_F8EC6623E934951A')) {
$this->addSql('CREATE INDEX IDX_F8EC6623E934951A ON c_quiz_rel_category (exercise_id)');
}
if (!$table->hasForeignKey('FK_F8EC6623E934951A')) {
$this->addSql('ALTER TABLE c_quiz_rel_category ADD CONSTRAINT FK_F8EC6623E934951A FOREIGN KEY (exercise_id) REFERENCES c_quiz (iid) ON DELETE CASCADE');
}
if ($table->hasIndex('exercise')) { if ($table->hasIndex('exercise')) {
$this->addSql('ALTER TABLE c_quiz_rel_question DROP KEY exercise'); $this->addSql('ALTER TABLE c_quiz_rel_question DROP KEY exercise');
} }

@ -32,8 +32,10 @@ class CExerciseCategory extends AbstractResource implements ResourceInterface
protected int $id; protected int $id;
/** /**
* @Gedmo\SortableGroup
*
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course")
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false) * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/ */
protected Course $course; protected Course $course;

@ -177,7 +177,7 @@ class CQuiz extends AbstractResource implements ResourceInterface
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CExerciseCategory", cascade={"persist"}) * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CExerciseCategory", cascade={"persist"})
* @ORM\JoinColumn(name="exercise_category_id", referencedColumnName="id", onDelete="SET NULL") * @ORM\JoinColumn(name="exercise_category_id", referencedColumnName="id", onDelete="SET NULL")
*/ */
protected ?CExerciseCategory $exerciseCategory; protected ?CExerciseCategory $exerciseCategory = null;
/** /**
* @ORM\Column(name="show_previous_button", type="boolean", nullable=false, options={"default":1}) * @ORM\Column(name="show_previous_button", type="boolean", nullable=false, options={"default":1})
@ -206,6 +206,13 @@ class CQuiz extends AbstractResource implements ResourceInterface
*/ */
protected $questions; protected $questions;
/**
* @var Collection|CQuizRelQuestionCategory[]
*
* @ORM\OneToMany(targetEntity="CQuizRelQuestionCategory", mappedBy="quiz", cascade={"persist"}))
*/
protected $questionsCategories;
public function __construct() public function __construct()
{ {
$this->hideQuestionTitle = false; $this->hideQuestionTitle = false;
@ -226,6 +233,7 @@ class CQuiz extends AbstractResource implements ResourceInterface
$this->reviewAnswers = 0; $this->reviewAnswers = 0;
$this->randomByCategory = 0; $this->randomByCategory = 0;
$this->displayCategoryName = 0; $this->displayCategoryName = 0;
$this->pageResultConfiguration = null;
$this->questions = new ArrayCollection(); $this->questions = new ArrayCollection();
} }
@ -275,10 +283,8 @@ class CQuiz extends AbstractResource implements ResourceInterface
* Set sound. * Set sound.
* *
* @param string $sound * @param string $sound
*
* @return CQuiz
*/ */
public function setSound($sound) public function setSound($sound): self
{ {
$this->sound = $sound; $this->sound = $sound;
@ -311,10 +317,8 @@ class CQuiz extends AbstractResource implements ResourceInterface
* Set random. * Set random.
* *
* @param int $random * @param int $random
*
* @return CQuiz
*/ */
public function setRandom($random) public function setRandom($random): self
{ {
$this->random = $random; $this->random = $random;
@ -335,10 +339,8 @@ class CQuiz extends AbstractResource implements ResourceInterface
* Set randomAnswers. * Set randomAnswers.
* *
* @param bool $randomAnswers * @param bool $randomAnswers
*
* @return CQuiz
*/ */
public function setRandomAnswers($randomAnswers) public function setRandomAnswers($randomAnswers): self
{ {
$this->randomAnswers = $randomAnswers; $this->randomAnswers = $randomAnswers;
@ -359,10 +361,8 @@ class CQuiz extends AbstractResource implements ResourceInterface
* Set active. * Set active.
* *
* @param bool $active * @param bool $active
*
* @return CQuiz
*/ */
public function setActive($active) public function setActive($active): self
{ {
$this->active = $active; $this->active = $active;
@ -383,10 +383,8 @@ class CQuiz extends AbstractResource implements ResourceInterface
* Set resultsDisabled. * Set resultsDisabled.
* *
* @param int $resultsDisabled * @param int $resultsDisabled
*
* @return CQuiz
*/ */
public function setResultsDisabled($resultsDisabled) public function setResultsDisabled($resultsDisabled): self
{ {
$this->resultsDisabled = $resultsDisabled; $this->resultsDisabled = $resultsDisabled;
@ -781,10 +779,8 @@ class CQuiz extends AbstractResource implements ResourceInterface
/** /**
* @param int $questionSelectionType * @param int $questionSelectionType
*
* @return CQuiz
*/ */
public function setQuestionSelectionType($questionSelectionType) public function setQuestionSelectionType($questionSelectionType): self
{ {
$this->questionSelectionType = $questionSelectionType; $this->questionSelectionType = $questionSelectionType;
@ -798,10 +794,8 @@ class CQuiz extends AbstractResource implements ResourceInterface
/** /**
* @param bool $hideQuestionTitle * @param bool $hideQuestionTitle
*
* @return CQuiz
*/ */
public function setHideQuestionTitle($hideQuestionTitle) public function setHideQuestionTitle($hideQuestionTitle): self
{ {
$this->hideQuestionTitle = $hideQuestionTitle; $this->hideQuestionTitle = $hideQuestionTitle;
@ -896,9 +890,19 @@ class CQuiz extends AbstractResource implements ResourceInterface
return $maxScore; return $maxScore;
} }
public function getAutoLaunch(): ?bool
{
return $this->autoLaunch;
}
/** /**
* Resource identifier. * @return CQuizRelQuestionCategory[]|Collection
*/ */
public function getQuestionsCategories()
{
return $this->questionsCategories;
}
public function getResourceIdentifier(): int public function getResourceIdentifier(): int
{ {
return $this->getIid(); return $this->getIid();

@ -15,7 +15,6 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table( * @ORM\Table(
* name="c_quiz_answer", * name="c_quiz_answer",
* indexes={ * indexes={
* @ORM\Index(name="c_id", columns={"c_id"}),
* @ORM\Index(name="idx_cqa_q", columns={"question_id"}), * @ORM\Index(name="idx_cqa_q", columns={"question_id"}),
* } * }
* ) * )
@ -31,14 +30,11 @@ class CQuizAnswer
protected int $iid; protected int $iid;
/** /**
* @ORM\Column(name="c_id", type="integer", options={"unsigned": true, "default": null}) * @Assert\NotBlank()
*/ * @ORM\ManyToOne(targetEntity="CQuizQuestion", inversedBy="answers", cascade={"persist"})
protected int $cId; * @ORM\JoinColumn(name="question_id", referencedColumnName="iid", onDelete="CASCADE")
/**
* @ORM\Column(name="question_id", type="integer", nullable=false)
*/ */
protected int $questionId; protected CQuizQuestion $question;
/** /**
* @Assert\NotBlank() * @Assert\NotBlank()
@ -88,6 +84,7 @@ class CQuizAnswer
public function __construct() public function __construct()
{ {
$this->answer = '';
$this->correct = null; $this->correct = null;
$this->comment = null; $this->comment = null;
$this->ponderation = 0.0; $this->ponderation = 0.0;
@ -97,50 +94,14 @@ class CQuizAnswer
$this->answerCode = null; $this->answerCode = null;
} }
/** public function setAnswer(string $answer): self
* Set questionId.
*
* @param int $questionId
*
* @return CQuizAnswer
*/
public function setQuestionId($questionId)
{
$this->questionId = $questionId;
return $this;
}
/**
* Get questionId.
*
* @return int
*/
public function getQuestionId()
{
return $this->questionId;
}
/**
* Set answer.
*
* @param string $answer
*
* @return CQuizAnswer
*/
public function setAnswer($answer)
{ {
$this->answer = $answer; $this->answer = $answer;
return $this; return $this;
} }
/** public function getAnswer(): string
* Get answer.
*
* @return string
*/
public function getAnswer()
{ {
return $this->answer; return $this->answer;
} }
@ -149,10 +110,8 @@ class CQuizAnswer
* Set correct. * Set correct.
* *
* @param int $correct * @param int $correct
*
* @return CQuizAnswer
*/ */
public function setCorrect($correct) public function setCorrect($correct): self
{ {
$this->correct = $correct; $this->correct = $correct;
@ -173,10 +132,8 @@ class CQuizAnswer
* Set comment. * Set comment.
* *
* @param string $comment * @param string $comment
*
* @return CQuizAnswer
*/ */
public function setComment($comment) public function setComment($comment): self
{ {
$this->comment = $comment; $this->comment = $comment;
@ -197,12 +154,10 @@ class CQuizAnswer
* Set weight. * Set weight.
* *
* @param float $weight * @param float $weight
*
* @return CQuizAnswer
*/ */
public function setPonderation($weight) public function setPonderation($weight): self
{ {
$this->ponderation = empty($weight) ? 0.0 : $weight; $this->ponderation = empty($weight) ? 0.0 : (float) $weight;
return $this; return $this;
} }
@ -221,10 +176,8 @@ class CQuizAnswer
* Set position. * Set position.
* *
* @param int $position * @param int $position
*
* @return CQuizAnswer
*/ */
public function setPosition($position) public function setPosition($position): self
{ {
$this->position = $position; $this->position = $position;
@ -245,10 +198,8 @@ class CQuizAnswer
* Set hotspotCoordinates. * Set hotspotCoordinates.
* *
* @param string $hotspotCoordinates * @param string $hotspotCoordinates
*
* @return CQuizAnswer
*/ */
public function setHotspotCoordinates($hotspotCoordinates) public function setHotspotCoordinates($hotspotCoordinates): self
{ {
$this->hotspotCoordinates = $hotspotCoordinates; $this->hotspotCoordinates = $hotspotCoordinates;
@ -269,10 +220,8 @@ class CQuizAnswer
* Set hotspotType. * Set hotspotType.
* *
* @param string $hotspotType * @param string $hotspotType
*
* @return CQuizAnswer
*/ */
public function setHotspotType($hotspotType) public function setHotspotType($hotspotType): self
{ {
$this->hotspotType = $hotspotType; $this->hotspotType = $hotspotType;
@ -293,8 +242,6 @@ class CQuizAnswer
* Set destination. * Set destination.
* *
* @param string $destination * @param string $destination
*
* @return CQuizAnswer
*/ */
public function setDestination($destination) public function setDestination($destination)
{ {
@ -313,14 +260,7 @@ class CQuizAnswer
return $this->destination; return $this->destination;
} }
/** public function setAnswerCode(string $answerCode): self
* Set answerCode.
*
* @param string $answerCode
*
* @return CQuizAnswer
*/
public function setAnswerCode($answerCode)
{ {
$this->answerCode = $answerCode; $this->answerCode = $answerCode;
@ -338,36 +278,24 @@ class CQuizAnswer
} }
/** /**
* Set cId. * Get iid.
*
* @param int $cId
* *
* @return CQuizAnswer * @return int
*/ */
public function setCId($cId) public function getIid()
{ {
$this->cId = $cId; return $this->iid;
return $this;
} }
/** public function getQuestion(): CQuizQuestion
* Get cId.
*
* @return int
*/
public function getCId()
{ {
return $this->cId; return $this->question;
} }
/** public function setQuestion(CQuizQuestion $question): self
* Get iid.
*
* @return int
*/
public function getIid()
{ {
return $this->iid; $this->question = $question;
return $this;
} }
} }

@ -1,135 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* CQuizCategory.
*
* Manages quiz question categories inside an exercise.
*
* @ORM\Table(name="c_quiz_rel_category")
* @ORM\Entity
*/
class CQuizCategory
{
/**
* @ORM\Column(name="iid", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected int $iid;
/**
* @ORM\Column(name="c_id", type="integer")
*/
protected int $cId;
/**
* @ORM\Column(name="category_id", type="integer", nullable=true)
*/
protected ?int $categoryId;
/**
* @ORM\Column(name="exercise_id", type="integer", nullable=false)
*/
protected int $exerciseId;
/**
* @ORM\Column(name="count_questions", type="integer", nullable=true)
*/
protected ?int $countQuestions;
/**
* @return int
*/
public function getIid()
{
return $this->iid;
}
/**
* @return int
*/
public function getCId()
{
return $this->cId;
}
/**
* @param int $cId
*
* @return CQuizCategory
*/
public function setCId($cId)
{
$this->cId = $cId;
return $this;
}
/**
* @return int
*/
public function getCategoryId()
{
return $this->categoryId;
}
/**
* @param int $categoryId
*
* @return CQuizCategory
*/
public function setCategoryId($categoryId)
{
$this->categoryId = $categoryId;
return $this;
}
/**
* @return int
*/
public function getExerciseId()
{
return $this->exerciseId;
}
/**
* @param int $exerciseId
*
* @return CQuizCategory
*/
public function setExerciseId($exerciseId)
{
$this->exerciseId = $exerciseId;
return $this;
}
/**
* @return int
*/
public function getCountQuestions()
{
return $this->countQuestions;
}
/**
* @param int $countQuestions
*
* @return CQuizCategory
*/
public function setCountQuestions($countQuestions)
{
$this->countQuestions = $countQuestions;
return $this;
}
}

@ -101,7 +101,14 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* *
* @ORM\OneToMany(targetEntity="CQuizRelQuestion", mappedBy="question", cascade={"persist"}) * @ORM\OneToMany(targetEntity="CQuizRelQuestion", mappedBy="question", cascade={"persist"})
*/ */
protected $relQuizzes; protected Collection $relQuizzes;
/**
* @var Collection|CQuizAnswer[]
*
* @ORM\OneToMany(targetEntity="CQuizAnswer", mappedBy="question", cascade={"persist"})
*/
protected Collection $answers;
/** /**
* @ORM\Column(name="mandatory", type="integer") * @ORM\Column(name="mandatory", type="integer")
@ -111,6 +118,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
public function __construct() public function __construct()
{ {
$this->categories = new ArrayCollection(); $this->categories = new ArrayCollection();
$this->relQuizzes = new ArrayCollection();
$this->answers = new ArrayCollection();
$this->ponderation = 0.0; $this->ponderation = 0.0;
$this->mandatory = 0; $this->mandatory = 0;
} }
@ -198,10 +207,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
/** /**
* Set ponderation. * Set ponderation.
*
* @param float $ponderation
*/ */
public function setPonderation($ponderation): self public function setPonderation(float $ponderation): self
{ {
$this->ponderation = $ponderation; $this->ponderation = $ponderation;
@ -220,10 +227,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
/** /**
* Set position. * Set position.
*
* @param int $position
*/ */
public function setPosition($position): self public function setPosition(int $position): self
{ {
$this->position = $position; $this->position = $position;
@ -266,10 +271,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set picture. * Set picture.
* *
* @param string $picture * @param string $picture
*
* @return CQuizQuestion
*/ */
public function setPicture($picture) public function setPicture($picture): self
{ {
$this->picture = $picture; $this->picture = $picture;
@ -290,10 +293,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set level. * Set level.
* *
* @param int $level * @param int $level
*
* @return CQuizQuestion
*/ */
public function setLevel($level) public function setLevel($level): self
{ {
$this->level = $level; $this->level = $level;
@ -314,10 +315,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set extra. * Set extra.
* *
* @param string $extra * @param string $extra
*
* @return CQuizQuestion
*/ */
public function setExtra($extra) public function setExtra($extra): self
{ {
$this->extra = $extra; $this->extra = $extra;
@ -338,10 +337,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set questionCode. * Set questionCode.
* *
* @param string $questionCode * @param string $questionCode
*
* @return CQuizQuestion
*/ */
public function setQuestionCode($questionCode) public function setQuestionCode($questionCode): self
{ {
$this->questionCode = $questionCode; $this->questionCode = $questionCode;
@ -376,6 +373,35 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
return $this; return $this;
} }
/**
* @return CQuizQuestionCategory[]|Collection
*/
public function getCategories()
{
return $this->categories;
}
/**
* @return CQuizRelQuestion[]|Collection
*/
public function getRelQuizzes()
{
return $this->relQuizzes;
}
/**
* @return CQuizAnswer[]|Collection
*/
public function getAnswers()
{
return $this->answers;
}
public function getMandatory(): int
{
return $this->mandatory;
}
/** /**
* Get iid. * Get iid.
* *

@ -7,9 +7,7 @@ declare(strict_types=1);
namespace Chamilo\CourseBundle\Entity; namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceInterface; use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait; use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
@ -23,7 +21,6 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table( * @ORM\Table(
* name="c_quiz_question_category", * name="c_quiz_question_category",
* indexes={ * indexes={
* @ORM\Index(name="course", columns={"c_id"})
* } * }
* ) * )
* @ORM\Entity * @ORM\Entity
@ -51,18 +48,6 @@ class CQuizQuestionCategory extends AbstractResource implements ResourceInterfac
*/ */
protected ?string $description; protected ?string $description;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course")
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
protected Course $course;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", cascade={"persist"})
* @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
*/
protected ?Session $session;
/** /**
* @var Collection|CQuizQuestion[] * @var Collection|CQuizQuestion[]
* *
@ -134,38 +119,6 @@ class CQuizQuestionCategory extends AbstractResource implements ResourceInterfac
return $this->description; return $this->description;
} }
public function getCourse(): Course
{
return $this->course;
}
public function setCourse(Course $course): self
{
$this->course = $course;
return $this;
}
public function getSession(): ?Session
{
return $this->session;
}
/**
* @param Session $session
*/
public function setSession($session): self
{
$this->session = $session;
return $this;
}
public function hasSession(): bool
{
return null !== $this->session;
}
/** /**
* @ORM\PostPersist() * @ORM\PostPersist()
*/ */

@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Quiz rel question categories.
*
* @ORM\Table(name="c_quiz_rel_category")
* @ORM\Entity
*/
class CQuizRelQuestionCategory
{
/**
* @ORM\Column(name="iid", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected int $iid;
/**
* @ORM\ManyToOne(targetEntity="CQuizQuestionCategory", cascade={"persist"})
* @ORM\JoinColumn(name="category_id", referencedColumnName="iid", onDelete="CASCADE")
*/
protected CQuizQuestionCategory $category;
/**
* @ORM\ManyToOne(targetEntity="CQuiz", cascade={"persist"})
* @ORM\JoinColumn(name="exercise_id", referencedColumnName="iid", onDelete="CASCADE")
*/
protected CQuiz $quiz;
/**
* @ORM\Column(name="count_questions", type="integer", nullable=false)
*/
protected int $countQuestions;
/**
* @return int
*/
public function getIid()
{
return $this->iid;
}
public function getCategory(): CQuizQuestionCategory
{
return $this->category;
}
public function getQuiz(): CQuiz
{
return $this->quiz;
}
public function getCountQuestions(): int
{
return $this->countQuestions;
}
public function setCountQuestions(int $countQuestions): self
{
$this->countQuestions = $countQuestions;
return $this;
}
}

@ -35,7 +35,7 @@ class CSurveyQuestion
* @ORM\ManyToOne(targetEntity="CSurveyQuestion", inversedBy="children") * @ORM\ManyToOne(targetEntity="CSurveyQuestion", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="iid") * @ORM\JoinColumn(name="parent_id", referencedColumnName="iid")
*/ */
protected CSurveyQuestion $parent; protected ?CSurveyQuestion $parent = null;
/** /**
* @var Collection|CSurveyQuestion[] * @var Collection|CSurveyQuestion[]
@ -47,7 +47,7 @@ class CSurveyQuestion
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CSurveyQuestionOption", cascade="remove") * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CSurveyQuestionOption", cascade="remove")
* @ORM\JoinColumn(name="parent_option_id", referencedColumnName="iid") * @ORM\JoinColumn(name="parent_option_id", referencedColumnName="iid")
*/ */
protected CSurveyQuestionOption $parentOption; protected ?CSurveyQuestionOption $parentOption = null;
/** /**
* @ORM\ManyToOne(targetEntity="CSurvey", inversedBy="questions") * @ORM\ManyToOne(targetEntity="CSurvey", inversedBy="questions")
@ -407,7 +407,7 @@ class CSurveyQuestion
return $this; return $this;
} }
public function getParent(): self public function getParent(): ?self
{ {
return $this->parent; return $this->parent;
} }
@ -437,7 +437,7 @@ class CSurveyQuestion
return $this; return $this;
} }
public function getParentOption(): CSurveyQuestionOption public function getParentOption(): ?CSurveyQuestionOption
{ {
return $this->parentOption; return $this->parentOption;
} }
@ -460,4 +460,12 @@ class CSurveyQuestion
return $this; return $this;
} }
/**
* @return CSurveyAnswer[]|Collection
*/
public function getAnswers()
{
return $this->answers;
}
} }

Loading…
Cancel
Save