Skip to content

Commit

Permalink
Merge branch 'release/0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Georg Schaathun committed Apr 30, 2023
2 parents 7b86354 + bc66482 commit 8b248f4
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 209 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ out/
docs/
node_modules/
vendor/
t
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).

+ Upgraded to work with Moodle 4.0

Tested for Moodle 4.0, 4.1, 4.0. Moodle 3.x is no longer supported,
due to the changes in the core quiz/question API.

Note that it is no longer testet with Moodle 3.x.

## [0.6.3] - 2023-04-28
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ See the [migration guide](https://github.com/KQMATH/moodle-mod_capquiz/wiki/Migr

+ [CAPQuiz](https://moodle.org/plugins/pluginversions.php?plugin=mod_capquiz) in the Moodle Plugin Repository

## Known Bugs

1. Users have to take care not to delete questions used by
instances of CAPQuiz. At present, there is no mechanism to
prevent accidental deletion.
2. Issues have been reported with the class list in old quizzes
after upgrading to the most recent versions. New quizzes created
in the new version seem to work as they should.
3. Further testing is required, so if you use CAPQuiz, please report
any trouble, preferably using
[githun issues](https://github.com/KQMATH/moodle-mod_capquiz/issues).

## History
The idea of an adaptive learning system at NTNU in Ålesund (then Ålesund University College) was first conceived by Siebe van Albada. His efforts led to a prototype, known as [MathGen](https://github.com/MathGen/oppgavegenerator), written as a standalone server in python.

Expand All @@ -28,7 +40,7 @@ CAPQuiz includes the work of many [contributors](https://github.com/KQMATH/moodl

**Project lead:** Hans Georg Schaathun: <[email protected]>

**Developers:**
**Previos Developers:**
* Aleksander Skrede <[email protected]>
* Sebastian S. Gundersen <[email protected]>
* [André Storhaug](https://github.com/andstor) <[email protected]>
Expand Down
51 changes: 51 additions & 0 deletions classes/bank/add_action_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
// 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 <http://www.gnu.org/licenses/>.

namespace mod_capquiz\bank;

/**
* A column type for the add this question to the quiz action.
*
* This class is copied to CAPQuiz from the Core Quiz, without
* modification (as of Fri 9 Sep 08:29:48 UTC 2022 ).
*
* @package mod_capquiz/mod_quiz
* @category question
* @copyright 2009 Tim Hunt
* @author 2021 Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class add_action_column extends \core_question\local\bank\action_column_base {

/** @var string caches a lang string used repeatedly. */
protected $stradd;

public function init(): void {
parent::init();
$this->stradd = get_string('addtoquiz', 'quiz');
}

public function get_name() {
return 'addtoquizaction';
}

protected function display_content($question, $rowclasses) {
if (!question_has_capability_on($question, 'use')) {
return;
}
$this->print_icon('t/add', $this->stradd, $this->qbank->add_to_quiz_url($question->id));
}
}
100 changes: 0 additions & 100 deletions classes/bank/add_question_to_list_column.php

This file was deleted.

165 changes: 101 additions & 64 deletions classes/bank/question_bank_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file defines a class represeting a question bank view
* This file defines a class represeting a question bank view.
*
* It is based on similar implementations from the Core Quiz,
* but intended to run in a pane rather than a modal overlay,
* some differences are needed. It includes legacy code from
* different versions of moodle, and should have been refactored.
*
* @package mod_capquiz
* @author Aleksander Skrede <aleksander.l.skrede@ntnu.no>
* @copyright 2018 NTNU
* @author Hans Georg Schaathun <hasc@ntnu.no>
* @copyright 2018/2022 NTNU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_capquiz\bank;

use \core_question\bank\checkbox_column;
use \core_question\bank\creator_name_column;
use \core_question\bank\delete_action_column;
use \core_question\bank\preview_action_column;
use \core_question\bank\question_name_column;
use \core_question\bank\question_type_column;
use \core_question\local\bank\checkbox_column;
use \qbank_viewcreator\creator_name_column;
use \qbank_editquestion\edit_action_column;
use \qbank_deletequestion\delete_action_column;
use \qbank_previewquestion\preview_action_column;
use \qbank_viewquestionname\viewquestionname_column_helper;
use \qbank_viewquestiontype\question_type_column;
use \core_question\bank\search\tag_condition as tag_condition;
use \core_question\bank\search\hidden_condition as hidden_condition;
use \core_question\bank\search\category_condition;
use mod_capquiz\capquiz_urls;
use mod_capquiz\local\capquiz_urls;
use mod_capquiz\bank\add_action_column;

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

Expand All @@ -46,72 +53,102 @@
* @copyright 2018 NTNU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_bank_view extends \core_question\bank\view {
class question_bank_view extends \core_question\local\bank\view {

/**
* Returns an array containing the required columns
* URL of add to quiz.
*
* @return array
* @param $questionid
* @return \moodle_url
*/
protected function wanted_columns() : array {
$this->requiredcolumns = [
new add_question_to_list_column($this),
new checkbox_column($this),
new question_type_column($this),
new question_name_column($this),
new creator_name_column($this),
new delete_action_column($this),
new preview_action_column($this)
public function add_to_quiz_url($questionid) {
return \mod_capquiz\capquiz_urls::add_question_to_list_url( $questionid ) ;
}

protected function get_question_bank_plugins(): array {
$questionbankclasscolumns = [];
$corequestionbankcolumns = [
'add_action_column',
'checkbox_column',
'question_type_column',
'question_name_text_column',
'preview_action_column',
'edit_action_column'
];
return $this->requiredcolumns;

if (question_get_display_preference('qbshowtext', 0, PARAM_BOOL, new \moodle_url(''))) {
$corequestionbankcolumns[] = 'question_text_row';
}

foreach ($corequestionbankcolumns as $fullname) {
$shortname = $fullname;
if (class_exists('mod_capquiz\\bank\\' . $fullname)) {
$fullname = 'mod_capquiz\\bank\\' . $fullname;
$questionbankclasscolumns[$shortname] = new $fullname($this);
} else if (class_exists('core_question\\local\\bank\\' . $fullname)) {
$fullname = 'core_question\\local\\bank\\' . $fullname;
$questionbankclasscolumns[$shortname] = new $fullname($this);
} else {
$questionbankclasscolumns[$shortname] = '';
}
}
$plugins = \core_component::get_plugin_list_with_class('qbank', 'plugin_feature', 'plugin_feature.php');
foreach ($plugins as $componentname => $plugin) {
$pluginentrypointobject = new $plugin();
$plugincolumnobjects = $pluginentrypointobject->get_question_columns($this);
// Don't need the plugins without column objects.
if (empty($plugincolumnobjects)) {
unset($plugins[$componentname]);
continue;
}
foreach ($plugincolumnobjects as $columnobject) {
$columnname = $columnobject->get_column_name();
foreach ($corequestionbankcolumns as $key => $corequestionbankcolumn) {
if (!\core\plugininfo\qbank::is_plugin_enabled($componentname)) {
unset($questionbankclasscolumns[$columnname]);
continue;
}
// Check if it has custom preference selector to view/hide.
if ($columnobject->has_preference() && !$columnobject->get_preference()) {
continue;
}
if ($corequestionbankcolumn === $columnname) {
$questionbankclasscolumns[$columnname] = $columnobject;
}
}
}
}

// Mitigate the error in case of any regression.
foreach ($questionbankclasscolumns as $shortname => $questionbankclasscolumn) {
if (empty($questionbankclasscolumn)) {
unset($questionbankclasscolumns[$shortname]);
}
}

return $questionbankclasscolumns;
}

protected function heading_column(): string {
return 'mod_capquiz\\bank\\question_name_text_column';
}

/**
* Renders the question bank view
* Renders the html question bank (same as display, but returns the result).
*
* Note that you can only output this rendered result once per page, as
* it contains IDs which must be unique.
*
* @param array $pagevars
* @param string $tabname
* @param int $page
* @param int $perpage
* @param string $category
* @param bool $subcategories
* @param bool $showhidden
* @param bool $showquestiontext
* @param array $tagids
* @return string
* @throws \coding_exception
* @return string HTML code for the form
*/
public function render(string $tabname, int $page, int $perpage, string $category,
bool $subcategories, bool $showhidden, bool $showquestiontext, array $tagids = []) : string {
global $PAGE;
if ($this->process_actions_needing_ui()) {
return '';
}
public function render($pagevars, $tabname): string {
ob_start();
$contexts = $this->contexts->having_one_edit_tab_cap($tabname);
list($categoryid, $contextid) = explode(',', $category);
$catcontext = \context::instance_by_id($contextid);
$thiscontext = $this->get_most_specific_context();
$this->display_question_bank_header();
$this->add_searchcondition(new tag_condition([$catcontext, $thiscontext], $tagids));
$this->add_searchcondition(new hidden_condition(!$showhidden));
$this->add_searchcondition(new category_condition($category, $subcategories,
$contexts, $this->baseurl, $this->course));
$this->display_options_form($showquestiontext, $this->baseurl->raw_out());
$this->display_question_list(
$contexts,
$this->baseurl,
$category,
$this->cm,
$subcategories,
$page,
$perpage,
$showhidden,
$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();
$this->display($pagevars, $tabname);
$out = ob_get_contents();
ob_end_clean();
return $out;
}

/**
Expand Down
Loading

0 comments on commit 8b248f4

Please sign in to comment.