From fb3b549e34d1fcf48c1c2d2b9f69308bf27d6aae Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Tue, 25 Jun 2019 12:10:12 +0200 Subject: [PATCH 01/24] added support for grades feature course reset support also added. closes #104 --- classes/capquiz.php | 4 + classes/capquiz_action_performer.php | 4 +- classes/capquiz_question_list.php | 21 ++-- .../question_list_selection_renderer.php | 8 +- classes/output/renderer.php | 4 +- grade.php | 45 ++++++++ lang/en/capquiz.php | 3 + lib.php | 104 +++++++++++++++++- version.php | 4 +- view.php | 3 +- 10 files changed, 177 insertions(+), 23 deletions(-) create mode 100644 grade.php diff --git a/classes/capquiz.php b/classes/capquiz.php index 3add9b5..a7bcb9e 100755 --- a/classes/capquiz.php +++ b/classes/capquiz.php @@ -66,6 +66,10 @@ public static function create() : capquiz { return self::create_from_id(capquiz_urls::require_course_module_id_param()); } + public function update_grades() { + capquiz_update_grades($this->record); + } + public static function create_from_id(int $id) : capquiz { return new capquiz($id); } diff --git a/classes/capquiz_action_performer.php b/classes/capquiz_action_performer.php index 1c72e65..31bd34f 100755 --- a/classes/capquiz_action_performer.php +++ b/classes/capquiz_action_performer.php @@ -76,7 +76,7 @@ public static function redirect() { public static function assign_question_list(capquiz $capquiz) { $qlistid = optional_param(capquiz_urls::$paramqlistid, 0, PARAM_INT); - $qlist = capquiz_question_list::load_any($qlistid); + $qlist = capquiz_question_list::load_any($qlistid, $capquiz->context()); if ($qlist) { $capquiz->validate_matchmaking_and_rating_systems(); $qlist->create_instance_copy($capquiz); @@ -158,7 +158,7 @@ private static function merge_question_list(capquiz $capquiz) { $srcqlistid = required_param('qlistid', PARAM_INT); $srcqlistrecord = $DB->get_record('capquiz_question_list', ['id' => $srcqlistid]); if ($srcqlistrecord) { - $capquiz->question_list()->merge(new capquiz_question_list($srcqlistrecord)); + $capquiz->question_list()->merge(new capquiz_question_list($srcqlistrecord, $capquiz->context())); } capquiz_urls::redirect_to_url(capquiz_urls::view_question_list_url()); } diff --git a/classes/capquiz_question_list.php b/classes/capquiz_question_list.php index b046646..44167d9 100755 --- a/classes/capquiz_question_list.php +++ b/classes/capquiz_question_list.php @@ -35,7 +35,7 @@ class capquiz_question_list { /** @var \question_usage_by_activity $quba */ private $quba; - public function __construct(\stdClass $record) { + public function __construct(\stdClass $record, $context) { global $DB; $this->record = $record; $entries = $DB->get_records('capquiz_question', ['question_list_id' => $this->record->id]); @@ -43,9 +43,8 @@ public function __construct(\stdClass $record) { foreach ($entries as $entry) { $this->questions[] = new capquiz_question($entry); } - if ($this->has_question_usage()) { - $this->quba = \question_engine::load_questions_usage_by_activity($this->record->question_usage_id); - } + $this->create_question_usage($context); + $this->quba = \question_engine::load_questions_usage_by_activity($this->record->question_usage_id); } public function question_usage() { @@ -269,7 +268,7 @@ private function create_copy(capquiz $capquiz, bool $template) { $this->copy_questions_to_list($newid); $DB->commit_delegated_transaction($transaction); $record->id = $newid; - return new capquiz_question_list($record); + return new capquiz_question_list($record, $capquiz->context()); } catch (\dml_exception $exception) { $DB->rollback_delegated_transaction($transaction, $exception); return null; @@ -297,7 +296,7 @@ public static function create_new_instance(capquiz $capquiz, string $title, stri $record->context_id = \context_course::instance($capquiz->course()->id)->id; try { $qlistid = $DB->insert_record('capquiz_question_list', $record); - $qlist = self::load_any($qlistid); + $qlist = self::load_any($qlistid, $capquiz->context()); if (!$qlist) { return null; } @@ -313,27 +312,27 @@ public static function load_question_list(capquiz $capquiz) { $conditions = ['capquiz_id' => $capquiz->id()]; $record = $DB->get_record('capquiz_question_list', $conditions); if ($record) { - return new capquiz_question_list($record); + return new capquiz_question_list($record, $capquiz->context()); } return null; } - public static function load_any(int $qlistid) { + public static function load_any(int $qlistid, $context) { global $DB; $conditions = ['id' => $qlistid]; $record = $DB->get_record('capquiz_question_list', $conditions); if ($record) { - return new capquiz_question_list($record); + return new capquiz_question_list($record, $context); } return null; } - public static function load_question_list_templates() : array { + public static function load_question_list_templates($context) : array { global $DB; $records = $DB->get_records('capquiz_question_list', ['is_template' => 1]); $qlists = []; foreach ($records as $record) { - $qlists[] = new capquiz_question_list($record); + $qlists[] = new capquiz_question_list($record, $context); } return $qlists; } diff --git a/classes/output/question_list_selection_renderer.php b/classes/output/question_list_selection_renderer.php index 3363de1..6eb08c3 100755 --- a/classes/output/question_list_selection_renderer.php +++ b/classes/output/question_list_selection_renderer.php @@ -32,12 +32,16 @@ class question_list_selection_renderer { /** @var renderer $renderer */ private $renderer; - public function __construct(renderer $renderer) { + /** @var $context */ + private $context; + + public function __construct(renderer $renderer, $context) { $this->renderer = $renderer; + $this->context = $context; } public function render() { - $templates = capquiz_question_list::load_question_list_templates(); + $templates = capquiz_question_list::load_question_list_templates($this->context); $lists = []; foreach ($templates as $template) { $lists[] = [ diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 1664b74..e765327 100755 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -112,8 +112,8 @@ public function display_question_list_create_view(capquiz $capquiz) { $this->display_view(new question_list_creator_renderer($capquiz, $this)); } - public function display_choose_question_list_view() { - $this->display_view(new question_list_selection_renderer($this)); + public function display_choose_question_list_view(capquiz $capquiz) { + $this->display_view(new question_list_selection_renderer($this, $capquiz->context())); } public function display_unauthorized_view() { diff --git a/grade.php b/grade.php new file mode 100644 index 0000000..38399f0 --- /dev/null +++ b/grade.php @@ -0,0 +1,45 @@ +. + +/** + * @package mod_capquiz + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_capquiz; + +require_once('../../config.php'); + +require_login(); + +$cmid = required_param('id', PARAM_INT); +$cm = get_coursemodule_from_id('capquiz', $cmid, 0, false, MUST_EXIST); +require_login($cm->course, false, $cm); + +$capquiz = capquiz::create(); +if (!$capquiz) { + capquiz_urls::redirect_to_front_page(); +} + +capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlview); + +if (has_capability('mod/capquiz:instructor', $capquiz->context())) { + redirect(capquiz_urls::view_classlist_url()); +} + +redirect(capquiz_urls::view_url()); diff --git a/lang/en/capquiz.php b/lang/en/capquiz.php index aa3c4d8..626dada 100755 --- a/lang/en/capquiz.php +++ b/lang/en/capquiz.php @@ -162,6 +162,9 @@ $string['problem_with_question_details'] = 'If you have feedback for this question, please type it below. The text will be sent to your instructor. You will be able to continue editing this when you have submitted your answer.'; $string['enter_comment_here'] = 'Enter your comment here...'; +$string['deleted_grades'] = 'Deleted grades'; +$string['deleted_attempts'] = 'Deleted attempts'; + $string['privacy:metadata:core_question'] = 'The CAPQuiz activity stores question usage information in the core_question subsystem.'; $string['privacy:metadata:capquiz_attempt'] = 'Details about each attempt on a CAPQuiz.'; $string['privacy:metadata:capquiz_attempt:userid'] = 'The user who made the attempt.'; diff --git a/lib.php b/lib.php index 898c655..6aaa896 100755 --- a/lib.php +++ b/lib.php @@ -25,6 +25,8 @@ defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot . '/lib/gradelib.php'); + function capquiz_add_instance(stdClass $modformdata) { global $DB; $modformdata->time_modified = time(); @@ -39,6 +41,7 @@ function capquiz_update_instance(stdClass $capquiz) { global $DB; $capquiz->id = $capquiz->instance; $DB->update_record('capquiz', $capquiz); + capquiz_update_grades($capquiz); return true; } @@ -50,19 +53,114 @@ function capquiz_delete_instance(int $id) { } } +function capquiz_reset_userdata($data) { + global $DB; + $status = []; + $strmodname = get_string('modulenameplural', 'capquiz'); + $strdeletegrades = get_string('deleted_grades', 'capquiz'); + $strdeleteattempts = get_string('deleted_attempts', 'capquiz'); + + capquiz_reset_gradebook($data->courseid); + $status[] = ['component' => $strmodname, 'item' => $strdeletegrades, 'error' => false]; + + $instances = $DB->get_records('capquiz', ['course' => $data->courseid]); + foreach ($instances as $instance) { + $qlist = $DB->get_record('capquiz_question_list', ['capquiz_id' => $instance->id]); + if (!$qlist) { + continue; + } + \question_engine::delete_questions_usage_by_activity($qlist->question_usage_id); + $users = $DB->get_records('capquiz_user', ['capquiz_id' => $instance->id]); + foreach ($users as $user) { + $DB->delete_records('capquiz_attempt', ['user_id' => $user->id]); + } + $DB->delete_records('capquiz_user', ['capquiz_id' => $instance->id]); + $qlist->question_usage_id = null; + $DB->update_record('capquiz_question_list', $qlist); + } + $status[] = ['component' => $strmodname, 'item' => $strdeleteattempts, 'error' => false]; + return $status; +} + function capquiz_cron() { return true; } +function capquiz_get_user_grades(stdClass $capquiz, int $userid = 0) { + global $DB; + $params = ['capquiz_id' => $capquiz->id]; + if ($userid > 0) { + $params['user_id'] = $userid; + } + $users = $DB->get_records('capquiz_user', $params); + if (!$users) { + return []; + } + $grades = []; + foreach ($users as $user) { + $grade = new stdClass(); + $grade->userid = $user->user_id; + $grade->rawgrade = $user->highest_level; + $grade->dategraded = time(); + $grade->datesubmitted = time(); + $grades[$user->user_id] = $grade; + } + return $grades; +} + +function capquiz_grade_item_update(stdClass $capquiz, $grades = null) { + $capquiz->cmidnumber = get_coursemodule_from_instance('capquiz', $capquiz->id)->id; + $params = [ + 'itemname' => $capquiz->name, + 'idnumber' => $capquiz->cmidnumber + ]; + $params['gradetype'] = GRADE_TYPE_VALUE; + $params['grademax'] = 5; + $params['grademin'] = 0; + if ($grades === 'reset') { + $params['reset'] = true; + $grades = null; + } + return grade_update('mod/capquiz', $capquiz->course, 'mod', 'capquiz', $capquiz->id, 0, $grades, $params); +} + +function capquiz_update_grades(stdClass $capquiz, int $userid = 0, $nullifnone = true) { + $grades = capquiz_get_user_grades($capquiz, $userid); + if ($grades) { + capquiz_grade_item_update($capquiz, $grades); + } else if ($userid && $nullifnone) { + $grade = new stdClass(); + $grade->userid = $userid; + $grade->rawgrade = null; + capquiz_grade_item_update($capquiz, [$userid => $grade]); + } else { + capquiz_grade_item_update($capquiz); + } +} + +function capquiz_reset_gradebook($courseid, $type = '') { + global $DB; + $instances = $DB->get_records_sql(" + SELECT cq.* + FROM {modules} m + JOIN {course_modules} cm + ON cm.module = m.id + AND cm.course = :courseid + JOIN {capquiz} cq + ON cq.id = cm.instance + WHERE m.name = 'capquiz'", ['courseid' => $courseid]); + foreach ($instances as $instance) { + capquiz_grade_item_update($instance, 'reset'); + } +} + function capquiz_supports($feature) { switch ($feature) { case FEATURE_MOD_INTRO: - return true; case FEATURE_BACKUP_MOODLE2: - return true; case FEATURE_SHOW_DESCRIPTION: - return true; case FEATURE_USES_QUESTIONS: + case FEATURE_GRADE_HAS_GRADE: return true; default: return false; diff --git a/version.php b/version.php index bd5eb08..cb977d9 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062400; +$plugin->version = 2019062501; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.0 (Build: 2019062400)'; +$plugin->release = '0.2.1 (Build: 2019062501)'; diff --git a/view.php b/view.php index 460c8a0..ec19ac7 100755 --- a/view.php +++ b/view.php @@ -42,7 +42,7 @@ if ($capquiz->has_question_list()) { $capquiz->renderer()->display_instructor_dashboard($capquiz); } else { - $capquiz->renderer()->display_choose_question_list_view(); + $capquiz->renderer()->display_choose_question_list_view($capquiz); } } else { require_capability('mod/capquiz:student', $capquiz->context()); @@ -51,5 +51,6 @@ if ($qengine) { $qengine->delete_invalid_attempt($capquiz->user()); } + $capquiz->update_grades(); $capquiz->renderer()->display_question_attempt_view($capquiz); } From 9c515a512422bd986c8c2ae27509fd5948bdb67e Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Tue, 25 Jun 2019 12:28:32 +0200 Subject: [PATCH 02/24] add missing strings --- lang/en/capquiz.php | 2 ++ templates/student_comment_list.mustache | 11 +++++++++-- version.php | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lang/en/capquiz.php b/lang/en/capquiz.php index 626dada..a939775 100755 --- a/lang/en/capquiz.php +++ b/lang/en/capquiz.php @@ -161,6 +161,8 @@ $string['problem_with_question_header'] = 'Is there a problem with this question? Send feedback to your instructor here.'; $string['problem_with_question_details'] = 'If you have feedback for this question, please type it below. The text will be sent to your instructor. You will be able to continue editing this when you have submitted your answer.'; $string['enter_comment_here'] = 'Enter your comment here...'; +$string['feedback_from_students'] = 'Feedback from students'; +$string['posted_by_student'] = 'Posted by {$a}'; $string['deleted_grades'] = 'Deleted grades'; $string['deleted_attempts'] = 'Deleted attempts'; diff --git a/templates/student_comment_list.mustache b/templates/student_comment_list.mustache index 2f4bfa4..842088f 100644 --- a/templates/student_comment_list.mustache +++ b/templates/student_comment_list.mustache @@ -34,14 +34,21 @@ } }}
-

Feedback from students

+

