Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed delete question - relation not deleted #173

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function get_lecturer_questions_relation_by_id(int $id): array {

/**
*
* Deletes lecturer_questions_relation by the relation id
* Deletes lecturer_questions_relation by the question id
*
*
* @param int $id
Expand All @@ -96,8 +96,8 @@ public static function get_lecturer_questions_relation_by_id(int $id): array {
* @throws dml_transaction_exception
*
*/
public static function delete_lecturer_questions_relation_by_id(int $id): void {
public static function delete_lecturer_questions_relation_by_question_id(int $id): void {
global $DB;
$DB->delete_records('livequiz_questions_lecturer', ['id' => $id]);
$DB->delete_records('livequiz_questions_lecturer', ['question_id' => $id]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ private static function delete_question(int $questionid): void {
$answers = questions_answers_relation::get_answers_from_question($questionid);
foreach ($answers as $answer) {
$currentanswerid = $answer->get_id();
self::delete_answer($currentanswerid, $questionid);
self::delete_answer($currentanswerid);
}
quiz_questions_relation::delete_question_quiz_relation($questionid);
livequiz_questions_lecturer_relation::delete_lecturer_questions_relation_by_id($questionid);
livequiz_questions_lecturer_relation::delete_lecturer_questions_relation_by_question_id($questionid);
question::delete_question($questionid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function test_delete_question(): void {
}

/**
* Test that deleting a question, with a relation, throws.
* Test that deleting a question, with a relation, throws an exception.
*
* @covers \mod_livequiz\services\livequiz_services::submit_quiz
* @throws dml_exception
Expand Down Expand Up @@ -500,9 +500,11 @@ public function test_delete_question_throws_if_relation_exist(): void {
array_shift($testquizsubmittedquestions);
$testquizsubmitted->set_questions($testquizsubmittedquestions);

// This sets up the test to expect the exception later in the code.
$this->expectException(dml_exception::class);
$this->expectExceptionMessage('error/Cannot delete answer with participations');

// This is the actual test where the exception is thrown.
$service->submit_quiz($testquizsubmitted, $lecturerid);
$testquizresubmittedquestions = $testquizsubmitted->get_questions();
}
Expand Down
Loading