Skip to content

Commit

Permalink
StudentQuiz: make the SQ working with Moodle 4.3 (#467)
Browse files Browse the repository at this point in the history
* StudentQuiz: make the SQ working with Moodle 4.3

Co-authored-by: hieuvu <[email protected]>
  • Loading branch information
vuvanhieu143 and hieuvu authored Jan 19, 2024
1 parent b55da1c commit 8877552
Show file tree
Hide file tree
Showing 44 changed files with 1,210 additions and 303 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ jobs:
include:
- {php: '7.3', moodle-branch: MOODLE_400_STABLE, database: pgsql}
- {php: '7.4', moodle-branch: MOODLE_401_STABLE, database: mariadb}
- {php: '8.1', moodle-branch: MOODLE_402_STABLE, database: pgsql}
- {php: '8.0', moodle-branch: MOODLE_402_STABLE, database: pgsql}
- {php: '8.2', moodle-branch: MOODLE_403_STABLE, database: mariadb}
- {php: '8.0', moodle-branch: master, database: pgsql}
- {php: '8.1', moodle-branch: main, database: pgsql}

steps:
- name: Check out repository code
Expand Down Expand Up @@ -77,6 +77,7 @@ jobs:

- name: PHP Copy/Paste Detector
if: ${{ always() }}
continue-on-error: true # This step will show errors but will not fail
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
Expand Down
5 changes: 2 additions & 3 deletions amd/build/question_nav_tabs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/question_nav_tabs.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions amd/src/question_nav_tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
* @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import * as UserRepository from 'core_user/repository';

/**
* Update the current active tab to user preferences.
*
* @private
* @param {Object} e Event
* @return {Promise} The promise object.
*/
const updateActiveTab = (e) => {
return M.util.set_user_preference('mod_studentquiz_question_active_tab', e.target.dataset.tabId);
if (typeof UserRepository.setUserPreference !== 'undefined') {
UserRepository.setUserPreference('mod_studentquiz_question_active_tab', e.target.dataset.tabId);
} else {
M.util.set_user_preference('mod_studentquiz_question_active_tab', e.target.dataset.tabId);
}
};

/**
Expand Down
41 changes: 31 additions & 10 deletions classes/condition/studentquiz_condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,36 @@
*/

namespace mod_studentquiz\condition;
defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/mod/studentquiz/classes/local/db.php');
use mod_studentquiz\local\db;
if (!class_exists('\core_question\local\bank\condition')) {
class_alias('\core_question\bank\search\condition', '\core_question\local\bank\condition');
}

/**
* Conditionally modify question bank queries.
*
* @copyright 2017 HSR (http://www.hsr.ch)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class studentquiz_condition extends \core_question\bank\search\condition {
class studentquiz_condition extends \core_question\local\bank\condition {

/**
* Return title of the condition
*
* @return string title of the condition
*/
public function get_title() {
return get_string('showhidden', 'core_question');
}

/**
* Return filter class associated with this condition
*
* @return string filter class
*/
public function get_filter_class() {
return 'qbank_deletequestion/datafilter/filtertypes/hidden';
}

/**
* Due to fix_sql_params not accepting repeated use of named params,
Expand All @@ -61,7 +79,7 @@ public function __construct($cm, $filterform, $report, $studentquiz) {
$this->cm = $cm;
$this->filterform = $filterform;
$this->tests = array();
$this->params = array();
$this->customparams = array();
$this->report = $report;
$this->studentquiz = $studentquiz;
$this->init();
Expand All @@ -82,8 +100,8 @@ public function __construct($cm, $filterform, $report, $studentquiz) {
/** @var array */
protected $tests;

/** @var array */
protected $params;
/** @var array we need to change the name so that it is avoid conflict existing params variable*/
protected $customparams = [];

/** @var bool */
protected $isfilteractive = false;
Expand All @@ -103,7 +121,7 @@ protected function init() {
if ($adddata = $this->filterform->get_data()) {

$this->tests = array();
$this->params = array();
$this->customparams = array();

foreach ($this->filterform->get_fields() as $field) {

Expand Down Expand Up @@ -153,7 +171,7 @@ protected function init() {
, $sqldata[0]);
$sqldata[0] = $this->get_special_sql($sqldata[0], $field->_name);
$this->tests[] = '((' . $sqldata[0] . '))';
$this->params = array_merge($this->params, $sqldata[1]);
$this->customparams = array_merge($this->customparams, $sqldata[1]);
}
}
}
Expand Down Expand Up @@ -246,6 +264,9 @@ public function where() {
* @return array parameter name => value.
*/
public function params() {
return $this->params;
if (isset($this->params)) {
return array_merge($this->params, $this->customparams);
}
return $this->customparams;
}
}
8 changes: 6 additions & 2 deletions classes/local/studentquiz_question.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ class studentquiz_question {
private $cm;

/** @var \context_module $context - Context. */
private $context;
protected $context;

/** @var stdClass - StudentQuiz data. */
private $studentquiz;
protected $studentquiz;

/** @var int - StudentQuiz question id. */
protected $id;


/**
* studentquiz_question constructor.
Expand Down
2 changes: 1 addition & 1 deletion classes/question/bank/anonym_creator_name_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

/**
* A column type for the name of the question creator.
Expand Down
11 changes: 10 additions & 1 deletion classes/question/bank/attempts_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

/**
* Represent performances column in studentquiz_bank_view
Expand All @@ -34,6 +34,15 @@ class attempts_column extends studentquiz_column_base {
/** @var \stdClass */
protected $studentquiz;

/** @var int category id*/
protected $categoryid;

/** @var int current user id*/
protected $currentuserid;

/** @var int student quiz id*/
protected $studentquizid;

/**
* Initialise Parameters for join
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

use mod_studentquiz\utils;

Expand Down
8 changes: 7 additions & 1 deletion classes/question/bank/difficulty_level_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

/**
* Representing difficulty level column in studentquiz_bank_view
Expand All @@ -34,6 +34,12 @@ class difficulty_level_column extends studentquiz_column_base {
/** @var \stdClass */
protected $studentquiz;

/** @var int current user id*/
protected $currentuserid;

/** @var int student quiz id*/
protected $studentquizid;

/**
* Initialise Parameters for join
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/question/bank/question_name_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

/**
* A column type for the name of the question name.
Expand Down
2 changes: 1 addition & 1 deletion classes/question/bank/question_text_row.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

/**
* A column type for the name of the question name.
Expand Down
8 changes: 7 additions & 1 deletion classes/question/bank/rate_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

/**
* Represent rate column in studentquiz_bank_view
Expand All @@ -31,6 +31,12 @@ class rate_column extends studentquiz_column_base {
*/
protected $renderer;

/** @var int current user id*/
protected $currentuserid;

/** @var int student quiz id*/
protected $studentquizid;

/**
* Initialise Parameters for join
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

use qbank_deletequestion\delete_action_column;
use mod_studentquiz\local\studentquiz_helper;

if (!class_exists('\qbank_deletequestion\delete_action')) {
class_alias('\qbank_deletequestion\delete_action_column', '\qbank_deletequestion\delete_action');
}
/**
* Represent delete action in studentquiz_bank_view.
*
* @package mod_studentquiz
* @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sq_delete_action_column extends delete_action_column {
class sq_delete_action extends \qbank_deletequestion\delete_action {

/**
* Override method to get url and label for delete action of the studentquiz.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
// 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_studentquiz\bank;
namespace mod_studentquiz\question\bank;

use qbank_editquestion\edit_action_column;
use mod_studentquiz\local\studentquiz_helper;

if (!class_exists('\qbank_editquestion\edit_action')) {
class_alias('\qbank_editquestion\edit_action_column', '\qbank_editquestion\edit_action');
}
/**
* Represent edit action in studentquiz_bank_view
*
Expand All @@ -27,7 +29,7 @@
* @copyright 2019 HSR (http://www.hsr.ch)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sq_edit_action_column extends edit_action_column {
class sq_edit_action extends \qbank_editquestion\edit_action {

/**
* Override method to get url and label for edit action of the studentquiz.
Expand All @@ -41,7 +43,7 @@ class sq_edit_action_column extends edit_action_column {
protected function get_url_icon_and_label(\stdClass $question): array {

if (($question->state == studentquiz_helper::STATE_APPROVED || $question->state == studentquiz_helper::STATE_DISAPPROVED) &&
!has_capability('mod/studentquiz:previewothers', $this->qbank->get_most_specific_context())) {
!has_capability('mod/studentquiz:previewothers', $this->qbank->get_most_specific_context())) {
// Do not render Edit icon if Question is in approved/disapproved state for Student.
return [null, null, null];
}
Expand Down
Loading

0 comments on commit 8877552

Please sign in to comment.