Skip to content

Commit

Permalink
code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed May 6, 2024
1 parent 8f1109e commit f4cc004
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion classes/event/course_module_instance_list_viewed.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
namespace mod_adleradaptivity\event;

use core\event\course_module_instance_list_viewed as core_event_course_module_instance_list_viewed;

defined('MOODLE_INTERNAL') || die();

/**
* The mod_adleradaptivity instance list viewed event.
*
* @package mod_adleradaptivity
*/
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
class course_module_instance_list_viewed extends core_event_course_module_instance_list_viewed {
// No code required here as the parent class handles it all.
}
2 changes: 1 addition & 1 deletion classes/external/external_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class external_helpers {
* @throws moodle_exception
*/
public static function generate_task_response_data(question_usage_by_activity $quba, stdClass $task): object {
$status = completion_helpers::check_task_status($quba, $task);
$status = completion_helpers::check_task_status($quba, $task->id, $task->required_difficulty);
return (object)[
'uuid' => $task->uuid,
'status' => match ($status) {
Expand Down
11 changes: 6 additions & 5 deletions classes/local/completion_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class completion_helpers {
* Check if task is completed.
*
* @param question_usage_by_activity $quba The question usage object.
* @param stdClass $task The task object.
* @param string $task_id The task ID.
* @param string|null $task_required_difficulty Required difficulty of the task
*
* @return string One of the following possible result values:
* - TASK_STATUS_CORRECT
Expand All @@ -41,12 +42,12 @@ class completion_helpers {
*
* @throws moodle_exception
*/
public static function check_task_status(question_usage_by_activity $quba, stdClass $task): string {
public static function check_task_status(question_usage_by_activity $quba, string $task_id, string|null $task_required_difficulty): string {
$success = false;
$attempted = false;
$optional = $task->required_difficulty == null;
$optional = $task_required_difficulty == null;

foreach (helpers::load_questions_by_task_id($task->id) as $question) {
foreach (helpers::load_questions_by_task_id($task_id) as $question) {
// get slot of question
foreach ($quba->get_slots() as $slot) {
if ($quba->get_question($slot)->id == $question->questionid) {
Expand All @@ -72,7 +73,7 @@ public static function check_task_status(question_usage_by_activity $quba, stdCl

// if question was answered correctly and question difficulty is equal or above required_difficulty, set task_success to true
// $is_correct can't be null here anymore, just true and false are left
if ($is_correct && $question->difficulty >= $task->required_difficulty) {
if ($is_correct && $question->difficulty >= $task_required_difficulty) {
$success = true;
}
}
Expand Down

0 comments on commit f4cc004

Please sign in to comment.