Surveys: Update entities to use collections + add migration

pull/3844/head
Julio Montoya 5 years ago
parent 8254af9939
commit 5a0940e7f6
  1. 12
      public/main/survey/edit_meeting.php
  2. 10
      public/main/survey/question.php
  3. 198
      public/main/survey/survey.lib.php
  4. 3
      public/main/survey/survey.php
  5. 20
      public/main/survey/survey_question.php
  6. 55
      src/CoreBundle/Migrations/Schema/V200/Version20180319145700.php
  7. 22
      src/CourseBundle/Entity/CSurvey.php
  8. 92
      src/CourseBundle/Entity/CSurveyAnswer.php
  9. 55
      src/CourseBundle/Entity/CSurveyQuestion.php
  10. 82
      src/CourseBundle/Entity/CSurveyQuestionOption.php

@ -107,7 +107,7 @@ for ($i = $currentQuestionsCount; $i <= $maxEvents; $i++) {
$form->addHtml('<script>
$(function() {
'.$hideList.'
var number = "'.--$currentQuestionsCount.'";
var number = "'.--$currentQuestionsCount.'";
$("#add_button").on("click", function() {
number++;
$("#time_" + number + "_date_time_wrapper").show();
@ -115,15 +115,15 @@ $(function() {
$("#time_" + number + "_time_range_end").val("");
$("#time_" + number + "_alt").val("");
});
$("#remove_button").on("click", function() {
if (number > 1) {
if (number > 1) {
console.log("#time_" + number + "_time_range_start");
$("#time_" + number + "_date_time_wrapper").hide();
$("#time_" + number).val("delete");
$("#time_" + number + "_alt").val("delete");
$("#time_" + number + "_time_range_start").val("delete");
$("#time_" + number + "_time_range_start").val("delete");
number--;
}
});
@ -235,7 +235,7 @@ if ($form->validate()) {
}
foreach ($deleteItems as $deleteId) {
SurveyManager::delete_survey_question($surveyData['iid'], $deleteId);
SurveyManager::deleteQuestion($surveyData['iid'], $deleteId);
}
}

@ -7,6 +7,9 @@
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup,
* refactoring and rewriting large parts of the code
*/
use Chamilo\CoreBundle\Framework\Container;
require_once __DIR__.'/../inc/global.inc.php';
$htmlHeadXtra[] = '<script>
@ -63,10 +66,10 @@ $interbreadcrumb[] = [
];
// Tool name
if ('add' == $_GET['action']) {
if ('add' === $_GET['action']) {
$tool_name = get_lang('Add a question');
}
if ('edit' == $_GET['action']) {
if ('edit' === $_GET['action']) {
$tool_name = get_lang('Edit question');
}
@ -136,7 +139,8 @@ $surveyQuestion->renderForm();
if ($surveyQuestion->getForm()->validate()) {
$values = $surveyQuestion->getForm()->getSubmitValues();
$surveyQuestion->save($surveyData, $values, $formData);
$survey = Container::getSurveyRepository()->find($surveyId);
$surveyQuestion->save($survey, $values, $formData);
}
Display::display_header($tool_name, 'Survey');

@ -227,7 +227,7 @@ class SurveyManager
$session_id = api_get_session_id();
$courseCode = api_get_course_id();
$table_survey = Database::get_course_table(TABLE_SURVEY);
$shared_survey_id = 0;
$shared_survey_id = '';
$repo = Container::getSurveyRepository();
if (!isset($values['survey_id'])) {
@ -361,9 +361,9 @@ class SurveyManager
->setTemplate('template')
->setIntro($values['survey_introduction'])
->setSurveyThanks($values['survey_thanks'])
->setAnonymous($values['anonymous'])
->setAnonymous((string) $values['anonymous'])
->setSessionId(api_get_session_id())
->setVisibleResults($values['visible_results'])
->setVisibleResults((int) $values['visible_results'])
->setParent($course)
->addCourseLink($course, $session)
;
@ -474,9 +474,9 @@ class SurveyManager
->setTemplate('template')
->setIntro($values['survey_introduction'])
->setSurveyThanks($values['survey_thanks'])
->setAnonymous($values['anonymous'])
->setAnonymous((string) $values['anonymous'])
->setSessionId(api_get_session_id())
->setVisibleResults($values['visible_results'])
->setVisibleResults((int) $values['visible_results'])
;
$repo->update($survey);
@ -1118,26 +1118,15 @@ class SurveyManager
return $questions;
}
/**
* This function saves a question in the database.
* This can be either an update of an existing survey or storing a new survey.
*
* @param array $survey_data
* @param array $form_content all the information of the form
*
* @return string
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version January 2007
*/
public static function save_question($survey_data, $form_content, $showMessage = true, $dataFromDatabase = [])
public static function saveQuestion(CSurvey $survey, array $form_content, bool $showMessage = true, array $dataFromDatabase = [])
{
$return_message = '';
$surveyId = $survey->getIid();
$message = '';
if (strlen($form_content['question']) > 1) {
// Checks length of the question
$empty_answer = false;
if (1 == $survey_data['survey_type']) {
if (1 == $survey->getSurveyType()) {
if (empty($form_content['choose'])) {
return 'PleaseChooseACondition';
}
@ -1171,7 +1160,6 @@ class SurveyManager
if (!$empty_answer) {
// Table definitions
$tbl_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$surveyId = (int) $form_content['survey_id'];
// Getting all the information of the survey
$survey_data = self::get_survey($surveyId);
@ -1209,11 +1197,11 @@ class SurveyManager
->setMaxValue($form_content['maximum_score'] ?? 0)
->setDisplay($form_content['horizontalvertical'] ?? '')
->setCId($course_id)
->setSurveyId($form_content['survey_id'])
->setSurvey($survey)
->setSurveyQuestion($form_content['question'])
->setType($form_content['type'])
->setSort($max_sort + 1)
->setSharedQuestionId($form_content['shared_question_id'])
->setSharedQuestionId((int) $form_content['shared_question_id'])
;
if (api_get_configuration_value('allow_required_survey_questions')) {
@ -1241,9 +1229,8 @@ class SurveyManager
/*$sql = "UPDATE $tbl_survey_question SET question_id = $question_id
WHERE iid = $question_id";
Database::query($sql);*/
$form_content['question_id'] = $question_id;
$return_message = 'QuestionAdded';
$message = 'QuestionAdded';
}
} else {
$repo = $em->getRepository(CSurveyQuestion::class);
@ -1251,8 +1238,6 @@ class SurveyManager
/** @var CSurveyQuestion $question */
$question = $repo->find($form_content['question_id']);
// Updating an existing question
$extraParams = [];
if (isset($_POST['choose'])) {
if (1 == $_POST['choose']) {
$question->setSurveyGroupPri($_POST['assigned']);
@ -1302,7 +1287,7 @@ class SurveyManager
],
]
);*/
$return_message = 'QuestionUpdated';
$message = 'QuestionUpdated';
}
if (!empty($form_content['survey_id'])) {
@ -1317,21 +1302,21 @@ class SurveyManager
}
// Storing the options of the question
self::save_question_options($form_content, $survey_data, $dataFromDatabase);
self::saveQuestionOptions($survey, $question, $form_content, $dataFromDatabase);
} else {
$return_message = 'PleasFillAllAnswer';
$message = 'PleasFillAllAnswer';
}
} else {
$return_message = 'PleaseEnterAQuestion';
$message = 'PleaseEnterAQuestion';
}
if ($showMessage) {
if (!empty($return_message)) {
Display::addFlash(Display::return_message(get_lang($return_message)));
if (!empty($message)) {
Display::addFlash(Display::return_message(get_lang($message)));
}
}
return $return_message;
return $message;
}
/**
@ -1491,47 +1476,30 @@ class SurveyManager
return true;
}
/**
* This function deletes a survey question and all its options.
*
* @param int $survey_id the id of the survey
* @param int $question_id the id of the question
* @param bool $shared
*
* @return mixed False on error, true if the question could be deleted
*
* @todo also delete the answers to this question
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version March 2007
*/
public static function delete_survey_question($survey_id, $question_id, $shared = false)
public static function deleteQuestion($survey_id, $questionId, $shared = false)
{
$survey_id = (int) $survey_id;
$question_id = (int) $question_id;
$questionId = (int) $questionId;
if (empty($questionId)) {
return false;
}
$course_id = api_get_course_int_id();
if ($shared) {
self::delete_shared_survey_question($survey_id, $question_id);
self::delete_shared_survey_question($survey_id, $questionId);
}
// Table definitions
$table = Database::get_course_table(TABLE_SURVEY_QUESTION);
// Deleting the survey questions
$sql = "DELETE FROM $table
WHERE
c_id = $course_id AND
survey_id = $survey_id AND
iid = $question_id";
$result = Database::query($sql);
if (false == $result) {
return false;
$em = Database::getManager();
$repo = Container::getSurveyQuestionRepository();
$question = $repo->find($questionId);
if ($question) {
$em->remove($question);
$em->flush();
return true;
}
self::delete_survey_question_option($survey_id, $question_id, $shared);
// Deleting the options of the question of the survey
return true;
return false;
}
/**
@ -1565,18 +1533,7 @@ class SurveyManager
Database::query($sql);
}
/**
* This function stores the options of the questions in the table.
*
* @param array $form_content
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version January 2007
*
* @todo writing the update statement when editing a question
*/
public static function save_question_options($form_content, $survey_data, $dataFromDatabase = [])
public static function saveQuestionOptions(CSurvey $survey, CSurveyQuestion $question, $form_content, $dataFromDatabase = [])
{
$course_id = api_get_course_int_id();
$type = $form_content['type'];
@ -1588,9 +1545,10 @@ class SurveyManager
}
}
$em = Database::getManager();
$shared = $survey->getIsShared();
if (is_numeric($survey_data['survey_share']) && 0 != $survey_data['survey_share']) {
self::save_shared_question_options($form_content, $survey_data);
if (is_numeric($shared) && 0 != $shared) {
self::saveSharedQuestionOptions($survey, $form_content);
}
// Table definition
@ -1626,7 +1584,7 @@ class SurveyManager
$counter = 1;
if (isset($form_content['answers']) && is_array($form_content['answers'])) {
for ($i = 0; $i < count($form_content['answers']); $i++) {
$values = isset($form_content['values']) ? $form_content['values'][$i] : '';
$values = isset($form_content['values']) ? (int) $form_content['values'][$i] : 0;
$answerId = 0;
if (isset($form_content['answersid']) && isset($form_content['answersid'][$i])) {
$answerId = $form_content['answersid'][$i];
@ -1635,21 +1593,16 @@ class SurveyManager
$option = new CSurveyQuestionOption();
$option
->setCId($course_id)
->setQuestionId($form_content['question_id'])
->setQuestion($question)
->setOptionText($form_content['answers'][$i])
->setSurveyId($form_content['survey_id'])
->setSurvey($survey)
->setValue($values)
->setSort($counter)
;
$em->persist($option);
$em->flush();
$insertId = $option->getIid();
if ($insertId) {
/*$sql = "UPDATE $table
SET question_option_id = $insertId
WHERE iid = $insertId";
Database::query($sql);*/
$counter++;
}
} else {
@ -1680,13 +1633,7 @@ class SurveyManager
'value' => 0,
'sort' => $counter,
];
$insertId = Database::insert($table, $params);
if ($insertId) {
/*$sql = "UPDATE $table
SET question_option_id = $insertId
WHERE iid = $insertId";
Database::query($sql);*/
}
Database::insert($table, $params);
} else {
$params = [
'option_text' => 'other',
@ -1709,19 +1656,9 @@ class SurveyManager
}
}
/**
* This function stores the options of the questions in the shared table.
*
* @param array $form_content
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version February 2007
*
* @todo writing the update statement when editing a question
*/
public static function save_shared_question_options($form_content, $survey_data)
public static function saveSharedQuestionOptions(CSurvey $survey, $form_content)
{
$shared = $survey->getIsShared();
if (is_array($form_content) && is_array($form_content['answers'])) {
// Table definition
$table = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
@ -1735,17 +1672,17 @@ class SurveyManager
foreach ($form_content['answers'] as &$answer) {
$params = [
'question_id' => $form_content['shared_question_id'],
'survey_id' => $survey_data['is_shared'],
'survey_id' => $shared,
'option_text' => $answer,
'sort' => $counter,
];
Database::insert($table, $params);
$counter++;
}
}
}
/**
* This function deletes all the options of the questions of a given survey
* This function is normally only called when a survey is deleted.
@ -1778,45 +1715,6 @@ class SurveyManager
return true;
}
/**
* This function deletes the options of a given question.
*
* @param int $survey_id
* @param int $question_id
* @param bool $shared
*
* @return bool
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Julio Montoya
*
* @version March 2007
*/
public static function delete_survey_question_option(
$survey_id,
$question_id,
$shared = false
) {
$course_id = api_get_course_int_id();
$course_condition = " c_id = $course_id AND ";
// Table definitions
$table = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
if ($shared) {
$course_condition = '';
$table = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
}
// Deleting the options of the survey questions
$sql = "DELETE FROM $table
WHERE
$course_condition survey_id='".intval($survey_id)."' AND
iid ='".intval($question_id)."'";
Database::query($sql);
return true;
}
/**
* SURVEY ANSWERS FUNCTIONS.
*/
@ -2350,7 +2248,7 @@ class SurveyManager
foreach ($questions as $question) {
// Questions marked with "geneated" were created using the "multiplicate" feature.
if ('generated' === $question['survey_question_comment']) {
self::delete_survey_question($surveyId, $question['question_id']);
self::deleteQuestion($surveyId, $question['question_id']);
}
}
}

@ -99,7 +99,6 @@ if ($is_survey_type_1 && ('addgroup' == $action || 'deletegroup' == $action)) {
$my_question_id_survey = isset($_GET['question_id']) ? (int) $_GET['question_id'] : null;
$my_survey_id_survey = (int) $_GET['survey_id'];
$message_information = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
// Displaying the header
if (!empty($action)) {
switch ($action) {
@ -112,7 +111,7 @@ if (!empty($action)) {
}
break;
case 'delete':
$result = SurveyManager::delete_survey_question(
$result = SurveyManager::deleteQuestion(
$my_survey_id_survey,
$my_question_id_survey,
$survey_data['is_shared']

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CSurvey;
use ChamiloSession as Session;
/**
@ -52,12 +53,12 @@ class survey_question
'survey.ajax.php?'.api_get_cidreq().'&a=load_question_options&survey_id='.$surveyId;
$form->addHtml('
<script>
$(function() {
$(function() {
$("#parent_id").on("change", function() {
var questionId = $(this).val()
var $select = $("#parent_option_id");
$select.empty();
if (questionId === "") {
$("#option_list").hide();
} else {
@ -69,7 +70,7 @@ class survey_question
$("<option>").val(key).text(value).appendTo($select);
});
}
});
});
}
});
});
@ -483,22 +484,17 @@ class survey_question
return $formData;
}
/**
* @param array $surveyData
* @param array $formData
*
* @return mixed
*/
public function save($surveyData, $formData, $dataFromDatabase = [])
public function save(CSurvey $survey, array $formData, array $dataFromDatabase = [])
{
// Saving a question
if (isset($_POST['buttons']) && isset($_POST['buttons']['save'])) {
Session::erase('answer_count');
Session::erase('answer_list');
$message = SurveyManager::save_question($surveyData, $formData, true, $dataFromDatabase);
$message = SurveyManager::saveQuestion($survey, $formData, true, $dataFromDatabase);
if ('QuestionAdded' === $message || 'QuestionUpdated' === $message) {
$url = api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.intval($_GET['survey_id']).'&message='.$message.'&'.api_get_cidreq();
Display::addFlash(Display::return_message($message));
$url = api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey->getIid().'&'.api_get_cidreq();
header('Location: '.$url);
exit;
}

@ -32,6 +32,34 @@ class Version20180319145700 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE c_survey CHANGE avail_from avail_from DATETIME DEFAULT NULL;');
$this->addSql('ALTER TABLE c_survey CHANGE avail_till avail_till DATETIME DEFAULT NULL;');
$this->addSql('ALTER TABLE c_survey_answer CHANGE survey_id survey_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE c_survey_answer CHANGE question_id question_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE c_survey_answer CHANGE option_id option_id INT DEFAULT NULL');
if (!$survey->hasForeignKey('FK_8A897DDB3FE509D')) {
$this->addSql('ALTER TABLE c_survey_answer ADD CONSTRAINT FK_8A897DDB3FE509D FOREIGN KEY (survey_id) REFERENCES c_survey (iid);');
}
if (!$survey->hasForeignKey('FK_8A897DD1E27F6BF')) {
$this->addSql('ALTER TABLE c_survey_answer ADD CONSTRAINT FK_8A897DD1E27F6BF FOREIGN KEY (question_id) REFERENCES c_survey_question (iid);');
}
if (!$survey->hasForeignKey('FK_8A897DDA7C41D6F')) {
$this->addSql('ALTER TABLE c_survey_answer ADD CONSTRAINT FK_8A897DDA7C41D6F FOREIGN KEY (option_id) REFERENCES c_survey_question_option (iid);');
}
if (!$survey->hasIndex('IDX_8A897DDB3FE509D')) {
$this->addSql('CREATE INDEX IDX_8A897DDB3FE509D ON c_survey_answer (survey_id);');
}
if (!$survey->hasIndex('IDX_8A897DD1E27F6BF')) {
$this->addSql('CREATE INDEX IDX_8A897DD1E27F6BF ON c_survey_answer (question_id);');
}
if (!$survey->hasIndex('IDX_8A897DDA7C41D6F')) {
$this->addSql('CREATE INDEX IDX_8A897DDA7C41D6F ON c_survey_answer (option_id);');
}
/*if (!$survey->hasIndex('idx_survey_code')) {
$this->addSql('CREATE INDEX idx_survey_code ON c_survey (code)');
}*/
@ -60,6 +88,16 @@ class Version20180319145700 extends AbstractMigrationChamilo
$this->addSql('CREATE INDEX idx_survey_q_qid ON c_survey_question (question_id)');
}*/
$this->addSql('ALTER TABLE c_survey_question CHANGE survey_id survey_id INT DEFAULT NULL;');
if ($table->hasForeignKey('FK_92F05EE7B3FE509D')) {
$this->addSql('ALTER TABLE c_survey_question ADD CONSTRAINT FK_92F05EE7B3FE509D FOREIGN KEY (survey_id) REFERENCES c_survey (iid);');
}
if ($table->hasIndex('IDX_92F05EE7B3FE509D')) {
$this->addSql('CREATE INDEX IDX_92F05EE7B3FE509D ON c_survey_question (survey_id);');
}
if ($table->hasIndex('idx_survey_q_qid')) {
$this->addSql('DROP INDEX idx_survey_q_qid ON c_survey_question;');
}
@ -77,8 +115,23 @@ class Version20180319145700 extends AbstractMigrationChamilo
}
$table = $schema->getTable('c_survey_question_option');
if (false === $table->hasIndex('idx_survey_qo_qid')) {
/*if (false === $table->hasIndex('idx_survey_qo_qid')) {
$this->addSql('CREATE INDEX idx_survey_qo_qid ON c_survey_question_option (question_id)');
}*/
$this->addSql('ALTER TABLE c_survey_question_option CHANGE question_id question_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE c_survey_question_option CHANGE survey_id survey_id INT DEFAULT NULL;');
if (false === $table->hasForeignKey('FK_C4B6F5F1E27F6BF')) {
$this->addSql('ALTER TABLE c_survey_question_option ADD CONSTRAINT FK_C4B6F5F1E27F6BF FOREIGN KEY (question_id) REFERENCES c_survey_question (iid);');
}
if (false === $table->hasForeignKey('FK_C4B6F5FB3FE509D')) {
$this->addSql('ALTER TABLE c_survey_question_option ADD CONSTRAINT FK_C4B6F5FB3FE509D FOREIGN KEY (survey_id) REFERENCES c_survey (iid);');
}
if (false === $table->hasIndex('IDX_C4B6F5FB3FE509D')) {
$this->addSql('CREATE INDEX IDX_C4B6F5FB3FE509D ON c_survey_question_option (survey_id);');
}
$em = $this->getEntityManager();

@ -9,6 +9,8 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -185,6 +187,13 @@ class CSurvey extends AbstractResource implements ResourceInterface
*/
protected bool $isMandatory = false;
/**
* @var Collection|CSurveyQuestion[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CSurveyQuestion", mappedBy="survey")
*/
protected Collection $questions;
public function __construct()
{
$this->creationDate = new DateTime();
@ -201,6 +210,7 @@ class CSurvey extends AbstractResource implements ResourceInterface
$this->surveyVersion = '';
$this->parentId = 0;
$this->surveyType = 0;
$this->questions = new ArrayCollection();
}
public function __toString(): string
@ -905,6 +915,18 @@ class CSurvey extends AbstractResource implements ResourceInterface
return $this->isMandatory;
}
public function getQuestions(): Collection
{
return $this->questions;
}
public function setQuestions(Collection $questions): self
{
$this->questions = $questions;
return $this;
}
public function getResourceIdentifier(): int
{
return $this->getIid();

@ -34,19 +34,22 @@ class CSurveyAnswer
protected int $cId;
/**
* @ORM\Column(name="survey_id", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="CSurvey")
* @ORM\JoinColumn(name="survey_id", referencedColumnName="iid")
*/
protected int $surveyId;
protected CSurvey $survey;
/**
* @ORM\Column(name="question_id", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="CSurveyQuestion", inversedBy="answers")
* @ORM\JoinColumn(name="question_id", referencedColumnName="iid")
*/
protected int $questionId;
protected CSurveyQuestion $question;
/**
* @ORM\Column(name="option_id", type="text", nullable=false)
* @ORM\ManyToOne(targetEntity="CSurveyQuestionOption")
* @ORM\JoinColumn(name="option_id", referencedColumnName="iid")
*/
protected string $optionId;
protected CSurveyQuestionOption $option;
/**
* @ORM\Column(name="value", type="integer", nullable=false)
@ -68,101 +71,68 @@ class CSurveyAnswer
}
/**
* Set surveyId.
* Set value.
*
* @param int $surveyId
* @param int $value
*
* @return CSurveyAnswer
*/
public function setSurveyId($surveyId)
public function setValue($value)
{
$this->surveyId = $surveyId;
$this->value = $value;
return $this;
}
/**
* Get surveyId.
* Get value.
*
* @return int
*/
public function getSurveyId()
public function getValue()
{
return $this->surveyId;
return $this->value;
}
public function getSurvey(): CSurvey
{
return $this->survey;
}
/**
* Set questionId.
*
* @param int $questionId
*
* @return CSurveyAnswer
*/
public function setQuestionId($questionId)
public function setSurvey(CSurvey $survey): self
{
$this->questionId = $questionId;
$this->survey = $survey;
return $this;
}
/**
* Get questionId.
*
* @return int
*/
public function getQuestionId()
public function getQuestion(): CSurveyQuestion
{
return $this->questionId;
return $this->question;
}
/**
* Set optionId.
*
* @param string $optionId
*
* @return CSurveyAnswer
*/
public function setOptionId($optionId)
public function setQuestion(CSurveyQuestion $question): self
{
$this->optionId = $optionId;
$this->question = $question;
return $this;
}
/**
* Get optionId.
*
* @return string
*/
public function getOptionId()
public function getOption(): CSurveyQuestionOption
{
return $this->optionId;
return $this->option;
}
/**
* Set value.
*
* @param int $value
*
* @return CSurveyAnswer
*/
public function setValue($value)
public function setOption(CSurveyQuestionOption $option): self
{
$this->value = $value;
$this->option = $option;
return $this;
}
/**
* Get value.
*
* @return int
*/
public function getValue()
{
return $this->value;
}
/**
* Set user.
*

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace Chamilo\CourseBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -37,26 +38,27 @@ class CSurveyQuestion
protected CSurveyQuestion $parent;
/**
* @var ArrayCollection|CSurveyQuestion[]
* @var Collection|CSurveyQuestion[]
* @ORM\OneToMany(targetEntity="CSurveyQuestion", mappedBy="parentEvent")
*/
protected $children;
protected Collection $children;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CSurveyQuestionOption")
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CSurveyQuestionOption", cascade="remove")
* @ORM\JoinColumn(name="parent_option_id", referencedColumnName="iid")
*/
protected CSurveyQuestionOption $parentOption;
/**
* @ORM\Column(name="c_id", type="integer")
* @ORM\ManyToOne(targetEntity="CSurvey", inversedBy="questions")
* @ORM\JoinColumn(name="survey_id", referencedColumnName="iid")
*/
protected int $cId;
protected CSurvey $survey;
/**
* @ORM\Column(name="survey_id", type="integer", nullable=false)
* @ORM\Column(name="c_id", type="integer")
*/
protected int $surveyId;
protected int $cId;
/**
* @Assert\NotBlank()
@ -117,6 +119,7 @@ class CSurveyQuestion
public function __construct()
{
$this->children = new ArrayCollection();
$this->surveyGroupPri = 0;
$this->surveyGroupSec1 = 0;
$this->surveyGroupSec2 = 0;
@ -127,30 +130,6 @@ class CSurveyQuestion
return $this->iid;
}
/**
* Set surveyId.
*
* @param int $surveyId
*
* @return CSurveyQuestion
*/
public function setSurveyId($surveyId)
{
$this->surveyId = $surveyId;
return $this;
}
/**
* Get surveyId.
*
* @return int
*/
public function getSurveyId()
{
return $this->surveyId;
}
/**
* Set surveyQuestion.
*
@ -433,7 +412,7 @@ class CSurveyQuestion
}
/**
* @return ArrayCollection|CSurveyQuestion[]
* @return Collection|CSurveyQuestion[]
*/
public function getChildren()
{
@ -461,4 +440,16 @@ class CSurveyQuestion
return $this;
}
public function getSurvey(): CSurvey
{
return $this->survey;
}
public function setSurvey(CSurvey $survey): self
{
$this->survey = $survey;
return $this;
}
}

@ -35,14 +35,16 @@ class CSurveyQuestionOption
protected int $cId;
/**
* @ORM\Column(name="question_id", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="CSurveyQuestion")
* @ORM\JoinColumn(name="question_id", referencedColumnName="iid")
*/
protected int $questionId;
protected CSurveyQuestion $question;
/**
* @ORM\Column(name="survey_id", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="CSurvey")
* @ORM\JoinColumn(name="survey_id", referencedColumnName="iid")
*/
protected int $surveyId;
protected CSurvey $survey;
/**
* @ORM\Column(name="option_text", type="text", nullable=false)
@ -68,54 +70,6 @@ class CSurveyQuestionOption
return $this->iid;
}
/**
* Set questionId.
*
* @param int $questionId
*
* @return CSurveyQuestionOption
*/
public function setQuestionId($questionId)
{
$this->questionId = $questionId;
return $this;
}
/**
* Get questionId.
*
* @return int
*/
public function getQuestionId()
{
return $this->questionId;
}
/**
* Set surveyId.
*
* @param int $surveyId
*
* @return CSurveyQuestionOption
*/
public function setSurveyId($surveyId)
{
$this->surveyId = $surveyId;
return $this;
}
/**
* Get surveyId.
*
* @return int
*/
public function getSurveyId()
{
return $this->surveyId;
}
/**
* Set optionText.
*
@ -211,4 +165,28 @@ class CSurveyQuestionOption
{
return $this->cId;
}
public function getQuestion(): CSurveyQuestion
{
return $this->question;
}
public function setQuestion(CSurveyQuestion $question): self
{
$this->question = $question;
return $this;
}
public function getSurvey(): CSurvey
{
return $this->survey;
}
public function setSurvey(CSurvey $survey): self
{
$this->survey = $survey;
return $this;
}
}

Loading…
Cancel
Save