diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dfe57bd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml new file mode 100644 index 0000000..50f9d58 --- /dev/null +++ b/.github/workflows/moodle-ci.yml @@ -0,0 +1,130 @@ +name: build + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-18.04 + + services: + postgres: + image: postgres:9.6 + env: + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 + mariadb: + image: mariadb:10 + env: + MYSQL_USER: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + + strategy: + fail-fast: false + matrix: + php: ['7.2', '7.3', '7.4'] + moodle-branch: ['MOODLE_310_STABLE', 'MOODLE_39_STABLE'] + database: [pgsql, mariadb] + + steps: + - name: Check out repository code + uses: actions/checkout@v2 + with: + path: plugin + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: Initialise moodle-plugin-ci + run: | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + echo $(cd ci/bin; pwd) >> $GITHUB_PATH + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH + sudo locale-gen en_AU.UTF-8 + + - 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: ${{ always() }} + run: moodle-plugin-ci phplint + + - name: PHP Copy/Paste Detector + continue-on-error: true # This step will show errors but will not fail + if: ${{ always() }} + run: moodle-plugin-ci phpcpd + + - name: PHP Mess Detector + continue-on-error: true # This step will show errors but will not fail + if: ${{ always() }} + run: moodle-plugin-ci phpmd + + - name: Moodle Code Checker + if: ${{ always() }} + run: moodle-plugin-ci codechecker --max-warnings 0 + + - name: Moodle PHPDoc Checker + if: ${{ always() }} + run: moodle-plugin-ci phpdoc + + - name: Validating + if: ${{ always() }} + run: moodle-plugin-ci validate + + - name: Check upgrade savepoints + if: ${{ always() }} + run: moodle-plugin-ci savepoints + + - name: Mustache Lint + if: ${{ always() }} + run: moodle-plugin-ci mustache + + - name: Grunt + if: ${{ always() }} + run: moodle-plugin-ci grunt --max-lint-warnings 0 + + - name: PHPUnit tests + if: ${{ always() }} + run: moodle-plugin-ci phpunit --coverage-clover + + - name: Behat features + if: ${{ always() }} + run: moodle-plugin-ci behat --profile chrome + + - name: Convert Coverage (clover2lcov) + uses: andstor/clover2lcov-action@v1 + if: ${{ always() }} + with: + src: ./coverage.xml + dst: ./coverage/lcov.info + + - name: Coveralls Parallel + if: ${{ always() }} + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + flag-name: run-${{ matrix.test_number }} + parallel: true + + finish: + needs: test + if: always() + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a367c48 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode + +*.code-workspace diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..13d7155 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,48 @@ +language: php + +addons: + postgresql: "9.5" + +services: + - mysql + - postgresql + - docker + +cache: + directories: + - $HOME/.composer/cache + - $HOME/.npm + +php: + - 7.2 + - 7.3 + - 7.4 + +env: + global: + - MOODLE_BRANCH=MOODLE_39_STABLE + matrix: + - DB=pgsql + - DB=mysqli + +before_install: + - phpenv config-rm xdebug.ini + - cd ../.. + - composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" + +install: + - moodle-plugin-ci install + +script: + - moodle-plugin-ci phplint + - moodle-plugin-ci phpcpd + - moodle-plugin-ci phpmd + - moodle-plugin-ci codechecker + - moodle-plugin-ci validate + - moodle-plugin-ci savepoints + - moodle-plugin-ci mustache + - moodle-plugin-ci grunt + - moodle-plugin-ci phpdoc + - moodle-plugin-ci phpunit + - moodle-plugin-ci behat diff --git a/README.md b/README.md index 3e1778d..9d042f6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ # moodle-block_capquizqtracker +[![build](https://github.com/KQMATH/moodle-block_capquizqtracker/actions/workflows/moodle-ci.yml/badge.svg?branch=master)](https://github.com/KQMATH/moodle-block_capquizqtracker/actions/workflows/moodle-ci.yml) + 🐛 Moodle Question Tracker Block plugin for CAPQuiz + +**Requires** [QTracker](https://github.com/KQMATH/moodle-local_qtracker) and [CAPQuiz](https://github.com/KQMATH/moodle-mod_capquiz). + +This plugin creates a block to be added to [CAPQuiz](https://github.com/KQMATH/moodle-mod_capquiz) activities in order to provide an interface to [QTracker](https://github.com/KQMATH/moodle-local_qtracker). + +See [QTracker](https://github.com/KQMATH/moodle-local_qtracker) for further information. + +## Documentation +Documentation is available [here](https://github.com/KQMATH/moodle-block_capquizqtracker/wiki), including [installation instructions](https://github.com/KQMATH/moodle-block_capquizqtracker/wiki/Installation-instructions). + +## Feedback: +**Project lead:** Hans Georg Schaathun + +**Developer:** [André Storhaug](https://github.com/andstor) + +## License +CAPQuiz QTracker is licensed under the [GNU General Public, License Version 3](https://github.com/KQMATH/moodle-block_capquizqtracker/LICENSE). + +## Related + +- [CAPQuiz](https://moodle.org/plugins/mod_capquiz) - Computer adaptive practice activity module for Moodle +- [Quiz QTracker](https://moodle.org/plugins/block_quizqtracker) - Moodle Question Tracker Block plugin for Moodle Quiz diff --git a/block_capquizqtracker.php b/block_capquizqtracker.php new file mode 100644 index 0000000..b5c0a52 --- /dev/null +++ b/block_capquizqtracker.php @@ -0,0 +1,113 @@ +. + +/** + * Main interface to Question Tracker + * + * Provides block for registering question issues for quiz module + * + * @package block_capquizqtracker + * @author André Storhaug + * @copyright 2020 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use \local_qtracker\output\issue_registration_block; +use \mod_capquiz\capquiz; +use \mod_capquiz\capquiz_attempt; + +defined('MOODLE_INTERNAL') || die(); + +class block_capquizqtracker extends block_base { + public function init() { + $this->title = get_string('capquizqtracker_quiz', 'block_capquizqtracker'); + } + + public function applicable_formats() { + return array('all' => false, 'mod-capquiz' => true); + } + + function has_config() { + return true; + } + + function get_content() { + global $COURSE, $USER, $PAGE; + + if ($this->content !== null) { + return $this->content; + } + + if (empty($this->instance)) { + $this->content = ''; + return $this->content; + } + + $this->content = new stdClass(); + $this->content->items = array(); + $this->content->icons = array(); + $this->content->text = ''; + $this->content->footer = ''; + + // Get submitted parameters. + $cmid = optional_param('id', null, PARAM_INT); + + if (is_null($cmid)) { + return $this->content->text; + } + + $capquiz = new capquiz($cmid); + + if (has_capability('mod/capquiz:instructor', $capquiz->context())) { + $url = new moodle_url('/local/qtracker/view.php', array('courseid' => $COURSE->id)); + $this->content->text = html_writer::link($url, "View issues..."); + return $this->content; + } + + $currentcontext = $this->page->context->get_course_context(false); + if (!empty($this->config->text)) { + $this->content->text = $this->config->text; + } + + if (empty($currentcontext)) { + return $this->content; + } + + if ($this->page->course->id == SITEID) { + $this->content->text .= "site context"; + } + + if (isset($this->config->text)) { + $this->content->text = $this->config->text; + } else { + $this->content->text = html_writer::tag('p', get_string('question_problem_details', 'block_capquizqtracker')); + } + + $this->userid = $USER->id; + + $user = $capquiz->user(); + $quba = $user->question_usage(); + $qengine = $capquiz->question_engine($user); + $attempt = $qengine->attempt_for_current_user(); + $slot = $attempt->question_slot(); + + $renderer = $this->page->get_renderer('local_qtracker'); + $context = $PAGE->context; + $templatable = new issue_registration_block($quba, [$slot], $context->id); + $this->content->text .= $renderer->render($templatable); + return $this->content; + } +} diff --git a/db/access.php b/db/access.php new file mode 100644 index 0000000..0aa8988 --- /dev/null +++ b/db/access.php @@ -0,0 +1,52 @@ +. + +/** + * Plugin capabilities. + * + * @package block_capquizqtracker + * @author André Storhaug + * @copyright 2020 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$capabilities = array( + + 'block/capquizqtracker:myaddinstance' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'user' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/my:manageblocks' + ), + + 'block/capquizqtracker:addinstance' => array( + 'riskbitmask' => RISK_SPAM | RISK_XSS, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_BLOCK, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + + 'clonepermissionsfrom' => 'moodle/site:manageblocks' + ), +); diff --git a/edit_form.php b/edit_form.php new file mode 100644 index 0000000..5c8bc86 --- /dev/null +++ b/edit_form.php @@ -0,0 +1,37 @@ +. + +/** + * @package block_capquizqtracker + * @author André Storhaug + * @copyright 2020 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +class block_capquizqtracker_edit_form extends block_edit_form { + + protected function specific_definition($mform) { + + // Section header title according to language file. + $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); + + // A sample string variable with a default value. + $mform->addElement('text', 'config_text', get_string('blockstring', 'block_capquizqtracker'), 'cols="30" rows="5"'); + $mform->setDefault('config_text', get_string('question_problem_details', 'block_capquizqtracker')); + $mform->setType('config_text', PARAM_TEXT); + + } +} diff --git a/lang/en/block_capquizqtracker.php b/lang/en/block_capquizqtracker.php new file mode 100755 index 0000000..06152b4 --- /dev/null +++ b/lang/en/block_capquizqtracker.php @@ -0,0 +1,36 @@ +. + +/** + * @package block_capquizqtracker + * @author André Storhaug + * @copyright 2020 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$string['pluginname'] = 'CAPQuiz Question Tracker'; +$string['capquizqtracker_quiz'] = 'CAPQuiz Question Tracker'; +$string['capquizqtracker:addinstance'] = 'Add a new CAPQuestion Tracker block'; +$string['capquizqtracker:myaddinstance'] = 'Add a new CAPQuestion Tracker block to the My Moodle page'; + +$string['blockstring'] = 'Block string'; +$string['descconfig'] = 'Description of the config section'; +$string['descfoo'] = 'Config description'; +$string['headerconfig'] = 'Config section header'; +$string['labelfoo'] = 'Config label'; +$string['question_problem_details'] = 'If you have question about or feedback to a question or its solution, please fill in the form below.'; diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..490b9c8 --- /dev/null +++ b/settings.php @@ -0,0 +1,35 @@ +. + +/** + * Main interface to Question Tracker + * + * @package block_capquizqtracker + * @author André Storhaug + * @copyright 2020 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$settings->add(new admin_setting_heading('sampleheader', + get_string('headerconfig', 'block_capquizqtracker'), + get_string('descconfig', 'block_capquizqtracker'))); + +$settings->add(new admin_setting_configcheckbox('capquizqtracker/foo', + get_string('labelfoo', 'block_capquizqtracker'), + get_string('descfoo', 'block_capquizqtracker'), + '0')); \ No newline at end of file diff --git a/version.php b/version.php new file mode 100755 index 0000000..f90f611 --- /dev/null +++ b/version.php @@ -0,0 +1,35 @@ +. + +/** + * @package block_capquizqtracker + * @author André Storhaug + * @copyright 2020 NTNU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->version = 2021072200; +$plugin->requires = 2016120500; +$plugin->cron = 0; +$plugin->component = 'block_capquizqtracker'; +$plugin->dependencies = array( + 'mod_capquiz' => ANY_VERSION, // The Foo activity must be present (any version). + 'local_qtracker' => ANY_VERSION, // The Bar enrolment plugin version 2014020300 or higher must be present. +); +$plugin->maturity = MATURITY_BETA; +$plugin->release = '0.1.0';