{{#str}} feedback_from_students, capquiz {{/str}}

{{#questions}}

{{question}}

{{#comments}}

{{comment}}

- posted by {{student}} at {{#userdate}}{{time_submitted}}, %A, %d %B %Y, %I:%M %p{{/userdate}} + {{#str}} + posted_by_student, + capquiz, + {{student}}, + {{#userdate}} + {{time_submitted}}, %A, %d %B %Y, %I:%M %p + {{/userdate}} + {{/str}}
{{/comments}}
diff --git a/version.php b/version.php index cb977d9..33c9690 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062501; +$plugin->version = 2019062503; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062501)'; +$plugin->release = '0.2.1 (Build: 2019062503)'; From 78a98ee030ea05e094e39a80882e4e5e6568fd3b Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Tue, 25 Jun 2019 14:48:46 +0200 Subject: [PATCH 03/24] simplify query it used to select columns from other tables, but not now --- lib.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib.php b/lib.php index 6aaa896..1238678 100755 --- a/lib.php +++ b/lib.php @@ -140,15 +140,7 @@ function capquiz_update_grades(stdClass $capquiz, int $userid = 0, $nullifnone = function capquiz_reset_gradebook($courseid, $type = '') { global $DB; - $instances = $DB->get_records_sql(" - SELECT cq.* - FROM {modules} m - JOIN {course_modules} cm - ON cm.module = m.id - AND cm.course = :courseid - JOIN {capquiz} cq - ON cq.id = cm.instance - WHERE m.name = 'capquiz'", ['courseid' => $courseid]); + $instances = $DB->get_records('capquiz', ['course' => $courseid]); foreach ($instances as $instance) { capquiz_grade_item_update($instance, 'reset'); } From 23c406169200251491af215cbaaa6d3788b2e34b Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Tue, 25 Jun 2019 15:05:35 +0200 Subject: [PATCH 04/24] add passing grade default is now 3, but will be editable soon --- lib.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib.php b/lib.php index 1238678..7b79163 100755 --- a/lib.php +++ b/lib.php @@ -121,7 +121,17 @@ function capquiz_grade_item_update(stdClass $capquiz, $grades = null) { $params['reset'] = true; $grades = null; } - return grade_update('mod/capquiz', $capquiz->course, 'mod', 'capquiz', $capquiz->id, 0, $grades, $params); + $status = grade_update('mod/capquiz', $capquiz->course, 'mod', 'capquiz', $capquiz->id, 0, $grades, $params); + $item = grade_item::fetch([ + 'courseid' => $capquiz->course, + 'itemtype' => 'mod', + 'itemmodule' => 'capquiz', + 'iteminstance' => $capquiz->id, + 'outcomeid' => null + ]); + $item->gradepass = 3; + $item->update(); + return $status; } function capquiz_update_grades(stdClass $capquiz, int $userid = 0, $nullifnone = true) { From 8542e0a60f90d92778c8d76107af01d044d9187d Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Wed, 26 Jun 2019 12:21:43 +0200 Subject: [PATCH 05/24] merge some tabs --- classes/capquiz.php | 9 +-- classes/capquiz_urls.php | 17 +---- .../form/view/capquiz_configuration_form.php | 68 ------------------- ...n_form.php => star_configuration_form.php} | 34 +++++----- .../output/capquiz_configuration_renderer.php | 62 ----------------- ...php => grading_configuration_renderer.php} | 28 ++++---- .../rating_system_configuration_renderer.php | 3 +- .../rating_system_selection_renderer.php | 2 +- classes/output/renderer.php | 24 ++----- lang/en/capquiz.php | 4 +- templates/capquiz_configuration.mustache | 26 ------- ...ng.mustache => configure_grading.mustache} | 4 +- version.php | 4 +- view_badge_configuration.php | 43 ------------ view_configuration.php => view_grading.php | 4 +- view_rating_system_configuration.php | 43 ------------ 16 files changed, 56 insertions(+), 319 deletions(-) delete mode 100755 classes/form/view/capquiz_configuration_form.php rename classes/form/view/{badge_rating_configuration_form.php => star_configuration_form.php} (64%) mode change 100755 => 100644 delete mode 100755 classes/output/capquiz_configuration_renderer.php rename classes/output/{badge_rating_configuration_renderer.php => grading_configuration_renderer.php} (73%) mode change 100755 => 100644 delete mode 100755 templates/capquiz_configuration.mustache rename templates/{configure_badge_rating.mustache => configure_grading.mustache} (91%) mode change 100755 => 100644 delete mode 100755 view_badge_configuration.php rename view_configuration.php => view_grading.php (92%) mode change 100755 => 100644 delete mode 100755 view_rating_system_configuration.php diff --git a/classes/capquiz.php b/classes/capquiz.php index a7bcb9e..9b4537a 100755 --- a/classes/capquiz.php +++ b/classes/capquiz.php @@ -188,14 +188,9 @@ public function course() : \stdClass { return $this->courserecord; } - public function configure(\stdClass $configuration) { + public function set_default_user_rating(float $rating) { global $DB; - if ($configuration->name) { - $this->record->name = $configuration->name; - } - if ($configuration->default_user_rating) { - $this->record->default_user_rating = $configuration->default_user_rating; - } + $this->record->default_user_rating = $rating; $DB->update_record('capquiz', $this->record); } diff --git a/classes/capquiz_urls.php b/classes/capquiz_urls.php index 3d200b5..dead1be 100755 --- a/classes/capquiz_urls.php +++ b/classes/capquiz_urls.php @@ -41,14 +41,12 @@ class capquiz_urls { public static $urlerror = '/mod/capquiz/error.php'; public static $urlaction = '/mod/capquiz/action.php'; public static $urlviewclasslist = '/mod/capquiz/view_classlist.php'; - public static $urlviewconfig = '/mod/capquiz/view_configuration.php'; + public static $urlviewgrading = '/mod/capquiz/view_grading.php'; public static $urlviewcomments = '/mod/capquiz/view_comments.php'; public static $urlviewimport = '/mod/capquiz/view_import.php'; public static $urledit = '/mod/capquiz/edit.php'; - public static $urlviewbadgeconfig = '/mod/capquiz/view_badge_configuration.php'; public static $urlviewcreateqlist = '/mod/capquiz/view_create_question_list.php'; public static $urlviewmatchmakingconfig = '/mod/capquiz/view_matchmaking_configuration.php'; - public static $urlviewratingsystemconfig = '/mod/capquiz/view_rating_system_configuration.php'; public static function redirect(\moodle_url $target) { $url = self::create_view_url(self::$urlaction); @@ -109,13 +107,8 @@ public static function view_matchmaking_configuration_url() { return $url; } - public static function view_rating_system_configuration_url() { - $url = self::create_view_url(self::$urlviewratingsystemconfig); - return $url; - } - - public static function view_badge_configuration_url() { - $url = self::create_view_url(self::$urlviewbadgeconfig); + public static function view_grading_url() { + $url = self::create_view_url(self::$urlviewgrading); return $url; } @@ -123,10 +116,6 @@ public static function view_classlist_url() { return self::create_view_url(self::$urlviewclasslist); } - public static function view_configuration_url() { - return self::create_view_url(self::$urlviewconfig); - } - public static function view_create_question_list_url() { return self::create_view_url(self::$urlviewcreateqlist); } diff --git a/classes/form/view/capquiz_configuration_form.php b/classes/form/view/capquiz_configuration_form.php deleted file mode 100755 index 3a7b33c..0000000 --- a/classes/form/view/capquiz_configuration_form.php +++ /dev/null @@ -1,68 +0,0 @@ -. - -namespace mod_capquiz\form\view; - -use mod_capquiz\capquiz; - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir . '/formslib.php'); - -/** - * @package mod_capquiz - * @author Aleksander Skrede - * @copyright 2018 NTNU - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class capquiz_configuration_form extends \moodleform { - private $capquiz; - - public function __construct(capquiz $capquiz, \moodle_url $url) { - $this->capquiz = $capquiz; - parent::__construct($url); - } - - public function definition() { - $form = $this->_form; - - $form->addElement('text', 'name', get_string('name', 'capquiz')); - $form->setType('name', PARAM_TEXT); - $form->setDefault('name', $this->capquiz->name()); - $form->addRule('name', get_string('name_required', 'capquiz'), 'required', null, 'client'); - - $form->addElement('text', 'default_user_rating', get_string('default_user_rating', 'capquiz')); - $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); - } - - public function validations($data, $files) { - $errors = []; - if (empty($data['name'])) { - $errors['name'] = get_string('name_required', 'capquiz'); - } - if (empty($data['description'])) { - $errors['description'] = get_string('description_required', 'capquiz'); - } - if (empty($data['default_user_rating'])) { - $errors['default_user_rating'] = get_string('default_user_rating_required', 'capquiz'); - } - return $errors; - } - -} diff --git a/classes/form/view/badge_rating_configuration_form.php b/classes/form/view/star_configuration_form.php old mode 100755 new mode 100644 similarity index 64% rename from classes/form/view/badge_rating_configuration_form.php rename to classes/form/view/star_configuration_form.php index f0f2ca8..b203093 --- a/classes/form/view/badge_rating_configuration_form.php +++ b/classes/form/view/star_configuration_form.php @@ -16,6 +16,7 @@ namespace mod_capquiz\form\view; +use mod_capquiz\capquiz; use mod_capquiz\capquiz_question_list; defined('MOODLE_INTERNAL') || die(); @@ -28,42 +29,43 @@ * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class badge_rating_configuration_form extends \moodleform { +class star_configuration_form extends \moodleform { - /** @var capquiz_question_list $qlist */ - private $qlist; + /** @var capquiz $capquiz */ + private $capquiz; - public function __construct(capquiz_question_list $qlist, \moodle_url $url) { - $this->qlist = $qlist; + public function __construct(capquiz $capquiz, \moodle_url $url) { + $this->capquiz = $capquiz; parent::__construct($url); } public function definition() { + $qlist = $this->capquiz->question_list(); $form = $this->_form; - for ($i = 0; $i < $this->qlist->level_count(); $i++) { - $level = $i + $this->qlist->first_level(); + $form->addElement('text', 'default_user_rating', get_string('default_user_rating', 'capquiz')); + $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'); + for ($i = 0; $i < $qlist->level_count(); $i++) { + $level = $i + $qlist->first_level(); $element = "level_{$level}_rating"; $text = get_string('level_rating', 'capquiz', $level); $requiredtext = get_string('level_rating_required', 'capquiz', $level); $form->addElement('text', $element, $text); $form->setType($element, PARAM_INT); $form->addRule($element, $requiredtext, 'required', null, 'client'); - $form->setDefault($element, $this->qlist->required_rating_for_level($level)); + $form->setDefault($element, $qlist->required_rating_for_level($level)); } - $form->addElement('submit', 'submitbutton', get_string('savechanges')); } public function validations($data, $files) { $errors = []; - if (empty($data['title'])) { - $errors['title'] = get_string('title_required', 'capquiz'); - } - if (empty($data['description'])) { - $errors['description'] = get_string('description_required', 'capquiz'); + if (empty($data['default_user_rating'])) { + $errors['default_user_rating'] = get_string('default_user_rating_required', 'capquiz'); } - for ($i = 0; $i < $this->qlist->level_count(); $i++) { - $level = $i + $this->qlist->first_level(); + for ($i = 0; $i < $qlist->level_count(); $i++) { + $level = $i + $qlist->first_level(); $element = "level_{$level}_rating"; if (empty($data[$element])) { $requiredtext = get_string('level_rating_required', 'capquiz', $level); diff --git a/classes/output/capquiz_configuration_renderer.php b/classes/output/capquiz_configuration_renderer.php deleted file mode 100755 index fff7903..0000000 --- a/classes/output/capquiz_configuration_renderer.php +++ /dev/null @@ -1,62 +0,0 @@ -. - -namespace mod_capquiz\output; - -use mod_capquiz\capquiz; -use mod_capquiz\capquiz_urls; -use mod_capquiz\form\view\capquiz_configuration_form; - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot . '/question/editlib.php'); - -/** - * @package mod_capquiz - * @author Aleksander Skrede - * @copyright 2018 NTNU - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class capquiz_configuration_renderer { - - /** @var capquiz $capquiz */ - private $capquiz; - - /** @var renderer $renderer */ - private $renderer; - - public function __construct(capquiz $capquiz, renderer $renderer) { - $this->capquiz = $capquiz; - $this->renderer = $renderer; - } - - public function render() { - global $PAGE; - $url = $PAGE->url; - $form = new capquiz_configuration_form($this->capquiz, $url); - if ($form->is_cancelled()) { - capquiz_urls::redirect_to_dashboard(); - } - $formdata = $form->get_data(); - if ($formdata) { - $this->capquiz->configure($formdata); - capquiz_urls::redirect_to_dashboard(); - } - return $this->renderer->render_from_template('capquiz/capquiz_configuration', [ - 'form' => $form->render() - ]); - } -} diff --git a/classes/output/badge_rating_configuration_renderer.php b/classes/output/grading_configuration_renderer.php old mode 100755 new mode 100644 similarity index 73% rename from classes/output/badge_rating_configuration_renderer.php rename to classes/output/grading_configuration_renderer.php index 785b258..fabbfe7 --- a/classes/output/badge_rating_configuration_renderer.php +++ b/classes/output/grading_configuration_renderer.php @@ -18,7 +18,8 @@ use mod_capquiz\capquiz; use mod_capquiz\capquiz_urls; -use mod_capquiz\form\view\badge_rating_configuration_form; +use mod_capquiz\form\view\user_configuration_form; +use mod_capquiz\form\view\star_configuration_form; defined('MOODLE_INTERNAL') || die(); @@ -30,7 +31,7 @@ * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class badge_rating_configuration_renderer { +class grading_configuration_renderer { /** @var capquiz $capquiz */ private $capquiz; @@ -44,15 +45,20 @@ public function __construct(capquiz $capquiz, renderer $renderer) { } public function render() { + return $this->renderer->render_from_template('capquiz/configure_grading', [ + 'rating_form' => $this->get_rating_configuration() + ]); + } + + private function get_rating_configuration() { global $PAGE; $url = $PAGE->url; - $qlist = $this->capquiz->question_list(); - if (!$qlist) { - return 'question list error'; - } - $form = new badge_rating_configuration_form($qlist, $url); + $form = new star_configuration_form($this->capquiz, $url); $formdata = $form->get_data(); if ($formdata) { + if ($formdata->default_user_rating) { + $this->capquiz->set_default_user_rating($formdata->default_user_rating); + } $ratings = [ $formdata->level_1_rating, $formdata->level_2_rating, @@ -60,12 +66,10 @@ public function render() { $formdata->level_4_rating, $formdata->level_5_rating ]; - $qlist->set_level_ratings($ratings); - redirect(capquiz_urls::create_view_url(capquiz_urls::$urledit)); + $this->capquiz->question_list()->set_level_ratings($ratings); + redirect(capquiz_urls::view_grading_url()); } - return $this->renderer->render_from_template('capquiz/configure_badge_rating', [ - 'form' => $form->render() - ]); + return $form->render(); } } diff --git a/classes/output/rating_system_configuration_renderer.php b/classes/output/rating_system_configuration_renderer.php index 88ceed3..6fc3520 100755 --- a/classes/output/rating_system_configuration_renderer.php +++ b/classes/output/rating_system_configuration_renderer.php @@ -30,6 +30,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class rating_system_configuration_renderer { + private $capquiz; private $renderer; private $registry; @@ -63,7 +64,7 @@ private function render_form() { $formdata = $form->get_data(); if ($formdata) { $this->registry->configure_current_rating_system($formdata); - redirect(capquiz_urls::view_rating_system_configuration_url()); + redirect(capquiz_urls::view_matchmaking_configuration_url()); } return $form->render(); } diff --git a/classes/output/rating_system_selection_renderer.php b/classes/output/rating_system_selection_renderer.php index 2e3a055..6b8b305 100755 --- a/classes/output/rating_system_selection_renderer.php +++ b/classes/output/rating_system_selection_renderer.php @@ -42,7 +42,7 @@ class rating_system_selection_renderer { public function __construct(capquiz $capquiz, renderer $renderer) { $this->capquiz = $capquiz; $this->renderer = $renderer; - $this->url = capquiz_urls::view_rating_system_configuration_url(); + $this->url = capquiz_urls::view_matchmaking_configuration_url(); } public function set_redirect_url(\moodle_url $url) { diff --git a/classes/output/renderer.php b/classes/output/renderer.php index e765327..df4fd66 100755 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -27,11 +27,10 @@ require_once($CFG->dirroot . '/mod/capquiz/classes/output/question_bank_renderer.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/output/question_attempt_renderer.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/output/unauthorized_view_renderer.php'); -require_once($CFG->dirroot . '/mod/capquiz/classes/output/capquiz_configuration_renderer.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/output/question_list_creator_renderer.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/output/instructor_dashboard_renderer.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/output/matchmaking_configuration_renderer.php'); -require_once($CFG->dirroot . '/mod/capquiz/classes/output/badge_rating_configuration_renderer.php'); +require_once($CFG->dirroot . '/mod/capquiz/classes/output/grading_configuration_renderer.php'); require_once($CFG->dirroot . '/mod/capquiz/classes/output/matchmaking_strategy_selection_renderer.php'); /** @@ -55,10 +54,8 @@ private function tabs(string $activetab) { $tabs = [ $this->tab('view_dashboard', 'dashboard', capquiz_urls::view_url()), $this->tab('view_matchmaking', 'matchmaking', capquiz_urls::view_matchmaking_configuration_url()), - $this->tab('view_rating_system', 'rating_system', capquiz_urls::view_rating_system_configuration_url()), $this->tab('view_questions', 'questions', capquiz_urls::view_question_list_url()), - $this->tab('view_badges', 'badges', capquiz_urls::view_badge_configuration_url()), - $this->tab('view_capquiz', 'pluginname', capquiz_urls::view_configuration_url()), + $this->tab('view_grading', 'grading', capquiz_urls::view_grading_url()), $this->tab('view_classlist', 'classlist', capquiz_urls::view_classlist_url()), $this->tab('view_comments', 'comments', capquiz_urls::view_comments_url()), $this->tab('view_import', 'other_question_lists', capquiz_urls::view_import_url()) @@ -145,15 +142,10 @@ public function render() { public function display_matchmaking_configuration(capquiz $capquiz) { $this->display_tabbed_views([ new matchmaking_strategy_selection_renderer($capquiz, $this), - new matchmaking_configuration_renderer($capquiz, $this) - ], 'view_matchmaking'); - } - - public function display_rating_system_configuration(capquiz $capquiz) { - $this->display_tabbed_views([ + new matchmaking_configuration_renderer($capquiz, $this), new rating_system_selection_renderer($capquiz, $this), new rating_system_configuration_renderer($capquiz, $this) - ], 'view_rating_system'); + ], 'view_matchmaking'); } public function display_leaderboard(capquiz $capquiz) { @@ -168,12 +160,8 @@ public function display_import(capquiz $capquiz) { $this->display_tabbed_view(new import_renderer($capquiz, $this), 'view_import'); } - public function display_capquiz_configuration(capquiz $capquiz) { - $this->display_tabbed_view(new capquiz_configuration_renderer($capquiz, $this), 'view_capquiz'); - } - - public function display_badge_configuration(capquiz $capquiz) { - $this->display_tabbed_view(new badge_rating_configuration_renderer($capquiz, $this), 'view_badges'); + public function display_grading_configuration(capquiz $capquiz) { + $this->display_tabbed_view(new grading_configuration_renderer($capquiz, $this), 'view_grading'); } } diff --git a/lang/en/capquiz.php b/lang/en/capquiz.php index a939775..1360ca4 100755 --- a/lang/en/capquiz.php +++ b/lang/en/capquiz.php @@ -39,7 +39,7 @@ $string['question_list'] = 'Question list'; $string['question_lists'] = 'Question lists'; -$string['configure_badge_rating'] = 'Configure badge rating'; +$string['configure_grading'] = 'Configure grading'; $string['comments'] = 'Comments'; $string['import'] = 'Import'; @@ -51,7 +51,7 @@ $string['title'] = 'Title'; $string['author'] = 'Author'; $string['created'] = 'Created'; -$string['badges'] = 'Badges'; +$string['grading'] = 'Grading'; $string['remove'] = 'Remove'; $string['rating'] = 'Rating'; $string['action'] = 'Action'; diff --git a/templates/capquiz_configuration.mustache b/templates/capquiz_configuration.mustache deleted file mode 100755 index 7806b98..0000000 --- a/templates/capquiz_configuration.mustache +++ /dev/null @@ -1,26 +0,0 @@ -{{! - 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 . -}} -{{! - @template mod_capquiz/capquiz_configuration - - Example context (json): - { - "form": "raw html for the configuration form" - } -}} -

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

-{{{ form }}} diff --git a/templates/configure_badge_rating.mustache b/templates/configure_grading.mustache old mode 100755 new mode 100644 similarity index 91% rename from templates/configure_badge_rating.mustache rename to templates/configure_grading.mustache index 508b95f..4f41bc7 --- a/templates/configure_badge_rating.mustache +++ b/templates/configure_grading.mustache @@ -22,5 +22,5 @@ "form": "raw html for the form" } }} -

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

-{{{ form }}} +

{{#str}} configure_grading, capquiz {{/str}}

+{{{ rating_form }}} diff --git a/version.php b/version.php index 33c9690..ddb45b9 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062503; +$plugin->version = 2019062507; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062503)'; +$plugin->release = '0.2.1 (Build: 2019062505)'; diff --git a/view_badge_configuration.php b/view_badge_configuration.php deleted file mode 100755 index 9a8e0f4..0000000 --- a/view_badge_configuration.php +++ /dev/null @@ -1,43 +0,0 @@ -. - -/** - * @package mod_capquiz - * @author Aleksander Skrede - * @copyright 2018 NTNU - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace mod_capquiz; - -require_once('../../config.php'); -require_once($CFG->dirroot . '/question/editlib.php'); -require_once($CFG->dirroot . '/mod/capquiz/lib.php'); - -$cmid = capquiz_urls::require_course_module_id_param(); -$cm = get_coursemodule_from_id('capquiz', $cmid, 0, false, MUST_EXIST); -require_login($cm->course, false, $cm); -$context = \context_module::instance($cmid); -require_capability('mod/capquiz:instructor', $context); - -$capquiz = capquiz::create(); -if (!$capquiz) { - capquiz_urls::redirect_to_front_page(); -} - -capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlviewbadgeconfig); -$renderer = $capquiz->renderer(); -$renderer->display_badge_configuration($capquiz); diff --git a/view_configuration.php b/view_grading.php old mode 100755 new mode 100644 similarity index 92% rename from view_configuration.php rename to view_grading.php index 34b4af3..85bc62f --- a/view_configuration.php +++ b/view_grading.php @@ -38,6 +38,6 @@ capquiz_urls::redirect_to_front_page(); } -capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlviewconfig); +capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlviewgrading); $renderer = $capquiz->renderer(); -$renderer->display_capquiz_configuration($capquiz); +$renderer->display_grading_configuration($capquiz); diff --git a/view_rating_system_configuration.php b/view_rating_system_configuration.php deleted file mode 100755 index 0a668b2..0000000 --- a/view_rating_system_configuration.php +++ /dev/null @@ -1,43 +0,0 @@ -. - -/** - * @package mod_capquiz - * @author Aleksander Skrede - * @copyright 2018 NTNU - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace mod_capquiz; - -require_once('../../config.php'); -require_once($CFG->dirroot . '/question/editlib.php'); -require_once($CFG->dirroot . '/mod/capquiz/lib.php'); - -$cmid = capquiz_urls::require_course_module_id_param(); -$cm = get_coursemodule_from_id('capquiz', $cmid, 0, false, MUST_EXIST); -require_login($cm->course, false, $cm); -$context = \context_module::instance($cmid); -require_capability('mod/capquiz:instructor', $context); - -$capquiz = capquiz::create(); -if (!$capquiz) { - capquiz_urls::redirect_to_front_page(); -} - -capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlviewratingsystemconfig); -$renderer = $capquiz->renderer(); -$renderer->display_rating_system_configuration($capquiz); From fbbd2c00d5bd2a65146730bfac21bdc7cf2153c9 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Wed, 26 Jun 2019 12:39:58 +0200 Subject: [PATCH 06/24] improved class list tab Added sorting for all columns, and improved the styling for the table --- amd/src/edit_questions.js | 7 +++++-- classes/output/classlist_renderer.php | 3 +++ .../output/grading_configuration_renderer.php | 5 ++--- styles.css | 16 +++++++++++++++- templates/classlist.mustache | 12 ++++++------ templates/question_list.mustache | 2 +- version.php | 4 ++-- 7 files changed, 34 insertions(+), 15 deletions(-) diff --git a/amd/src/edit_questions.js b/amd/src/edit_questions.js index 9032f48..a40308c 100755 --- a/amd/src/edit_questions.js +++ b/amd/src/edit_questions.js @@ -15,8 +15,8 @@ /** * @package mod_capquiz - * @author Sebastian S. Gundersen - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -189,6 +189,9 @@ define(['jquery'], function($) { $(document).on('click', '.capquiz-sortable', function() { sortTable($(this)); }); + $('.capquiz-sortable-default').each(function () { + sortTable($(this)); + }); } /** diff --git a/classes/output/classlist_renderer.php b/classes/output/classlist_renderer.php index ce194bc..2e627bd 100755 --- a/classes/output/classlist_renderer.php +++ b/classes/output/classlist_renderer.php @@ -43,6 +43,9 @@ public function __construct(capquiz $capquiz, renderer $renderer) { } public function render() { + global $PAGE; + $cmid = $this->capquiz->course_module_id(); + $PAGE->requires->js_call_amd('mod_capquiz/edit_questions', 'initialize', [$cmid]); $users = capquiz_user::list_users($this->capquiz); $rows = []; for ($i = 0; $i < count($users); $i++) { diff --git a/classes/output/grading_configuration_renderer.php b/classes/output/grading_configuration_renderer.php index fabbfe7..d1be8ce 100644 --- a/classes/output/grading_configuration_renderer.php +++ b/classes/output/grading_configuration_renderer.php @@ -18,7 +18,6 @@ use mod_capquiz\capquiz; use mod_capquiz\capquiz_urls; -use mod_capquiz\form\view\user_configuration_form; use mod_capquiz\form\view\star_configuration_form; defined('MOODLE_INTERNAL') || die(); @@ -27,8 +26,8 @@ /** * @package mod_capquiz - * @author Sebastian S. Gundersen - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class grading_configuration_renderer { diff --git a/styles.css b/styles.css index 573478b..f75874a 100755 --- a/styles.css +++ b/styles.css @@ -21,6 +21,11 @@ width: 50%; } +.capquiz-tree tr td, +.capquiz-tree tr th { + padding: 6px; +} + .capquiz-tree tr:first-child { background: #fafafa; } @@ -42,7 +47,7 @@ background: #fafafa; } -.capquiz-tree tr td { +.capquiz-qlist-questions tr td { padding: 2px 4px; } @@ -231,3 +236,12 @@ .capquiz-question-rating input { width: 80px; } + +.capquiz-classlist tr td, +.capquiz-classlist tr th { + padding: 4px 16px; +} + +.capquiz-classlist tr:nth-child(odd) td { + background: #fafafa; +} diff --git a/templates/classlist.mustache b/templates/classlist.mustache index a56424c..3106709 100755 --- a/templates/classlist.mustache +++ b/templates/classlist.mustache @@ -32,14 +32,14 @@ } }}

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

- +
- - - - - + + + + + {{#users}} diff --git a/templates/question_list.mustache b/templates/question_list.mustache index b5432a6..785aa35 100755 --- a/templates/question_list.mustache +++ b/templates/question_list.mustache @@ -52,7 +52,7 @@ {{{message}}} {{/message}} -
#{{#str}} username, capquiz {{/str}}{{#str}} firstname, capquiz {{/str}}{{#str}} lastname, capquiz {{/str}}{{#str}} rating, capquiz {{/str}}{{#str}} stars, capquiz {{/str}}{{#str}} username, capquiz {{/str}}{{#str}} firstname, capquiz {{/str}}{{#str}} lastname, capquiz {{/str}}{{#str}} rating, capquiz {{/str}}{{#str}} stars, capquiz {{/str}}
+
diff --git a/version.php b/version.php index ddb45b9..ab9715a 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062507; +$plugin->version = 2019062510; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062505)'; +$plugin->release = '0.2.1 (Build: 2019062510)'; From 07baed2f5ec95a5f18aa634a0fad99ed668e8955 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Wed, 26 Jun 2019 14:17:27 +0200 Subject: [PATCH 07/24] add configurable number of stars for passing grade and time for final grading. Also added some columns for grade and pass/fail in class list --- classes/capquiz.php | 48 +++++++++++------- classes/capquiz_question_registry.php | 49 ------------------- classes/capquiz_user.php | 8 +-- ...orm.php => grading_configuration_form.php} | 19 ++++++- classes/output/classlist_renderer.php | 4 +- .../output/grading_configuration_renderer.php | 10 +++- classes/output/question_attempt_renderer.php | 5 +- db/install.xml | 7 ++- db/upgrade.php | 17 +++++++ lang/en/capquiz.php | 17 +++++-- lib.php | 8 ++- templates/classlist.mustache | 7 +++ templates/student_question_attempt.mustache | 10 ++++ version.php | 4 +- 14 files changed, 128 insertions(+), 85 deletions(-) delete mode 100755 classes/capquiz_question_registry.php rename classes/form/view/{star_configuration_form.php => grading_configuration_form.php} (75%) diff --git a/classes/capquiz.php b/classes/capquiz.php index 9b4537a..8c1bbca 100755 --- a/classes/capquiz.php +++ b/classes/capquiz.php @@ -67,7 +67,9 @@ public static function create() : capquiz { } public function update_grades() { - capquiz_update_grades($this->record); + if (!$this->is_grading_completed()) { + capquiz_update_grades($this->record); + } } public static function create_from_id(int $id) : capquiz { @@ -78,16 +80,32 @@ public function id() : int { return $this->record->id; } - public function name() : string { - return $this->record->name; + public function is_published() : bool { + return $this->record->published; } - public function description() : string { - return $this->record->description; + public function stars_to_pass() : int { + return $this->record->stars_to_pass; } - public function is_published() : bool { - return $this->record->published; + public function set_stars_to_pass(int $stars) { + global $DB; + $this->record->stars_to_pass = $stars; + $DB->update_record('capquiz', $this->record); + } + + public function time_due() : int { + return $this->record->timedue; + } + + public function set_time_due(int $time) { + global $DB; + $this->record->timedue = $time; + $DB->update_record('capquiz', $this->record); + } + + public function is_grading_completed() : bool { + return $this->record->timedue < time() && $this->record->timedue > 0; } public function can_publish() : bool { @@ -104,11 +122,7 @@ public function publish() : bool { } $this->question_list()->create_question_usage($this->context()); $this->record->published = true; - try { - $DB->update_record('capquiz', $this->record); - } catch (\dml_exception $e) { - return false; - } + $DB->update_record('capquiz', $this->record); return $this->is_published(); } @@ -138,14 +152,10 @@ public function rating_system_registry() : capquiz_rating_system_registry { public function question_engine() { $quba = $this->question_usage(); - if ($quba) { - return new capquiz_question_engine($this, $quba, $this->selection_strategy_loader(), $this->rating_system_loader()); + if (!$quba) { + return null; } - return null; - } - - public function question_registry() : capquiz_question_registry { - return new capquiz_question_registry($this); + return new capquiz_question_engine($this, $quba, $this->selection_strategy_loader(), $this->rating_system_loader()); } public function has_question_list() : bool { diff --git a/classes/capquiz_question_registry.php b/classes/capquiz_question_registry.php deleted file mode 100755 index 22465e3..0000000 --- a/classes/capquiz_question_registry.php +++ /dev/null @@ -1,49 +0,0 @@ -. - -namespace mod_capquiz; - -defined('MOODLE_INTERNAL') || die(); - -/** - * @package mod_capquiz - * @author Aleksander Skrede - * @copyright 2018 NTNU - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class capquiz_question_registry { - - /** @var capquiz $capquiz */ - private $capquiz; - - public function __construct(capquiz $capquiz) { - $this->capquiz = $capquiz; - } - - public function capquiz_instance() : capquiz { - return $this->capquiz; - } - - public function question_ids() : array { - $questions = $this->capquiz->question_list()->questions(); - $ret = []; - foreach ($questions as $question) { - $ret[] = $question->id(); - } - return $ret; - } - -} diff --git a/classes/capquiz_user.php b/classes/capquiz_user.php index 686476a..34fad7c 100755 --- a/classes/capquiz_user.php +++ b/classes/capquiz_user.php @@ -91,10 +91,6 @@ public function last_name() : string { return $this->moodlerecord->lastname; } - public function capquiz_id() : int { - return $this->record->capquiz_id; - } - public function rating() : float { return $this->record->rating; } @@ -103,6 +99,10 @@ public function highest_level() : int { return $this->record->highest_level; } + public function stars_graded() : int { + return $this->record->stars_graded; + } + public function set_highest_level(int $highestlevel) { global $DB; $record = $this->record; diff --git a/classes/form/view/star_configuration_form.php b/classes/form/view/grading_configuration_form.php similarity index 75% rename from classes/form/view/star_configuration_form.php rename to classes/form/view/grading_configuration_form.php index b203093..c859349 100644 --- a/classes/form/view/star_configuration_form.php +++ b/classes/form/view/grading_configuration_form.php @@ -29,7 +29,7 @@ * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class star_configuration_form extends \moodleform { +class grading_configuration_form extends \moodleform { /** @var capquiz $capquiz */ private $capquiz; @@ -56,6 +56,19 @@ public function definition() { $form->addRule($element, $requiredtext, 'required', null, 'client'); $form->setDefault($element, $qlist->required_rating_for_level($level)); } + + $strstarstopass = get_string('stars_to_pass', 'capquiz'); + $strstarstopassrequired = get_string('stars_to_pass_required', 'capquiz'); + $form->addElement('text', 'starstopass', $strstarstopass); + $form->setType('starstopass', PARAM_INT); + $form->setDefault('starstopass', $this->capquiz->stars_to_pass()); + $form->addRule('starstopass', $strstarstopassrequired, 'required', null, 'client'); + + $strduedate = get_string('due_time_grading', 'capquiz'); + $form->addElement('date_time_selector', 'timedue', $strduedate); + $form->setType('timedue', PARAM_INT); + $form->setDefault('timedue', $this->capquiz->time_due()); + $form->addElement('submit', 'submitbutton', get_string('savechanges')); } @@ -64,6 +77,7 @@ public function validations($data, $files) { if (empty($data['default_user_rating'])) { $errors['default_user_rating'] = get_string('default_user_rating_required', 'capquiz'); } + $qlist = $this->capquiz->question_list(); for ($i = 0; $i < $qlist->level_count(); $i++) { $level = $i + $qlist->first_level(); $element = "level_{$level}_rating"; @@ -72,6 +86,9 @@ public function validations($data, $files) { $errors[$element] = $requiredtext; } } + if (empty($data['starstopass']) || $data['starstopass'] < 0 || $data['starstopass'] > 5) { + $errors['starstopass'] = get_string('stars_to_pass_required', 'capquiz'); + } return $errors; } diff --git a/classes/output/classlist_renderer.php b/classes/output/classlist_renderer.php index 2e627bd..ed194af 100755 --- a/classes/output/classlist_renderer.php +++ b/classes/output/classlist_renderer.php @@ -56,7 +56,9 @@ public function render() { 'firstname' => $user->first_name(), 'lastname' => $user->last_name(), 'rating' => $user->rating(), - 'stars' => $user->highest_level() + 'stars' => $user->highest_level(), + 'graded_stars' => $user->stars_graded(), + 'passing_grade' => $user->stars_graded() >= $this->capquiz->stars_to_pass() ]; } $leaderboard = $this->renderer->render_from_template('capquiz/classlist', [ diff --git a/classes/output/grading_configuration_renderer.php b/classes/output/grading_configuration_renderer.php index d1be8ce..656d2fc 100644 --- a/classes/output/grading_configuration_renderer.php +++ b/classes/output/grading_configuration_renderer.php @@ -18,7 +18,7 @@ use mod_capquiz\capquiz; use mod_capquiz\capquiz_urls; -use mod_capquiz\form\view\star_configuration_form; +use mod_capquiz\form\view\grading_configuration_form; defined('MOODLE_INTERNAL') || die(); @@ -52,7 +52,7 @@ public function render() { private function get_rating_configuration() { global $PAGE; $url = $PAGE->url; - $form = new star_configuration_form($this->capquiz, $url); + $form = new grading_configuration_form($this->capquiz, $url); $formdata = $form->get_data(); if ($formdata) { if ($formdata->default_user_rating) { @@ -66,6 +66,12 @@ private function get_rating_configuration() { $formdata->level_5_rating ]; $this->capquiz->question_list()->set_level_ratings($ratings); + if ($formdata->starstopass) { + $this->capquiz->set_stars_to_pass($formdata->starstopass); + } + if ($formdata->timedue) { + $this->capquiz->set_time_due($formdata->timedue); + } redirect(capquiz_urls::view_grading_url()); } return $form->render(); diff --git a/classes/output/question_attempt_renderer.php b/classes/output/question_attempt_renderer.php index 18f99ec..2de8200 100755 --- a/classes/output/question_attempt_renderer.php +++ b/classes/output/question_attempt_renderer.php @@ -124,7 +124,10 @@ public function render_question_attempt(capquiz_question_attempt $attempt, \ques 'body' => $quba->render_question($attempt->question_slot(), $options, $attempt->question_id()), 'slots' => '', 'comment' => $attempt->student_comment() - ] + ], + 'gradingdone' => $this->capquiz->is_grading_completed(), + 'finalgrade' => $this->capquiz->user()->stars_graded(), + 'gradingpass' => $this->capquiz->user()->stars_graded() >= $this->capquiz->stars_to_pass() ]); } diff --git a/db/install.xml b/db/install.xml index 569abd8..7699d24 100755 --- a/db/install.xml +++ b/db/install.xml @@ -14,7 +14,9 @@ - + + + @@ -67,7 +69,8 @@ - + + diff --git a/db/upgrade.php b/db/upgrade.php index 6819682..46feda8 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -41,5 +41,22 @@ function xmldb_capquiz_upgrade($oldversion) { } upgrade_mod_savepoint(true, 2019061700, 'capquiz'); } + if ($oldversion < 2019062550) { + $table = new xmldb_table('capquiz'); + $field = new xmldb_field('stars_to_pass', XMLDB_TYPE_INTEGER, 10, null, true, null, 3); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + $field = new xmldb_field('timedue', XMLDB_TYPE_INTEGER, 10, null, true, null, 0); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + $table = new xmldb_table('capquiz_user'); + $field = new xmldb_field('stars_graded', XMLDB_TYPE_INTEGER, 10, null, true, null, 0); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + upgrade_mod_savepoint(true, 2019062550, 'capquiz'); + } return true; } diff --git a/lang/en/capquiz.php b/lang/en/capquiz.php index 1360ca4..fd6e83b 100755 --- a/lang/en/capquiz.php +++ b/lang/en/capquiz.php @@ -41,6 +41,17 @@ $string['question_lists'] = 'Question lists'; $string['configure_grading'] = 'Configure grading'; +$string['stars_to_pass'] = 'Number of stars required for passing grade'; +$string['stars_to_pass_required'] = 'Stars for passing grade is required (0-5)'; +$string['due_time_grading'] = 'Time for final grading'; +$string['grading_is_completed'] = 'Grading is completed.'; +$string['grade_has_been_set_pass'] = 'You achieved {$a} stars, which is a passing grade.'; +$string['grade_has_been_set_fail'] = 'You achieved {$a} stars, which is a failing grade.'; +$string['graded_stars'] = 'Grade'; +$string['pass_or_fail'] = 'Pass / Fail'; +$string['grade_pass'] = 'Passed'; +$string['grade_fail'] = 'Failed'; + $string['comments'] = 'Comments'; $string['import'] = 'Import'; $string['home'] = 'Home'; @@ -108,8 +119,8 @@ $string['level_stars'] = '{$a} Stars'; $string['earned_first_star'] = 'You earned your first star in this activity!'; $string['earned_level_star'] = 'You earned {$a} stars in this activity!'; -$string['level_rating'] = 'Level {$a} rating'; -$string['level_rating_required'] = 'Rating for level {$a} is required'; +$string['level_rating'] = 'Rating required for {$a} stars'; +$string['level_rating_required'] = 'Rating required for {$a} stars is a required field'; $string['user_win_probability'] = 'Desired user win probability'; $string['user_win_probability_required'] = 'Desired user win probability is required'; @@ -176,4 +187,4 @@ $string['privacy:metadata:capquiz_user'] = 'Additional details stored about the user'; $string['privacy:metadata:capquiz_user:userid'] = 'The CAPQuiz user.'; $string['privacy:metadata:capquiz_user:rating'] = 'The rating of the user.'; -$string['privacy:metadata:capquiz_user:highest_level'] = 'The user\'s highest achieved level.'; +$string['privacy:metadata:capquiz_user:highest_level'] = 'The user\'s highest number of stars achieved.'; diff --git a/lib.php b/lib.php index 7b79163..83ab1ae 100755 --- a/lib.php +++ b/lib.php @@ -109,6 +109,7 @@ function capquiz_get_user_grades(stdClass $capquiz, int $userid = 0) { } function capquiz_grade_item_update(stdClass $capquiz, $grades = null) { + global $DB; $capquiz->cmidnumber = get_coursemodule_from_instance('capquiz', $capquiz->id)->id; $params = [ 'itemname' => $capquiz->name, @@ -129,8 +130,13 @@ function capquiz_grade_item_update(stdClass $capquiz, $grades = null) { 'iteminstance' => $capquiz->id, 'outcomeid' => null ]); - $item->gradepass = 3; + $item->gradepass = $capquiz->stars_to_pass; $item->update(); + $users = $DB->get_records('capquiz_user', ['capquiz_id' => $capquiz->id]); + foreach ($users as $user) { + $user->stars_graded = $user->highest_level; + $DB->update_record('capquiz_user', $user); + } return $status; } diff --git a/templates/classlist.mustache b/templates/classlist.mustache index 3106709..a85c8bf 100755 --- a/templates/classlist.mustache +++ b/templates/classlist.mustache @@ -40,6 +40,8 @@ + + {{#users}} @@ -50,6 +52,11 @@ + + {{/.}} {{/users}} diff --git a/templates/student_question_attempt.mustache b/templates/student_question_attempt.mustache index bee22cb..87c7d1f 100755 --- a/templates/student_question_attempt.mustache +++ b/templates/student_question_attempt.mustache @@ -27,6 +27,16 @@ } } }} +{{#gradingdone}} +

{{#str}} grading_is_completed, capquiz {{/str}}

+ {{#gradingpass}} +

{{#str}} grade_has_been_set_pass, capquiz, {{finalgrade}} {{/str}}

+ {{/gradingpass}} + {{^gradingpass}} +

{{#str}} grade_has_been_set_fail, capquiz, {{finalgrade}} {{/str}}

+ {{/gradingpass}} +{{/gradingdone}} + {{#attempt}}
diff --git a/version.php b/version.php index ab9715a..c97e240 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062510; +$plugin->version = 2019062550; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062510)'; +$plugin->release = '0.2.1 (Build: 2019062550)'; From 9d30d7a3694868fd835eb31f5f521b9bb66e6cfa Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Wed, 26 Jun 2019 14:21:38 +0200 Subject: [PATCH 08/24] update mustache context examples --- templates/classlist.mustache | 6 ++++-- templates/student_question_attempt.mustache | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/templates/classlist.mustache b/templates/classlist.mustache index a85c8bf..7d6ca58 100755 --- a/templates/classlist.mustache +++ b/templates/classlist.mustache @@ -25,8 +25,10 @@ "username": "sebastsg", "firstname": "Sebastian", "lastname": "Gundersen", - "rating": 1553.6, - "stars": 3 + "rating": 1653.6, + "stars": 4, + "graded_stars": 3, + "passing_grade": true } ] } diff --git a/templates/student_question_attempt.mustache b/templates/student_question_attempt.mustache index 87c7d1f..6b7ecde 100755 --- a/templates/student_question_attempt.mustache +++ b/templates/student_question_attempt.mustache @@ -24,7 +24,10 @@ "body": "raw html to render the question", "slots": "", "comment": "Student comment for this attempt" - } + }, + "gradingdone": true, + "finalgrade": 2, + "gradingpass": false } }} {{#gradingdone}} From 0f74787d7494a6dd67fdb527cb532e4313136e6f Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Wed, 26 Jun 2019 15:14:36 +0200 Subject: [PATCH 09/24] remove some static factory methods that seem unnecessary --- action.php | 3 ++- async.php | 3 ++- classes/capquiz.php | 11 ----------- edit.php | 3 ++- error.php | 3 ++- grade.php | 3 ++- lib.php | 4 ++-- view.php | 3 ++- view_classlist.php | 3 ++- view_comments.php | 3 ++- view_create_question_list.php | 3 ++- view_grading.php | 3 ++- view_import.php | 3 ++- view_matchmaking_configuration.php | 3 ++- 14 files changed, 26 insertions(+), 25 deletions(-) diff --git a/action.php b/action.php index f5bb625..37ddc5e 100755 --- a/action.php +++ b/action.php @@ -36,7 +36,8 @@ $action = required_param(capquiz_actions::$parameter, PARAM_TEXT); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if ($capquiz) { capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlasync); capquiz_action_performer::perform($action, $capquiz); diff --git a/async.php b/async.php index 064adc8..124b7e6 100755 --- a/async.php +++ b/async.php @@ -34,7 +34,8 @@ $action = required_param(capquiz_actions::$parameter, PARAM_TEXT); $attemptid = optional_param(capquiz_urls::$paramattempt, null, PARAM_INT); $comment = optional_param('studentcomment', '', PARAM_TEXT); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlasync); diff --git a/classes/capquiz.php b/classes/capquiz.php index 8c1bbca..6e7bd2e 100755 --- a/classes/capquiz.php +++ b/classes/capquiz.php @@ -59,23 +59,12 @@ public function __construct(int $cmid) { $this->qlist = capquiz_question_list::load_question_list($this); } - /** - * @throws \coding_exception if no id/cmid param - */ - public static function create() : capquiz { - return self::create_from_id(capquiz_urls::require_course_module_id_param()); - } - public function update_grades() { if (!$this->is_grading_completed()) { capquiz_update_grades($this->record); } } - public static function create_from_id(int $id) : capquiz { - return new capquiz($id); - } - public function id() : int { return $this->record->id; } diff --git a/edit.php b/edit.php index caa09e3..5fbd555 100755 --- a/edit.php +++ b/edit.php @@ -34,7 +34,8 @@ require_capability('mod/capquiz:instructor', $context); try { - $capquiz = capquiz::create(); + $cmid = capquiz_urls::require_course_module_id_param(); + $capquiz = new capquiz($cmid); capquiz_urls::set_page_url($capquiz, capquiz_urls::$urledit); $bankrenderer = new output\question_bank_renderer($capquiz, $capquiz->renderer()); $bankview = $bankrenderer->create_view(); diff --git a/error.php b/error.php index c541e09..24ee234 100755 --- a/error.php +++ b/error.php @@ -31,7 +31,8 @@ $cm = get_coursemodule_from_id('capquiz', $cmid, 0, false, MUST_EXIST); require_login($cm->course, false, $cm); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/grade.php b/grade.php index 38399f0..7998653 100644 --- a/grade.php +++ b/grade.php @@ -31,7 +31,8 @@ $cm = get_coursemodule_from_id('capquiz', $cmid, 0, false, MUST_EXIST); require_login($cm->course, false, $cm); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/lib.php b/lib.php index 83ab1ae..8561613 100755 --- a/lib.php +++ b/lib.php @@ -45,8 +45,8 @@ function capquiz_update_instance(stdClass $capquiz) { return true; } -function capquiz_delete_instance(int $id) { - $capquiz = capquiz::create_from_id($id); +function capquiz_delete_instance(int $cmid) { + $capquiz = new capquiz($cmid); if ($capquiz) { $quba = $capquiz->question_usage(); \question_engine::delete_questions_usage_by_activity($quba->get_id()); diff --git a/view.php b/view.php index ec19ac7..849d9b3 100755 --- a/view.php +++ b/view.php @@ -31,7 +31,8 @@ $cm = get_coursemodule_from_id('capquiz', $cmid, 0, false, MUST_EXIST); require_login($cm->course, false, $cm); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/view_classlist.php b/view_classlist.php index fd46236..1d1d551 100755 --- a/view_classlist.php +++ b/view_classlist.php @@ -33,7 +33,8 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:instructor', $context); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/view_comments.php b/view_comments.php index d4d9640..856df55 100644 --- a/view_comments.php +++ b/view_comments.php @@ -33,7 +33,8 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:instructor', $context); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/view_create_question_list.php b/view_create_question_list.php index 20bb0f8..763d33f 100755 --- a/view_create_question_list.php +++ b/view_create_question_list.php @@ -33,7 +33,8 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:instructor', $context); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/view_grading.php b/view_grading.php index 85bc62f..6784f3d 100644 --- a/view_grading.php +++ b/view_grading.php @@ -33,7 +33,8 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:instructor', $context); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/view_import.php b/view_import.php index a134f7a..06a22c5 100644 --- a/view_import.php +++ b/view_import.php @@ -33,7 +33,8 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:instructor', $context); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } diff --git a/view_matchmaking_configuration.php b/view_matchmaking_configuration.php index d935c43..d586610 100755 --- a/view_matchmaking_configuration.php +++ b/view_matchmaking_configuration.php @@ -33,7 +33,8 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:instructor', $context); -$capquiz = capquiz::create(); +$cmid = capquiz_urls::require_course_module_id_param(); +$capquiz = new capquiz($cmid); if (!$capquiz) { capquiz_urls::redirect_to_front_page(); } From 913293f06adc858a540c00ed48115accfec51ddc Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Wed, 26 Jun 2019 15:45:22 +0200 Subject: [PATCH 10/24] round user rating in class list --- classes/output/classlist_renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/output/classlist_renderer.php b/classes/output/classlist_renderer.php index ed194af..5fc7fa4 100755 --- a/classes/output/classlist_renderer.php +++ b/classes/output/classlist_renderer.php @@ -55,7 +55,7 @@ public function render() { 'username' => $user->username(), 'firstname' => $user->first_name(), 'lastname' => $user->last_name(), - 'rating' => $user->rating(), + 'rating' => round($user->rating(), 2), 'stars' => $user->highest_level(), 'graded_stars' => $user->stars_graded(), 'passing_grade' => $user->stars_graded() >= $this->capquiz->stars_to_pass() From e58ca7a1b58d8125f3a698d27dcb647813f38052 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 08:31:21 +0200 Subject: [PATCH 11/24] tidy up som code, add comments, update author tags --- README.md | 2 +- action.php | 2 +- amd/src/attempt.js | 12 +- async.php | 8 +- classes/capquiz.php | 95 ++++++-------- classes/capquiz_action_performer.php | 33 ++--- classes/capquiz_actions.php | 42 ------- .../capquiz_matchmaking_strategy_loader.php | 4 + classes/capquiz_question.php | 2 + classes/capquiz_question_attempt.php | 111 ++++++++++------ classes/capquiz_question_list.php | 8 +- classes/capquiz_urls.php | 110 ++++++++-------- classes/capquiz_user.php | 118 +++++++----------- .../matchmaking_strategy_selection_form.php | 7 +- .../view/rating_system_selection_form.php | 6 +- .../capquiz_matchmaking_strategy_registry.php | 5 + classes/output/classlist_renderer.php | 7 +- classes/output/import_renderer.php | 4 +- .../output/instructor_dashboard_renderer.php | 2 +- .../matchmaking_configuration_renderer.php | 2 +- ...atchmaking_strategy_selection_renderer.php | 6 +- classes/output/question_list_renderer.php | 6 +- .../question_list_selection_renderer.php | 2 +- .../rating_system_configuration_renderer.php | 5 +- .../rating_system_selection_renderer.php | 6 +- classes/output/unauthorized_view_renderer.php | 2 +- .../capquiz_rating_system_registry.php | 5 + db/upgrade.php | 2 +- index.php | 2 +- package.json | 5 +- view_create_question_list.php | 2 +- 31 files changed, 300 insertions(+), 323 deletions(-) delete mode 100755 classes/capquiz_actions.php diff --git a/README.md b/README.md index db1b63a..95e3974 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ CAPQuiz includes the work of many [contributors](https://github.com/KQMATH/moodl **Developers:** * Aleksander Skrede -* Sebastian S. Gundersen +* Sebastian S. Gundersen <> * [André Storhaug](https://github.com/andstor) **Original idea:** diff --git a/action.php b/action.php index 37ddc5e..f5a2edd 100755 --- a/action.php +++ b/action.php @@ -34,7 +34,7 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:instructor', $context); -$action = required_param(capquiz_actions::$parameter, PARAM_TEXT); +$action = required_param('action', PARAM_TEXT); $cmid = capquiz_urls::require_course_module_id_param(); $capquiz = new capquiz($cmid); diff --git a/amd/src/attempt.js b/amd/src/attempt.js index 699b1bb..6510aaa 100644 --- a/amd/src/attempt.js +++ b/amd/src/attempt.js @@ -23,7 +23,6 @@ define(['jquery', 'core/str'], function($, mString) { /** - * * @param $form */ function moveCommentFieldToForm($form) { @@ -34,6 +33,11 @@ define(['jquery', 'core/str'], function($, mString) { $form.prepend($comment); } + /** + * Show star tooltip. + * @param $element + * @param text + */ function showTooltip($element, text) { var $tooltip = $('.capquiz-star-tooltip'); $tooltip.html(text); @@ -44,10 +48,16 @@ define(['jquery', 'core/str'], function($, mString) { $tooltip.css('top', y + 'px'); } + /** + * Hide star tooltip. + */ function hideTooltip() { $('.capquiz-star-tooltip').css('display', 'none'); } + /** + * Register event listeners for showing tooltips on the stars. + */ function enableTooltips() { $(document).on('mouseover', '.capquiz-quiz-stars span', function () { var $self = $(this); diff --git a/async.php b/async.php index 124b7e6..5d8eccf 100755 --- a/async.php +++ b/async.php @@ -31,8 +31,8 @@ $context = \context_module::instance($cmid); require_capability('mod/capquiz:student', $context); -$action = required_param(capquiz_actions::$parameter, PARAM_TEXT); -$attemptid = optional_param(capquiz_urls::$paramattempt, null, PARAM_INT); +$action = required_param('action', PARAM_TEXT); +$attemptid = optional_param('attempt', null, PARAM_INT); $comment = optional_param('studentcomment', '', PARAM_TEXT); $cmid = capquiz_urls::require_course_module_id_param(); $capquiz = new capquiz($cmid); @@ -43,9 +43,9 @@ $user = $capquiz->user(); $attempt = capquiz_question_attempt::load_attempt($capquiz, $user, $attemptid); $attempt->update_student_comment($comment); - if ($action === capquiz_actions::$attemptanswered) { + if ($action === 'answered') { $capquiz->question_engine()->attempt_answered($user, $attempt); - } else if ($action === capquiz_actions::$attemptreviewed) { + } else if ($action === 'reviewed') { $capquiz->question_engine()->attempt_reviewed($attempt); } capquiz_urls::redirect_to_dashboard(); diff --git a/classes/capquiz.php b/classes/capquiz.php index 6e7bd2e..7cd6462 100755 --- a/classes/capquiz.php +++ b/classes/capquiz.php @@ -24,8 +24,9 @@ /** * @package mod_capquiz + * @author Sebastian S. Gundersen * @author Aleksander Skrede - * @copyright 2018 NTNU + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class capquiz { @@ -73,35 +74,34 @@ public function is_published() : bool { return $this->record->published; } + public function is_grading_completed() : bool { + return $this->record->timedue < time() && $this->record->timedue > 0; + } + public function stars_to_pass() : int { return $this->record->stars_to_pass; } + public function time_due() : int { + return $this->record->timedue; + } + public function set_stars_to_pass(int $stars) { global $DB; $this->record->stars_to_pass = $stars; $DB->update_record('capquiz', $this->record); } - public function time_due() : int { - return $this->record->timedue; - } - public function set_time_due(int $time) { global $DB; $this->record->timedue = $time; $DB->update_record('capquiz', $this->record); } - public function is_grading_completed() : bool { - return $this->record->timedue < time() && $this->record->timedue > 0; - } - - public function can_publish() : bool { - if (!$this->has_question_list() || $this->is_published()) { - return false; - } - return $this->question_list()->has_questions(); + public function set_default_user_rating(float $rating) { + global $DB; + $this->record->default_user_rating = $rating; + $DB->update_record('capquiz', $this->record); } public function publish() : bool { @@ -115,28 +115,11 @@ public function publish() : bool { return $this->is_published(); } - public function renderer() : \renderer_base { - return $this->renderer; - } - - public function output() : \renderer_base { - return $this->renderer->output_renderer(); - } - - public function selection_strategy_loader() : capquiz_matchmaking_strategy_loader { - return new capquiz_matchmaking_strategy_loader($this); - } - - public function selection_strategy_registry() : capquiz_matchmaking_strategy_registry { - return new capquiz_matchmaking_strategy_registry($this); - } - - public function rating_system_loader() : capquiz_rating_system_loader { - return new capquiz_rating_system_loader($this); - } - - public function rating_system_registry() : capquiz_rating_system_registry { - return new capquiz_rating_system_registry(); + public function can_publish() : bool { + if (!$this->has_question_list() || $this->is_published()) { + return false; + } + return $this->question_list()->has_questions(); } public function question_engine() { @@ -144,15 +127,9 @@ public function question_engine() { if (!$quba) { return null; } - return new capquiz_question_engine($this, $quba, $this->selection_strategy_loader(), $this->rating_system_loader()); - } - - public function has_question_list() : bool { - return $this->qlist !== null; - } - - public function question_list() { - return $this->qlist; + $ratingsystemloader = new capquiz_rating_system_loader($this); + $strategyloader = new capquiz_matchmaking_strategy_loader($this); + return new capquiz_question_engine($this, $quba, $strategyloader, $ratingsystemloader); } public function question_usage() { @@ -171,6 +148,14 @@ public function default_user_rating() : float { return $this->record->default_user_rating; } + public function has_question_list() : bool { + return $this->qlist !== null; + } + + public function question_list() { + return $this->qlist; + } + public function context() : \context_module { return $this->context; } @@ -179,26 +164,22 @@ public function course_module() : \stdClass { return $this->cm; } - public function course_module_id() : int { - return $this->cm->id; - } - public function course() : \stdClass { return $this->courserecord; } - public function set_default_user_rating(float $rating) { - global $DB; - $this->record->default_user_rating = $rating; - $DB->update_record('capquiz', $this->record); + public function renderer() : \renderer_base { + return $this->renderer; } public function validate_matchmaking_and_rating_systems() { - if (!$this->rating_system_loader()->has_rating_system()) { - $this->rating_system_loader()->set_default_rating_system(); + $ratingsystemloader = new capquiz_rating_system_loader($this); + if (!$ratingsystemloader->has_rating_system()) { + $ratingsystemloader->set_default_rating_system(); } - if (!$this->selection_strategy_loader()->has_strategy()) { - $this->selection_strategy_loader()->set_default_strategy(); + $strategyloader = new capquiz_matchmaking_strategy_loader($this); + if (!$strategyloader->has_strategy()) { + $strategyloader->set_default_strategy(); } } diff --git a/classes/capquiz_action_performer.php b/classes/capquiz_action_performer.php index 31bd34f..79b1154 100755 --- a/classes/capquiz_action_performer.php +++ b/classes/capquiz_action_performer.php @@ -25,35 +25,36 @@ /** * @package mod_capquiz * @author Aleksander Skrede - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class capquiz_action_performer { public static function perform(string $action, capquiz $capquiz) { switch ($action) { - case capquiz_actions::$redirect: + case 'redirect': self::redirect(); break; - case capquiz_actions::$setquestionlist: + case 'set-question-list': self::assign_question_list($capquiz); break; - case capquiz_actions::$addquestion: + case 'add-question': self::add_question_to_list($capquiz); break; - case capquiz_actions::$removequestion: + case 'remove-question': self::remove_question_from_list($capquiz); break; - case capquiz_actions::$publishquestionlist: + case 'publish-question-list': self::publish_capquiz($capquiz); break; - case capquiz_actions::$setquestionrating: + case 'set-question-rating': self::set_question_rating($capquiz); break; - case capquiz_actions::$setdefaultqrating: + case 'set-default-question-rating': self::set_default_question_rating($capquiz); break; - case capquiz_actions::$createqlisttemplate: + case 'create-question-list-template': self::create_question_list_template($capquiz); break; case 'merge_qlist': @@ -68,14 +69,14 @@ public static function perform(string $action, capquiz $capquiz) { } public static function redirect() { - $url = optional_param(capquiz_urls::$paramtargeturl, null, PARAM_TEXT); + $url = optional_param('target-url', null, PARAM_TEXT); if ($url) { capquiz_urls::redirect_to_url(new \moodle_url($url)); } } public static function assign_question_list(capquiz $capquiz) { - $qlistid = optional_param(capquiz_urls::$paramqlistid, 0, PARAM_INT); + $qlistid = optional_param('question-list-id', 0, PARAM_INT); $qlist = capquiz_question_list::load_any($qlistid, $capquiz->context()); if ($qlist) { $capquiz->validate_matchmaking_and_rating_systems(); @@ -85,7 +86,7 @@ public static function assign_question_list(capquiz $capquiz) { public static function add_question_to_list(capquiz $capquiz) { $qlist = $capquiz->question_list(); - $questionid = optional_param(capquiz_urls::$paramquestionid, 0, PARAM_INT); + $questionid = optional_param('question-id', 0, PARAM_INT); if ($questionid) { self::create_capquiz_question($questionid, $qlist, $qlist->default_question_rating()); } @@ -93,7 +94,7 @@ public static function add_question_to_list(capquiz $capquiz) { } public static function remove_question_from_list(capquiz $capquiz) { - $questionid = optional_param(capquiz_urls::$paramquestionid, 0, PARAM_INT); + $questionid = optional_param('question-id', 0, PARAM_INT); if ($questionid && $capquiz->has_question_list()) { self::remove_capquiz_question($questionid, $capquiz->question_list()->id()); } @@ -105,12 +106,12 @@ public static function publish_capquiz(capquiz $capquiz) { } public static function set_question_rating(capquiz $capquiz) { - $questionid = required_param(capquiz_urls::$paramquestionid, PARAM_INT); + $questionid = required_param('question-id', PARAM_INT); $question = $capquiz->question_list()->question($questionid); if (!$question) { throw new \Exception('The specified question does not exist'); } - $rating = optional_param(capquiz_urls::$paramrating, null, PARAM_FLOAT); + $rating = optional_param('rating', null, PARAM_FLOAT); if ($rating !== null) { $question->set_rating($rating); } @@ -118,7 +119,7 @@ public static function set_question_rating(capquiz $capquiz) { } public static function set_default_question_rating(capquiz $capquiz) { - $rating = optional_param(capquiz_urls::$paramrating, null, PARAM_FLOAT); + $rating = optional_param('rating', null, PARAM_FLOAT); if ($rating !== null) { $capquiz->question_list()->set_default_question_rating($rating); } diff --git a/classes/capquiz_actions.php b/classes/capquiz_actions.php deleted file mode 100755 index c1a4ffb..0000000 --- a/classes/capquiz_actions.php +++ /dev/null @@ -1,42 +0,0 @@ -. - -/** - * @package mod_capquiz - * @author Aleksander Skrede - * @copyright 2018 NTNU - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace mod_capquiz; - -defined('MOODLE_INTERNAL') || die(); - -class capquiz_actions { - - public static $parameter = 'action'; - public static $redirect = 'redirect'; - public static $attemptanswered = 'answered'; - public static $attemptreviewed = 'reviewed'; - public static $setquestionlist = 'set-question-list'; - public static $setquestionrating = "set-question-rating"; - public static $setdefaultqrating = "set-default-question-rating"; - public static $addquestion = 'add-question'; - public static $publishquestionlist = 'publish-question-list'; - public static $removequestion = 'remove-question'; - public static $createqlisttemplate = 'create-question-list-template'; - -} diff --git a/classes/capquiz_matchmaking_strategy_loader.php b/classes/capquiz_matchmaking_strategy_loader.php index 4a502cf..68f2844 100755 --- a/classes/capquiz_matchmaking_strategy_loader.php +++ b/classes/capquiz_matchmaking_strategy_loader.php @@ -61,6 +61,10 @@ public static function localized_strategy_name($name) { } } + /** + * @return capquiz_matchmaking_strategy|null + * @throws \Exception + */ public function selector() { if (!$this->record) { return null; diff --git a/classes/capquiz_question.php b/classes/capquiz_question.php index 3c71eae..1c795f1 100755 --- a/classes/capquiz_question.php +++ b/classes/capquiz_question.php @@ -21,6 +21,7 @@ /** * @package mod_capquiz * @author Aleksander Skrede + * @author Sebastian S. Gundersen * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -32,6 +33,7 @@ class capquiz_question { public function __construct(\stdClass $record) { global $DB; $this->record = $record; + // TODO: This query should probably be done in question list. $question = $DB->get_record('question', ['id' => $record->question_id]); if ($question !== false) { $this->record->name = $question->name; diff --git a/classes/capquiz_question_attempt.php b/classes/capquiz_question_attempt.php index 040ffe3..8fa4ba1 100755 --- a/classes/capquiz_question_attempt.php +++ b/classes/capquiz_question_attempt.php @@ -32,11 +32,22 @@ class capquiz_question_attempt { /** @var \question_usage_by_activity $quba */ private $quba; + /** + * capquiz_question_attempt constructor. + * @param \question_usage_by_activity $quba + * @param \stdClass $record + */ public function __construct(\question_usage_by_activity $quba, \stdClass $record) { $this->record = $record; $this->quba = $quba; } + /** + * @param capquiz $capquiz + * @param capquiz_user $user + * @param capquiz_question $question + * @return capquiz_question_attempt|null + */ public static function create_attempt(capquiz $capquiz, capquiz_user $user, capquiz_question $question) { $quba = $capquiz->question_usage(); $questions = question_load_questions([$question->question_id()]); @@ -51,54 +62,78 @@ public static function create_attempt(capquiz $capquiz, capquiz_user $user, capq return self::insert_attempt_entry($capquiz, $user, $question, $slot); } + /** + * @param capquiz $capquiz + * @param capquiz_user $user + * @return capquiz_question_attempt|null + */ public static function active_attempt(capquiz $capquiz, capquiz_user $user) { global $DB; - $criteria = [ - 'user_id' => $user->id(), - 'reviewed' => false - ]; try { - $entry = $DB->get_record('capquiz_attempt', $criteria, '*', MUST_EXIST); + $entry = $DB->get_record('capquiz_attempt', [ + 'user_id' => $user->id(), + 'reviewed' => false + ], '*', MUST_EXIST); return new capquiz_question_attempt($capquiz->question_usage(), $entry); } catch (\dml_exception $e) { return null; } } + /** + * @param capquiz $capquiz + * @param capquiz_user $user + * @param int $attemptid + * @return capquiz_question_attempt|null + */ public static function load_attempt(capquiz $capquiz, capquiz_user $user, int $attemptid) { global $DB; - $criteria = [ - 'id' => $attemptid, - 'user_id' => $user->id() - ]; try { - $entry = $DB->get_record('capquiz_attempt', $criteria, '*', MUST_EXIST); + $entry = $DB->get_record('capquiz_attempt', [ + 'id' => $attemptid, + 'user_id' => $user->id() + ], '*', MUST_EXIST); return new capquiz_question_attempt($capquiz->question_usage(), $entry); } catch (\dml_exception $e) { return null; } } + /** + * @param capquiz $capquiz + * @param capquiz_user $user + * @return capquiz_question_attempt|null + */ public static function previous_attempt(capquiz $capquiz, capquiz_user $user) { global $DB; try { - $sql = 'SELECT * FROM {capquiz_attempt} WHERE user_id = ? ORDER BY time_reviewed DESC LIMIT 1'; - $attempt = $DB->get_record_sql($sql, [$user->id()], MUST_EXIST); + $sql = 'SELECT * + FROM {capquiz_attempt} + WHERE user_id = :userid + ORDER BY time_reviewed DESC + LIMIT 1'; + $attempt = $DB->get_record_sql($sql, ['userid' => $user->id()], MUST_EXIST); return new capquiz_question_attempt($capquiz->question_usage(), $attempt); } catch (\dml_exception $e) { return null; } } + /** + * @param capquiz $capquiz + * @param capquiz_user $user + * @return capquiz_question_attempt[] + * @throws \dml_exception + */ public static function inactive_attempts(capquiz $capquiz, capquiz_user $user) : array { global $DB; - $records = []; - $criteria = [ + $entries = $DB->get_records('capquiz_attempt', [ 'user_id' => $user->id(), 'answered' => true, 'reviewed' => true - ]; - foreach ($DB->get_records('capquiz_attempt', $criteria) as $entry) { + ]); + $records = []; + foreach ($entries as $entry) { array_push($records, new capquiz_question_attempt($capquiz->question_usage(), $entry)); } return $records; @@ -156,28 +191,28 @@ public function student_comment() : string { return isset($this->record->feedback) ? $this->record->feedback : ''; } - public function mark_as_answered() : bool { + public function mark_as_answered() { + global $DB; $submitteddata = $this->quba->extract_responses($this->question_slot()); $this->quba->process_action($this->question_slot(), $submitteddata); - $record = $this->record; - $record->answered = true; - $record->time_answered = time(); + $this->record->answered = true; + $this->record->time_answered = time(); $this->quba->finish_question($this->question_slot(), time()); \question_engine::save_questions_usage_by_activity($this->quba); - return $this->update_record($record); + $DB->update_record('capquiz_attempt', $this->record); } - public function mark_as_reviewed() : bool { - $record = $this->record; - $record->reviewed = true; - $record->time_reviewed = time(); - return $this->update_record($record); + public function mark_as_reviewed() { + global $DB; + $this->record->reviewed = true; + $this->record->time_reviewed = time(); + $DB->update_record('capquiz_attempt', $this->record); } public function update_student_comment(string $feedback) { - $record = $this->record; - $record->feedback = ($feedback !== '' ? $feedback : null); - $this->update_record($record); + global $DB; + $this->record->feedback = ($feedback !== '' ? $feedback : null); + $DB->update_record('capquiz_attempt', $this->record); } /** @@ -211,6 +246,13 @@ public static function all_comments_for_question(int $questionid) { return $comments; } + /** + * @param capquiz $capquiz + * @param capquiz_user $user + * @param capquiz_question $question + * @param int $slot + * @return capquiz_question_attempt|null + */ private static function insert_attempt_entry(capquiz $capquiz, capquiz_user $user, capquiz_question $question, int $slot) { global $DB; $record = new \stdClass(); @@ -225,15 +267,4 @@ private static function insert_attempt_entry(capquiz $capquiz, capquiz_user $use } } - private function update_record($record) : bool { - global $DB; - try { - $DB->update_record('capquiz_attempt', $record); - $this->record = $record; - return true; - } catch (\dml_exception $e) { - return false; - } - } - } \ No newline at end of file diff --git a/classes/capquiz_question_list.php b/classes/capquiz_question_list.php index 44167d9..e93ba76 100755 --- a/classes/capquiz_question_list.php +++ b/classes/capquiz_question_list.php @@ -21,7 +21,8 @@ /** * @package mod_capquiz * @author Aleksander Skrede - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class capquiz_question_list { @@ -327,6 +328,11 @@ public static function load_any(int $qlistid, $context) { return null; } + /** + * @param $context + * @return capquiz_question_list[] + * @throws \dml_exception + */ public static function load_question_list_templates($context) : array { global $DB; $records = $DB->get_records('capquiz_question_list', ['is_template' => 1]); diff --git a/classes/capquiz_urls.php b/classes/capquiz_urls.php index dead1be..22ba971 100755 --- a/classes/capquiz_urls.php +++ b/classes/capquiz_urls.php @@ -21,21 +21,12 @@ /** * @package mod_capquiz * @author Aleksander Skrede - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class capquiz_urls { - public static $paramid = 'id'; - public static $paramcmid = 'cmid'; - public static $paramrating = 'rating'; - public static $paramattempt = 'attempt'; - public static $paramtargeturl = 'target-url'; - public static $paramquestionid = 'question-id'; - public static $paramquestionpage = 'qpage'; - public static $paramdeleteselected = 'deleteselected'; - public static $paramqlistid = 'question-list-id'; - public static $urlview = '/mod/capquiz/view.php'; public static $urlasync = '/mod/capquiz/async.php'; public static $urlerror = '/mod/capquiz/error.php'; @@ -48,10 +39,10 @@ class capquiz_urls { public static $urlviewcreateqlist = '/mod/capquiz/view_create_question_list.php'; public static $urlviewmatchmakingconfig = '/mod/capquiz/view_matchmaking_configuration.php'; - public static function redirect(\moodle_url $target) { + public static function redirect(\moodle_url $target) : \moodle_url { $url = self::create_view_url(self::$urlaction); - $url->param(capquiz_actions::$parameter, capquiz_actions::$redirect); - $url->param(self::$paramtargeturl, $target->out_as_local_url()); + $url->param('action', 'redirect'); + $url->param('target-url', $target->out_as_local_url()); return $url; } @@ -82,126 +73,125 @@ public static function set_page_url(capquiz $capquiz, string $url) { } /** + * @return int * @throws \coding_exception */ - public static function require_course_module_id_param() { - $id = optional_param(self::$paramid, 0, PARAM_INT); + public static function require_course_module_id_param() : int { + $id = optional_param('id', 0, PARAM_INT); if ($id !== 0) { return $id; } - return required_param(self::$paramcmid, PARAM_INT); + return required_param('cmid', PARAM_INT); } - public static function view_url() { + public static function view_url() : \moodle_url { return self::create_view_url(self::$urlview); } - public static function view_question_list_url(int $questionpage = 0) { + public static function view_question_list_url(int $questionpage = 0) : \moodle_url { $url = self::create_view_url(self::$urledit); - $url->param(self::$paramquestionpage, $questionpage); + $url->param('qpage', $questionpage); return $url; } - public static function view_matchmaking_configuration_url() { - $url = self::create_view_url(self::$urlviewmatchmakingconfig); - return $url; + public static function view_matchmaking_configuration_url() : \moodle_url { + return self::create_view_url(self::$urlviewmatchmakingconfig); } - public static function view_grading_url() { - $url = self::create_view_url(self::$urlviewgrading); - return $url; + public static function view_grading_url() : \moodle_url { + return self::create_view_url(self::$urlviewgrading); } - public static function view_classlist_url() { + public static function view_classlist_url() : \moodle_url { return self::create_view_url(self::$urlviewclasslist); } - public static function view_create_question_list_url() { + public static function view_create_question_list_url() : \moodle_url { return self::create_view_url(self::$urlviewcreateqlist); } - public static function view_comments_url() { + public static function view_comments_url() : \moodle_url { return self::create_view_url(self::$urlviewcomments); } - public static function view_import_url() { + public static function view_import_url() : \moodle_url { return self::create_view_url(self::$urlviewimport); } - public static function add_question_to_list_url(int $questionid) { + public static function add_question_to_list_url(int $questionid) : \moodle_url { $url = self::create_view_url(self::$urlaction); - $url->param(capquiz_actions::$parameter, capquiz_actions::$addquestion); - $url->param(self::$paramquestionid, $questionid); + $url->param('action', 'add-question'); + $url->param('question-id', $questionid); return $url; } - public static function remove_question_from_list_url(int $questionid) { + public static function remove_question_from_list_url(int $questionid) : \moodle_url { $url = self::create_view_url(self::$urlaction); - $url->param(capquiz_actions::$parameter, capquiz_actions::$removequestion); - $url->param(self::$paramquestionid, $questionid); + $url->param('action', 'remove-question'); + $url->param('question-id', $questionid); return $url; } - public static function question_list_publish_url(capquiz_question_list $qlist) { + public static function question_list_publish_url(capquiz_question_list $qlist) : \moodle_url { $url = self::create_view_url(self::$urlaction); - $url->param(self::$paramqlistid, $qlist->id()); - $url->param(capquiz_actions::$parameter, capquiz_actions::$publishquestionlist); + $url->param('action', 'publish-question-list'); + $url->param('question-list-id', $qlist->id()); return $url; } - public static function question_list_create_template_url(capquiz_question_list $qlist) { + public static function question_list_create_template_url(capquiz_question_list $qlist) : \moodle_url { $url = self::create_view_url(self::$urlaction); - $url->param(self::$paramqlistid, $qlist->id()); - $url->param(capquiz_actions::$parameter, capquiz_actions::$createqlisttemplate); + $url->param('action', 'create-question-list-template'); + $url->param('question-list-id', $qlist->id()); return $url; } - public static function question_list_select_url(capquiz_question_list $qlist) { + public static function question_list_select_url(capquiz_question_list $qlist) : \moodle_url { $url = self::create_view_url(self::$urlaction); - $url->param(capquiz_actions::$parameter, capquiz_actions::$setquestionlist); - $url->param(self::$paramqlistid, $qlist->id()); + $url->param('action', 'set-question-list'); + $url->param('question-list-id', $qlist->id()); return $url; } - public static function set_question_rating_url(int $questionid) { + public static function set_question_rating_url(int $questionid) : \moodle_url { $url = self::create_view_url(self::$urlaction); - $url->param(self::$paramquestionid, $questionid); - $url->param(capquiz_actions::$parameter, capquiz_actions::$setquestionrating); + $url->param('action', 'set-question-rating'); + $url->param('question-id', $questionid); return $url; } - public static function merge_qlist(int $qlistid) { + public static function merge_qlist(int $qlistid) : \moodle_url { $url = self::create_view_url(self::$urlaction); + $url->param('action', 'merge_qlist'); $url->param('qlistid', $qlistid); - $url->param(capquiz_actions::$parameter, 'merge_qlist'); return $url; } - public static function delete_qlist(int $qlistid) { + public static function delete_qlist(int $qlistid) : \moodle_url { $url = self::create_view_url(self::$urlaction); + $url->param('action', 'delete_qlist'); $url->param('qlistid', $qlistid); - $url->param(capquiz_actions::$parameter, 'delete_qlist'); return $url; } - public static function response_submit_url(capquiz_question_attempt $attempt) { + public static function response_submit_url(capquiz_question_attempt $attempt) : \moodle_url { $url = self::create_view_url(self::$urlasync); - $url->param(self::$paramattempt, $attempt->id()); - $url->param(capquiz_actions::$parameter, capquiz_actions::$attemptanswered); + $url->param('action', 'answered'); + $url->param('attempt', $attempt->id()); return $url; } - public static function response_reviewed_url(capquiz_question_attempt $attempt) { + public static function response_reviewed_url(capquiz_question_attempt $attempt) : \moodle_url { $url = self::create_view_url(self::$urlasync); - $url->param(self::$paramattempt, $attempt->id()); - $url->param(capquiz_actions::$parameter, capquiz_actions::$attemptreviewed); + $url->param('action', 'reviewed'); + $url->param('attempt', $attempt->id()); return $url; } - public static function create_view_url(string $relativeurl) { + public static function create_view_url(string $relativeurl) : \moodle_url { global $CFG; $url = new \moodle_url($CFG->wwwroot . $relativeurl); - $url->param(self::$paramid, self::require_course_module_id_param()); + $url->param('id', self::require_course_module_id_param()); return $url; } diff --git a/classes/capquiz_user.php b/classes/capquiz_user.php index 34fad7c..c59cc82 100755 --- a/classes/capquiz_user.php +++ b/classes/capquiz_user.php @@ -21,7 +21,8 @@ /** * @package mod_capquiz * @author Aleksander Skrede - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class capquiz_user { @@ -29,38 +30,53 @@ class capquiz_user { /** @var \stdClass $record */ private $record; - /** @var \stdClass $moodlerecord */ - private $moodlerecord; + /** @var \stdClass $user */ + private $user; + /** + * capquiz_user constructor. + * @param \stdClass $record + * @throws \dml_exception + */ public function __construct(\stdClass $record) { + global $DB; $this->record = $record; - $this->moodlerecord = null; + $this->user = $DB->get_record('user', ['id' => $this->record->user_id]); } + /** + * @param capquiz $capquiz + * @param int $moodleuserid + * @return capquiz_user|null + * @throws \Exception + */ public static function load_user(capquiz $capquiz, int $moodleuserid) { + global $DB; if ($user = self::load_db_entry($capquiz, $moodleuserid)) { return $user; } - return self::insert_db_entry($capquiz, $moodleuserid); + $record = new \stdClass(); + $record->user_id = $moodleuserid; + $record->capquiz_id = $capquiz->id(); + $record->rating = $capquiz->default_user_rating(); + $DB->insert_record('capquiz_user', $record); + return self::load_db_entry($capquiz, $moodleuserid); } - public static function user_count(capquiz $capquiz) : int { + public static function user_count(int $capquizid) : int { global $DB; - $criteria = ['capquiz_id' => $capquiz->id()]; - $count = $DB->count_records('capquiz_user', $criteria); - return $count; + return $DB->count_records('capquiz_user', ['capquiz_id' => $capquizid]); } /** - * @param capquiz $capquiz + * @param int $capquizid * @return capquiz_user[] * @throws \dml_exception */ - public static function list_users(capquiz $capquiz) : array { + public static function list_users(int $capquizid) : array { global $DB; - $criteria = ['capquiz_id' => $capquiz->id()]; $users = []; - foreach ($DB->get_records('capquiz_user', $criteria) as $user) { + foreach ($DB->get_records('capquiz_user', ['capquiz_id' => $capquizid]) as $user) { $users[] = new capquiz_user($user); } return $users; @@ -71,24 +87,15 @@ public function id() : int { } public function username() : string { - if ($this->moodlerecord === null) { - $this->load_moodle_entry(); - } - return $this->moodlerecord->username; + return $this->user->username; } public function first_name() : string { - if ($this->moodlerecord === null) { - $this->load_moodle_entry(); - } - return $this->moodlerecord->firstname; + return $this->user->firstname; } public function last_name() : string { - if ($this->moodlerecord === null) { - $this->load_moodle_entry(); - } - return $this->moodlerecord->lastname; + return $this->user->lastname; } public function rating() : float { @@ -105,64 +112,29 @@ public function stars_graded() : int { public function set_highest_level(int $highestlevel) { global $DB; - $record = $this->record; - $record->highest_level = $highestlevel; - if ($DB->update_record('capquiz_user', $record)) { - $this->record = $record; - } + $this->record->highest_level = $highestlevel; + $DB->update_record('capquiz_user', $this->record); } public function set_rating(float $rating) { global $DB; - $record = $this->record; - $record->rating = $rating; - if ($DB->update_record('capquiz_user', $record)) { - $this->record = $record; - } - } - - private function load_moodle_entry() { - global $DB; - $criteria = ['id' => $this->moodle_user_id()]; - $record = $DB->get_record('user', $criteria); - if ($record) { - $this->moodlerecord = $record; - } else { - throw new \Exception('Unable to load user with id ' . $this->moodle_user_id()); - } - } - - private function moodle_user_id() : int { - return $this->record->user_id; + $this->record->rating = $rating; + $DB->update_record('capquiz_user', $this->record); } + /** + * @param capquiz $capquiz + * @param int $moodleuserid + * @return capquiz_user|null + * @throws \dml_exception + */ private static function load_db_entry(capquiz $capquiz, int $moodleuserid) { global $DB; - $criteria = [ + $entry = $entry = $DB->get_record('capquiz_user', [ 'user_id' => $moodleuserid, 'capquiz_id' => $capquiz->id() - ]; - if ($entry = $DB->get_record('capquiz_user', $criteria)) { - return new capquiz_user($entry); - } - return null; - } - - private static function insert_db_entry(capquiz $capquiz, int $moodleuserid) { - global $DB; - $record = new \stdClass(); - $record->user_id = $moodleuserid; - $record->capquiz_id = $capquiz->id(); - $record->rating = $capquiz->default_user_rating(); - try { - if ($DB->insert_record('capquiz_user', $record)) { - return self::load_db_entry($capquiz, $moodleuserid); - } else { - throw new \Exception('Unable to persist capquiz user'); - } - } catch (\Exception $e) { - throw $e; - } + ]); + return $entry ? new capquiz_user($entry) : null; } } diff --git a/classes/form/view/matchmaking_strategy_selection_form.php b/classes/form/view/matchmaking_strategy_selection_form.php index 7163306..967db69 100755 --- a/classes/form/view/matchmaking_strategy_selection_form.php +++ b/classes/form/view/matchmaking_strategy_selection_form.php @@ -18,6 +18,7 @@ use mod_capquiz\capquiz; use mod_capquiz\capquiz_matchmaking_strategy_loader; +use mod_capquiz\capquiz_matchmaking_strategy_registry; defined('MOODLE_INTERNAL') || die(); @@ -41,8 +42,8 @@ public function __construct(capquiz $capquiz, \moodle_url $url) { public function definition() { $form = $this->_form; - $loader = $this->capquiz->selection_strategy_loader(); - $registry = $this->capquiz->selection_strategy_registry(); + $loader = new capquiz_matchmaking_strategy_loader($this->capquiz); + $registry = new capquiz_matchmaking_strategy_registry($this->capquiz); $strategies = $registry->selection_strategies(); $index = 0; $selectedindex = -1; @@ -66,4 +67,4 @@ public function validations($data, $files) { return []; } -} \ No newline at end of file +} diff --git a/classes/form/view/rating_system_selection_form.php b/classes/form/view/rating_system_selection_form.php index 9a8f39e..7a277a5 100755 --- a/classes/form/view/rating_system_selection_form.php +++ b/classes/form/view/rating_system_selection_form.php @@ -17,6 +17,8 @@ namespace mod_capquiz\form\view; use mod_capquiz\capquiz; +use mod_capquiz\capquiz_rating_system_loader; +use mod_capquiz\capquiz_rating_system_registry; defined('MOODLE_INTERNAL') || die(); @@ -38,8 +40,8 @@ public function __construct(capquiz $capquiz, \moodle_url $url) { public function definition() { $form = $this->_form; - $loader = $this->capquiz->rating_system_loader(); - $registry = $this->capquiz->rating_system_registry(); + $loader = new capquiz_rating_system_loader($this->capquiz); + $registry = new capquiz_rating_system_registry(); $index = 0; $selectedindex = -1; $radioarray = []; diff --git a/classes/matchmaking/capquiz_matchmaking_strategy_registry.php b/classes/matchmaking/capquiz_matchmaking_strategy_registry.php index 99654b2..73d7df3 100755 --- a/classes/matchmaking/capquiz_matchmaking_strategy_registry.php +++ b/classes/matchmaking/capquiz_matchmaking_strategy_registry.php @@ -42,6 +42,11 @@ public function __construct(capquiz $capquiz) { $this->register_selection_strategies(); } + /** + * @param string $strategy + * @return capquiz_matchmaking_strategy + * @throws \Exception + */ public function selector(string $strategy) { if ($value = $this->strategies[$strategy]) { return array_values($value)[0](); diff --git a/classes/output/classlist_renderer.php b/classes/output/classlist_renderer.php index 5fc7fa4..734737c 100755 --- a/classes/output/classlist_renderer.php +++ b/classes/output/classlist_renderer.php @@ -26,7 +26,8 @@ /** * @package mod_capquiz * @author Aleksander Skrede - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class classlist_renderer { @@ -44,9 +45,9 @@ public function __construct(capquiz $capquiz, renderer $renderer) { public function render() { global $PAGE; - $cmid = $this->capquiz->course_module_id(); + $cmid = $this->capquiz->course_module()->id; $PAGE->requires->js_call_amd('mod_capquiz/edit_questions', 'initialize', [$cmid]); - $users = capquiz_user::list_users($this->capquiz); + $users = capquiz_user::list_users($this->capquiz->id()); $rows = []; for ($i = 0; $i < count($users); $i++) { $user = $users[$i]; diff --git a/classes/output/import_renderer.php b/classes/output/import_renderer.php index 95482e2..39b377e 100644 --- a/classes/output/import_renderer.php +++ b/classes/output/import_renderer.php @@ -23,8 +23,8 @@ /** * @package mod_capquiz - * @author Aleksander Skrede - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class import_renderer { diff --git a/classes/output/instructor_dashboard_renderer.php b/classes/output/instructor_dashboard_renderer.php index 604c17e..76d50b6 100755 --- a/classes/output/instructor_dashboard_renderer.php +++ b/classes/output/instructor_dashboard_renderer.php @@ -63,7 +63,7 @@ private function render_summary() { 'published_status' => $this->capquiz->is_published() ? $strpublished : $strnotpublished, 'question_list_title' => $qlist ? $qlist->title() : $strnoqlistassigned, 'question_count' => $qlist ? $qlist->question_count() : $strnoquestions, - 'enrolled_student_count' => capquiz_user::user_count($this->capquiz) + 'enrolled_student_count' => capquiz_user::user_count($this->capquiz->id()) ]); } diff --git a/classes/output/matchmaking_configuration_renderer.php b/classes/output/matchmaking_configuration_renderer.php index 93ade38..a80510c 100755 --- a/classes/output/matchmaking_configuration_renderer.php +++ b/classes/output/matchmaking_configuration_renderer.php @@ -44,7 +44,7 @@ class matchmaking_configuration_renderer { public function __construct(capquiz $capquiz, renderer $renderer) { $this->capquiz = $capquiz; $this->renderer = $renderer; - $this->registry = $this->capquiz->selection_strategy_loader(); + $this->registry = new capquiz_matchmaking_strategy_loader($this->capquiz); } public function render() { diff --git a/classes/output/matchmaking_strategy_selection_renderer.php b/classes/output/matchmaking_strategy_selection_renderer.php index 76902ee..ace58c0 100755 --- a/classes/output/matchmaking_strategy_selection_renderer.php +++ b/classes/output/matchmaking_strategy_selection_renderer.php @@ -17,6 +17,8 @@ namespace mod_capquiz\output; use mod_capquiz\capquiz; +use mod_capquiz\capquiz_matchmaking_strategy_loader; +use mod_capquiz\capquiz_matchmaking_strategy_registry; use mod_capquiz\capquiz_urls; use mod_capquiz\form\view\matchmaking_strategy_selection_form; @@ -55,8 +57,8 @@ public function render() { $form = new matchmaking_strategy_selection_form($this->capquiz, $url); $formdata = $form->get_data(); if ($formdata) { - $loader = $this->capquiz->selection_strategy_loader(); - $registry = $this->capquiz->selection_strategy_registry(); + $loader = new capquiz_matchmaking_strategy_loader($this->capquiz); + $registry = new capquiz_matchmaking_strategy_registry($this->capquiz); $strategy = $registry->selection_strategies()[$formdata->strategy]; $loader->set_strategy($strategy); redirect($this->url); diff --git a/classes/output/question_list_renderer.php b/classes/output/question_list_renderer.php index 3b56e89..cd60d7e 100755 --- a/classes/output/question_list_renderer.php +++ b/classes/output/question_list_renderer.php @@ -25,7 +25,8 @@ /** * @package mod_capquiz * @author Aleksander Skrede - * @copyright 2018 NTNU + * @author Sebastian S. Gundersen + * @copyright 2019 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class question_list_renderer { @@ -53,10 +54,9 @@ public function render() { private function render_questions(capquiz_question_list $qlist) { global $PAGE, $CFG; - $cmid = $this->capquiz->course_module_id(); + $cmid = $this->capquiz->course_module()->id; $PAGE->requires->js_call_amd('mod_capquiz/edit_questions', 'initialize', [$cmid]); $rows = []; - $quba = $this->capquiz->question_usage(); $questions = $qlist->questions(); for ($i = 0; $i < $qlist->question_count(); $i++) { $question = $questions[$i]; diff --git a/classes/output/question_list_selection_renderer.php b/classes/output/question_list_selection_renderer.php index 6eb08c3..c339433 100755 --- a/classes/output/question_list_selection_renderer.php +++ b/classes/output/question_list_selection_renderer.php @@ -23,7 +23,7 @@ /** * @package mod_capquiz - * @author Sebastian S. Gundersen + * @author Sebastian S. Gundersen * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/classes/output/rating_system_configuration_renderer.php b/classes/output/rating_system_configuration_renderer.php index 6fc3520..1f2851e 100755 --- a/classes/output/rating_system_configuration_renderer.php +++ b/classes/output/rating_system_configuration_renderer.php @@ -17,6 +17,7 @@ namespace mod_capquiz\output; use mod_capquiz\capquiz; +use mod_capquiz\capquiz_rating_system_loader; use mod_capquiz\capquiz_urls; defined('MOODLE_INTERNAL') || die(); @@ -33,12 +34,14 @@ class rating_system_configuration_renderer { private $capquiz; private $renderer; + + /** @var capquiz_rating_system_loader $registry */ private $registry; public function __construct(capquiz $capquiz, renderer $renderer) { $this->capquiz = $capquiz; $this->renderer = $renderer; - $this->registry = $this->capquiz->rating_system_loader(); + $this->registry = new capquiz_rating_system_loader($capquiz); } public function render() { diff --git a/classes/output/rating_system_selection_renderer.php b/classes/output/rating_system_selection_renderer.php index 6b8b305..5fd61d6 100755 --- a/classes/output/rating_system_selection_renderer.php +++ b/classes/output/rating_system_selection_renderer.php @@ -17,6 +17,8 @@ namespace mod_capquiz\output; use mod_capquiz\capquiz; +use mod_capquiz\capquiz_rating_system_loader; +use mod_capquiz\capquiz_rating_system_registry; use mod_capquiz\capquiz_urls; use mod_capquiz\form\view\rating_system_selection_form; @@ -55,8 +57,8 @@ public function render() { $form = new rating_system_selection_form($this->capquiz, $url); $formdata = $form->get_data(); if ($formdata) { - $loader = $this->capquiz->rating_system_loader(); - $registry = $this->capquiz->rating_system_registry(); + $registry = new capquiz_rating_system_registry(); + $loader = new capquiz_rating_system_loader($this->capquiz); $loader->set_rating_system($registry->rating_systems()[$formdata->rating_system]); redirect($this->url); } diff --git a/classes/output/unauthorized_view_renderer.php b/classes/output/unauthorized_view_renderer.php index 6c9c809..c986291 100755 --- a/classes/output/unauthorized_view_renderer.php +++ b/classes/output/unauthorized_view_renderer.php @@ -20,7 +20,7 @@ /** * @package mod_capquiz - * @author Sebastian S. Gundersen + * @author Sebastian S. Gundersen * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/classes/rating_system/capquiz_rating_system_registry.php b/classes/rating_system/capquiz_rating_system_registry.php index 36a7eb2..4a46857 100755 --- a/classes/rating_system/capquiz_rating_system_registry.php +++ b/classes/rating_system/capquiz_rating_system_registry.php @@ -36,6 +36,11 @@ public function __construct() { $this->register_rating_systems(); } + /** + * @param $system + * @return capquiz_rating_system + * @throws \Exception + */ public function rating_system($system) { if ($value = $this->systems[$system]) { return array_values($value)[0](); diff --git a/db/upgrade.php b/db/upgrade.php index 46feda8..a5fcd50 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -18,7 +18,7 @@ /** * @package mod_capquiz - * @author Sebastian S. Gundersen + * @author Sebastian S. Gundersen * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/index.php b/index.php index eaa9486..aacb8f6 100755 --- a/index.php +++ b/index.php @@ -27,7 +27,7 @@ require_login(); -$courseid = required_param(capquiz_urls::$paramid, PARAM_INT); +$courseid = required_param('id', PARAM_INT); $course = $DB->get_record('course', ['id' => $courseid]); if ($course) { $PAGE->set_url(capquiz_urls::create_view_url(capquiz_urls::$urlview)); diff --git a/package.json b/package.json index 829dadf..25e49f1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "moodle-mod_capquiz", - "version": "0.1.2", + "version": "0.2.1", "description": "Computer adaptive practice activity module for Moodle", "main": "", "dependencies": { @@ -25,7 +25,8 @@ }, { "name": "Sebastian S. Gundersen", - "email": "sebastsg@stud.ntnu.no" + "email": "sebastian@sgundersen.com", + "url": "https://github.com/sebastsg" }, { "name": "Aleksander Skrede", diff --git a/view_create_question_list.php b/view_create_question_list.php index 763d33f..9ffbe9f 100755 --- a/view_create_question_list.php +++ b/view_create_question_list.php @@ -16,7 +16,7 @@ /** * @package mod_capquiz - * @author Sebastian S. Gundersen + * @author Sebastian S. Gundersen * @copyright 2018 NTNU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ From fb20aadb838e13e854e53d900e559ce6730bf2a3 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 08:38:41 +0200 Subject: [PATCH 12/24] rename matchmaking tab to rating system --- classes/capquiz_urls.php | 6 +++--- classes/output/matchmaking_configuration_renderer.php | 2 +- classes/output/matchmaking_strategy_selection_renderer.php | 2 +- classes/output/rating_system_configuration_renderer.php | 2 +- classes/output/rating_system_selection_renderer.php | 2 +- classes/output/renderer.php | 6 +++--- ..._matchmaking_configuration.php => view_rating_system.php | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) rename view_matchmaking_configuration.php => view_rating_system.php (91%) mode change 100755 => 100644 diff --git a/classes/capquiz_urls.php b/classes/capquiz_urls.php index 22ba971..dfbd454 100755 --- a/classes/capquiz_urls.php +++ b/classes/capquiz_urls.php @@ -37,7 +37,7 @@ class capquiz_urls { public static $urlviewimport = '/mod/capquiz/view_import.php'; public static $urledit = '/mod/capquiz/edit.php'; public static $urlviewcreateqlist = '/mod/capquiz/view_create_question_list.php'; - public static $urlviewmatchmakingconfig = '/mod/capquiz/view_matchmaking_configuration.php'; + public static $urlviewratingsystemconfig = '/mod/capquiz/view_rating_system.php'; public static function redirect(\moodle_url $target) : \moodle_url { $url = self::create_view_url(self::$urlaction); @@ -94,8 +94,8 @@ public static function view_question_list_url(int $questionpage = 0) : \moodle_u return $url; } - public static function view_matchmaking_configuration_url() : \moodle_url { - return self::create_view_url(self::$urlviewmatchmakingconfig); + public static function view_rating_system_url() : \moodle_url { + return self::create_view_url(self::$urlviewratingsystemconfig); } public static function view_grading_url() : \moodle_url { diff --git a/classes/output/matchmaking_configuration_renderer.php b/classes/output/matchmaking_configuration_renderer.php index a80510c..c1ba077 100755 --- a/classes/output/matchmaking_configuration_renderer.php +++ b/classes/output/matchmaking_configuration_renderer.php @@ -72,7 +72,7 @@ private function render_form() { $formdata = $form->get_data(); if ($formdata) { $this->registry->configure_current_strategy($formdata); - $url = capquiz_urls::view_matchmaking_configuration_url(); + $url = capquiz_urls::view_rating_system_url(); redirect($url); } return $form->render(); diff --git a/classes/output/matchmaking_strategy_selection_renderer.php b/classes/output/matchmaking_strategy_selection_renderer.php index ace58c0..d377223 100755 --- a/classes/output/matchmaking_strategy_selection_renderer.php +++ b/classes/output/matchmaking_strategy_selection_renderer.php @@ -44,7 +44,7 @@ class matchmaking_strategy_selection_renderer { public function __construct(capquiz $capquiz, renderer $renderer) { $this->capquiz = $capquiz; $this->renderer = $renderer; - $this->url = capquiz_urls::view_matchmaking_configuration_url(); + $this->url = capquiz_urls::view_rating_system_url(); } public function set_redirect_url(\moodle_url $url) { diff --git a/classes/output/rating_system_configuration_renderer.php b/classes/output/rating_system_configuration_renderer.php index 1f2851e..87e9969 100755 --- a/classes/output/rating_system_configuration_renderer.php +++ b/classes/output/rating_system_configuration_renderer.php @@ -67,7 +67,7 @@ private function render_form() { $formdata = $form->get_data(); if ($formdata) { $this->registry->configure_current_rating_system($formdata); - redirect(capquiz_urls::view_matchmaking_configuration_url()); + redirect(capquiz_urls::view_rating_system_url()); } return $form->render(); } diff --git a/classes/output/rating_system_selection_renderer.php b/classes/output/rating_system_selection_renderer.php index 5fd61d6..e611c01 100755 --- a/classes/output/rating_system_selection_renderer.php +++ b/classes/output/rating_system_selection_renderer.php @@ -44,7 +44,7 @@ class rating_system_selection_renderer { public function __construct(capquiz $capquiz, renderer $renderer) { $this->capquiz = $capquiz; $this->renderer = $renderer; - $this->url = capquiz_urls::view_matchmaking_configuration_url(); + $this->url = capquiz_urls::view_rating_system_url(); } public function set_redirect_url(\moodle_url $url) { diff --git a/classes/output/renderer.php b/classes/output/renderer.php index df4fd66..984dfe4 100755 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -53,7 +53,7 @@ private function tab(string $name, string $title, \moodle_url $link) { private function tabs(string $activetab) { $tabs = [ $this->tab('view_dashboard', 'dashboard', capquiz_urls::view_url()), - $this->tab('view_matchmaking', 'matchmaking', capquiz_urls::view_matchmaking_configuration_url()), + $this->tab('view_rating_system', 'rating_system', capquiz_urls::view_rating_system_url()), $this->tab('view_questions', 'questions', capquiz_urls::view_question_list_url()), $this->tab('view_grading', 'grading', capquiz_urls::view_grading_url()), $this->tab('view_classlist', 'classlist', capquiz_urls::view_classlist_url()), @@ -139,13 +139,13 @@ public function render() { $this->display_tabbed_view($render, 'view_questions'); } - public function display_matchmaking_configuration(capquiz $capquiz) { + public function display_rating_system_configuration(capquiz $capquiz) { $this->display_tabbed_views([ new matchmaking_strategy_selection_renderer($capquiz, $this), new matchmaking_configuration_renderer($capquiz, $this), new rating_system_selection_renderer($capquiz, $this), new rating_system_configuration_renderer($capquiz, $this) - ], 'view_matchmaking'); + ], 'view_rating_system'); } public function display_leaderboard(capquiz $capquiz) { diff --git a/view_matchmaking_configuration.php b/view_rating_system.php old mode 100755 new mode 100644 similarity index 91% rename from view_matchmaking_configuration.php rename to view_rating_system.php index d586610..c9fb035 --- a/view_matchmaking_configuration.php +++ b/view_rating_system.php @@ -39,6 +39,6 @@ capquiz_urls::redirect_to_front_page(); } -capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlviewmatchmakingconfig); +capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlviewratingsystemconfig); $renderer = $capquiz->renderer(); -$renderer->display_matchmaking_configuration($capquiz); +$renderer->display_rating_system_configuration($capquiz); From 6c4807cf46b835e5647562c9d1ff211c216c2095 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 08:41:13 +0200 Subject: [PATCH 13/24] update js build files, and fix an author tag --- README.md | 2 +- amd/build/edit_questions.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 95e3974..6a5738d 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ CAPQuiz includes the work of many [contributors](https://github.com/KQMATH/moodl **Developers:** * Aleksander Skrede -* Sebastian S. Gundersen <> +* Sebastian S. Gundersen * [André Storhaug](https://github.com/andstor) **Original idea:** diff --git a/amd/build/edit_questions.min.js b/amd/build/edit_questions.min.js index de495dd..8460848 100755 --- a/amd/build/edit_questions.min.js +++ b/amd/build/edit_questions.min.js @@ -1 +1 @@ -define(["jquery"],function(t){var n={capquizId:0};function i(n,i,a){t.ajax({type:"post",url:"action.php",data:n,success:i,error:a})}function a(t,a,e,r){i({action:"set-default-question-rating",id:n.capquizId,rating:a},e,r)}function e(t,a,e,r){i({action:"set-question-rating",id:n.capquizId,"question-id":t.questionId,rating:a},e,r)}function r(t,n,i){t.data("saving",!0),t.data("dirty",!1);var a=t.next();a.css("color","blue"),n(i,t.val(),function(){!0===t.data("dirty")?r(t,n,i):(a.css("color","green"),t.data("dirty",!1),t.data("saving",!1))},function(){a.css("color","red")})}function u(t){r(t,e,{questionId:t.data("question-id")})}function c(t){r(t,a,null)}function o(n,i){t(document).on("input",n,function(n){var a=t(n.target);!0!==a.data("saving")?i(a):a.data("dirty",!0)})}function d(){t(document).on("click",".capquiz-sortable",function(){!function(n){var i=n.index(),a=n.parent().parent(),e=a.find("tr:gt(0)").toArray().sort(function(n,i){var a=t(n).children("td").eq(0),e=t(i).children("td").eq(0);return parseInt(a.text())-parseInt(e.text())});a.append(e),e=a.find("tr:gt(0)").toArray().sort(function(n,a){var e=t(n).children("td").eq(i),r=t(a).children("td").eq(i),u=e.find(".capquiz-sortable-item"),c=r.find(".capquiz-sortable-item"),o=0===u.length?e.html():0===u.val().length?u.html():u.val(),d=0===c.length?r.html():0===c.val().length?c.html():c.val();return t.isNumeric(o)&&t.isNumeric(d)?o-d:o.toString().localeCompare(d)});var r="true"===a.data("asc");a.data("asc",r?"false":"true");var u=r?"fa-arrow-up":"fa-arrow-down";t.each(a.find(".capquiz-sortable"),function(){t(this).find(".fa").remove()}),n.prepend(''),r||(e=e.reverse()),a.append(e);var c=1;a.find("tr:gt(0)").each(function(){t(this).find("td:first-child").html(c),c++})}(t(this))})}return{initialize:function(i){n.capquizId=i,o(".capquiz-question-rating input",u),o(".capquiz-default-question-rating input",c),t(".capquiz-question-rating-submit-wrapper button").each(function(n,i){t(i).attr("tabindex",-1)}),d()}}}); \ No newline at end of file +define(["jquery"],function(t){var n={capquizId:0};function i(n,i,a){t.ajax({type:"post",url:"action.php",data:n,success:i,error:a})}function a(t,a,e,r){i({action:"set-default-question-rating",id:n.capquizId,rating:a},e,r)}function e(t,a,e,r){i({action:"set-question-rating",id:n.capquizId,"question-id":t.questionId,rating:a},e,r)}function r(t,n,i){t.data("saving",!0),t.data("dirty",!1);var a=t.next();a.css("color","blue"),n(i,t.val(),function(){!0===t.data("dirty")?r(t,n,i):(a.css("color","green"),t.data("dirty",!1),t.data("saving",!1))},function(){a.css("color","red")})}function u(t){r(t,e,{questionId:t.data("question-id")})}function c(t){r(t,a,null)}function o(n,i){t(document).on("input",n,function(n){var a=t(n.target);!0!==a.data("saving")?i(a):a.data("dirty",!0)})}function d(n){var i=n.index(),a=n.parent().parent(),e=a.find("tr:gt(0)").toArray().sort(function(n,i){var a=t(n).children("td").eq(0),e=t(i).children("td").eq(0);return parseInt(a.text())-parseInt(e.text())});a.append(e),e=a.find("tr:gt(0)").toArray().sort(function(n,a){var e=t(n).children("td").eq(i),r=t(a).children("td").eq(i),u=e.find(".capquiz-sortable-item"),c=r.find(".capquiz-sortable-item"),o=0===u.length?e.html():0===u.val().length?u.html():u.val(),d=0===c.length?r.html():0===c.val().length?c.html():c.val();return t.isNumeric(o)&&t.isNumeric(d)?o-d:o.toString().localeCompare(d)});var r="true"===a.data("asc");a.data("asc",r?"false":"true");var u=r?"fa-arrow-up":"fa-arrow-down";t.each(a.find(".capquiz-sortable"),function(){t(this).find(".fa").remove()}),n.prepend(''),r||(e=e.reverse()),a.append(e);var c=1;a.find("tr:gt(0)").each(function(){t(this).find("td:first-child").html(c),c++})}return{initialize:function(i){n.capquizId=i,o(".capquiz-question-rating input",u),o(".capquiz-default-question-rating input",c),t(".capquiz-question-rating-submit-wrapper button").each(function(n,i){t(i).attr("tabindex",-1)}),t(document).on("click",".capquiz-sortable",function(){d(t(this))}),t(".capquiz-sortable-default").each(function(){d(t(this))})}}}); \ No newline at end of file From 1d3b1418f4f57e9bdd728676f5fdf691bd836c87 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 09:08:10 +0200 Subject: [PATCH 14/24] add button to add all selected questions to quiz --- amd/build/edit_questions.min.js | 2 +- amd/src/edit_questions.js | 31 +++++++++++++++++++---- classes/bank/question_bank_view.php | 6 +++++ classes/capquiz_action_performer.php | 10 +++++--- classes/output/question_list_renderer.php | 22 +++++----------- lang/en/capquiz.php | 1 + styles.css | 4 +++ version.php | 4 +-- 8 files changed, 54 insertions(+), 26 deletions(-) diff --git a/amd/build/edit_questions.min.js b/amd/build/edit_questions.min.js index 8460848..f5a9fa2 100755 --- a/amd/build/edit_questions.min.js +++ b/amd/build/edit_questions.min.js @@ -1 +1 @@ -define(["jquery"],function(t){var n={capquizId:0};function i(n,i,a){t.ajax({type:"post",url:"action.php",data:n,success:i,error:a})}function a(t,a,e,r){i({action:"set-default-question-rating",id:n.capquizId,rating:a},e,r)}function e(t,a,e,r){i({action:"set-question-rating",id:n.capquizId,"question-id":t.questionId,rating:a},e,r)}function r(t,n,i){t.data("saving",!0),t.data("dirty",!1);var a=t.next();a.css("color","blue"),n(i,t.val(),function(){!0===t.data("dirty")?r(t,n,i):(a.css("color","green"),t.data("dirty",!1),t.data("saving",!1))},function(){a.css("color","red")})}function u(t){r(t,e,{questionId:t.data("question-id")})}function c(t){r(t,a,null)}function o(n,i){t(document).on("input",n,function(n){var a=t(n.target);!0!==a.data("saving")?i(a):a.data("dirty",!0)})}function d(n){var i=n.index(),a=n.parent().parent(),e=a.find("tr:gt(0)").toArray().sort(function(n,i){var a=t(n).children("td").eq(0),e=t(i).children("td").eq(0);return parseInt(a.text())-parseInt(e.text())});a.append(e),e=a.find("tr:gt(0)").toArray().sort(function(n,a){var e=t(n).children("td").eq(i),r=t(a).children("td").eq(i),u=e.find(".capquiz-sortable-item"),c=r.find(".capquiz-sortable-item"),o=0===u.length?e.html():0===u.val().length?u.html():u.val(),d=0===c.length?r.html():0===c.val().length?c.html():c.val();return t.isNumeric(o)&&t.isNumeric(d)?o-d:o.toString().localeCompare(d)});var r="true"===a.data("asc");a.data("asc",r?"false":"true");var u=r?"fa-arrow-up":"fa-arrow-down";t.each(a.find(".capquiz-sortable"),function(){t(this).find(".fa").remove()}),n.prepend(''),r||(e=e.reverse()),a.append(e);var c=1;a.find("tr:gt(0)").each(function(){t(this).find("td:first-child").html(c),c++})}return{initialize:function(i){n.capquizId=i,o(".capquiz-question-rating input",u),o(".capquiz-default-question-rating input",c),t(".capquiz-question-rating-submit-wrapper button").each(function(n,i){t(i).attr("tabindex",-1)}),t(document).on("click",".capquiz-sortable",function(){d(t(this))}),t(".capquiz-sortable-default").each(function(){d(t(this))})}}}); \ No newline at end of file +define(["jquery"],function(t){var n={courseModuleId:0};function i(n,i,a){t.ajax({type:"post",url:"action.php",data:n,success:i,error:a})}function a(t,a,e,o){i({action:"set-default-question-rating",id:n.courseModuleId,rating:a},e,o)}function e(t,a,e,o){i({action:"set-question-rating",id:n.courseModuleId,"question-id":t.questionId,rating:a},e,o)}function o(t,n,i){t.data("saving",!0),t.data("dirty",!1);var a=t.next();a.css("color","blue"),n(i,t.val(),function(){!0===t.data("dirty")?o(t,n,i):(a.css("color","green"),t.data("dirty",!1),t.data("saving",!1))},function(){a.css("color","red")})}function r(t){o(t,e,{questionId:t.data("question-id")})}function c(t){o(t,a,null)}function u(n,i){t(document).on("input",n,function(n){var a=t(n.target);!0!==a.data("saving")?i(a):a.data("dirty",!0)})}function d(n){var i=n.index(),a=n.parent().parent(),e=a.find("tr:gt(0)").toArray().sort(function(n,i){var a=t(n).children("td").eq(0),e=t(i).children("td").eq(0);return parseInt(a.text())-parseInt(e.text())});a.append(e),e=a.find("tr:gt(0)").toArray().sort(function(n,a){var e=t(n).children("td").eq(i),o=t(a).children("td").eq(i),r=e.find(".capquiz-sortable-item"),c=o.find(".capquiz-sortable-item"),u=0===r.length?e.html():0===r.val().length?r.html():r.val(),d=0===c.length?o.html():0===c.val().length?c.html():c.val();return t.isNumeric(u)&&t.isNumeric(d)?u-d:u.toString().localeCompare(d)});var o="true"===a.data("asc");a.data("asc",o?"false":"true");var r=o?"fa-arrow-up":"fa-arrow-down";t.each(a.find(".capquiz-sortable"),function(){t(this).find(".fa").remove()}),n.prepend(''),o||(e=e.reverse()),a.append(e);var c=1;a.find("tr:gt(0)").each(function(){t(this).find("td:first-child").html(c),c++})}return{initialize:function(i){n.courseModuleId=i,u(".capquiz-question-rating input",r),u(".capquiz-default-question-rating input",c),t(".capquiz-question-rating-submit-wrapper button").each(function(n,i){t(i).attr("tabindex",-1)}),t(document).on("click",".capquiz-sortable",function(){d(t(this))}),t(".capquiz-sortable-default").each(function(){d(t(this))}),t(".capquiz-add-selected-questions").on("click",function(){var i="";t("#categoryquestions td input[type=checkbox]:checked").each(function(){i+=t(this).attr("name").slice(1)+","}),t.post("action.php",{action:"add-question",id:n.courseModuleId,"question-id":i},function(){location.reload()})})}}}); \ No newline at end of file diff --git a/amd/src/edit_questions.js b/amd/src/edit_questions.js index a40308c..10ddf6e 100755 --- a/amd/src/edit_questions.js +++ b/amd/src/edit_questions.js @@ -23,7 +23,7 @@ define(['jquery'], function($) { var parameters = { - capquizId: 0, + courseModuleId: 0, }; /** @@ -52,7 +52,7 @@ define(['jquery'], function($) { function sendDefaultQuestionRating(data, rating, onSuccess, onError) { sendAction({ 'action': 'set-default-question-rating', - 'id': parameters.capquizId, + 'id': parameters.courseModuleId, 'rating': rating, }, onSuccess, onError); } @@ -67,7 +67,7 @@ define(['jquery'], function($) { function sendQuestionRating(data, rating, onSuccess, onError) { sendAction({ 'action': 'set-question-rating', - 'id': parameters.capquizId, + 'id': parameters.courseModuleId, 'question-id': data.questionId, 'rating': rating, }, onSuccess, onError); @@ -203,13 +203,34 @@ define(['jquery'], function($) { }); } + /** + * + * @param courseModuleId + */ + function listenAddToQuiz() { + $('.capquiz-add-selected-questions').on('click', function () { + var questionIds = ''; + $('#categoryquestions td input[type=checkbox]:checked').each(function () { + questionIds += $(this).attr('name').slice(1) + ','; + }); + $.post('action.php', { + 'action': 'add-question', + 'id': parameters.courseModuleId, + 'question-id': questionIds, + }, function () { + location.reload(); + }); + }); + } + return { - initialize: function(capquizId) { - parameters.capquizId = capquizId; + initialize: function(courseModuleId) { + parameters.courseModuleId = courseModuleId; registerListener('.capquiz-question-rating input', submitQuestionRating); registerListener('.capquiz-default-question-rating input', submitDefaultQuestionRating); fixTabIndicesForQuestionRatingInputs(); registerSortListener(); + listenAddToQuiz(); } }; diff --git a/classes/bank/question_bank_view.php b/classes/bank/question_bank_view.php index 0c2a9a5..addb523 100755 --- a/classes/bank/question_bank_view.php +++ b/classes/bank/question_bank_view.php @@ -79,8 +79,14 @@ public function render(string $tabname, int $page, int $perpage, string $categor $showquestiontext, $this->contexts->having_cap('moodle/question:add') ); + $this->display_add_selected_questions_button(); $PAGE->requires->js_call_amd('core_question/edit_tags', 'init', ['#questionscontainer']); return ob_get_clean(); } + private function display_add_selected_questions_button() { + $straddtoquiz = get_string('add_to_quiz', 'capquiz'); + echo ''; + } + } diff --git a/classes/capquiz_action_performer.php b/classes/capquiz_action_performer.php index 79b1154..257ca7a 100755 --- a/classes/capquiz_action_performer.php +++ b/classes/capquiz_action_performer.php @@ -86,9 +86,10 @@ public static function assign_question_list(capquiz $capquiz) { public static function add_question_to_list(capquiz $capquiz) { $qlist = $capquiz->question_list(); - $questionid = optional_param('question-id', 0, PARAM_INT); - if ($questionid) { - self::create_capquiz_question($questionid, $qlist, $qlist->default_question_rating()); + $questionids = required_param('question-id', PARAM_TEXT); + $questionids = explode(',', $questionids); + foreach ($questionids as $questionid) { + self::create_capquiz_question((int)$questionid, $qlist, $qlist->default_question_rating()); } capquiz_urls::redirect_to_previous(); } @@ -142,6 +143,9 @@ public static function create_question_list_template(capquiz $capquiz) { private static function create_capquiz_question(int $questionid, capquiz_question_list $list, float $rating) { global $DB; + if ($questionid === 0){ + return; + } $ratedquestion = new \stdClass(); $ratedquestion->question_list_id = $list->id(); $ratedquestion->question_id = $questionid; diff --git a/classes/output/question_list_renderer.php b/classes/output/question_list_renderer.php index cd60d7e..49bc7a5 100755 --- a/classes/output/question_list_renderer.php +++ b/classes/output/question_list_renderer.php @@ -43,6 +43,9 @@ public function __construct(capquiz $capquiz, renderer $renderer) { } public function render() { + global $PAGE; + $cmid = $this->capquiz->course_module()->id; + $PAGE->requires->js_call_amd('mod_capquiz/edit_questions', 'initialize', [$cmid]); $qlist = $this->capquiz->question_list(); if ($qlist && $qlist->has_questions()) { return $this->render_questions($qlist); @@ -53,9 +56,7 @@ public function render() { } private function render_questions(capquiz_question_list $qlist) { - global $PAGE, $CFG; - $cmid = $this->capquiz->course_module()->id; - $PAGE->requires->js_call_amd('mod_capquiz/edit_questions', 'initialize', [$cmid]); + global $CFG; $rows = []; $questions = $qlist->questions(); for ($i = 0; $i < $qlist->question_count(); $i++) { @@ -69,27 +70,18 @@ private function render_questions(capquiz_question_list $qlist) { 'courseid' => $courseid, 'id' => $question->question_id() ]); + $targetblank = ['name' => 'target', 'value' => '_blank']; $edit = $courseid === 0 ? false : [ 'url' => $editurl->out(false), 'label' => get_string('edit'), 'classes' => 'fa fa-edit', - 'attributes' => [ - [ - 'name' => 'target', - 'value' => '_blank' - ] - ] + 'attributes' => [$targetblank] ]; $preview = $courseid === 0 ? false : [ 'url' => $previewurl->out(false), 'label' => get_string('preview'), 'classes' => 'fa fa-search-plus', - 'attributes' => [ - [ - 'name' => 'target', - 'value' => '_blank' - ] - ] + 'attributes' => [$targetblank] ]; $rows[] = [ 'index' => $i + 1, diff --git a/lang/en/capquiz.php b/lang/en/capquiz.php index fd6e83b..672dbae 100755 --- a/lang/en/capquiz.php +++ b/lang/en/capquiz.php @@ -36,6 +36,7 @@ $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['add_to_quiz'] = 'Add to quiz'; $string['question_list'] = 'Question list'; $string['question_lists'] = 'Question lists'; diff --git a/styles.css b/styles.css index f75874a..17c8e4e 100755 --- a/styles.css +++ b/styles.css @@ -245,3 +245,7 @@ .capquiz-classlist tr:nth-child(odd) td { background: #fafafa; } + +.capquiz-add-selected-questions { + margin: 4px; +} diff --git a/version.php b/version.php index c97e240..3e4e427 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062550; +$plugin->version = 2019062551; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062550)'; +$plugin->release = '0.2.1 (Build: 2019062551)'; From 6d4e368b0c1e9156d23a609298318181d1213716 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 09:10:44 +0200 Subject: [PATCH 15/24] fix js function doc --- amd/src/edit_questions.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/amd/src/edit_questions.js b/amd/src/edit_questions.js index 10ddf6e..965599e 100755 --- a/amd/src/edit_questions.js +++ b/amd/src/edit_questions.js @@ -204,8 +204,7 @@ define(['jquery'], function($) { } /** - * - * @param courseModuleId + * Register click event listener for "Add to quiz" button. */ function listenAddToQuiz() { $('.capquiz-add-selected-questions').on('click', function () { From 5702585be9928dfeeff2f47146a9eadd9ec6b643 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 11:09:21 +0200 Subject: [PATCH 16/24] added regrade all button in class list --- classes/capquiz.php | 4 ++-- classes/capquiz_action_performer.php | 5 ++++- classes/capquiz_urls.php | 6 ++++++ classes/output/classlist_renderer.php | 11 ++++++++++- lang/en/capquiz.php | 1 + styles.css | 4 ++++ templates/classlist.mustache | 14 +++++++++++++- 7 files changed, 40 insertions(+), 5 deletions(-) diff --git a/classes/capquiz.php b/classes/capquiz.php index 7cd6462..35f1149 100755 --- a/classes/capquiz.php +++ b/classes/capquiz.php @@ -60,8 +60,8 @@ public function __construct(int $cmid) { $this->qlist = capquiz_question_list::load_question_list($this); } - public function update_grades() { - if (!$this->is_grading_completed()) { + public function update_grades(bool $force = false) { + if (!$this->is_grading_completed() || $force) { capquiz_update_grades($this->record); } } diff --git a/classes/capquiz_action_performer.php b/classes/capquiz_action_performer.php index 257ca7a..68f75a7 100755 --- a/classes/capquiz_action_performer.php +++ b/classes/capquiz_action_performer.php @@ -63,6 +63,9 @@ public static function perform(string $action, capquiz $capquiz) { case 'delete_qlist': self::delete_question_list(); break; + case 'regrade-all': + $capquiz->update_grades(true); + break; default: break; } @@ -143,7 +146,7 @@ public static function create_question_list_template(capquiz $capquiz) { private static function create_capquiz_question(int $questionid, capquiz_question_list $list, float $rating) { global $DB; - if ($questionid === 0){ + if ($questionid === 0) { return; } $ratedquestion = new \stdClass(); diff --git a/classes/capquiz_urls.php b/classes/capquiz_urls.php index dfbd454..8e364c9 100755 --- a/classes/capquiz_urls.php +++ b/classes/capquiz_urls.php @@ -160,6 +160,12 @@ public static function set_question_rating_url(int $questionid) : \moodle_url { return $url; } + public static function regrade_all_url() : \moodle_url { + $url = self::create_view_url(self::$urlaction); + $url->param('action', 'regrade-all'); + return $url; + } + public static function merge_qlist(int $qlistid) : \moodle_url { $url = self::create_view_url(self::$urlaction); $url->param('action', 'merge_qlist'); diff --git a/classes/output/classlist_renderer.php b/classes/output/classlist_renderer.php index 734737c..ab27112 100755 --- a/classes/output/classlist_renderer.php +++ b/classes/output/classlist_renderer.php @@ -17,6 +17,7 @@ namespace mod_capquiz\output; use mod_capquiz\capquiz; +use mod_capquiz\capquiz_urls; use mod_capquiz\capquiz_user; defined('MOODLE_INTERNAL') || die(); @@ -63,7 +64,15 @@ public function render() { ]; } $leaderboard = $this->renderer->render_from_template('capquiz/classlist', [ - 'users' => $rows + 'users' => $rows, + 'regrade' => [ + 'method' => 'post', + 'classes' => 'capquiz-regrade-all', + 'url' => capquiz_urls::regrade_all_url()->out(false), + 'primary' => true, + 'label' => get_string('regrade_all', 'capquiz'), + 'disabled' => !$this->capquiz->is_grading_completed() + ] ]); return $leaderboard; } diff --git a/lang/en/capquiz.php b/lang/en/capquiz.php index 672dbae..4aba8fe 100755 --- a/lang/en/capquiz.php +++ b/lang/en/capquiz.php @@ -52,6 +52,7 @@ $string['pass_or_fail'] = 'Pass / Fail'; $string['grade_pass'] = 'Passed'; $string['grade_fail'] = 'Failed'; +$string['regrade_all'] = 'Regrade all'; $string['comments'] = 'Comments'; $string['import'] = 'Import'; diff --git a/styles.css b/styles.css index 17c8e4e..9a94a01 100755 --- a/styles.css +++ b/styles.css @@ -249,3 +249,7 @@ .capquiz-add-selected-questions { margin: 4px; } + +.capquiz-regrade-all { + margin-top: 16px; +} diff --git a/templates/classlist.mustache b/templates/classlist.mustache index 7d6ca58..b4c4a5d 100755 --- a/templates/classlist.mustache +++ b/templates/classlist.mustache @@ -30,7 +30,15 @@ "graded_stars": 3, "passing_grade": true } - ] + ], + "regrade": { + "method:" "post", + "classes": "capquiz-regrade-all", + "url": "", + "primary": true, + "label": "Regrade all", + "diabled": false + } } }}

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

@@ -67,3 +75,7 @@ {{^users}}

{{#str}} no_enrolled_students, capquiz {{/str}}

{{/users}} + +{{#regrade}} + {{>core/single_button}} +{{/regrade}} From a6ea25a39608bed5e4e80059da2cfb29373676ce Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:02:52 +0200 Subject: [PATCH 17/24] number of stars for a question list is now configurable --- classes/capquiz_action_performer.php | 1 + classes/capquiz_question_engine.php | 24 ++-- classes/capquiz_question_list.php | 131 +++++++----------- classes/capquiz_user.php | 8 +- .../form/view/grading_configuration_form.php | 32 ++--- classes/output/classlist_renderer.php | 6 +- .../output/grading_configuration_renderer.php | 44 +++--- classes/output/question_attempt_renderer.php | 10 +- db/install.xml | 6 +- db/upgrade.php | 26 ++++ version.php | 4 +- 11 files changed, 142 insertions(+), 150 deletions(-) diff --git a/classes/capquiz_action_performer.php b/classes/capquiz_action_performer.php index 68f75a7..9d0dd41 100755 --- a/classes/capquiz_action_performer.php +++ b/classes/capquiz_action_performer.php @@ -65,6 +65,7 @@ public static function perform(string $action, capquiz $capquiz) { break; case 'regrade-all': $capquiz->update_grades(true); + capquiz_urls::redirect_to_url(capquiz_urls::view_classlist_url()); break; default: break; diff --git a/classes/capquiz_question_engine.php b/classes/capquiz_question_engine.php index ff268a6..e056549 100755 --- a/classes/capquiz_question_engine.php +++ b/classes/capquiz_question_engine.php @@ -84,7 +84,7 @@ public function attempt_answered(capquiz_user $user, capquiz_question_attempt $a $question = $this->capquiz->question_list()->question($attempt->question_id()); if ($attempt->is_correctly_answered()) { $ratingsystem->update_user_rating($user, $question, 1); - $this->set_new_highest_level_if_attained($user); + $this->set_new_highest_star_if_attained($user); } else { $ratingsystem->update_user_rating($user, $question, 0); } @@ -94,15 +94,13 @@ public function attempt_answered(capquiz_user $user, capquiz_question_attempt $a } } - private function set_new_highest_level_if_attained(capquiz_user $user) { - $list = $this->capquiz->question_list(); - for ($level = $list->level_count(); $level > 0; $level--) { - $required = $list->required_rating_for_level($level); - if ($user->rating() >= $required) { - if ($user->highest_level() < $level) { - $user->set_highest_level($level); - break; - } + private function set_new_highest_star_if_attained(capquiz_user $user) { + $qlist = $this->capquiz->question_list(); + for ($star = $qlist->max_stars(); $star > 0; $star--) { + $required = $qlist->star_rating($star); + if ($user->rating() >= $required && $user->highest_stars_achieved() < $star) { + $user->set_highest_star($star); + break; } } } @@ -112,10 +110,8 @@ public function attempt_reviewed(capquiz_question_attempt $attempt) { } private function new_attempt_for_user(capquiz_user $user) { - if ($question = $this->find_question_for_user($user)) { - return capquiz_question_attempt::create_attempt($this->capquiz, $user, $question); - } - return null; + $question = $this->find_question_for_user($user); + return $question ? capquiz_question_attempt::create_attempt($this->capquiz, $user, $question) : null; } private function find_question_for_user(capquiz_user $user) { diff --git a/classes/capquiz_question_list.php b/classes/capquiz_question_list.php index e93ba76..090a275 100755 --- a/classes/capquiz_question_list.php +++ b/classes/capquiz_question_list.php @@ -48,6 +48,50 @@ public function __construct(\stdClass $record, $context) { $this->quba = \question_engine::load_questions_usage_by_activity($this->record->question_usage_id); } + public function star_ratings_array() { + $ratings = explode(',', $this->record->star_ratings); + foreach ($ratings as &$rating) { + $rating = (int)$rating; + } + return $ratings; + } + + public function max_stars() { + return count($this->star_ratings_array()); + } + + public function star_rating(int $star) { + $stars = $this->star_ratings_array(); + return $stars[$star - 1]; + } + + /** + * @param int[] $ratings + * @throws \dml_exception + */ + public function set_star_ratings(array $ratings) { + global $DB; + $starratings = implode(',', $ratings); + if (strlen($starratings) < 250) { + $this->record->star_ratings = $starratings; + $DB->update_record('capquiz_question_list', $this->record); + } + } + + public function next_level_percent(capquiz $capquiz, int $rating) : int { + $goal = 0; + for ($star = 1; $star <= $this->max_stars(); $star++) { + $goal = $this->star_rating($star); + if ($goal > $rating) { + $previous = $star > 1 ? $this->star_rating($star - 1) : $capquiz->default_user_rating(); + $rating -= $previous; + $goal -= $previous; + break; + } + } + return $goal >= 1 ? (int)($rating / $goal * 100) : 0; + } + public function question_usage() { return $this->quba; } @@ -58,9 +102,7 @@ public function id() : int { public function author() { global $DB; - $criteria = ['id' => $this->record->author]; - $record = $DB->get_record('user', $criteria); - // Returning null instead of false on failure. + $record = $DB->get_record('user', ['id' => $this->record->author]); return $record ? $record : null; } @@ -90,67 +132,6 @@ public function description() : string { return $this->record->description; } - public function first_level() : int { - return 1; - } - - public function level_count() : int { - return 5; - } - - public function required_rating_for_level(int $level) { - $field = "level_{$level}_rating"; - if (!isset($this->record->{$field})) { - return null; - } - return (int)$this->record->{$field}; - } - - public function set_level_ratings(array $ratings) { - global $DB; - $numratings = count($ratings); - if ($numratings !== $this->level_count()) { - throw new \Exception("$numratings ratings given. " . $this->level_count() . ' required.'); - } - $level = $this->first_level(); - foreach ($ratings as $rating) { - $field = "level_{$level}_rating"; - $this->record->{$field} = $rating; - $level++; - } - $DB->update_record('capquiz_question_list', $this->record); - } - - public function user_level(capquiz_user $user) : int { - $stars = 0; - for ($level = 1; $level < 6; $level++) { - if ($user->rating() >= $this->required_rating_for_level($level)) { - $stars++; - } - } - return $stars; - } - - public function next_level_percent(capquiz $capquiz, int $rating) : int { - $goal = 0; - for ($level = 1; $level < 6; $level++) { - $goal = $this->required_rating_for_level($level); - if ($goal > $rating) { - $previous = $capquiz->default_user_rating(); - if ($level > 1) { - $previous = $this->required_rating_for_level($level - 1); - } - $rating -= $previous; - $goal -= $previous; - break; - } - } - if ($goal < 1) { - return 0; - } - return (int)($rating / $goal * 100); - } - public function time_created() : string { return $this->record->time_created; } @@ -285,11 +266,7 @@ public static function create_new_instance(capquiz $capquiz, string $title, stri $record->capquiz_id = $capquiz->id(); $record->title = $title; $record->description = $description; - $record->level_1_rating = $ratings[0]; - $record->level_2_rating = $ratings[1]; - $record->level_3_rating = $ratings[2]; - $record->level_4_rating = $ratings[3]; - $record->level_5_rating = $ratings[4]; + $record->star_ratings = implode(',', $ratings); $record->author = $USER->id; $record->is_template = 0; $record->time_created = time(); @@ -310,22 +287,14 @@ public static function create_new_instance(capquiz $capquiz, string $title, stri public static function load_question_list(capquiz $capquiz) { global $DB; - $conditions = ['capquiz_id' => $capquiz->id()]; - $record = $DB->get_record('capquiz_question_list', $conditions); - if ($record) { - return new capquiz_question_list($record, $capquiz->context()); - } - return null; + $record = $DB->get_record('capquiz_question_list', ['capquiz_id' => $capquiz->id()]); + return $record ? new capquiz_question_list($record, $capquiz->context()) : null; } public static function load_any(int $qlistid, $context) { global $DB; - $conditions = ['id' => $qlistid]; - $record = $DB->get_record('capquiz_question_list', $conditions); - if ($record) { - return new capquiz_question_list($record, $context); - } - return null; + $record = $DB->get_record('capquiz_question_list', ['id' => $qlistid]); + return $record ? new capquiz_question_list($record, $context) : null; } /** diff --git a/classes/capquiz_user.php b/classes/capquiz_user.php index c59cc82..988d183 100755 --- a/classes/capquiz_user.php +++ b/classes/capquiz_user.php @@ -102,17 +102,17 @@ public function rating() : float { return $this->record->rating; } - public function highest_level() : int { + public function highest_stars_achieved() : int { return $this->record->highest_level; } - public function stars_graded() : int { + public function highest_stars_graded() : int { return $this->record->stars_graded; } - public function set_highest_level(int $highestlevel) { + public function set_highest_star(int $higheststar) { global $DB; - $this->record->highest_level = $highestlevel; + $this->record->highest_level = $higheststar; $DB->update_record('capquiz_user', $this->record); } diff --git a/classes/form/view/grading_configuration_form.php b/classes/form/view/grading_configuration_form.php index c859349..a6a1afd 100644 --- a/classes/form/view/grading_configuration_form.php +++ b/classes/form/view/grading_configuration_form.php @@ -46,17 +46,22 @@ 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'); - for ($i = 0; $i < $qlist->level_count(); $i++) { - $level = $i + $qlist->first_level(); - $element = "level_{$level}_rating"; - $text = get_string('level_rating', 'capquiz', $level); - $requiredtext = get_string('level_rating_required', 'capquiz', $level); - $form->addElement('text', $element, $text); - $form->setType($element, PARAM_INT); - $form->addRule($element, $requiredtext, 'required', null, 'client'); - $form->setDefault($element, $qlist->required_rating_for_level($level)); + for ($star = 1; $star <= $qlist->max_stars(); $star++) { + $groupname = "star_group_$star"; + $input = "star_rating_$star"; + $text = get_string('level_rating', 'capquiz', $star); + $elements = []; + $elements[] = $form->createElement('text', $input, $text); + if ($star > 1) { + $elements[] = $form->createElement('submit', "delstarbutton$star", 'Delete star'); + } + $form->addGroup($elements, $groupname, $text, [''], false); + $form->setType($input, PARAM_INT); + $form->setDefault($input, $qlist->star_rating($star)); } + $form->addElement('submit', 'addstarbutton', 'Add star'); + $strstarstopass = get_string('stars_to_pass', 'capquiz'); $strstarstopassrequired = get_string('stars_to_pass_required', 'capquiz'); $form->addElement('text', 'starstopass', $strstarstopass); @@ -77,15 +82,6 @@ public function validations($data, $files) { if (empty($data['default_user_rating'])) { $errors['default_user_rating'] = get_string('default_user_rating_required', 'capquiz'); } - $qlist = $this->capquiz->question_list(); - for ($i = 0; $i < $qlist->level_count(); $i++) { - $level = $i + $qlist->first_level(); - $element = "level_{$level}_rating"; - if (empty($data[$element])) { - $requiredtext = get_string('level_rating_required', 'capquiz', $level); - $errors[$element] = $requiredtext; - } - } if (empty($data['starstopass']) || $data['starstopass'] < 0 || $data['starstopass'] > 5) { $errors['starstopass'] = get_string('stars_to_pass_required', 'capquiz'); } diff --git a/classes/output/classlist_renderer.php b/classes/output/classlist_renderer.php index ab27112..92da53e 100755 --- a/classes/output/classlist_renderer.php +++ b/classes/output/classlist_renderer.php @@ -58,9 +58,9 @@ public function render() { 'firstname' => $user->first_name(), 'lastname' => $user->last_name(), 'rating' => round($user->rating(), 2), - 'stars' => $user->highest_level(), - 'graded_stars' => $user->stars_graded(), - 'passing_grade' => $user->stars_graded() >= $this->capquiz->stars_to_pass() + 'stars' => $user->highest_stars_achieved(), + 'graded_stars' => $user->highest_stars_graded(), + 'passing_grade' => $user->highest_stars_graded() >= $this->capquiz->stars_to_pass() ]; } $leaderboard = $this->renderer->render_from_template('capquiz/classlist', [ diff --git a/classes/output/grading_configuration_renderer.php b/classes/output/grading_configuration_renderer.php index 656d2fc..afaf2c9 100644 --- a/classes/output/grading_configuration_renderer.php +++ b/classes/output/grading_configuration_renderer.php @@ -55,26 +55,34 @@ private function get_rating_configuration() { $form = new grading_configuration_form($this->capquiz, $url); $formdata = $form->get_data(); if ($formdata) { - if ($formdata->default_user_rating) { - $this->capquiz->set_default_user_rating($formdata->default_user_rating); - } - $ratings = [ - $formdata->level_1_rating, - $formdata->level_2_rating, - $formdata->level_3_rating, - $formdata->level_4_rating, - $formdata->level_5_rating - ]; - $this->capquiz->question_list()->set_level_ratings($ratings); - if ($formdata->starstopass) { - $this->capquiz->set_stars_to_pass($formdata->starstopass); - } - if ($formdata->timedue) { - $this->capquiz->set_time_due($formdata->timedue); - } - redirect(capquiz_urls::view_grading_url()); + $this->process_rating_configuration($formdata); } return $form->render(); } + private function process_rating_configuration($formdata) { + $star = 1; + $ratings = []; + while (isset($formdata->{"star_rating_$star"})) { + if (!isset($formdata->{"delstarbutton$star"})) { + $ratings[] = (int)$formdata->{"star_rating_$star"}; + } + $star++; + } + if (isset($formdata->addstarbutton)) { + $ratings[] = end($ratings) + 100; + } + if ($formdata->default_user_rating) { + $this->capquiz->set_default_user_rating($formdata->default_user_rating); + } + $this->capquiz->question_list()->set_star_ratings($ratings); + if ($formdata->starstopass) { + $this->capquiz->set_stars_to_pass($formdata->starstopass); + } + if ($formdata->timedue) { + $this->capquiz->set_time_due($formdata->timedue); + } + redirect(capquiz_urls::view_grading_url()); + } + } diff --git a/classes/output/question_attempt_renderer.php b/classes/output/question_attempt_renderer.php index 2de8200..e28cfde 100755 --- a/classes/output/question_attempt_renderer.php +++ b/classes/output/question_attempt_renderer.php @@ -126,8 +126,8 @@ public function render_question_attempt(capquiz_question_attempt $attempt, \ques 'comment' => $attempt->student_comment() ], 'gradingdone' => $this->capquiz->is_grading_completed(), - 'finalgrade' => $this->capquiz->user()->stars_graded(), - 'gradingpass' => $this->capquiz->user()->stars_graded() >= $this->capquiz->stars_to_pass() + 'finalgrade' => $this->capquiz->user()->highest_stars_graded(), + 'gradingpass' => $this->capquiz->user()->highest_stars_graded() >= $this->capquiz->stars_to_pass() ]); } @@ -154,9 +154,9 @@ private function user_star_progress(capquiz_user $user, capquiz_question_list $q $stars = []; $blankstars = []; $nostars = []; - for ($star = 1; $star < $qlist->level_count() + 1; $star++) { - if ($user->highest_level() >= $star) { - if ($user->rating() >= $qlist->required_rating_for_level($star)) { + for ($star = 1; $star <= $qlist->max_stars(); $star++) { + if ($user->highest_stars_achieved() >= $star) { + if ($user->rating() >= $qlist->star_rating($star)) { $stars[] = true; } else { $blankstars[] = true; diff --git a/db/install.xml b/db/install.xml index 7699d24..65be112 100755 --- a/db/install.xml +++ b/db/install.xml @@ -31,11 +31,7 @@ - - - - - + diff --git a/db/upgrade.php b/db/upgrade.php index a5fcd50..08272b5 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -58,5 +58,31 @@ function xmldb_capquiz_upgrade($oldversion) { } upgrade_mod_savepoint(true, 2019062550, 'capquiz'); } + if ($oldversion < 2019062553) { + $table = new xmldb_table('capquiz_question_list'); + $default = '1300,1450,1600,1800,2000'; + $field = new xmldb_field('star_ratings', XMLDB_TYPE_CHAR, 255, null, true, null, $default); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + $qlists = $DB->get_records('capquiz_question_list'); + foreach ($qlists as $qlist) { + $qlist->star_ratings = implode(',', [ + $qlist->level_1_rating, + $qlist->level_2_rating, + $qlist->level_3_rating, + $qlist->level_4_rating, + $qlist->level_5_rating + ]); + $DB->update_record('capquiz_question_list', $qlist); + } + for ($i = 1; $i <= 5; $i++) { + $field = new xmldb_field("level_{$i}_rating", XMLDB_TYPE_INTEGER, 10); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + } + upgrade_mod_savepoint(true, 2019062553, 'capquiz'); + } return true; } diff --git a/version.php b/version.php index 3e4e427..fbd9d2b 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062551; +$plugin->version = 2019062553; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062551)'; +$plugin->release = '0.2.1 (Build: 2019062553)'; From 9b091d84530dc0cd8393127d1ecd828a72cdde95 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:13:15 +0200 Subject: [PATCH 18/24] default asc sort by rating in question list and made the default sorting class into asc and desc, so it's easy to change --- amd/src/edit_questions.js | 6 +++++- templates/classlist.mustache | 2 +- templates/question_list.mustache | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/amd/src/edit_questions.js b/amd/src/edit_questions.js index 965599e..38fb337 100755 --- a/amd/src/edit_questions.js +++ b/amd/src/edit_questions.js @@ -189,7 +189,11 @@ define(['jquery'], function($) { $(document).on('click', '.capquiz-sortable', function() { sortTable($(this)); }); - $('.capquiz-sortable-default').each(function () { + $('.capquiz-sortable-default-asc').each(function () { + sortTable($(this)); + sortTable($(this)); + }); + $('.capquiz-sortable-default-desc').each(function () { sortTable($(this)); }); } diff --git a/templates/classlist.mustache b/templates/classlist.mustache index b4c4a5d..821c0db 100755 --- a/templates/classlist.mustache +++ b/templates/classlist.mustache @@ -48,7 +48,7 @@
- + diff --git a/templates/question_list.mustache b/templates/question_list.mustache index 785aa35..cdf49a3 100755 --- a/templates/question_list.mustache +++ b/templates/question_list.mustache @@ -56,7 +56,7 @@ - + {{#questions}} From 7af1e1fe742e262b62af1ed28df624251bdab5e9 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:13:43 +0200 Subject: [PATCH 19/24] update js build files --- amd/build/edit_questions.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amd/build/edit_questions.min.js b/amd/build/edit_questions.min.js index f5a9fa2..4d2c8a3 100755 --- a/amd/build/edit_questions.min.js +++ b/amd/build/edit_questions.min.js @@ -1 +1 @@ -define(["jquery"],function(t){var n={courseModuleId:0};function i(n,i,a){t.ajax({type:"post",url:"action.php",data:n,success:i,error:a})}function a(t,a,e,o){i({action:"set-default-question-rating",id:n.courseModuleId,rating:a},e,o)}function e(t,a,e,o){i({action:"set-question-rating",id:n.courseModuleId,"question-id":t.questionId,rating:a},e,o)}function o(t,n,i){t.data("saving",!0),t.data("dirty",!1);var a=t.next();a.css("color","blue"),n(i,t.val(),function(){!0===t.data("dirty")?o(t,n,i):(a.css("color","green"),t.data("dirty",!1),t.data("saving",!1))},function(){a.css("color","red")})}function r(t){o(t,e,{questionId:t.data("question-id")})}function c(t){o(t,a,null)}function u(n,i){t(document).on("input",n,function(n){var a=t(n.target);!0!==a.data("saving")?i(a):a.data("dirty",!0)})}function d(n){var i=n.index(),a=n.parent().parent(),e=a.find("tr:gt(0)").toArray().sort(function(n,i){var a=t(n).children("td").eq(0),e=t(i).children("td").eq(0);return parseInt(a.text())-parseInt(e.text())});a.append(e),e=a.find("tr:gt(0)").toArray().sort(function(n,a){var e=t(n).children("td").eq(i),o=t(a).children("td").eq(i),r=e.find(".capquiz-sortable-item"),c=o.find(".capquiz-sortable-item"),u=0===r.length?e.html():0===r.val().length?r.html():r.val(),d=0===c.length?o.html():0===c.val().length?c.html():c.val();return t.isNumeric(u)&&t.isNumeric(d)?u-d:u.toString().localeCompare(d)});var o="true"===a.data("asc");a.data("asc",o?"false":"true");var r=o?"fa-arrow-up":"fa-arrow-down";t.each(a.find(".capquiz-sortable"),function(){t(this).find(".fa").remove()}),n.prepend(''),o||(e=e.reverse()),a.append(e);var c=1;a.find("tr:gt(0)").each(function(){t(this).find("td:first-child").html(c),c++})}return{initialize:function(i){n.courseModuleId=i,u(".capquiz-question-rating input",r),u(".capquiz-default-question-rating input",c),t(".capquiz-question-rating-submit-wrapper button").each(function(n,i){t(i).attr("tabindex",-1)}),t(document).on("click",".capquiz-sortable",function(){d(t(this))}),t(".capquiz-sortable-default").each(function(){d(t(this))}),t(".capquiz-add-selected-questions").on("click",function(){var i="";t("#categoryquestions td input[type=checkbox]:checked").each(function(){i+=t(this).attr("name").slice(1)+","}),t.post("action.php",{action:"add-question",id:n.courseModuleId,"question-id":i},function(){location.reload()})})}}}); \ No newline at end of file +define(["jquery"],function(t){var n={courseModuleId:0};function i(n,i,a){t.ajax({type:"post",url:"action.php",data:n,success:i,error:a})}function a(t,a,e,o){i({action:"set-default-question-rating",id:n.courseModuleId,rating:a},e,o)}function e(t,a,e,o){i({action:"set-question-rating",id:n.courseModuleId,"question-id":t.questionId,rating:a},e,o)}function o(t,n,i){t.data("saving",!0),t.data("dirty",!1);var a=t.next();a.css("color","blue"),n(i,t.val(),function(){!0===t.data("dirty")?o(t,n,i):(a.css("color","green"),t.data("dirty",!1),t.data("saving",!1))},function(){a.css("color","red")})}function r(t){o(t,e,{questionId:t.data("question-id")})}function c(t){o(t,a,null)}function u(n,i){t(document).on("input",n,function(n){var a=t(n.target);!0!==a.data("saving")?i(a):a.data("dirty",!0)})}function d(n){var i=n.index(),a=n.parent().parent(),e=a.find("tr:gt(0)").toArray().sort(function(n,i){var a=t(n).children("td").eq(0),e=t(i).children("td").eq(0);return parseInt(a.text())-parseInt(e.text())});a.append(e),e=a.find("tr:gt(0)").toArray().sort(function(n,a){var e=t(n).children("td").eq(i),o=t(a).children("td").eq(i),r=e.find(".capquiz-sortable-item"),c=o.find(".capquiz-sortable-item"),u=0===r.length?e.html():0===r.val().length?r.html():r.val(),d=0===c.length?o.html():0===c.val().length?c.html():c.val();return t.isNumeric(u)&&t.isNumeric(d)?u-d:u.toString().localeCompare(d)});var o="true"===a.data("asc");a.data("asc",o?"false":"true");var r=o?"fa-arrow-up":"fa-arrow-down";t.each(a.find(".capquiz-sortable"),function(){t(this).find(".fa").remove()}),n.prepend(''),o||(e=e.reverse()),a.append(e);var c=1;a.find("tr:gt(0)").each(function(){t(this).find("td:first-child").html(c),c++})}return{initialize:function(i){n.courseModuleId=i,u(".capquiz-question-rating input",r),u(".capquiz-default-question-rating input",c),t(".capquiz-question-rating-submit-wrapper button").each(function(n,i){t(i).attr("tabindex",-1)}),t(document).on("click",".capquiz-sortable",function(){d(t(this))}),t(".capquiz-sortable-default-asc").each(function(){d(t(this)),d(t(this))}),t(".capquiz-sortable-default-desc").each(function(){d(t(this))}),t(".capquiz-add-selected-questions").on("click",function(){var i="";t("#categoryquestions td input[type=checkbox]:checked").each(function(){i+=t(this).attr("name").slice(1)+","}),t.post("action.php",{action:"add-question",id:n.courseModuleId,"question-id":i},function(){location.reload()})})}}}); \ No newline at end of file From 4585dee58147fb4886f3abcd6edbca6ae18e8ef9 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:22:22 +0200 Subject: [PATCH 20/24] fix default due grade date, and also json error in classlist mustache template --- classes/form/view/grading_configuration_form.php | 4 +++- templates/classlist.mustache | 2 +- version.php | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/classes/form/view/grading_configuration_form.php b/classes/form/view/grading_configuration_form.php index a6a1afd..847397c 100644 --- a/classes/form/view/grading_configuration_form.php +++ b/classes/form/view/grading_configuration_form.php @@ -72,7 +72,9 @@ public function definition() { $strduedate = get_string('due_time_grading', 'capquiz'); $form->addElement('date_time_selector', 'timedue', $strduedate); $form->setType('timedue', PARAM_INT); - $form->setDefault('timedue', $this->capquiz->time_due()); + $timedue = $this->capquiz->time_due(); + $oneweek = 60 * 60 * 24 * 7; + $form->setDefault('timedue', $timedue ? $timedue : time() + $oneweek); $form->addElement('submit', 'submitbutton', get_string('savechanges')); } diff --git a/templates/classlist.mustache b/templates/classlist.mustache index 821c0db..fd50c77 100755 --- a/templates/classlist.mustache +++ b/templates/classlist.mustache @@ -32,7 +32,7 @@ } ], "regrade": { - "method:" "post", + "method": "post", "classes": "capquiz-regrade-all", "url": "", "primary": true, diff --git a/version.php b/version.php index fbd9d2b..4b6a4b3 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019062553; +$plugin->version = 2019062700; $plugin->requires = 2016120500; $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062553)'; +$plugin->release = '0.2.1 (Build: 2019062700)'; From 9f736ef8d4c66a72f4002eb1847f676bc73f1353 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:30:18 +0200 Subject: [PATCH 21/24] update backup --- backup/moodle2/backup_capquiz_stepslib.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backup/moodle2/backup_capquiz_stepslib.php b/backup/moodle2/backup_capquiz_stepslib.php index bccf864..cce9f11 100644 --- a/backup/moodle2/backup_capquiz_stepslib.php +++ b/backup/moodle2/backup_capquiz_stepslib.php @@ -27,8 +27,7 @@ protected function define_structure() { ]); $questionlist = new backup_nested_element('questionlist', null, [ 'id', 'capquiz_id', 'question_usage_id', 'title', 'author', 'description', - 'level_1_rating', 'level_2_rating', 'level_3_rating', 'level_4_rating', 'level_5_rating', - 'is_template', 'time_created', 'time_modified', 'default_question_rating' + 'star_ratings', 'is_template', 'time_created', 'time_modified', 'default_question_rating' ]); $this->add_question_usages($questionlist, 'question_usage_id'); $questions = new backup_nested_element('questions'); From 01d9a6f3c912f00765d53e905798e761eceb04bc Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:33:00 +0200 Subject: [PATCH 22/24] update version number --- version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.php b/version.php index 4b6a4b3..f78e30c 100755 --- a/version.php +++ b/version.php @@ -28,4 +28,4 @@ $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.2.1 (Build: 2019062700)'; +$plugin->release = '0.3.0 (Build: 2019062700)'; From 5d1a2c4376513784b574be0baaa1b0cbe0dab3e5 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:40:44 +0200 Subject: [PATCH 23/24] update changelog --- CHANGELOG.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d60a94..24d987e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,20 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Changed - +## [0.3.0] - 2019-06-27 +### Added +- Added support for Moodle grading system +- Added button to add all selected (checked) questions to question list +- Number of stars is now configurable +- Class list is improved (sorting by columns) + +### Changed +- Merged some tabs to simplify user interface +- Rounded user ratings in class list + +### Fixed +- Add some missing language strings + ## [0.2.0] - 2019-06-24 ### Added * Questions can now be sorted by name and rating @@ -45,8 +59,9 @@ and this project adheres to [Semantic Versioning](https://semver.org). ## 0.1.0 - 2018-09-28 -[Unreleased]: https://github.com/KQMATH/moodle-mod_capquiz/compare/v0.2.0...HEAD +[Unreleased]: https://github.com/KQMATH/moodle-mod_capquiz/compare/v0.3.0...HEAD +[0.3.0]: https://github.com/KQMATH/moodle-mod_capquiz/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/KQMATH/moodle-mod_capquiz/compare/v0.1.5...v0.2.0 [0.1.5]: https://github.com/KQMATH/moodle-mod_capquiz/compare/v0.1.4...v0.1.5 [0.1.4]: https://github.com/KQMATH/moodle-mod_capquiz/compare/v0.1.3...v0.1.4 From e2811621598b9f5adb149cef0b9ce0e7ac801e00 Mon Sep 17 00:00:00 2001 From: rgbenergy Date: Thu, 27 Jun 2019 15:43:27 +0200 Subject: [PATCH 24/24] Remove one single space. --- classes/form/view/grading_configuration_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/form/view/grading_configuration_form.php b/classes/form/view/grading_configuration_form.php index 847397c..5cc0456 100644 --- a/classes/form/view/grading_configuration_form.php +++ b/classes/form/view/grading_configuration_form.php @@ -72,7 +72,7 @@ public function definition() { $strduedate = get_string('due_time_grading', 'capquiz'); $form->addElement('date_time_selector', 'timedue', $strduedate); $form->setType('timedue', PARAM_INT); - $timedue = $this->capquiz->time_due(); + $timedue = $this->capquiz->time_due(); $oneweek = 60 * 60 * 24 * 7; $form->setDefault('timedue', $timedue ? $timedue : time() + $oneweek);
# {{#str}}title, capquiz{{/str}}{{#str}} lastname, capquiz {{/str}} {{#str}} rating, capquiz {{/str}} {{#str}} stars, capquiz {{/str}}{{#str}} graded_stars, capquiz {{/str}}{{#str}} pass_or_fail, capquiz {{/str}}
{{ lastname }} {{ rating }} {{ stars }}{{ graded_stars }} + {{#passing_grade}}{{#str}} grade_pass, capquiz {{/str}}{{/passing_grade}} + {{^passing_grade}}{{#str}} grade_fail, capquiz {{/str}}{{/passing_grade}} +
{{#str}} username, capquiz {{/str}} {{#str}} firstname, capquiz {{/str}} {{#str}} lastname, capquiz {{/str}}{{#str}} rating, capquiz {{/str}}{{#str}} rating, capquiz {{/str}} {{#str}} stars, capquiz {{/str}} {{#str}} graded_stars, capquiz {{/str}} {{#str}} pass_or_fail, capquiz {{/str}}
# {{#str}}title, capquiz{{/str}}{{#str}}rating, capquiz{{/str}}{{#str}}rating, capquiz{{/str}} {{#str}}action, capquiz{{/str}}