diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..ee339a1
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,115 @@
+name: Moodle Plugin CI
+
+on:
+ push:
+ pull_request:
+ schedule:
+ - cron: '33 2 * * 1' # weekly, on Monday morning
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ services:
+ mariadb:
+ image: mariadb:10
+ env:
+ MYSQL_USER: 'root'
+ MYSQL_ALLOW_EMPTY_PASSWORD: "true"
+ MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
+ MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
+ ports:
+ - 3306:3306
+ options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
+
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - php: '8.2'
+ moodle-branch: 'main'
+ database: 'mariadb'
+ - php: '8.2'
+ moodle-branch: 'MOODLE_403_STABLE'
+ database: 'mariadb'
+ - php: '8.1'
+ moodle-branch: 'MOODLE_402_STABLE'
+ database: 'mariadb'
+ - php: '8.1'
+ moodle-branch: 'MOODLE_401_STABLE'
+ database: 'mariadb'
+ steps:
+ - name: Check out repository code
+ uses: actions/checkout@v3
+ with:
+ path: plugin
+
+ - name: Setup PHP ${{ matrix.php }}
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: ${{ matrix.extensions }}
+ ini-values: max_input_vars=5000
+ # If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
+ # If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
+ coverage: none
+
+ - name: Initialise moodle-plugin-ci
+ run: |
+ composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
+ echo $(cd ci/bin; pwd) >> $GITHUB_PATH
+ echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
+ sudo locale-gen en_AU.UTF-8
+ echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
+
+ - name: Install moodle-plugin-ci
+ run: |
+ moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
+ env:
+ DB: ${{ matrix.database }}
+ MOODLE_BRANCH: ${{ matrix.moodle-branch }}
+
+ - name: PHP Lint
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci phplint
+
+ - name: PHP Mess Detector
+ continue-on-error: true # This step will show errors but will not fail
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci phpmd
+
+ - name: Moodle Code Checker
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci phpcs --max-warnings 0
+
+ - name: Moodle PHPDoc Checker
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci phpdoc --max-warnings 0
+
+ - name: Validating
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci validate
+
+ - name: Check upgrade savepoints
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci savepoints
+
+ - name: Mustache Lint
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci mustache
+
+ - name: Grunt
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci grunt --max-lint-warnings 0
+
+ - name: PHPUnit tests
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci phpunit --fail-on-warning
+
+ - name: Behat features
+ if: ${{ !cancelled() }}
+ run: moodle-plugin-ci behat --profile chrome
+
+ - name: Mark cancelled jobs as failed.
+ if: ${{ cancelled() }}
+ run: exit 1
\ No newline at end of file
diff --git a/.phpcs.xml b/.phpcs.xml
new file mode 100644
index 0000000..2c248fc
--- /dev/null
+++ b/.phpcs.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/README.md b/README.md
index c3d10c0..a772433 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,6 @@
A custom question type for Moodle.
-Copyright (c) 2016 by The Regents of the University of California
+Copyright (c) by The Regents of the University of California
This is Open Source Software, published under the GPL v3 license.
diff --git a/backup/moodle2/backup_qtype_knowledgecheck_plugin.class.php b/backup/moodle2/backup_qtype_knowledgecheck_plugin.class.php
index 156953d..f65ddde 100644
--- a/backup/moodle2/backup_qtype_knowledgecheck_plugin.class.php
+++ b/backup/moodle2/backup_qtype_knowledgecheck_plugin.class.php
@@ -15,20 +15,19 @@
// along with Moodle. If not, see .
/**
- * @package knowledgecheck
+ * Backup plugin for the Knowledge check question type.
+ *
+ * @package qtype_knowledgecheck
* @subpackage backup-moodle2
- * @copyright 2016 The Regents of the University of California
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
/**
- * Provides the information to backup knowledge check questions.
+ * Provides the information to backup knowledgecheck questions.
*
- * @copyright 2016 The Regents of the University of California
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_qtype_knowledgecheck_plugin extends backup_qtype_plugin {
@@ -52,14 +51,14 @@ protected function define_question_plugin_structure() {
$this->add_question_question_answers($pluginwrapper);
// Now create the qtype own structures.
- $knowledgecheck = new backup_nested_element('knowledgecheck', array('id'), array('responsetemplate'));
+ $knowledgecheck = new backup_nested_element('knowledgecheck', ['id'], ['responsetemplate']);
// Now the own qtype tree.
$pluginwrapper->add_child($knowledgecheck);
// Set source to populate the data.
$knowledgecheck->set_source_table('qtype_knowledgecheck_options',
- array('questionid' => backup::VAR_PARENTID));
+ ['questionid' => backup::VAR_PARENTID]);
// Don't need to annotate ids nor files.
diff --git a/backup/moodle2/restore_qtype_knowledgecheck_plugin.class.php b/backup/moodle2/restore_qtype_knowledgecheck_plugin.class.php
index 3792649..bdbbf15 100644
--- a/backup/moodle2/restore_qtype_knowledgecheck_plugin.class.php
+++ b/backup/moodle2/restore_qtype_knowledgecheck_plugin.class.php
@@ -15,21 +15,19 @@
// along with Moodle. If not, see .
/**
- * @package knowledgecheck
+ * Restore plugin for the Knowledge check question type.
+ *
+ * @package qtype_knowledgecheck
* @subpackage backup-moodle2
- * @copyright 2016 The Regents of the University of California
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
/**
- * restore plugin class that provides the necessary information
- * needed to restore one knowledgecheck qtype plugin
+ * Restore plugin class that provides the necessary information needed to restore one knowledgecheck qtype plugin.
*
- * @copyright 2016 The Regents of the University of California
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_qtype_knowledgecheck_plugin extends restore_qtype_plugin {
@@ -39,7 +37,7 @@ class restore_qtype_knowledgecheck_plugin extends restore_qtype_plugin {
*/
protected function define_question_plugin_structure() {
- $paths = array();
+ $paths = [];
// This qtype uses question_answers, add them.
$this->add_question_question_answers($paths);
@@ -55,6 +53,7 @@ protected function define_question_plugin_structure() {
/**
* Process the qtype/knowledgecheck element
+ * @param array $data The data to restore.
*/
public function process_knowledgecheck($data) {
global $DB;
@@ -79,7 +78,7 @@ public function process_knowledgecheck($data) {
// It is possible for old backup files to contain unique key violations.
// We need to check to avoid that.
- if (!$DB->record_exists('qtype_knowledgecheck_options', array('questionid' => $data->questionid))) {
+ if (!$DB->record_exists('qtype_knowledgecheck_options', ['questionid' => $data->questionid])) {
$newitemid = $DB->insert_record('qtype_knowledgecheck_options', $data);
$this->set_mapping('qtype_knowledgecheck_options', $oldid, $newitemid);
}
diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php
new file mode 100644
index 0000000..36b3cab
--- /dev/null
+++ b/classes/privacy/provider.php
@@ -0,0 +1,65 @@
+.
+
+/**
+ * Privacy Subsystem implementation for qtype_knowledgecheck.
+ *
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace qtype_knowledgecheck\privacy;
+
+use core_privacy\local\metadata\collection;
+use core_privacy\local\metadata\provider as base_provider;
+use core_privacy\local\request\user_preference_provider;
+use core_privacy\local\request\writer;
+
+/**
+ * Privacy Subsystem for qtype_knowledgecheck implementing user_preference_provider.
+ *
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class provider implements base_provider, user_preference_provider {
+
+
+ /**
+ * Returns meta-data about this system.
+ *
+ * @param collection $collection The initialised collection to add items to.
+ * @return collection A listing of user data stored through this system.
+ */
+ public static function get_metadata(collection $collection): collection {
+ $collection->add_user_preference('qtype_knowledgecheck_defaultmark', 'privacy:preference:defaultmark');
+ return $collection;
+ }
+
+ /**
+ * Export all user preferences for the plugin.
+ *
+ * @param int $userid The userid of the user whose data is to be exported.
+ */
+ public static function export_user_preferences(int $userid) {
+ $preference = get_user_preferences('qtype_knowledgecheck_defaultmark', null, $userid);
+ if (null !== $preference) {
+ $desc = get_string('privacy:preference:defaultmark', 'qtype_knowledgecheck');
+ writer::export_user_preference('qtype_knowledgecheck', 'defaultmark', $preference, $desc);
+ }
+ }
+}
diff --git a/edit_knowledgecheck_form.php b/edit_knowledgecheck_form.php
index 8477172..001af3d 100644
--- a/edit_knowledgecheck_form.php
+++ b/edit_knowledgecheck_form.php
@@ -17,34 +17,39 @@
/**
* Defines the editing form for the knowledge check question type.
*
- * @package qtype
- * @subpackage knowledgecheck
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
/**
* Knowledge check question editing form definition.
*
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_knowledgecheck_edit_form extends question_edit_form {
+ /**
+ * {@inheritdoc}
+ *
+ * @param object $mform The form being built.
+ */
protected function definition_inner($mform) {
$mform->addElement('editor', 'responsetemplate', get_string('responsetemplate', 'qtype_knowledgecheck'),
- array('rows' => 10), array_merge($this->editoroptions, array('maxfiles' => 0)));
+ ['rows' => 10], array_merge($this->editoroptions, ['maxfiles' => 0]));
$mform->addHelpButton('responsetemplate', 'responsetemplate', 'qtype_knowledgecheck');
$this->add_per_answer_fields($mform, get_string('answerno', 'qtype_knowledgecheck', '{no}'),
- array('1.0' => '100%'), 1, 0);
+ ['1.0' => '100%'], 1, 0);
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param object $question The data being passed to the form.
+ * @return object $question The modified data.
+ */
protected function data_preprocessing($question) {
$question = parent::data_preprocessing($question);
$question = $this->data_preprocessing_answers($question);
@@ -53,14 +58,19 @@ protected function data_preprocessing($question) {
if (empty($question->options)) {
return $question;
}
- $question->responsetemplate = array(
+ $question->responsetemplate = [
'text' => $question->options->responsetemplate,
'format' => 1,
- );
+ ];
return $question;
}
+ /**
+ * {@inheritdoc}
+ *
+ * @return string The question type name.
+ */
public function qtype() {
return 'knowledgecheck';
}
diff --git a/lang/en/qtype_knowledgecheck.php b/lang/en/qtype_knowledgecheck.php
index d626d6f..a15a3f1 100644
--- a/lang/en/qtype_knowledgecheck.php
+++ b/lang/en/qtype_knowledgecheck.php
@@ -15,12 +15,10 @@
// along with Moodle. If not, see .
/**
- * Strings for component 'qtype_knowledgecheck', language 'en', branch 'MOODLE_20_STABLE'
+ * Strings for component 'qtype_knowledgecheck'.
*
- * @package qtype
- * @subpackage knowledgecheck
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['answerno'] = 'Answer {$a}';
@@ -30,6 +28,8 @@
$string['pluginnameadding'] = 'Adding a knowledge check question';
$string['pluginnameediting'] = 'Editing a knowledge check question';
$string['pluginnamesummary'] = 'Students can check their knowledge and get immediate or delayed feedback (depending on the question settings). All answers are automatically graded and assumed to be correct. The main purpose of this question type is to automatically provide students with feedback on their responses.';
+$string['privacy:metadata'] = 'Knowledgecheck question type plugin allows question authors to set default options as user preferences.';
+$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.';
$string['responsetemplate'] = 'Response template';
$string['responsetemplate_help'] = 'Any text entered here will be displayed in the response input box when a new attempt at the question starts.';
diff --git a/lib.php b/lib.php
index eba5a14..6ad750f 100644
--- a/lib.php
+++ b/lib.php
@@ -15,21 +15,16 @@
// along with Moodle. If not, see .
/**
- * Serve question type files
+ * Serve question type files.
*
- * @since 2.0
* @package qtype_knowledgecheck
- * @copyright 2016 The Regents of the University of California
-
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
/**
* Checks file access for knowledge check questions.
+ *
* @package qtype_knowledgecheck
* @category files
* @param stdClass $course course object
@@ -41,7 +36,7 @@
* @param array $options additional options affecting the file serving
* @return bool
*/
-function qtype_knowledgecheck_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
+function qtype_knowledgecheck_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=[]) {
global $DB, $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_knowledgecheck', $filearea, $args, $forcedownload, $options);
diff --git a/question.php b/question.php
index f7b7587..8df090c 100644
--- a/question.php
+++ b/question.php
@@ -17,22 +17,16 @@
/**
* Knowledge check question definition class.
*
- * @package qtype
- * @subpackage knowledgecheck
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
/**
* Represents a knowledge check question.
*
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_knowledgecheck_question extends question_graded_by_strategy
@@ -50,16 +44,30 @@ class qtype_knowledgecheck_question extends question_graded_by_strategy
/**
* @var question_answer[]
*/
- public $answers = array();
+ public $answers = [];
+ /**
+ * {@inheritdoc}
+ */
public function __construct() {
parent::__construct(new question_first_matching_answer_grading_strategy($this));
}
+ /**
+ * {@inheritdoc}
+ *
+ * @return array A structure defining what data is expected in the response to this question.
+ */
public function get_expected_data() {
- return array('answer' => PARAM_RAW_TRIMMED);
+ return ['answer' => PARAM_RAW_TRIMMED];
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param array $response A given response.
+ * @return string|null A plain text summary of that response, that could be used in reports.
+ */
public function summarise_response(array $response) {
if (isset($response['answer'])) {
return $response['answer'];
@@ -68,38 +76,81 @@ public function summarise_response(array $response) {
}
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param array $response A list of responses.
+ * @return bool whether this response is a complete answer to this question.
+ */
public function is_complete_response(array $response) {
return array_key_exists('answer', $response) &&
($response['answer'] || $response['answer'] === '0');
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param array $response The given response
+ * @return string the validation error message.
+ */
public function get_validation_error(array $response) {
return get_string('pleaseenterananswer', 'qtype_knowledgecheck');
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param array $prevresponse the responses previously recorded for this question.
+ * @param array $newresponse the new responses, in the same format.
+ * @return bool whether the two sets of responses are the same - that is
+ * whether the new set of responses can safely be discarded.
+ */
public function is_same_response(array $prevresponse, array $newresponse) {
return question_utils::arrays_same_at_key_missing_is_blank(
$prevresponse, $newresponse, 'answer');
}
+ /**
+ * Returns a list of possible answers to this question.
+ *
+ * @return array A list of possible answers to this question.
+ */
public function get_answers() {
return $this->answers;
}
+ /**
+ * Compares the given response with a given possible answer.
+ *
+ * @param array $response the response.
+ * @param question_answer $answer an answer.
+ * @return bool whether the response matches the answer.
+ */
public function compare_response_with_answer(array $response, question_answer $answer) {
if (!array_key_exists('answer', $response) || is_null($response['answer'])) {
return false;
}
- // whatever the answer is - it's always correct.
+ // Whatever the answer is - it's always correct.
return true;
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param question_attempt $qa the question attempt being displayed.
+ * @param question_display_options $options the options that control display of the question.
+ * @param string $component the name of the component we are serving files for.
+ * @param string $filearea the name of the file area.
+ * @param array $args the remaining bits of the file path.
+ * @param bool $forcedownload whether the user must be forced to download the file.
+ * @return bool true if the user can access this file.
+ */
public function check_file_access($qa, $options, $component, $filearea,
$args, $forcedownload) {
if ($component == 'question' && $filearea == 'answerfeedback') {
$currentanswer = $qa->get_last_qt_var('answer');
- $answer = $this->get_matching_answer(array('answer' => $currentanswer));
+ $answer = $this->get_matching_answer(['answer' => $currentanswer]);
$answerid = reset($args); // Itemid is answer id.
return $options->feedback && $answer && $answerid == $answer->id;
diff --git a/questiontype.php b/questiontype.php
index 9e6e0ef..6288274 100644
--- a/questiontype.php
+++ b/questiontype.php
@@ -17,14 +17,11 @@
/**
* Question type class for the knowledge check question type.
*
- * @package qtype
- * @subpackage knowledgecheck
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/questionlib.php');
@@ -35,25 +32,45 @@
/**
* The knowledge check question type.
*
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_knowledgecheck extends question_type {
+ /**
+ * {@inheritdoc}
+ *
+ * @param int $questionid the question being moved.
+ * @param int $oldcontextid the context it is moving from.
+ * @param int $newcontextid the context it is moving to.
+ */
public function move_files($questionid, $oldcontextid, $newcontextid) {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param int $questionid the question being deleted.
+ * @param int $contextid the context the question is in.
+ */
protected function delete_files($questionid, $contextid) {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_hints($questionid, $contextid);
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param object $question This holds the information from the editing form,
+ * it is not a standard question object.
+ * @return object $result->error or $result->notice
+ */
public function save_question_options($question) {
global $DB;
- $options = $DB->get_record('qtype_knowledgecheck_options', array('questionid' => $question->id));
+ $options = $DB->get_record('qtype_knowledgecheck_options', ['questionid' => $question->id]);
if (!$options) {
$options = new stdClass();
$options->questionid = $question->id;
@@ -66,18 +83,27 @@ public function save_question_options($question) {
$this->save_hints($question);
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param question_definition $question the question_definition we are creating.
+ * @param object $questiondata the question data loaded from the database.
+ */
protected function initialise_question_instance(question_definition $question, $questiondata) {
parent::initialise_question_instance($question, $questiondata);
$this->initialise_question_answers($question, $questiondata);
}
- public function get_random_guess_score($questiondata) {
- return 0;
- }
-
+ /**
+ * {@inheritdoc}
+ *
+ * @param object $questiondata the question definition data.
+ * @return array keys are subquestionid, values are arrays of possible
+ * responses to that subquestion.
+ */
public function get_possible_responses($questiondata) {
- $responses = array();
+ $responses = [];
foreach ($questiondata->options->answers as $aid => $answer) {
$responses[$aid] = new question_possible_response($answer->answer, $answer->fraction);
@@ -86,13 +112,25 @@ public function get_possible_responses($questiondata) {
$responses[0] = new question_possible_response(get_string('didnotmatchanyanswer', 'question'), 0);
$responses[null] = question_possible_response::no_response();
- return array($questiondata->id => $responses);
+ return [$questiondata->id => $responses];
}
+ /**
+ * {@inheritdoc}
+ *
+ * @return mixed array as above, or null to tell the base class to do nothing.
+ */
public function extra_question_fields() {
- return array('qtype_knowledgecheck_options', 'responsetemplate');
+ return ['qtype_knowledgecheck_options', 'responsetemplate'];
}
+ /**
+ * {@inheritdoc}
+ *
+ * @return bool override this to return false if this is not really a
+ * question type, for example the description question type is not
+ * really a question type.
+ */
public function is_real_question_type() {
return false;
}
diff --git a/renderer.php b/renderer.php
index 2095361..3a5ffc4 100644
--- a/renderer.php
+++ b/renderer.php
@@ -17,25 +17,29 @@
/**
* Knowledge check question renderer class.
*
- * @package qtype
- * @subpackage knowledgecheck
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
defined('MOODLE_INTERNAL') || die();
-
/**
* Generates the output for knowledge check questions.
*
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_knowledgecheck_renderer extends qtype_renderer {
+
+ /**
+ * {@inheritdoc}
+ *
+ * @param question_attempt $qa the question attempt to display.
+ * @param question_display_options $options controls what should and should not be displayed.
+ * @return string HTML fragment.
+ */
public function formulation_and_controls(question_attempt $qa,
question_display_options $options) {
@@ -46,10 +50,9 @@ public function formulation_and_controls(question_attempt $qa,
// Answer field.
$step = $qa->get_last_step_with_qt_var('answer');
-
if (!$step->has_qt_var('answer') && empty($options->readonly)) {
// Question has never been answered, fill it with response template.
- $step = new question_attempt_step(array('answer'=>$question->responsetemplate));
+ $step = new question_attempt_step(['answer' => $question->responsetemplate]);
}
if (empty($options->readonly)) {
@@ -63,25 +66,31 @@ public function formulation_and_controls(question_attempt $qa,
$result = '';
$result .= html_writer::tag('div', $question->format_questiontext($qa),
- array('class' => 'qtext'));
+ ['class' => 'qtext']);
- $result .= html_writer::start_tag('div', array('class' => 'ablock'));
- $result .= html_writer::tag('div', $answer, array('class' => 'answer'));
+ $result .= html_writer::start_tag('div', ['class' => 'ablock']);
+ $result .= html_writer::tag('div', $answer, ['class' => 'answer']);
$result .= html_writer::end_tag('div');
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
- $question->get_validation_error(array('answer' => $answer)),
- array('class' => 'validationerror'));
+ $question->get_validation_error(['answer' => $answer]),
+ ['class' => 'validationerror']);
}
return $result;
}
+ /**
+ * {@inheritdoc}
+ *
+ * @param question_attempt $qa the question attempt to display.
+ * @return string HTML fragment.
+ */
public function specific_feedback(question_attempt $qa) {
$question = $qa->get_question();
- $answer = $question->get_matching_answer(array('answer' => $qa->get_last_qt_var('answer')));
+ $answer = $question->get_matching_answer(['answer' => $qa->get_last_qt_var('answer')]);
if (!$answer || !$answer->feedback) {
return '';
}
@@ -91,26 +100,51 @@ public function specific_feedback(question_attempt $qa) {
}
}
-
/**
- * A format renderer for knowledge checks where the student should use the HTML
- * editor without the file picker.
+ * A format renderer for knowledge checks where the student should use the HTML editor without the file picker.
*
* Copied and modified from the Essay question type for our purposes.
*
- * @copyright 2016 The Regents of the University of California
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_knowledgecheck_format_editor_renderer extends plugin_renderer_base {
+
+ /**
+ * Gets a specific class name to add to the input element.
+ *
+ * @return string specific class name to add to the input element.
+ */
protected function class_name() {
return 'qtype_knowledgecheck_editor';
}
+ /**
+ * Render the student's response when the question is in read-only mode.
+ *
+ * @param string $name the variable name this input edits.
+ * @param question_attempt $qa the question attempt being display.
+ * @param question_attempt_step $step the current step.
+ * @param int $lines approximate size of input box to display.
+ * @param object $context the context teh output belongs to.
+ * @return string html to display the response.
+ */
public function response_area_read_only($name, $qa, $step, $lines, $context) {
return html_writer::tag('div', $this->prepare_response($name, $qa, $step, $context),
- array('class' => $this->class_name() . ' qtype_knowledgecheck_editor readonly'));
+ ['class' => $this->class_name() . ' qtype_knowledgecheck_editor readonly']);
}
+ /**
+ * Render the student's response when the question is in read-only mode.
+ *
+ * @param string $name the variable name this input edits.
+ * @param question_attempt $qa the question attempt being display.
+ * @param question_attempt_step $step the current step.
+ * @param int $lines approximate size of input box to display.
+ * @param object $context the context teh output belongs to.
+ * @return string html to display the response for editing.
+ */
public function response_area_input($name, $qa, $step, $lines, $context) {
global $CFG;
require_once($CFG->dirroot . '/repository/lib.php');
@@ -133,17 +167,17 @@ public function response_area_input($name, $qa, $step, $lines, $context) {
$this->get_filepicker_options($context, $draftitemid));
$output = '';
- $output .= html_writer::start_tag('div', array('class' =>
- $this->class_name() . ' qtype_knowledgecheck_response'));
+ $output .= html_writer::start_tag('div', ['class' =>
+ $this->class_name() . ' qtype_knowledgecheck_response']);
$output .= html_writer::tag('div', html_writer::tag('textarea', s($response),
- array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60)));
+ ['id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60]));
$output .= html_writer::start_tag('div');
if (count($formats) == 1) {
reset($formats);
- $output .= html_writer::empty_tag('input', array('type' => 'hidden',
- 'name' => $inputname . 'format', 'value' => key($formats)));
+ $output .= html_writer::empty_tag('input', ['type' => 'hidden',
+ 'name' => $inputname . 'format', 'value' => key($formats)]);
} else {
$output .= html_writer::label(get_string('format'), 'menu' . $inputname . 'format', false);
@@ -160,6 +194,7 @@ public function response_area_input($name, $qa, $step, $lines, $context) {
/**
* Prepare the response for read-only display.
+ *
* @param string $name the variable name this input edits.
* @param question_attempt $qa the question attempt being display.
* @param question_attempt_step $step the current step.
@@ -180,6 +215,7 @@ protected function prepare_response($name, question_attempt $qa,
/**
* Prepare the response for editing.
+ *
* @param string $name the variable name this input edits.
* @param question_attempt_step $step the current step.
* @param object $context the context the attempt belongs to.
@@ -187,27 +223,33 @@ protected function prepare_response($name, question_attempt $qa,
*/
protected function prepare_response_for_editing($name,
question_attempt_step $step, $context) {
- return array(0, $step->get_qt_var($name));
+ return [0, $step->get_qt_var($name)];
}
/**
+ * Get editor options for question response text area.
+ *
* @param object $context the context the attempt belongs to.
* @return array options for the editor.
*/
protected function get_editor_options($context) {
- return array('context' => $context);
+ return ['context' => $context];
}
/**
+ * Get filepicker options for the editor.
+ *
* @param object $context the context the attempt belongs to.
* @param int $draftitemid draft item id.
* @return array filepicker options for the editor.
*/
protected function get_filepicker_options($context, $draftitemid) {
- return array('return_types' => FILE_INTERNAL | FILE_EXTERNAL);
+ return ['return_types' => FILE_INTERNAL | FILE_EXTERNAL];
}
/**
+ * Get HTML for the filepicker, if used.
+ *
* @param string $inputname input field name.
* @param int $draftitemid draft file area itemid.
* @return string HTML for the filepicker, if used.
diff --git a/styles.css b/styles.css
index 5a2eb2e..e142055 100644
--- a/styles.css
+++ b/styles.css
@@ -17,11 +17,11 @@ body#page-question-type-knowledgecheck div[id^=fgroup_id_][id*=answeroptions_] {
display: none;
}
-body#page-question-type-knowledgecheck div[id^=fgroup_id_][id*=answeroptions_] .fgrouplabel label{
+body#page-question-type-knowledgecheck div[id^=fgroup_id_][id*=answeroptions_] .fgrouplabel label {
display: none;
}
-body#page-question-type-knowledgecheck div[id^=fgroup_id_][id*=answeroptions_] label[for^='id_answer_']{
+body#page-question-type-knowledgecheck div[id^=fgroup_id_][id*=answeroptions_] label[for^='id_answer_'] {
display: none;
}
@@ -30,12 +30,12 @@ body#page-question-type-knowledgecheck div[id^=fitem_id_][id*=fraction_] {
}
body#page-question-type-knowledgecheck div[id^=fitem_id_][id*=feedback_] {
- background: #EEE;
+ background: #eee;
margin-bottom: 2em;
margin-top: 0;
padding-bottom: 5px;
padding-top: 5px;
- border: 1px solid #BBB;
+ border: 1px solid #bbb;
}
body#page-question-type-knowledgecheck div[id=fitem_id_addanswers] {
diff --git a/version.php b/version.php
index 2d283eb..a2f2865 100644
--- a/version.php
+++ b/version.php
@@ -17,16 +17,16 @@
/**
* Knowledge check question type version information.
*
- * @package qtype
- * @subpackage knowledgecheck
- * @copyright 2016 The Regents of the University of California
-
+ * @package qtype_knowledgecheck
+ * @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qtype_knowledgecheck';
-$plugin->version = 2022121200;
-$plugin->requires = 2022111800;
+$plugin->version = 2024031600;
+$plugin->release = 'v4.1';
+$plugin->requires = 2022112800;
+$plugin->supported = [401, 401];
$plugin->maturity = MATURITY_STABLE;