diff --git a/classes/bank/question_bank_view.php b/classes/bank/question_bank_view.php index b328d1e..0af1c5e 100644 --- a/classes/bank/question_bank_view.php +++ b/classes/bank/question_bank_view.php @@ -36,7 +36,7 @@ */ class question_bank_view extends \core_question\bank\view { - protected function wanted_columns() { + protected function wanted_columns() : array { $this->requiredcolumns = [ new add_question_to_list_column($this), new checkbox_column($this), @@ -49,7 +49,7 @@ protected function wanted_columns() { return $this->requiredcolumns; } - public function render(string $tabname, int $page, int $perpage, string $category, bool $show_subcategories, bool $showhidden, bool $showquestiontext, array $tagids = []) { + public function render(string $tabname, int $page, int $perpage, string $category, bool $show_subcategories, bool $showhidden, bool $showquestiontext, array $tagids = []) : string { global $PAGE; if ($this->process_actions_needing_ui()) { return ''; diff --git a/classes/capquiz.php b/classes/capquiz.php index cc39615..c3c17c0 100644 --- a/classes/capquiz.php +++ b/classes/capquiz.php @@ -31,19 +31,23 @@ */ class capquiz { + /** @var \context_module $context */ private $context; + + /** @var \stdClass $course_module */ private $course_module; + + /** @var \stdClass $course_db_entry */ private $course_db_entry; + + /** @var \stdClass $capquiz_db_entry */ private $capquiz_db_entry; - /** - * @var output\renderer - */ + /** @var \renderer_base|output\renderer $capquiz_renderer */ private $capquiz_renderer; public function __construct(int $course_module_id) { - global $DB; - global $PAGE; + global $DB, $PAGE; $this->course_module = get_coursemodule_from_id('capquiz', $course_module_id, 0, false, MUST_EXIST); @@ -60,31 +64,31 @@ public function __construct(int $course_module_id) { /** * @throws \coding_exception */ - public static function create() { + public static function create() : capquiz { return self::create_from_id(capquiz_urls::require_course_module_id_param()); // throws if no id/cmid param } - public static function create_from_id(int $id) { + public static function create_from_id(int $id) : capquiz { return new capquiz($id); } - public function id() { + public function id() : int { return $this->capquiz_db_entry->id; } - public function name() { + public function name() : string { return $this->capquiz_db_entry->name; } - public function description() { + public function description() : string { return $this->capquiz_db_entry->description; } - public function is_published() { + public function is_published() : bool { return $this->capquiz_db_entry->published; } - public function can_publish() { + public function can_publish() : bool { if (!$this->has_question_list()) { return false; } @@ -94,23 +98,23 @@ public function can_publish() { return $this->question_list()->has_questions(); } - public function is_student() { + public function is_student() : bool { return $this->has_capability('mod/capquiz:student'); } - public function is_instructor() { + public function is_instructor() : bool { return $this->has_capability('mod/capquiz:instructor'); } - public function question_list_id() { + public function question_list_id() : int { return $this->capquiz_db_entry->question_list_id; } - public function has_question_list() { + public function has_question_list() : bool { return $this->capquiz_db_entry->question_list_id != null; } - public function assign_question_list(int $question_list_id) { + public function assign_question_list(int $question_list_id) : bool { global $DB; $this->validate_matchmaking_and_rating_systems(); $question_list = capquiz_question_list::load_any($this, $question_list_id); @@ -129,62 +133,66 @@ public function assign_question_list(int $question_list_id) { return false; } - public function publish() { - if (!$this->can_publish()) - throw new \Exception("Attempt to publish when capquiz::can_publish() returns false"); + public function publish() : bool { global $DB; + if (!$this->can_publish()) { + return false; + } $capquiz_entry = $this->capquiz_db_entry; $capquiz_entry->published = true; $capquiz_entry->question_usage_id = $this->create_question_usage(); - if ($DB->update_record(database_meta::$table_capquiz, $capquiz_entry)) { + try { + $DB->update_record(database_meta::$table_capquiz, $capquiz_entry); $this->capquiz_db_entry = $capquiz_entry; + } catch (\dml_exception $e) { + return false; } return $this->is_published(); } - public function renderer() { + public function renderer() : \renderer_base { return $this->capquiz_renderer; } - public function output() { + public function output() : \renderer_base { return $this->capquiz_renderer->output_renderer(); } - public function selection_strategy_loader() { + public function selection_strategy_loader() : capquiz_matchmaking_strategy_loader { return new capquiz_matchmaking_strategy_loader($this); } - public function selection_strategy_registry() { + public function selection_strategy_registry() : capquiz_matchmaking_strategy_registry { return new capquiz_matchmaking_strategy_registry($this); } - public function rating_system_loader() { + public function rating_system_loader() : capquiz_rating_system_loader { return new capquiz_rating_system_loader($this); } - public function rating_system_registry() { + public function rating_system_registry() : capquiz_rating_system_registry { return new capquiz_rating_system_registry($this); } - public function question_engine() { + public function question_engine() : ?capquiz_question_engine { if ($question_usage = $this->question_usage()) { return new capquiz_question_engine($this, $question_usage, $this->selection_strategy_loader(), $this->rating_system_loader()); } return null; } - public function question_registry() { + public function question_registry() : capquiz_question_registry { return new capquiz_question_registry($this); } - public function question_list() { + public function question_list() : ?capquiz_question_list { if ($this->has_question_list()) { return capquiz_question_list::load_question_list($this, $this->question_list_id()); } return null; } - public function question_usage() { + public function question_usage() : ?\question_usage_by_activity { if (!$this->has_question_list()) { return null; } @@ -194,52 +202,52 @@ public function question_usage() { return \question_engine::load_questions_usage_by_activity($this->capquiz_db_entry->question_usage_id); } - public function user() { + public function user() : capquiz_user { global $USER; return capquiz_user::load_user($this, $USER->id); } - public function default_user_rating() { + public function default_user_rating() : float { return $this->capquiz_db_entry->default_user_rating; } - public function context() { + public function context() : \context_module { return $this->context; } - public function course_module() { + public function course_module() : \stdClass { return $this->course_module; } - public function course_module_id() { + public function course_module_id() : int { return $this->course_module->id; } - public function course() { + public function course() : \stdClass { return $this->course_db_entry; } - public function require_student_capability() { + public function require_student_capability() : void { require_capability('mod/capquiz:student', $this->context); } - public function require_instructor_capability() { + public function require_instructor_capability() : void { require_capability('mod/capquiz:instructor', $this->context); } - public function require_capability(string $capability) { + public function require_capability(string $capability) : void { require_capability($capability, $this->context); } - public function has_capability(string $capability) { + public function has_capability(string $capability) : bool { return has_capability($capability, $this->context); } - public function user_has_capability(string $capability, int $user_id) { + public function user_has_capability(string $capability, int $user_id) : bool { return has_capability($capability, $this->context, $user_id); } - public function configure(\stdClass $configuration) { + public function configure(\stdClass $configuration) : void { global $DB; $db_entry = $this->capquiz_db_entry; if ($name = $configuration->name) { @@ -248,22 +256,27 @@ public function configure(\stdClass $configuration) { if ($default_user_rating = $configuration->default_user_rating) { $db_entry->default_user_rating = $default_user_rating; } - if ($DB->update_record(database_meta::$table_capquiz, $db_entry)) { + try { + $DB->update_record(database_meta::$table_capquiz, $db_entry); $this->capquiz_db_entry = $db_entry; + } catch (\dml_exception $e) { } } - private function create_question_usage() { + private function create_question_usage() : int { $question_usage = \question_engine::make_questions_usage_by_activity('mod_capquiz', $this->context()); $question_usage->set_preferred_behaviour('immediatefeedback'); - \question_engine::save_questions_usage_by_activity($question_usage); + // TODO: Don't suppress the error if it becomes possible to save QUBAs without slots. + @\question_engine::save_questions_usage_by_activity($question_usage); return $question_usage->get_id(); } - private function validate_matchmaking_and_rating_systems() { - if (!$this->rating_system_loader()->has_rating_system()) + private function validate_matchmaking_and_rating_systems() : void { + if (!$this->rating_system_loader()->has_rating_system()) { $this->rating_system_loader()->set_default_rating_system(); - if (!$this->selection_strategy_loader()->has_strategy()) + } + if (!$this->selection_strategy_loader()->has_strategy()) { $this->selection_strategy_loader()->set_default_strategy(); + } } } diff --git a/classes/capquiz_matchmaking_strategy.php b/classes/capquiz_matchmaking_strategy.php index eb3ee5a..55e5a1b 100644 --- a/classes/capquiz_matchmaking_strategy.php +++ b/classes/capquiz_matchmaking_strategy.php @@ -26,11 +26,12 @@ */ abstract class capquiz_matchmaking_strategy { - public abstract function configure(\stdClass $configuration); + public abstract function configure(\stdClass $configuration) : void; - public abstract function configuration(); + public abstract function configuration() : ?\stdClass; - public abstract function default_configuration(); + public abstract function default_configuration() : ?\stdClass; - public abstract function next_question_for_user(capquiz_user $user, capquiz_question_list $question_list, array $inactive_capquiz_attempts); -} \ No newline at end of file + public abstract function next_question_for_user(capquiz_user $user, capquiz_question_list $question_list, array $inactive_capquiz_attempts) : ?capquiz_question; + +} diff --git a/classes/capquiz_matchmaking_strategy_loader.php b/classes/capquiz_matchmaking_strategy_loader.php index e6ca273..0a3d631 100644 --- a/classes/capquiz_matchmaking_strategy_loader.php +++ b/classes/capquiz_matchmaking_strategy_loader.php @@ -17,7 +17,6 @@ namespace mod_capquiz; require_once($CFG->dirroot . '/mod/capquiz/classes/matchmaking/capquiz_matchmaking_strategy_registry.php'); - require_once($CFG->dirroot . '/mod/capquiz/classes/matchmaking/chronologic/chronologic_selector.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/matchmaking/n_closest/n_closest_selector.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/matchmaking/n_closest/n_closest_configuration_form.php'); @@ -32,9 +31,16 @@ */ class capquiz_matchmaking_strategy_loader { + /** @var capquiz $capquiz */ private $capquiz; + + /** @var \stdClass $db_entry */ private $db_entry; + + /** @var capquiz_matchmaking_strategy_registry $registry */ private $registry; + + /** @var \stdClass $configuration */ private $configuration; public function __construct(capquiz $capquiz) { @@ -43,7 +49,7 @@ public function __construct(capquiz $capquiz) { $this->load_configuration(); } - public function selector() { + public function selector() : ?capquiz_matchmaking_strategy { if ($db_entry = $this->db_entry) { $strategy = $this->registry->selector($db_entry->strategy); if ($config = $this->configuration) { @@ -54,7 +60,7 @@ public function selector() { return null; } - public function configuration_form(\moodle_url $url) { + public function configuration_form(\moodle_url $url) : ?\moodleform { if ($db_entry = $this->db_entry) { if ($config = $this->configuration) { return $this->registry->configuration_form($db_entry->strategy, $config, $url); @@ -63,21 +69,21 @@ public function configuration_form(\moodle_url $url) { return null; } - public function has_strategy() { + public function has_strategy() : bool { if ($db_entry = $this->db_entry) { return $this->selector() != null; } return false; } - public function current_strategy_name() { + public function current_strategy_name() : string { if ($db_entry = $this->db_entry) { return $db_entry->strategy; } - return "No strategy specified"; + return 'No strategy specified'; } - public function configure_current_strategy(\stdClass $candidate_configuration) { + public function configure_current_strategy(\stdClass $candidate_configuration) : void { if ($db_entry = $this->db_entry) { $selector = $this->selector($db_entry->strategy); $selector->configure($candidate_configuration); @@ -90,11 +96,11 @@ public function configure_current_strategy(\stdClass $candidate_configuration) { } } - public function set_default_strategy() { + public function set_default_strategy() : void { $this->set_strategy($this->registry->default_selection_strategy()); } - public function set_strategy(string $strategy) { + public function set_strategy(string $strategy) : void { $selector = $this->registry->selector($strategy); $db_entry = new \stdClass; $db_entry->strategy = $strategy; @@ -114,18 +120,17 @@ public function set_strategy(string $strategy) { } } - private function load_configuration() { + private function load_configuration() : void { + global $DB; $conditions = [ database_meta::$field_capquiz_id => $this->capquiz->id() ]; - global $DB; if ($configuration = $DB->get_record(database_meta::$table_capquiz_question_selection, $conditions)) { $this->set_configuration($configuration); } } - private function update_configuration(\stdClass $configuration) { - + private function update_configuration(\stdClass $configuration) : void { global $DB; if ($DB->update_record(database_meta::$table_capquiz_question_selection, $configuration)) { $this->set_configuration($configuration); @@ -141,11 +146,12 @@ private function set_configuration(\stdClass $database_entry) { } } - private function serialize(\stdClass $configuration) { + private function serialize(\stdClass $configuration) : string { return json_encode($configuration); } - private function deserialize(string $configuration) { - return json_decode($configuration); + private function deserialize(string $configuration) : ?\stdClass { + return json_decode($configuration, false); } + } diff --git a/classes/capquiz_question.php b/classes/capquiz_question.php index 9cb443d..6e46fdc 100644 --- a/classes/capquiz_question.php +++ b/classes/capquiz_question.php @@ -26,6 +26,7 @@ */ class capquiz_question { + /** @var \stdClass $db_entry */ private $db_entry; public function __construct(\stdClass $db_entry) { @@ -43,33 +44,34 @@ public function __construct(\stdClass $db_entry) { } } - public static function load(int $question_id) { + public static function load(int $question_id) : ?capquiz_question { global $DB; $entry = $DB->get_record(database_meta::$table_capquiz_question, [ database_meta::$field_id => $question_id ]); - if ($entry) - return new capquiz_question($entry); - return null; + if ($entry === false) { + return null; + } + return new capquiz_question($entry); } - public function id() { + public function id() : int { return $this->db_entry->id; } - public function question_id() { + public function question_id() : int { return $this->db_entry->question_id; } - public function question_list_id() { + public function question_list_id() : int { return $this->db_entry->question_list_id; } - public function rating() { + public function rating() : float { return $this->db_entry->rating; } - public function set_rating(float $rating) { + public function set_rating(float $rating) : bool { global $DB; $db_entry = $this->db_entry; $db_entry->rating = $rating; @@ -80,11 +82,11 @@ public function set_rating(float $rating) { return false; } - public function name() { + public function name() : string { return $this->db_entry->name; } - public function text() { + public function text() : string { return $this->db_entry->text; } diff --git a/classes/capquiz_question_attempt.php b/classes/capquiz_question_attempt.php index 8cd5dd9..8f6cc64 100644 --- a/classes/capquiz_question_attempt.php +++ b/classes/capquiz_question_attempt.php @@ -16,8 +16,6 @@ namespace mod_capquiz; -use core\session\database; - defined('MOODLE_INTERNAL') || die(); /** @@ -28,7 +26,10 @@ */ class capquiz_question_attempt { + /** @var \stdClass $db_entry */ private $db_entry; + + /** @var \question_usage_by_activity $question_usage */ private $question_usage; public function __construct(\question_usage_by_activity $question_usage, \stdClass $db_entry) { @@ -36,12 +37,13 @@ public function __construct(\question_usage_by_activity $question_usage, \stdCla $this->question_usage = $question_usage; } - public static function create_attempt(capquiz $capquiz, capquiz_user $user, capquiz_question $question) { + public static function create_attempt(capquiz $capquiz, capquiz_user $user, capquiz_question $question) : ?capquiz_question_attempt { $question_usage = $capquiz->question_usage(); $questions = question_load_questions([$question->question_id()]); $target_question = reset($questions); - if (!$target_question) + if (!$target_question) { return null; + } $question_definition = \question_bank::make_question($target_question); $slot = $question_usage->add_question($question_definition); $question_usage->start_question($slot); @@ -49,31 +51,35 @@ public static function create_attempt(capquiz $capquiz, capquiz_user $user, capq return self::insert_attempt_entry($capquiz, $user, $question, $slot); } - public static function active_attempt(capquiz $capquiz, capquiz_user $user) { + public static function active_attempt(capquiz $capquiz, capquiz_user $user) : ?capquiz_question_attempt { global $DB; $criteria = [ database_meta::$field_user_id => $user->id(), database_meta::$field_reviewed => false ]; - if ($entry = $DB->get_record(database_meta::$table_capquiz_attempt, $criteria)) { + try { + $entry = $DB->get_record(database_meta::$table_capquiz_attempt, $criteria, '*', MUST_EXIST); return new capquiz_question_attempt($capquiz->question_usage(), $entry); + } catch (\dml_exception $e) { + return null; } - return null; } - public static function load_attempt(capquiz $capquiz, capquiz_user $user, int $attempt_id) { + public static function load_attempt(capquiz $capquiz, capquiz_user $user, int $attempt_id) : ?capquiz_question_attempt { global $DB; $criteria = [ database_meta::$field_id => $attempt_id, database_meta::$field_user_id => $user->id() ]; - if ($entry = $DB->get_record(database_meta::$table_capquiz_attempt, $criteria)) { + try { + $entry = $DB->get_record(database_meta::$table_capquiz_attempt, $criteria, '*', MUST_EXIST); return new capquiz_question_attempt($capquiz->question_usage(), $entry); + } catch (\dml_exception $e) { + return null; } - return null; } - public static function previous_attempt(capquiz $capquiz, capquiz_user $user) { + public static function previous_attempt(capquiz $capquiz, capquiz_user $user) : ?capquiz_question_attempt { global $DB; $table = database_meta::$table_capquiz_attempt; $target_field = database_meta::$field_user_id; @@ -82,16 +88,14 @@ public static function previous_attempt(capquiz $capquiz, capquiz_user $user) { $sql = "SELECT * FROM {" . $table . "} WHERE $target_field=$userid"; $sql .= " ORDER BY $sort_field DESC LIMIT 1;"; try { - if ($question_db_entry = $DB->get_record_sql($sql)) { - return new capquiz_question_attempt($capquiz->question_usage(), $question_db_entry); - } - } catch (\Exception $e) { - throw e; + $question_db_entry = $DB->get_record_sql($sql, null, MUST_EXIST); + return new capquiz_question_attempt($capquiz->question_usage(), $question_db_entry); + } catch (\dml_exception $e) { + return null; } - return null; } - public static function inactive_attempts(capquiz $capquiz, capquiz_user $user) { + public static function inactive_attempts(capquiz $capquiz, capquiz_user $user) : array { global $DB; $records = []; $criteria = [ @@ -105,31 +109,31 @@ public static function inactive_attempts(capquiz $capquiz, capquiz_user $user) { return $records; } - public function id() { + public function id() : int { return $this->db_entry->id; } - public function moodle_attempt_id() { + public function moodle_attempt_id() : int { return $this->db_entry->attempt_id; } - public function question_id() { + public function question_id() : int { return $this->db_entry->question_id; } - public function question_slot() { + public function question_slot() : int { return $this->db_entry->slot; } - public function question_usage() { + public function question_usage() : \question_usage_by_activity { return $this->question_usage; } - public function is_answered() { + public function is_answered() : bool { return $this->db_entry->answered; } - public function is_correctly_answered() { + public function is_correctly_answered() : bool { if (!$this->is_answered()) { return false; } @@ -137,15 +141,15 @@ public function is_correctly_answered() { return $moodle_attempt->get_state()->is_correct(); } - public function is_reviewed() { + public function is_reviewed() : bool { return $this->db_entry->reviewed; } - public function is_pending() { + public function is_pending() : bool { return !$this->is_reviewed(); } - public function mark_as_answered() { + public function mark_as_answered() : bool { global $DB; $submitteddata = $this->question_usage->extract_responses($this->question_slot(), $_POST); $this->question_usage->process_action($this->question_slot(), $submitteddata); @@ -155,46 +159,39 @@ public function mark_as_answered() { $this->question_usage->finish_question($this->question_slot(), time()); \question_engine::save_questions_usage_by_activity($this->question_usage); try { - if ($DB->update_record(database_meta::$table_capquiz_attempt, $db_entry)) { - $this->db_entry = $db_entry; - } else { - throw new \Exception("Unable to mark attempt as answered"); - } - } catch (\Exception $e) { - throw $e; + $DB->update_record(database_meta::$table_capquiz_attempt, $db_entry); + $this->db_entry = $db_entry; + return true; + } catch (\dml_exception $e) { + return false; } } - public function mark_as_reviewed() { + public function mark_as_reviewed() : bool { global $DB; $db_entry = $this->db_entry; $db_entry->reviewed = true; $db_entry->time_reviewed = time(); try { - if ($DB->update_record(database_meta::$table_capquiz_attempt, $db_entry)) { - $this->db_entry = $db_entry; - } else { - throw new \Exception("Unable to mark attempt as reviewed"); - } - } catch (\Exception $e) { - throw $e; + $DB->update_record(database_meta::$table_capquiz_attempt, $db_entry); + $this->db_entry = $db_entry; + return true; + } catch (\dml_exception $e) { + return false; } } - private static function insert_attempt_entry(capquiz $capquiz, capquiz_user $user, capquiz_question $question, int $slot) { + private static function insert_attempt_entry(capquiz $capquiz, capquiz_user $user, capquiz_question $question, int $slot) : ?capquiz_question_attempt { + global $DB; $attempt_entry = new \stdClass(); $attempt_entry->slot = $slot; $attempt_entry->user_id = $user->id(); $attempt_entry->question_id = $question->id(); - global $DB; try { - if ($DB->insert_record(database_meta::$table_capquiz_attempt, $attempt_entry)) { - return self::active_attempt($capquiz, $user); - } else { - throw new \Exception("Unable to store new attempt"); - } - } catch (\Exception $e) { - throw $e; + $DB->insert_record(database_meta::$table_capquiz_attempt, $attempt_entry); + return self::active_attempt($capquiz, $user); + } catch (\dml_exception $e) { + return null; } } diff --git a/classes/capquiz_question_engine.php b/classes/capquiz_question_engine.php index 3aede5b..b0f81f0 100644 --- a/classes/capquiz_question_engine.php +++ b/classes/capquiz_question_engine.php @@ -25,9 +25,17 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class capquiz_question_engine { + + /** @var capquiz $capquiz */ private $capquiz; + + /** @var \question_usage_by_activity $question_usage */ private $question_usage; + + /** @var capquiz_matchmaking_strategy_loader $matchmaking_loader */ private $matchmaking_loader; + + /** @var capquiz_rating_system_loader $rating_system_loader */ private $rating_system_loader; public function __construct(capquiz $capquiz, \question_usage_by_activity $question_usage, capquiz_matchmaking_strategy_loader $strategy_loader, capquiz_rating_system_loader $rating_system_loder) { @@ -37,7 +45,7 @@ public function __construct(capquiz $capquiz, \question_usage_by_activity $quest $this->rating_system_loader = $rating_system_loder; } - public function user_is_completed(capquiz_user $user) { + public function user_is_completed(capquiz_user $user) : bool { if ($attempt = capquiz_question_attempt::active_attempt($this->capquiz, $user)) { return false; } @@ -47,18 +55,18 @@ public function user_is_completed(capquiz_user $user) { return true; } - public function attempt_for_user(capquiz_user $user) { + public function attempt_for_user(capquiz_user $user) : ?capquiz_question_attempt { if ($attempt = capquiz_question_attempt::active_attempt($this->capquiz, $user)) { return $attempt; } return $this->new_attempt_for_user($user); } - public function attempt_for_current_user() { + public function attempt_for_current_user() : ?capquiz_question_attempt { return $this->attempt_for_user($this->capquiz->user()); } - public function attempt_answered(capquiz_user $user, capquiz_question_attempt $attempt) { + public function attempt_answered(capquiz_user $user, capquiz_question_attempt $attempt) : void { $rating_system = $this->rating_system_loader->rating_system(); $attempt->mark_as_answered(); $question = $this->capquiz->question_list()->question($attempt->question_id()); @@ -73,10 +81,10 @@ public function attempt_answered(capquiz_user $user, capquiz_question_attempt $a } } - private function set_new_highest_level_if_attained(capquiz_user $user) { + private function set_new_highest_level_if_attained(capquiz_user $user) : void { $list = $this->capquiz->question_list(); for ($level = $list->level_count(); $level > 0; $level--) { - $required = $list->level_rating($level); + $required = $list->required_rating_for_level($level); if ($user->rating() >= $required) { if ($user->highest_level() < $level) { $user->set_highest_level($level); @@ -86,23 +94,25 @@ private function set_new_highest_level_if_attained(capquiz_user $user) { } } - public function attempt_reviewed(capquiz_user $user, capquiz_question_attempt $attempt) { + public function attempt_reviewed(capquiz_user $user, capquiz_question_attempt $attempt) : void { $attempt->mark_as_reviewed(); } - private function new_attempt_for_user(capquiz_user $user) { + private function new_attempt_for_user(capquiz_user $user) : ?capquiz_question_attempt { if ($question = $this->find_question_for_user($user)) { return capquiz_question_attempt::create_attempt($this->capquiz, $user, $question); } return null; } - private function find_question_for_user(capquiz_user $user) { - $question_selector = $this->matchmaking_loader->selector(); - return $question_selector->next_question_for_user($user, $this->capquiz->question_list(), capquiz_question_attempt::inactive_attempts($this->capquiz, $user)); + private function find_question_for_user(capquiz_user $user) : ?capquiz_question { + $selector = $this->matchmaking_loader->selector(); + $questionlist = $this->capquiz->question_list(); + $inactiveattempts = capquiz_question_attempt::inactive_attempts($this->capquiz, $user); + return $selector->next_question_for_user($user, $questionlist, $inactiveattempts); } - private function update_question_rating(capquiz_question_attempt $previous, capquiz_question_attempt $current) { + private function update_question_rating(capquiz_question_attempt $previous, capquiz_question_attempt $current) : void { $rating_system = $this->rating_system_loader->rating_system(); $current_correct = $current->is_correctly_answered(); $previous_correct = $previous->is_correctly_answered(); diff --git a/classes/capquiz_question_list.php b/classes/capquiz_question_list.php index 2f492eb..cc27c8e 100644 --- a/classes/capquiz_question_list.php +++ b/classes/capquiz_question_list.php @@ -16,8 +16,6 @@ namespace mod_capquiz; -use core\session\database; - defined('MOODLE_INTERNAL') || die(); /** @@ -50,11 +48,11 @@ public function __construct(\stdClass $db_entry, capquiz $capquiz) { } } - public function id() { + public function id() : int { return $this->db_entry->id; } - public function author() { + public function author() : ?\stdClass { global $DB; $criteria = [ database_meta::$field_id => $this->db_entry->author @@ -66,48 +64,43 @@ public function author() { } } - public function can_create_template() { + public function can_create_template() : bool { return $this->has_questions(); } - public function has_questions() { + public function has_questions() : bool { return count($this->questions) > 0; } - public function is_template() { + public function is_template() : bool { return $this->db_entry->is_template; } - public function capquiz_origin_id() { + public function capquiz_origin_id() : int { return $this->db_entry->capquiz_origin_id; } - public function default_question_rating() { + public function default_question_rating() : float { return $this->db_entry->default_question_rating; } - public function title() { + public function title() : string { return $this->db_entry->title; } - public function description() { + public function description() : string { return $this->db_entry->description; } - public function first_level() { + public function first_level() : int { return 1; } - public function level_count() { + public function level_count() : int { return 5; } - /** - * Get the rating required to earn a badge for the specified level. - * @param int $level - * @return int | null - */ - public function level_rating(int $level) { + public function required_rating_for_level(int $level) : ?int { $field = "level_{$level}_rating"; if (!isset($this->db_entry->{$field})) { return null; @@ -115,14 +108,14 @@ public function level_rating(int $level) { return (int)$this->db_entry->{$field}; } - public function set_level_rating(int $level, int $rating) { + public function set_level_rating(int $level, int $rating) : void { $db_entry = $this->db_entry; $field = "level_{$level}_rating"; $db_entry->{$field} = $rating; $this->update_database($db_entry); } - public function set_level_ratings(array $ratings) { + public function set_level_ratings(array $ratings) : void { $counts = count($ratings); if ($counts !== $this->level_count()) { throw new \Exception("Wrong number of ratings specified for badges: $counts given and " . $this->level_count() . ' required'); @@ -137,24 +130,24 @@ public function set_level_ratings(array $ratings) { $this->update_database($db_entry); } - public function user_level(capquiz_user $user) { + public function user_level(capquiz_user $user) : int { $stars = 0; for ($level = 1; $level < 6; $level++) { - if ($user->rating() >= $this->level_rating($level)) { + if ($user->rating() >= $this->required_rating_for_level($level)) { $stars++; } } return $stars; } - public function next_level_percent(int $rating) { + public function next_level_percent(int $rating) : int { $goal = 0; for ($level = 1; $level < 6; $level++) { - $goal = $this->level_rating($level); + $goal = $this->required_rating_for_level($level); if ($goal > $rating) { $previous = $this->capquiz->default_user_rating(); if ($level > 1) { - $previous = $this->level_rating($level - 1); + $previous = $this->required_rating_for_level($level - 1); } $rating -= $previous; $goal -= $previous; @@ -167,23 +160,26 @@ public function next_level_percent(int $rating) { return (int)($rating / $goal * 100); } - public function time_created() { + public function time_created() : string { return $this->db_entry->time_created; } - public function time_modified() { + public function time_modified() : string { return $this->db_entry->time_modified; } - public function question_count() { + public function question_count() : int { return count($this->questions); } - public function questions() { + /** + * @return capquiz_question[] + */ + public function questions() : array { return $this->questions; } - public function question(string $question_id) { + public function question(int $question_id) : ?capquiz_question { foreach ($this->questions as $question) { if ($question->id() === $question_id) { return $question; @@ -192,7 +188,7 @@ public function question(string $question_id) { return null; } - public static function load_question_list(capquiz $capquiz, int $question_list_id) { + public static function load_question_list(capquiz $capquiz, int $question_list_id) : ?capquiz_question_list { global $DB; $conditions = [database_meta::$field_id => $question_list_id, database_meta::$field_is_template => 0]; if ($entry = $DB->get_record(database_meta::$table_capquiz_question_list, $conditions)) { @@ -201,7 +197,7 @@ public static function load_question_list(capquiz $capquiz, int $question_list_i return null; } - public static function load_question_template(capquiz $capquiz, int $question_list_id) { + public static function load_question_template(capquiz $capquiz, int $question_list_id) : ?capquiz_question_list { $conditions = [database_meta::$field_id => $question_list_id, database_meta::$field_is_template => 1]; global $DB; if ($entry = $DB->get_record(database_meta::$table_capquiz_question_list, $conditions)) { @@ -210,7 +206,7 @@ public static function load_question_template(capquiz $capquiz, int $question_li return null; } - public static function load_any(capquiz $capquiz, int $question_list_id) { + public static function load_any(capquiz $capquiz, int $question_list_id) : ?capquiz_question_list { global $DB; $conditions = [database_meta::$field_id => $question_list_id]; if ($entry = $DB->get_record(database_meta::$table_capquiz_question_list, $conditions)) { @@ -219,15 +215,15 @@ public static function load_any(capquiz $capquiz, int $question_list_id) { return null; } - public static function load_question_lists(capquiz $capquiz) { + public static function load_question_lists(capquiz $capquiz) : array { return capquiz_question_list::load_question_lists_from_criteria($capquiz, [database_meta::$field_is_template => 0]); } - public static function load_question_list_templates(capquiz $capquiz) { + public static function load_question_list_templates(capquiz $capquiz) : array { return capquiz_question_list::load_question_lists_from_criteria($capquiz, [database_meta::$field_is_template => 1]); } - public static function copy(capquiz_question_list $question_list, bool $insert_as_template) { + public static function copy(capquiz_question_list $question_list, bool $insert_as_template) : int { global $DB; $question_list_entry = $question_list->db_entry; $question_list_id = $question_list_entry->id; @@ -250,14 +246,14 @@ public static function copy(capquiz_question_list $question_list, bool $insert_a } } - private function update_database(\stdClass $db_entry) { + private function update_database(\stdClass $db_entry) : void { global $DB; if ($DB->update_record(database_meta::$table_capquiz_question_list, $db_entry)) { $this->db_entry = $db_entry; } } - private static function load_question_lists_from_criteria(capquiz $capquiz, array $conditions) { + private static function load_question_lists_from_criteria(capquiz $capquiz, array $conditions) : array { global $DB; $lists = []; $records = $DB->get_records(database_meta::$table_capquiz_question_list, $conditions); diff --git a/classes/capquiz_question_registry.php b/classes/capquiz_question_registry.php index c7b9255..e85c93b 100644 --- a/classes/capquiz_question_registry.php +++ b/classes/capquiz_question_registry.php @@ -26,17 +26,18 @@ */ class capquiz_question_registry { + /** @var capquiz $capquiz */ private $capquiz; public function __construct(capquiz $capquiz) { $this->capquiz = $capquiz; } - public function capquiz_instance() { + public function capquiz_instance() : capquiz { return $this->capquiz; } - public function question_ids(int $question_list_id) { + public function question_ids(int $question_list_id) : array { $questions = $this->question_list($question_list_id)->questions(); $ret = []; foreach ($questions as $question) { @@ -45,8 +46,8 @@ public function question_ids(int $question_list_id) { return $ret; } - public function question_list(int $list_id) { - return capquiz_question_list::load_question_list($list_id); + public function question_list(int $list_id) : ?capquiz_question_list { + return capquiz_question_list::load_question_list($this->capquiz, $list_id); } /** diff --git a/classes/capquiz_rating_system.php b/classes/capquiz_rating_system.php index 95d7213..29a337a 100644 --- a/classes/capquiz_rating_system.php +++ b/classes/capquiz_rating_system.php @@ -28,12 +28,12 @@ abstract class capquiz_rating_system { public abstract function configure(\stdClass $configuration); - public abstract function configuration(); + public abstract function configuration() : ?\stdClass; - public abstract function default_configuration(); + public abstract function default_configuration() : ?\stdClass; - public abstract function update_user_rating(capquiz_user $user, capquiz_question $question, float $score); + public abstract function update_user_rating(capquiz_user $user, capquiz_question $question, float $score) : void; - public abstract function question_victory_ratings(capquiz_question $winner, capquiz_question $loser); + public abstract function question_victory_ratings(capquiz_question $winner, capquiz_question $loser) : void; } diff --git a/classes/capquiz_rating_system_loader.php b/classes/capquiz_rating_system_loader.php index 13cbe90..cef9776 100644 --- a/classes/capquiz_rating_system_loader.php +++ b/classes/capquiz_rating_system_loader.php @@ -17,7 +17,6 @@ namespace mod_capquiz; require_once($CFG->dirroot . '/mod/capquiz/classes/rating_system/capquiz_rating_system_registry.php'); - require_once($CFG->dirroot . '/mod/capquiz/classes/rating_system/elo_rating/elo_rating_system.php'); defined('MOODLE_INTERNAL') || die(); @@ -30,9 +29,16 @@ */ class capquiz_rating_system_loader { + /** @var capquiz $capquiz */ private $capquiz; + + /** @var \stdClass $db_entry */ private $db_entry; + + /** @var capquiz_rating_system_registry $registry */ private $registry; + + /** @var \stdClass $configuration */ private $configuration; public function __construct(capquiz $capquiz) { @@ -41,18 +47,18 @@ public function __construct(capquiz $capquiz) { $this->load_configuration(); } - public function rating_system() { + public function rating_system() : ?capquiz_rating_system { if ($db_entry = $this->db_entry) { - $rating_system = $this->registry->rating_system($db_entry->rating_system); + $system = $this->registry->rating_system($db_entry->rating_system); if ($config = $this->configuration) { - $rating_system->configure($config); + $system->configure($config); } - return $rating_system; + return $system; } return null; } - public function configuration_form(\moodle_url $url) { + public function configuration_form(\moodle_url $url) : ?\moodleform { if ($db_entry = $this->db_entry) { if ($config = $this->configuration) { return $this->registry->configuration_form($db_entry->rating_system, $config, $url); @@ -61,21 +67,21 @@ public function configuration_form(\moodle_url $url) { return null; } - public function has_rating_system() { + public function has_rating_system() : bool { if ($db_entry = $this->db_entry) { return $this->rating_system() != null; } return false; } - public function current_rating_system_name() { + public function current_rating_system_name() : string { if ($db_entry = $this->db_entry) { return $db_entry->rating_system; } - return "No rating system specified"; + return 'No rating system specified'; } - public function configure_current_rating_system(\stdClass $candidate_configuration) { + public function configure_current_rating_system(\stdClass $candidate_configuration) : void { if ($db_entry = $this->db_entry) { $system = $this->rating_system($db_entry->rating_system); $system->configure($candidate_configuration); @@ -88,11 +94,11 @@ public function configure_current_rating_system(\stdClass $candidate_configurati } } - public function set_default_rating_system() { + public function set_default_rating_system() : void { $this->set_rating_system($this->registry->default_rating_system()); } - public function set_rating_system(string $rating_system) { + public function set_rating_system(string $rating_system) : void { $system = $this->registry->rating_system($rating_system); $db_entry = new \stdClass; $db_entry->rating_system = $rating_system; @@ -112,38 +118,37 @@ public function set_rating_system(string $rating_system) { } } - private function load_configuration() { + private function load_configuration() : void { + global $DB; $conditions = [ database_meta::$field_capquiz_id => $this->capquiz->id() ]; - global $DB; if ($configuration = $DB->get_record(database_meta::$table_capquiz_rating_system, $conditions)) { $this->set_configuration($configuration); } } - private function update_configuration(\stdClass $configuration) { - + private function update_configuration(\stdClass $configuration) : void { global $DB; if ($DB->update_record(database_meta::$table_capquiz_rating_system, $configuration)) { $this->set_configuration($configuration); } } - private function set_configuration(\stdClass $database_entry) { - $this->db_entry = $database_entry; - if ($configuration = $this->deserialize($database_entry->configuration)) { + private function set_configuration(\stdClass $db_entry) : void { + $this->db_entry = $db_entry; + if ($configuration = $this->deserialize($db_entry->configuration)) { $this->configuration = $configuration; } else { $this->configuration = null; } } - private function serialize(\stdClass $configuration) { + private function serialize(\stdClass $configuration) : string { return json_encode($configuration); } - private function deserialize(string $configuration) { - return json_decode($configuration); + private function deserialize(string $configuration) : ?\stdClass { + return json_decode($configuration, false); } } diff --git a/classes/capquiz_user.php b/classes/capquiz_user.php index 17ed78b..551554f 100644 --- a/classes/capquiz_user.php +++ b/classes/capquiz_user.php @@ -25,7 +25,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class capquiz_user { + + /** @var \stdClass $db_entry */ private $db_entry; + + /** @var \stdClass $moodle_db_entry */ private $moodle_db_entry; public function __construct(\stdClass $user_db_entry) { @@ -33,14 +37,14 @@ public function __construct(\stdClass $user_db_entry) { $this->moodle_db_entry = null; } - public static function load_user(capquiz $capquiz, int $moodle_userid) { + public static function load_user(capquiz $capquiz, int $moodle_userid) : ?capquiz_user { if ($user = self::load_db_entry($capquiz, $moodle_userid)) { return $user; } return self::insert_db_entry($capquiz, $moodle_userid); } - public static function user_count(capquiz $capquiz) { + public static function user_count(capquiz $capquiz) : int { global $DB; $criteria = [ database_meta::$field_capquiz_id => $capquiz->id() @@ -49,7 +53,7 @@ public static function user_count(capquiz $capquiz) { return $count; } - public static function list_users(capquiz $capquiz) { + public static function list_users(capquiz $capquiz) : array { global $DB; $criteria = [ database_meta::$field_capquiz_id => $capquiz->id() @@ -61,45 +65,48 @@ public static function list_users(capquiz $capquiz) { return $users; } - public function id() { + public function id() : int { return $this->db_entry->id; } - public function username() { - if ($this->moodle_db_entry === null) + public function username() : string { + if ($this->moodle_db_entry === null) { $this->load_moodle_entry(); + } return $this->moodle_db_entry->username; } - public function first_name() { - if ($this->moodle_db_entry === null) + public function first_name() : string { + if ($this->moodle_db_entry === null) { $this->load_moodle_entry(); + } return $this->moodle_db_entry->firstname; } - public function last_name() { - if ($this->moodle_db_entry === null) + public function last_name() : string { + if ($this->moodle_db_entry === null) { $this->load_moodle_entry(); + } return $this->moodle_db_entry->lastname; } - public function capquiz_id() { + public function capquiz_id() : int { return $this->db_entry->capquiz_id; } - public function moodle_user_id() { + public function moodle_user_id() : int { return $this->db_entry->user_id; } - public function rating() { + public function rating() : float { return $this->db_entry->rating; } - public function highest_level() { + public function highest_level() : int { return $this->db_entry->highest_level; } - public function set_highest_level(int $highest_level) { + public function set_highest_level(int $highest_level) : void { global $DB; $db_entry = $this->db_entry; $db_entry->highest_level = $highest_level; @@ -108,7 +115,7 @@ public function set_highest_level(int $highest_level) { } } - public function set_rating(float $rating) { + public function set_rating(float $rating) : void { global $DB; $db_entry = $this->db_entry; $db_entry->rating = $rating; @@ -117,7 +124,7 @@ public function set_rating(float $rating) { } } - private function load_moodle_entry() { + private function load_moodle_entry() : void { global $DB; $criteria = [ database_meta::$field_id => $this->moodle_user_id() @@ -129,7 +136,7 @@ private function load_moodle_entry() { } } - private static function load_db_entry(capquiz $capquiz, int $moodle_userid) { + private static function load_db_entry(capquiz $capquiz, int $moodle_userid) : ?capquiz_user { global $DB; $criteria = [ database_meta::$field_user_id => $moodle_userid, @@ -141,7 +148,7 @@ private static function load_db_entry(capquiz $capquiz, int $moodle_userid) { return null; } - private static function insert_db_entry(capquiz $capquiz, int $moodle_userid) { + private static function insert_db_entry(capquiz $capquiz, int $moodle_userid) : ?capquiz_user { global $DB; $user_entry = new \stdClass(); $user_entry->user_id = $moodle_userid; @@ -158,4 +165,5 @@ private static function insert_db_entry(capquiz $capquiz, int $moodle_userid) { throw $e; } } + } diff --git a/classes/form/view/badge_rating_configuration_form.php b/classes/form/view/badge_rating_configuration_form.php index 7ed943e..304467d 100644 --- a/classes/form/view/badge_rating_configuration_form.php +++ b/classes/form/view/badge_rating_configuration_form.php @@ -47,10 +47,10 @@ public function definition() { $form->addElement('text', $element, $text); $form->setType($element, PARAM_INT); $form->addRule($element, $requiredtext, 'required', null, 'client'); - $form->setDefault($element, $this->question_list->level_rating($level)); + $form->setDefault($element, $this->question_list->required_rating_for_level($level)); } - $form->addElement('submit', 'submitbutton', get_string('configure', 'capquiz')); + $form->addElement('submit', 'submitbutton', get_string('savechanges')); } public function validations($data, $files) { diff --git a/classes/form/view/capquiz_configuration_form.php b/classes/form/view/capquiz_configuration_form.php index 2a344d9..fc0abd2 100644 --- a/classes/form/view/capquiz_configuration_form.php +++ b/classes/form/view/capquiz_configuration_form.php @@ -49,7 +49,7 @@ public function definition() { $form->setType('default_user_rating', PARAM_INT); $form->setDefault('default_user_rating', $this->capquiz->default_user_rating()); $form->addRule('default_user_rating', get_string('default_user_rating_required', 'capquiz'), 'required', null, 'client'); - $this->add_action_buttons(false, 'submit'); + $this->add_action_buttons(false); } public function validations($data, $files) { diff --git a/classes/form/view/matchmaking_strategy_selection_form.php b/classes/form/view/matchmaking_strategy_selection_form.php index 006d03c..de61564 100644 --- a/classes/form/view/matchmaking_strategy_selection_form.php +++ b/classes/form/view/matchmaking_strategy_selection_form.php @@ -29,6 +29,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class matchmaking_strategy_selection_form extends \moodleform { + + /** @var capquiz $capquiz */ private $capquiz; public function __construct(capquiz $capquiz, \moodle_url $url) { @@ -51,7 +53,7 @@ public function definition() { $radioarray[] = $form->createElement('radio', 'strategy', '', $strategy, $index++, [$strategy]); } $form->addGroup($radioarray, 'radioar', '', '
', false); - $this->add_action_buttons(false, 'submit'); + $this->add_action_buttons(false); if ($selected_index > -1) { $form->setDefault('strategy', $selected_index); } diff --git a/classes/form/view/rating_system_selection_form.php b/classes/form/view/rating_system_selection_form.php index 58d590c..bd4cb11 100644 --- a/classes/form/view/rating_system_selection_form.php +++ b/classes/form/view/rating_system_selection_form.php @@ -50,7 +50,7 @@ public function definition() { $radioarray[] = $form->createElement('radio', 'rating_system', '', $rating_system, $index++, [$rating_system]); } $form->addGroup($radioarray, 'radioar', '', '
', false); - $this->add_action_buttons(false, 'submit'); + $this->add_action_buttons(false); if ($selected_index > -1) { $form->setDefault('rating_system', $selected_index); } diff --git a/classes/matchmaking/capquiz_matchmaking_strategy_registry.php b/classes/matchmaking/capquiz_matchmaking_strategy_registry.php index c79f763..8354d20 100644 --- a/classes/matchmaking/capquiz_matchmaking_strategy_registry.php +++ b/classes/matchmaking/capquiz_matchmaking_strategy_registry.php @@ -17,7 +17,6 @@ namespace mod_capquiz; require_once($CFG->dirroot . '/mod/capquiz/classes/capquiz_matchmaking_strategy.php'); - require_once($CFG->dirroot . '/mod/capquiz/classes/matchmaking/chronologic/chronologic_selector.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/matchmaking/n_closest/n_closest_selector.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/matchmaking/n_closest/n_closest_configuration_form.php'); @@ -32,7 +31,10 @@ */ class capquiz_matchmaking_strategy_registry { + /** @var capquiz $capquiz */ private $capquiz; + + /** @var */ private $strategies; public function __construct(capquiz $capquiz) { @@ -40,36 +42,38 @@ public function __construct(capquiz $capquiz) { $this->register_selection_strategies(); } - - public function selector(string $strategy) { + public function selector(string $strategy) : ?capquiz_matchmaking_strategy { if ($value = $this->strategies[$strategy]) { return array_values($value)[0](); } $this->throw_strategy_exception($strategy); } - public function configuration_form(string $strategy, \stdClass $configuration, \moodle_url $url) { + public function configuration_form(string $strategy, \stdClass $configuration, \moodle_url $url) : ?\moodleform { if ($value = $this->strategies[$strategy]) { return array_values($value)[1]($url, $configuration); } $this->throw_strategy_exception($strategy); } - public function has_strategy(string $strategy) { + public function has_strategy(string $strategy) : bool { if ($value = $this->strategies[$strategy]) { return true; } return false; } - public function default_selection_strategy(){ - // default selection strategy is added first. - //Modify caquiz_matchmaking_strategy_registry::register_selection_strategies() to change this. + public function default_selection_strategy() : string { + // The default selection strategy is added first. + // Modify capquiz_matchmaking_strategy_registry::register_selection_strategies() to change this. $selection_strategies = $this->selection_strategies(); return reset($selection_strategies); } - public function selection_strategies() { + /** + * @return string[] + */ + public function selection_strategies() : array { $names = []; foreach (array_keys($this->strategies) as $value) { $names[] = $value; @@ -77,7 +81,7 @@ public function selection_strategies() { return $names; } - private function register_selection_strategies() { + private function register_selection_strategies() : void { //The first listed will be selected by default when creating a new activity $capquiz = $this->capquiz; $this->strategies = [ @@ -91,7 +95,7 @@ function (\moodle_url $url, \stdClass $configuration) { ], 'Chronological' => [ function () use ($capquiz) { - return new chronologic_selector($capquiz); + return new chronologic_selector(); }, function (\moodle_url $url, \stdClass $configuration) { return null; @@ -100,7 +104,7 @@ function (\moodle_url $url, \stdClass $configuration) { ]; } - private function throw_strategy_exception(string $strategy) { + private function throw_strategy_exception(string $strategy) : void { $msg = "The specified strategy '$strategy' does not exist."; $msg .= " Options are {'" . implode("', '", $this->selection_strategies()); $msg .= "'}. This issue must be fixed by a programmer"; diff --git a/classes/matchmaking/chronologic/chronologic_selector.php b/classes/matchmaking/chronologic/chronologic_selector.php index 9967d61..81c44ed 100644 --- a/classes/matchmaking/chronologic/chronologic_selector.php +++ b/classes/matchmaking/chronologic/chronologic_selector.php @@ -26,19 +26,19 @@ */ class chronologic_selector extends capquiz_matchmaking_strategy { - public function configure(\stdClass $configuration) { + public function configure(\stdClass $configuration) : void { } - public function configuration() { + public function configuration() : ?\stdClass { return null; } - public function default_configuration() { + public function default_configuration() : ?\stdClass { return null; } - public function next_question_for_user(capquiz_user $user, capquiz_question_list $question_list, array $inactive_capquiz_attempts) { + public function next_question_for_user(capquiz_user $user, capquiz_question_list $question_list, array $inactive_capquiz_attempts) : ?capquiz_question { $is_answered = function (capquiz_question $q) use ($inactive_capquiz_attempts) { foreach ($inactive_capquiz_attempts as $attempt) { if ($attempt->question_id() === $q->id()) { diff --git a/classes/matchmaking/n_closest/n_closest_configuration_form.php b/classes/matchmaking/n_closest/n_closest_configuration_form.php index 46b3944..37305bc 100644 --- a/classes/matchmaking/n_closest/n_closest_configuration_form.php +++ b/classes/matchmaking/n_closest/n_closest_configuration_form.php @@ -58,7 +58,7 @@ public function definition() { $form->addRule('prevent_same_question_for_turns', get_string('field_required', 'capquiz'), 'required', null, 'client'); $form->addHelpButton('prevent_same_question_for_turns', 'prevent_question_n_times', 'capquiz'); - $this->add_action_buttons(false, 'submit'); + $this->add_action_buttons(false); } public function validations($data, $files) { diff --git a/classes/matchmaking/n_closest/n_closest_selector.php b/classes/matchmaking/n_closest/n_closest_selector.php index 56b38bb..aedf69b 100644 --- a/classes/matchmaking/n_closest/n_closest_selector.php +++ b/classes/matchmaking/n_closest/n_closest_selector.php @@ -36,7 +36,7 @@ public function __construct(capquiz $capquiz) { $this->configure($this->default_configuration()); } - public function configure(\stdClass $configuration) { + public function configure(\stdClass $configuration) : void { if ($user_win_probability = $configuration->user_win_probability) { $this->user_win_probability = $user_win_probability; } @@ -48,7 +48,7 @@ public function configure(\stdClass $configuration) { } } - public function configuration() { + public function configuration() : \stdClass { $config = new \stdClass; $config->prevent_same_question_for_turns = $this->prevent_same_question_for_turns; $config->user_win_probability = $this->user_win_probability; @@ -56,7 +56,7 @@ public function configuration() { return $config; } - public function default_configuration() { + public function default_configuration() : \stdClass { $config = new \stdClass; $config->user_win_probability = 0.75; $config->prevent_same_question_for_turns = 0; @@ -64,7 +64,7 @@ public function default_configuration() { return $config; } - public function next_question_for_user(capquiz_user $user, capquiz_question_list $question_list, array $inactive_capquiz_attempts) { + public function next_question_for_user(capquiz_user $user, capquiz_question_list $question_list, array $inactive_capquiz_attempts) : ?capquiz_question { $candidate_questions = $this->find_questions_closest_to_rating($user, $this->determine_excluded_questions($inactive_capquiz_attempts)); $index = mt_rand(0, count($candidate_questions) - 1); if ($question = $candidate_questions[$index]) { @@ -73,7 +73,7 @@ public function next_question_for_user(capquiz_user $user, capquiz_question_list return null; } - private function find_questions_closest_to_rating(capquiz_user $user, array $excluded_questions) { + private function find_questions_closest_to_rating(capquiz_user $user, array $excluded_questions) : array { global $DB; $table = database_meta::$table_capquiz_question; $field_list_id = database_meta::$field_question_list_id; @@ -94,11 +94,11 @@ private function find_questions_closest_to_rating(capquiz_user $user, array $exc return $questions; } - private function ideal_question_rating(capquiz_user $user) { + private function ideal_question_rating(capquiz_user $user) : float { return 400.0 * log((1.0 / $this->user_win_probability) - 1.0, 10.0) + $user->rating(); } - private function determine_excluded_questions(array $inactive_attempts) { + private function determine_excluded_questions(array $inactive_attempts) : array { $it = new \ArrayIterator(array_reverse($inactive_attempts, true)); $excluded = []; for ($i = 0; $i < $this->prevent_same_question_for_turns; $i++) { diff --git a/classes/output/classlist_renderer.php b/classes/output/classlist_renderer.php index c9c0f6b..6cdc8a3 100644 --- a/classes/output/classlist_renderer.php +++ b/classes/output/classlist_renderer.php @@ -47,7 +47,6 @@ public function render() { $user = $users[$i]; $rows[] = [ 'index' => $i + 1, - 'student_id' => $user->id(), 'username' => $user->username(), 'firstname' => $user->first_name(), 'lastname' => $user->last_name(), diff --git a/classes/output/question_attempt_renderer.php b/classes/output/question_attempt_renderer.php index e466c73..d45663c 100644 --- a/classes/output/question_attempt_renderer.php +++ b/classes/output/question_attempt_renderer.php @@ -47,7 +47,7 @@ private function render_question_head_html() { $this->capquiz->question_usage()->render_question_head_html($attempt->question_slot()); } - public function render() { + public function render() : string { if (!$this->capquiz->is_published()) { return 'Nothing here yet'; } @@ -65,21 +65,21 @@ public function render() { } } - private function render_attempt(capquiz_question_attempt $attempt, \question_display_options $displayoptions) { + private function render_attempt(capquiz_question_attempt $attempt, \question_display_options $displayoptions) : string { $user = $this->capquiz->user(); $html = $this->render_progress($user); $html .= $this->render_question_attempt($attempt, $displayoptions); - $html .= $this->render_metainfo($user, $attempt); + //$html .= $this->render_metainfo($user, $attempt); return $html; } - private function render_review(capquiz_question_attempt $attempt) { + private function render_review(capquiz_question_attempt $attempt) : string { $html = $this->render_attempt($attempt, $this->review_display_options()); $html .= $this->render_review_next_button($attempt); return $html; } - public function render_review_next_button(capquiz_question_attempt $attempt) { + public function render_review_next_button(capquiz_question_attempt $attempt) : string { return basic_renderer::render_action_button( $this->renderer, capquiz_urls::response_reviewed_url($attempt), @@ -87,26 +87,26 @@ public function render_review_next_button(capquiz_question_attempt $attempt) { ); } - private function render_progress(capquiz_user $user) { + private function render_progress(capquiz_user $user) : string { $questionlist = $this->capquiz->question_list(); $percent = $questionlist->next_level_percent($user->rating()); - if ( $percent >= 0 ) { - $student = [ - 'up' => [ 'percent' => $percent ], - 'stars' => $this->user_star_progress($user, $questionlist) - ] ; + if ($percent >= 0) { + $student = [ + 'up' => ['percent' => $percent], + 'stars' => $this->user_star_progress($user, $questionlist) + ]; } else { - $student = [ - 'down' => [ 'percent' => -$percent ], - 'stars' => $this->user_star_progress($user, $questionlist) - ] ; + $student = [ + 'down' => ['percent' => -$percent], + 'stars' => $this->user_star_progress($user, $questionlist) + ]; } return $this->renderer->render_from_template('capquiz/student_progress', [ - 'progress' => [ 'student' => $student ] + 'progress' => ['student' => $student] ]); } - public function render_question_attempt(capquiz_question_attempt $attempt, \question_display_options $displayoptions) { + public function render_question_attempt(capquiz_question_attempt $attempt, \question_display_options $displayoptions) : string { global $PAGE; $question_usage = $this->capquiz->question_usage(); $PAGE->requires->js_module('core_question_engine'); @@ -119,9 +119,11 @@ public function render_question_attempt(capquiz_question_attempt $attempt, \ques ]); } - public function render_metainfo(capquiz_user $user, capquiz_question_attempt $attempt) { + public function render_metainfo(capquiz_user $user, capquiz_question_attempt $attempt) : string { $question = capquiz_question::load($attempt->question_id()); - + if ($question == null) { + return 'Question was not found.'; + } return $this->renderer->render_from_template('capquiz/student_question_metainfo', [ 'metainfo' => [ 'rating' => [ @@ -136,7 +138,7 @@ public function render_metainfo(capquiz_user $user, capquiz_question_attempt $at ]); } - private function user_star_progress(capquiz_user $user, capquiz_question_list $list) { + private function user_star_progress(capquiz_user $user, capquiz_question_list $list) : array { $result = []; for ($star = 1; $star < $list->level_count() + 1; $star++) { $result[] = $user->highest_level() >= $star; @@ -144,7 +146,7 @@ private function user_star_progress(capquiz_user $user, capquiz_question_list $l return $result; } - private function review_display_options() { + private function review_display_options() : \question_display_options { $options = new \question_display_options(); $options->context = $this->capquiz->context(); $options->readonly = true; @@ -153,11 +155,11 @@ private function review_display_options() { $options->rightanswer = \question_display_options::VISIBLE; $options->numpartscorrect = \question_display_options::VISIBLE; $options->manualcomment = \question_display_options::HIDDEN; -// $options->manualcommentlink = 'insert the link to solve issue #44'; + //$options->manualcommentlink = 'insert the link to solve issue #44'; return $options; } - private function attempt_display_options() { + private function attempt_display_options() : \question_display_options { $options = new \question_display_options(); $options->context = $this->capquiz->context(); $options->flags = \question_display_options::HIDDEN; @@ -165,7 +167,7 @@ private function attempt_display_options() { $options->rightanswer = \question_display_options::HIDDEN; $options->numpartscorrect = \question_display_options::HIDDEN; $options->manualcomment = \question_display_options::HIDDEN; -// $options->manualcommentlink = 'insert the link to solve issue #44'; + //$options->manualcommentlink = 'insert the link to solve issue #44'; return $options; } diff --git a/classes/output/renderer.php b/classes/output/renderer.php index c87c07a..17cd930 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -46,21 +46,10 @@ public function output_renderer() { return $this->output; } - /** - * @param string $name - * @param \moodle_url $link - * @return \tabobject - * @throws \coding_exception - */ private function tab(string $name, string $title, \moodle_url $link) { return new \tabobject($name, $link, $title); } - /** - * @param string $activetab - * @return string html - * @throws \coding_exception - */ private function tabs(string $activetab) { $tabs = [ $this->tab('view_dashboard', get_string('dashboard', 'capquiz'), capquiz_urls::view_url()), @@ -175,4 +164,5 @@ public function display_capquiz_configuration(capquiz $capquiz) { public function display_badge_configuration(capquiz $capquiz) { $this->display_tabbed_view(new badge_rating_configuration_renderer($capquiz, $this), 'view_badges'); } + } diff --git a/classes/rating_system/capquiz_rating_system_registry.php b/classes/rating_system/capquiz_rating_system_registry.php index 7d7c9ff..61d5bdf 100644 --- a/classes/rating_system/capquiz_rating_system_registry.php +++ b/classes/rating_system/capquiz_rating_system_registry.php @@ -29,7 +29,10 @@ */ class capquiz_rating_system_registry { + /** @var capquiz $capquiz */ private $capquiz; + + /** @var callable[][] $systems */ private $systems; public function __construct(capquiz $capquiz) { @@ -37,36 +40,38 @@ public function __construct(capquiz $capquiz) { $this->register_rating_systems(); } - - public function rating_system(string $rating_system) { - if ($value = $this->systems[$rating_system]) { + public function rating_system(string $system) : ?capquiz_rating_system { + if ($value = $this->systems[$system]) { return array_values($value)[0](); } - $this->throw_rating_system_exception($rating_system); + $this->throw_rating_system_exception($system); } - public function configuration_form(string $rating_system, \stdClass $configuration, \moodle_url $url) { - if ($value = $this->systems[$rating_system]) { + public function configuration_form(string $system, \stdClass $configuration, \moodle_url $url) : ?\moodleform { + if ($value = $this->systems[$system]) { return array_values($value)[1]($url, $configuration); } - $this->throw_rating_system_exception($rating_system); + $this->throw_rating_system_exception($system); } - public function has_rating_system(string $rating_system) { - if ($value = $this->systems[$rating_system]) { + public function has_rating_system(string $system) : bool { + if ($value = $this->systems[$system]) { return true; } return false; } - public function default_rating_system(){ + public function default_rating_system() : string { // Default rating system is added first. // Modify caquiz_rating_system_registry::register_rating_systems() to change this. $rating_systems = $this->rating_systems(); return reset($rating_systems); } - public function rating_systems() { + /** + * @return string[] + */ + public function rating_systems() : array { $names = []; foreach (array_keys($this->systems) as $value) { $names[] = $value; @@ -74,7 +79,7 @@ public function rating_systems() { return $names; } - private function register_rating_systems() { + private function register_rating_systems() : void { //The first listed will be selected by default when creating a new activity $capquiz = $this->capquiz; $this->systems = [ @@ -89,8 +94,8 @@ function (\moodle_url $url, \stdClass $configuration) { ]; } - private function throw_rating_system_exception(string $rating_system) { - $msg = "The specified rating system '$rating_system' does not exist."; + private function throw_rating_system_exception(string $system) : void { + $msg = "The specified rating system '$system' does not exist."; $msg .= " Options are {'" . implode("', '", $this->rating_systems()); $msg .= "'}. This issue must be fixed by a programmer"; throw new \Exception($msg); diff --git a/classes/rating_system/elo_rating/elo_rating_system.php b/classes/rating_system/elo_rating/elo_rating_system.php index a87c5e8..fbd701f 100644 --- a/classes/rating_system/elo_rating/elo_rating_system.php +++ b/classes/rating_system/elo_rating/elo_rating_system.php @@ -38,27 +38,27 @@ public function configure(\stdClass $configuration) { } } - public function configuration() { + public function configuration() : ?\stdClass { $config = new \stdClass; $config->student_k_factor = $this->student_k_factor; $config->question_k_factor = $this->question_k_factor; return $config; } - public function default_configuration() { + public function default_configuration() : ?\stdClass { $config = new \stdClass; $config->student_k_factor = 32; $config->question_k_factor = 8; return $config; } - public function update_user_rating(capquiz_user $user, capquiz_question $question, float $score) { + public function update_user_rating(capquiz_user $user, capquiz_question $question, float $score) : void { $user_rating = $user->rating(); $updated_rating = $user_rating + $this->student_k_factor * ($score - $this->expected_result($user_rating, $question->rating())); $user->set_rating($updated_rating); } - public function question_victory_ratings(capquiz_question $winner, capquiz_question $loser) { + public function question_victory_ratings(capquiz_question $winner, capquiz_question $loser) : void { $loser_rating = $loser->rating(); $winner_rating = $winner->rating(); $updated_loser_rating = $loser_rating + $this->question_k_factor * (0 - $this->expected_result($winner_rating, $loser_rating)); @@ -67,7 +67,7 @@ public function question_victory_ratings(capquiz_question $winner, capquiz_quest $winner->set_rating($updated_winner_rating); } - private function expected_result(float $rating_a, float $rating_b) { + private function expected_result(float $rating_a, float $rating_b) : float { $exponent = ($rating_b - $rating_a) / 400.0; return 1.0 / (1.0 + pow(10.0, $exponent)); } diff --git a/classes/rating_system/elo_rating/elo_rating_system_form.php b/classes/rating_system/elo_rating/elo_rating_system_form.php index d94b92f..8825aa8 100644 --- a/classes/rating_system/elo_rating/elo_rating_system_form.php +++ b/classes/rating_system/elo_rating/elo_rating_system_form.php @@ -30,16 +30,15 @@ */ class elo_rating_system_form extends \moodleform { - private $capquiz; + /** @var \stdClass $configuration */ private $configuration; public function __construct(\stdClass $configuration, \moodle_url $url) { $this->configuration = $configuration; parent::__construct($url); - } - public function definition() { + public function definition() : void { $form = $this->_form; $form->addElement('text', 'student_k_factor', get_string('student_k_factor', 'capquiz')); @@ -57,6 +56,6 @@ public function definition() { $form->setDefault('question_k_factor', $this->configuration->question_k_factor); $form->addHelpButton('question_k_factor', 'question_k_factor', 'capquiz'); - $this->add_action_buttons(false, 'submit'); + $this->add_action_buttons(false); } } \ No newline at end of file diff --git a/lang/en/capquiz.php b/lang/en/capquiz.php index 2feb74c..b332764 100644 --- a/lang/en/capquiz.php +++ b/lang/en/capquiz.php @@ -1,6 +1,18 @@ . /** * @package mod_capquiz @@ -9,27 +21,28 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + $string['pluginname'] = 'CAPQuiz'; $string['modulename'] = 'CAPQuiz'; $string['modulenameplural'] = 'CAPQuizzes'; $string['modulename_help'] = '

The CAPQuiz activity enables a teacher to create quizzes comprising of questions of various types.' . 'Questions can be rated to different difficulties while students are given an initial rating. ' . 'Using these ratings CAPQuiz will match questions to individual students based on their skill level.

'; -$string['pluginadministration'] = 'JazzQuiz administration'; +$string['pluginadministration'] = 'CAPQuiz administration'; $string['questions_in_list'] = 'Questions in the list'; $string['add_a_quiz_question'] = 'Add a question to the list'; $string['add_the_quiz_question'] = 'Add the question to the list'; -$string['question_list'] = "Question list"; -$string['question_lists'] = "Question lists"; +$string['question_list'] = 'Question list'; +$string['question_lists'] = 'Question lists'; $string['configure_badge_rating'] = 'Configure badge rating'; -$string['id'] = 'ID'; $string['home'] = 'Home'; $string['name'] = 'Name'; -$string['next'] = "Next"; -$string['stars'] = "Stars"; +$string['next'] = 'Next'; +$string['stars'] = 'Stars'; $string['title'] = 'Title'; $string['author'] = 'Author'; $string['created'] = 'Created'; @@ -37,40 +50,37 @@ $string['remove'] = 'Remove'; $string['rating'] = 'Rating'; $string['action'] = 'Action'; -$string['select'] = "Select"; -$string['status'] = "Status"; +$string['select'] = 'Select'; +$string['status'] = 'Status'; $string['created'] = 'Created'; -$string['publish'] = "Publish"; -$string['template'] = "Template"; -$string['username'] = "Username"; -$string['lastname'] = "Last name"; -$string['moodleid'] = 'Moodle ID'; -$string['capquizid'] = 'CAPQuiz ID'; -$string['firstname'] = "First name"; +$string['publish'] = 'Publish'; +$string['template'] = 'Template'; +$string['username'] = 'Username'; +$string['lastname'] = 'Last name'; +$string['firstname'] = 'First name'; $string['configure'] = 'Configure'; $string['dashboard'] = 'Dashboard'; $string['questions'] = 'Questions'; $string['classlist'] = 'Class list'; -$string['questionid'] = 'Question ID'; $string['description'] = 'Description'; $string['matchmaking'] = 'Matchmaking'; $string['rating_system'] = 'Rating system'; $string['name_required'] = 'Name is required'; $string['title_required'] = 'Title is required'; -$string['question_count'] = "Question count"; +$string['question_count'] = 'Question count'; $string['create_template'] = 'Make template'; -$string['enrolled_students'] = "Enrolled students"; +$string['enrolled_students'] = 'Enrolled students'; $string['configure_capquiz'] = 'Configure CAPQuiz'; $string['create_question_list'] = 'Create question list'; $string['field_required'] = 'This field is required'; $string['description_required'] = 'Description is required.'; -$string['student_k_factor_required'] = 'Student k factor is required.'; +$string['student_k_factor_required'] = 'Student k-factor is required.'; $string['default_user_rating_required'] = 'Default user rating is required.'; -$string['question_k_factor_required'] = 'Question k factor is required.'; +$string['question_k_factor_required'] = 'Question k-factor is required.'; -$string['yourrating'] = 'Your rating'; -$string['questionrating'] = 'Question rating'; +$string['your_rating'] = 'Your rating'; +$string['question_rating'] = 'Question rating'; $string['need_to_log_in'] = 'You need to log in'; @@ -79,7 +89,7 @@ $string['no_questions_added_to_list'] = 'No questions added to the list'; $string['no_matchmaking_strategy_selected'] = 'No selection strategy has been specified'; -$string['update_rating_explanation'] = '

Update ratings by modifying the specified value and press enter

'; +$string['update_rating_explanation'] = '

The question ratings can be edited below. Changes are saved automatically.

'; $string['question_list_no_questions'] = 'This quiz has no questions. Add some questions from the list to the right'; $string['one_star'] = '1 Star'; @@ -140,6 +150,6 @@ $string['publish_no_questions_in_list'] = "

There doesn't seem to be any questions in the question list for this CAPQuiz instance. You must have at least one question before you can publish

"; $string['publish_already_published'] = "

This CAPQuiz is already published

"; -$string['no_question_list_assigned'] = "no question list assigned"; -$string['published'] = "published"; -$string['not_published'] = "not published"; +$string['no_question_list_assigned'] = 'No question list has been assigned'; +$string['published'] = 'Published'; +$string['not_published'] = 'Not published'; diff --git a/styles.css b/styles.css index 22dcd67..bd2dd7c 100644 --- a/styles.css +++ b/styles.css @@ -125,3 +125,7 @@ .capquiz-response-form .que .content { margin: 0; } + +.capquiz-response-form .content .im-controls .submit { + border: 1px solid #bbb; +} diff --git a/templates/button.mustache b/templates/button.mustache index d63ba19..3b978d1 100644 --- a/templates/button.mustache +++ b/templates/button.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} {{#button}} {{>core/single_button}} {{/button}} diff --git a/templates/capquiz_configuration.mustache b/templates/capquiz_configuration.mustache index 8560938..4c45051 100644 --- a/templates/capquiz_configuration.mustache +++ b/templates/capquiz_configuration.mustache @@ -1,2 +1,18 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} configure_capquiz, capquiz {{/str}}

{{{ form }}} diff --git a/templates/classlist.mustache b/templates/classlist.mustache index 2a8e914..b509371 100644 --- a/templates/classlist.mustache +++ b/templates/classlist.mustache @@ -1,8 +1,23 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} classlist, capquiz {{/str}}

- @@ -16,7 +31,6 @@ {{#.}} - diff --git a/templates/configure_badge_rating.mustache b/templates/configure_badge_rating.mustache index b70c117..4ddae67 100644 --- a/templates/configure_badge_rating.mustache +++ b/templates/configure_badge_rating.mustache @@ -1,2 +1,18 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} configure_badge_rating, capquiz {{/str}}

{{{ form }}} diff --git a/templates/create_question_list.mustache b/templates/create_question_list.mustache index d5b178e..96a7a7c 100644 --- a/templates/create_question_list.mustache +++ b/templates/create_question_list.mustache @@ -1,2 +1,18 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} create_question_list, capquiz {{/str}}

{{{ form }}} diff --git a/templates/instructor_dashboard_publish.mustache b/templates/instructor_dashboard_publish.mustache index bc74619..1601a67 100644 --- a/templates/instructor_dashboard_publish.mustache +++ b/templates/instructor_dashboard_publish.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} publish, capquiz {{/str}}

{{#str}} publish_explanation, capquiz {{/str}} diff --git a/templates/instructor_dashboard_summary.mustache b/templates/instructor_dashboard_summary.mustache index 20b3f6f..2c1227c 100644 --- a/templates/instructor_dashboard_summary.mustache +++ b/templates/instructor_dashboard_summary.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} dashboard, capquiz {{/str}}

#{{#str}} id, capquiz {{/str}} {{#str}} username, capquiz {{/str}} {{#str}} firstname, capquiz {{/str}} {{#str}} lastname, capquiz {{/str}}
{{ index }}{{ student_id }} {{ username }} {{ firstname }} {{ lastname }}
diff --git a/templates/instructor_dashboard_template.mustache b/templates/instructor_dashboard_template.mustache index 9781340..9a5b0ec 100644 --- a/templates/instructor_dashboard_template.mustache +++ b/templates/instructor_dashboard_template.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} template, capquiz {{/str}}

{{#str}}template_explanation, capquiz {{/str}} {{#crate_template}} diff --git a/templates/matchmaking_configuration.mustache b/templates/matchmaking_configuration.mustache index 93ccd07..77e590b 100644 --- a/templates/matchmaking_configuration.mustache +++ b/templates/matchmaking_configuration.mustache @@ -1,2 +1,18 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} configure, capquiz {{/str}} {{strategy}}

{{{ form }}} diff --git a/templates/matchmaking_selection_strategy.mustache b/templates/matchmaking_selection_strategy.mustache index 1569063..90d062a 100644 --- a/templates/matchmaking_selection_strategy.mustache +++ b/templates/matchmaking_selection_strategy.mustache @@ -1,2 +1,18 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} choose_selection_strategy, capquiz {{/str}}

{{{ form }}} diff --git a/templates/question_list.mustache b/templates/question_list.mustache index 133830e..af5d2e7 100644 --- a/templates/question_list.mustache +++ b/templates/question_list.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}}question_list, capquiz{{/str}}

diff --git a/templates/question_list_selection.mustache b/templates/question_list_selection.mustache index c56bfbb..5218e55 100644 --- a/templates/question_list_selection.mustache +++ b/templates/question_list_selection.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} question_lists, capquiz {{/str}}

diff --git a/templates/rating_system_configuration.mustache b/templates/rating_system_configuration.mustache index 93ccd07..77e590b 100644 --- a/templates/rating_system_configuration.mustache +++ b/templates/rating_system_configuration.mustache @@ -1,2 +1,18 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} configure, capquiz {{/str}} {{strategy}}

{{{ form }}} diff --git a/templates/rating_system_selection.mustache b/templates/rating_system_selection.mustache index e09407f..503fae1 100644 --- a/templates/rating_system_selection.mustache +++ b/templates/rating_system_selection.mustache @@ -1,2 +1,18 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}} choose_rating_system, capquiz {{/str}}

{{{ form }}} diff --git a/templates/student_progress.mustache b/templates/student_progress.mustache index 691556f..e998125 100644 --- a/templates/student_progress.mustache +++ b/templates/student_progress.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} {{#progress}}
{{#student}} diff --git a/templates/student_question.mustache b/templates/student_question.mustache index a0b6b24..046c06b 100644 --- a/templates/student_question.mustache +++ b/templates/student_question.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} {{#attempt}}
diff --git a/templates/student_question_attempt.mustache b/templates/student_question_attempt.mustache index 32b6571..cf0737d 100644 --- a/templates/student_question_attempt.mustache +++ b/templates/student_question_attempt.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} {{#attempt}} diff --git a/templates/student_question_metainfo.mustache b/templates/student_question_metainfo.mustache index ac4c474..5633be4 100644 --- a/templates/student_question_metainfo.mustache +++ b/templates/student_question_metainfo.mustache @@ -1,3 +1,19 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} {{#metainfo}}
@@ -6,7 +22,7 @@
- {{#str}}yourrating, capquiz{{/str}}: + {{#str}}your_rating, capquiz{{/str}}: {{ student }} @@ -14,7 +30,7 @@
- {{#str}}questionrating, capquiz{{/str}}: + {{#str}}question_rating, capquiz{{/str}}: {{ question }} @@ -28,7 +44,7 @@
- {{#str}}capquizid, capquiz{{/str}}: + CAPQuiz ID: {{ capquiz_id }} @@ -36,7 +52,7 @@
- {{#str}}moodleid, capquiz{{/str}}: + Moodle ID: {{ moodle_id }} diff --git a/templates/unauthorized.mustache b/templates/unauthorized.mustache index ffa773d..589c39b 100644 --- a/templates/unauthorized.mustache +++ b/templates/unauthorized.mustache @@ -1 +1,17 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}}

{{#str}}need_to_log_in, capquiz{{/str}}

\ No newline at end of file diff --git a/version.php b/version.php index c2134fc..305aaa9 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2018091700; +$plugin->version = 2018092806; $plugin->requires = 2016120500 ; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; diff --git a/view.php b/view.php index 43694cc..74cb418 100644 --- a/view.php +++ b/view.php @@ -29,6 +29,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + $capquiz = capquiz::create(); if (!$capquiz) {