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
{
const LEVEL_DARKGREEN = 1;
const LEVEL_LIGHTGREEN = 2;
const LEVEL_WHITE = 3;
const LEVEL_LIGHTRED = 4;
const LEVEL_DARKRED = 5;
public const LEVEL_DARKGREEN = 1;
public const LEVEL_LIGHTGREEN = 2;
public const LEVEL_WHITE = 3;
public const LEVEL_LIGHTRED = 4;
public const LEVEL_DARKRED = 5;
public $typePicture = 'mccert.png';
public $explanationLangVar = 'Multiple answer true/false/degree of certainty';
public $optionsTitle;
public $options;
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
@ -288,7 +285,9 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
if (empty($options)) {
// 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
$goodAnswer = $sortedByPosition[$goodAnswer]['id'];
if (!empty($goodAnswer)) {
$goodAnswer = $sortedByPosition[$goodAnswer]['iid'];
}
}
$questionWeighting += $extraValues[0]; //By default 0 has the correct answers
$objAnswer->createAnswer($answer, $goodAnswer, $comment, '', $i);

@ -89,7 +89,6 @@ class TestCategory
$category = new CQuizQuestionCategory();
$category
->setTitle($this->name)
->setCourse($course)
->setDescription($this->description)
->setParent($course)
->addCourseLink($course, api_get_session_entity());
@ -181,46 +180,6 @@ class TestCategory
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
* In this version, a question has only 1 TestCategory.
@ -286,7 +245,7 @@ class TestCategory
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$sql = "SELECT title
FROM $table
WHERE iid = $categoryId AND c_id = $courseId";
WHERE iid = $categoryId ";
$res = Database::query($sql);
$data = Database::fetch_array($res);
$result = '';
@ -474,10 +433,10 @@ class TestCategory
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
$categories = self::getCategoryListInfo('', $courseId);
$result = ['0' => get_lang('No category selected')];
for ($i = 0; $i < count($categories); $i++) {
$result[$categories[$i]->id] = $categories[$i]->name;
$categories = self::getCategories($courseId);
$result = [0 => get_lang('No category selected')];
foreach ($categories as $category) {
$result[$category->getIid()] = $category->getTitle();
}
return $result;
@ -867,30 +826,6 @@ class TestCategory
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 int $courseId
@ -1105,14 +1040,11 @@ class TestCategory
*/
public static function categoryTitleExists($name, $courseId = 0)
{
$categories = self::getCategoryListInfo('title', $courseId);
foreach ($categories as $title) {
if ($title == $name) {
return true;
}
}
$repo = Container::getQuestionCategoryRepository();
$courseEntity = api_get_course_entity($courseId);
$resource = $repo->findResourceByTitle($name, $courseEntity->getResourceNode(), $courseEntity);
return false;
return null !== $resource;
}
/**

@ -2,7 +2,9 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CQuizAnswer;
use Chamilo\CourseBundle\Entity\CQuizQuestion;
/**
* Class Answer
@ -125,7 +127,6 @@ class Answer
$sql = "SELECT * FROM $table
WHERE
c_id = {$this->course_id} AND
question_id ='".$questionId."'
ORDER BY position";
@ -150,33 +151,6 @@ class Answer
$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
*
@ -328,7 +302,7 @@ class Answer
*/
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);
$auto_id = (int) $auto_id;
$sql = "SELECT iid, answer FROM $table
WHERE c_id = {$this->course_id} AND iid='$auto_id'";
WHERE iid='$auto_id'";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
@ -697,12 +671,16 @@ class Answer
$courseId = $this->course['real_id'];
$answerList = [];
$questionRepo = Container::getQuestionRepository();
/** @var CQuizQuestion $question */
$question = $questionRepo->find($questionId);
$questionType = $question->getType();
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;
$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;
$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;
@ -713,8 +691,7 @@ class Answer
if (!isset($this->position[$i])) {
$quizAnswer = new CQuizAnswer();
$quizAnswer
->setCId($courseId)
->setQuestionId($questionId)
->setQuestion($question)
->setAnswer($answer)
->setCorrect($correct)
->setComment($comment)
@ -730,11 +707,7 @@ class Answer
$iid = $quizAnswer->getIid();
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->read();
$correctAnswerId = $answer->selectAnswerIdByPosition($correct);
@ -771,8 +744,6 @@ class Answer
$answerList[$i] = $iid;
}
$questionType = $this->getQuestionType();
switch ($questionType) {
case MATCHING_DRAGGABLE:
foreach ($this->new_correct as $value => $status) {
@ -934,7 +905,6 @@ class Answer
$quizAnswer = new CQuizAnswer();
$quizAnswer
->setCId($courseId)
->setQuestionId($newQuestionId)
->setAnswer($answer['answer'])
->setCorrect($answer['correct'])
@ -982,7 +952,6 @@ class Answer
$quizAnswer = new CQuizAnswer();
$quizAnswer
->setCId($courseId)
->setQuestionId($newQuestionId)
->setAnswer($this->answer[$i])
->setCorrect($correct)

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

@ -15,7 +15,7 @@ $courseCode = api_get_course_id();
$data = [];
$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);
$sql = "SELECT iid, title FROM $table
@ -32,12 +32,11 @@ $header[] = get_lang('LastName');
$header[] = get_lang('Email');
$header[] = get_lang('OfficialCode');
/** @var TestCategory $categoryInfo */
foreach ($categories as $categoryInfo) {
$header[] = 'Aciertos: '.$categoryInfo->name;
$header[] = 'Errores: '.$categoryInfo->name;
$header[] = 'Omisiones: '.$categoryInfo->name;
$header[] = 'Puntos: '.$categoryInfo->name;
$header[] = 'Aciertos: '.$categoryInfo->getTitle();
$header[] = 'Errores: '.$categoryInfo->getTitle();
$header[] = 'Omisiones: '.$categoryInfo->getTitle();
$header[] = 'Puntos: '.$categoryInfo->getTitle();
}
foreach ($exercises as $exerciseInfo) {

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

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

@ -459,64 +459,4 @@ class UniqueAnswer extends Question
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;
}
if (null === $answer) {
$answer = '';
}
if (null === $score) {
$score = 0;
}
if (null != $answer) {
$answer = (int) $answer;
}
$attempt = [
'user_id' => $user_id,
'question_id' => $question_id,
@ -619,8 +619,8 @@ class Event
->setExeId($attempt_id)
->setQuestionId($question_id)
->setAnswer($answer)
->setMarks($score)
->setAuthor('')
->setMarks((int) $score)
//->setAuthor('')
->setSessionId($session_id)
;
$em->persist($recording);

@ -77,6 +77,7 @@ class TrackEAttemptRecording
$this->teacherComment = '';
$this->answer = null;
$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('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');
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 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(
'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 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.
$table = $schema->getTable('c_quiz_question');
if (false === $table->hasColumn('resource_node_id')) {
@ -141,7 +146,7 @@ class Version20170904145500 extends AbstractMigrationChamilo
// c_quiz_question_category.
$table = $schema->getTable('c_quiz_question_category');
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')) {
$this->addSql('CREATE INDEX IDX_1414369D613FECDF ON c_quiz_question_category (session_id)');
}
@ -149,15 +154,22 @@ class Version20170904145500 extends AbstractMigrationChamilo
$this->addSql(
'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;');
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(
'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');
if ($table->hasColumn('id')) {
@ -166,6 +178,27 @@ class Version20170904145500 extends AbstractMigrationChamilo
$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')) {
$this->addSql('ALTER TABLE c_quiz_rel_question DROP KEY exercise');
}

@ -32,8 +32,10 @@ class CExerciseCategory extends AbstractResource implements ResourceInterface
protected int $id;
/**
* @Gedmo\SortableGroup
*
* @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;

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

@ -15,7 +15,6 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(
* name="c_quiz_answer",
* indexes={
* @ORM\Index(name="c_id", columns={"c_id"}),
* @ORM\Index(name="idx_cqa_q", columns={"question_id"}),
* }
* )
@ -31,14 +30,11 @@ class CQuizAnswer
protected int $iid;
/**
* @ORM\Column(name="c_id", type="integer", options={"unsigned": true, "default": null})
*/
protected int $cId;
/**
* @ORM\Column(name="question_id", type="integer", nullable=false)
* @Assert\NotBlank()
* @ORM\ManyToOne(targetEntity="CQuizQuestion", inversedBy="answers", cascade={"persist"})
* @ORM\JoinColumn(name="question_id", referencedColumnName="iid", onDelete="CASCADE")
*/
protected int $questionId;
protected CQuizQuestion $question;
/**
* @Assert\NotBlank()
@ -88,6 +84,7 @@ class CQuizAnswer
public function __construct()
{
$this->answer = '';
$this->correct = null;
$this->comment = null;
$this->ponderation = 0.0;
@ -97,50 +94,14 @@ class CQuizAnswer
$this->answerCode = null;
}
/**
* 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)
public function setAnswer(string $answer): self
{
$this->answer = $answer;
return $this;
}
/**
* Get answer.
*
* @return string
*/
public function getAnswer()
public function getAnswer(): string
{
return $this->answer;
}
@ -149,10 +110,8 @@ class CQuizAnswer
* Set correct.
*
* @param int $correct
*
* @return CQuizAnswer
*/
public function setCorrect($correct)
public function setCorrect($correct): self
{
$this->correct = $correct;
@ -173,10 +132,8 @@ class CQuizAnswer
* Set comment.
*
* @param string $comment
*
* @return CQuizAnswer
*/
public function setComment($comment)
public function setComment($comment): self
{
$this->comment = $comment;
@ -197,12 +154,10 @@ class CQuizAnswer
* Set 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;
}
@ -221,10 +176,8 @@ class CQuizAnswer
* Set position.
*
* @param int $position
*
* @return CQuizAnswer
*/
public function setPosition($position)
public function setPosition($position): self
{
$this->position = $position;
@ -245,10 +198,8 @@ class CQuizAnswer
* Set hotspotCoordinates.
*
* @param string $hotspotCoordinates
*
* @return CQuizAnswer
*/
public function setHotspotCoordinates($hotspotCoordinates)
public function setHotspotCoordinates($hotspotCoordinates): self
{
$this->hotspotCoordinates = $hotspotCoordinates;
@ -269,10 +220,8 @@ class CQuizAnswer
* Set hotspotType.
*
* @param string $hotspotType
*
* @return CQuizAnswer
*/
public function setHotspotType($hotspotType)
public function setHotspotType($hotspotType): self
{
$this->hotspotType = $hotspotType;
@ -293,8 +242,6 @@ class CQuizAnswer
* Set destination.
*
* @param string $destination
*
* @return CQuizAnswer
*/
public function setDestination($destination)
{
@ -313,14 +260,7 @@ class CQuizAnswer
return $this->destination;
}
/**
* Set answerCode.
*
* @param string $answerCode
*
* @return CQuizAnswer
*/
public function setAnswerCode($answerCode)
public function setAnswerCode(string $answerCode): self
{
$this->answerCode = $answerCode;
@ -338,36 +278,24 @@ class CQuizAnswer
}
/**
* Set cId.
*
* @param int $cId
* Get iid.
*
* @return CQuizAnswer
* @return int
*/
public function setCId($cId)
public function getIid()
{
$this->cId = $cId;
return $this;
return $this->iid;
}
/**
* Get cId.
*
* @return int
*/
public function getCId()
public function getQuestion(): CQuizQuestion
{
return $this->cId;
return $this->question;
}
/**
* Get iid.
*
* @return int
*/
public function getIid()
public function setQuestion(CQuizQuestion $question): self
{
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"})
*/
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")
@ -111,6 +118,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
public function __construct()
{
$this->categories = new ArrayCollection();
$this->relQuizzes = new ArrayCollection();
$this->answers = new ArrayCollection();
$this->ponderation = 0.0;
$this->mandatory = 0;
}
@ -198,10 +207,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
/**
* Set ponderation.
*
* @param float $ponderation
*/
public function setPonderation($ponderation): self
public function setPonderation(float $ponderation): self
{
$this->ponderation = $ponderation;
@ -220,10 +227,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
/**
* Set position.
*
* @param int $position
*/
public function setPosition($position): self
public function setPosition(int $position): self
{
$this->position = $position;
@ -266,10 +271,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set picture.
*
* @param string $picture
*
* @return CQuizQuestion
*/
public function setPicture($picture)
public function setPicture($picture): self
{
$this->picture = $picture;
@ -290,10 +293,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set level.
*
* @param int $level
*
* @return CQuizQuestion
*/
public function setLevel($level)
public function setLevel($level): self
{
$this->level = $level;
@ -314,10 +315,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set extra.
*
* @param string $extra
*
* @return CQuizQuestion
*/
public function setExtra($extra)
public function setExtra($extra): self
{
$this->extra = $extra;
@ -338,10 +337,8 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
* Set questionCode.
*
* @param string $questionCode
*
* @return CQuizQuestion
*/
public function setQuestionCode($questionCode)
public function setQuestionCode($questionCode): self
{
$this->questionCode = $questionCode;
@ -376,6 +373,35 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface
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.
*

@ -7,9 +7,7 @@ declare(strict_types=1);
namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -23,7 +21,6 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(
* name="c_quiz_question_category",
* indexes={
* @ORM\Index(name="course", columns={"c_id"})
* }
* )
* @ORM\Entity
@ -51,18 +48,6 @@ class CQuizQuestionCategory extends AbstractResource implements ResourceInterfac
*/
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[]
*
@ -134,38 +119,6 @@ class CQuizQuestionCategory extends AbstractResource implements ResourceInterfac
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()
*/

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

Loading…
Cancel
Save