Skip to content

Commit

Permalink
Merge branch 'MDL-71378_main' of https://github.com/SimonasAdams/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Nov 25, 2024
2 parents 6ef1549 + a0cf3d2 commit 0af9b5c
Show file tree
Hide file tree
Showing 327 changed files with 8,193 additions and 3,844 deletions.
17 changes: 17 additions & 0 deletions .upgradenotes/MDL-71378-2024070813542859.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
issueNumber: MDL-71378
notes:
tool_brickfield:
- message: >
tool_brickfield\local\areas\core_question\answerbase::find_system_areas
No replacement. System context no longer a valid context to assign a
question category
type: deprecated
- message: >
tool_brickfield\local\areas\core_question\base::find_system_areas
No replacement. System context no longer a valid context to assign a
question category
type: deprecated
42 changes: 42 additions & 0 deletions .upgradenotes/MDL-71378-2024070813572581.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
issueNumber: MDL-71378
notes:
core:
- message: >
question_make_default_categories()
No longer creates a default category in either CONTEXT_SYSTEM,
CONTEXT_COURSE, or CONTEXT_COURSECAT.
Superceded by question_get_default_category which can optionally create one if it does not exist.
type: deprecated
- message: |
question_delete_course()
No replacement. Course contexts no longer hold question categories.
type: deprecated
- message: |
question_delete_course_category()
Course category contexts no longer hold question categories.
type: deprecated
qbank_bulkmove:
- message: >
qbank_bulkmove/helper::get_displaydata
Superceded by a modal and webservice, see
qbank_bulkmove/modal_question_bank_bulkmove and
core_question_external\move_questions
type: deprecated
- message: |
qbank_bulkmove\output\renderer::render_bulk_move_form
Superceded by qbank_bulkmove\output\bulk_move
type: deprecated
core_question:
- message: |
question_type::generate_test
No replacement, not used anywhere in core.
type: deprecated
3 changes: 0 additions & 3 deletions admin/settings/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_userscompletion', new lang_string('generaluserscompletion','backup'), new lang_string('configgeneraluserscompletion','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_logs', new lang_string('generallogs','backup'), new lang_string('configgenerallogs','backup'), array('value'=>0, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), array('value'=>0, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_groups',
new lang_string('generalgroups', 'backup'), new lang_string('configgeneralgroups', 'backup'),
array('value' => 1, 'locked' => 0)));
Expand Down Expand Up @@ -460,7 +459,6 @@
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_blocks', new lang_string('generalblocks','backup'), new lang_string('configgeneralblocks','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_groups',
new lang_string('generalgroups', 'backup'), new lang_string('configgeneralgroups', 'backup'),
array('value' => 1, 'locked' => 0)));
Expand Down Expand Up @@ -596,7 +594,6 @@
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_userscompletion', new lang_string('generaluserscompletion','backup'), new lang_string('configgeneraluserscompletion','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', new lang_string('generallogs', 'backup'), new lang_string('configgenerallogs', 'backup'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_groups', new lang_string('generalgroups', 'backup'),
new lang_string('configgeneralgroups', 'backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_competencies', new lang_string('generalcompetencies','backup'), new lang_string('configgeneralcompetencies','backup'), 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ public function find_relevant_areas(\core\event\base $event): ?\moodle_recordset
* question categories at the system context, or course category context.
*
* @return mixed
* @deprecated since Moodle 5.0.
* @todo MDL-82413 Final deprecation in Moodle 6.0.
*/
#[\core\attribute\deprecated(null, since: '5.0', reason: 'This method should not be used', mdl: 'MDL-71378')]
public function find_system_areas(): ?\moodle_recordset {
\core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]);
global $DB;
$params = [
'syscontext' => CONTEXT_SYSTEM,
Expand Down Expand Up @@ -132,8 +136,6 @@ public function find_course_areas(int $courseid): ?\moodle_recordset {

$coursecontext = \context_course::instance($courseid);
$param = [
'ctxcourse' => CONTEXT_COURSE,
'courseid' => $courseid,
'module' => CONTEXT_MODULE,
'coursecontextpath' => $DB->sql_like_escape($coursecontext->path) . '/%',
];
Expand All @@ -157,11 +159,8 @@ public function find_course_areas(int $courseid): ?\moodle_recordset {
ON qc.id = qbe.questioncategoryid
INNER JOIN {context} ctx
ON ctx.id = qc.contextid
WHERE (ctx.contextlevel = :ctxcourse
AND ctx.id = qc.contextid
AND ctx.instanceid = :courseid)
OR (ctx.contextlevel = :module
AND {$DB->sql_like('ctx.path', ':coursecontextpath')})
WHERE ctx.contextlevel = :module
AND {$DB->sql_like('ctx.path', ':coursecontextpath')}
ORDER BY a.id ASC";

return $DB->get_recordset_sql($sql, $param);
Expand Down
29 changes: 12 additions & 17 deletions admin/tool/brickfield/classes/local/areas/core_question/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public function find_course_areas(int $courseid): ?\moodle_recordset {
global $DB;
$coursecontext = \context_course::instance($courseid);
$param = [
'ctxcourse' => CONTEXT_COURSE,
'courseid' => $courseid,
'module' => CONTEXT_MODULE,
'coursecontextpath' => $DB->sql_like_escape($coursecontext->path) . '/%',
];
Expand All @@ -96,11 +94,8 @@ public function find_course_areas(int $courseid): ?\moodle_recordset {
ON qc.id = qbe.questioncategoryid
INNER JOIN {context} ctx
ON ctx.id = qc.contextid
WHERE (ctx.contextlevel = :ctxcourse
AND ctx.id = qc.contextid
AND ctx.instanceid = :courseid)
OR (ctx.contextlevel = :module
AND {$DB->sql_like('ctx.path', ':coursecontextpath')})
WHERE ctx.contextlevel = :module
AND {$DB->sql_like('ctx.path', ':coursecontextpath')}
ORDER BY q.id ASC";

return $DB->get_recordset_sql($sql, $param);
Expand All @@ -111,8 +106,12 @@ public function find_course_areas(int $courseid): ?\moodle_recordset {
* question categories at the system context only.
*
* @return \moodle_recordset
* @deprecated since Moodle 5.0.
* @todo MDL-82413 Final deprecation in Moodle 6.0.
*/
#[\core\attribute\deprecated(null, since: '5.0', reason: 'This method should not be used', mdl: 'MDL-71378')]
public function find_system_areas(): ?\moodle_recordset {
\core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]);
global $DB;
$params = [
'syscontext' => CONTEXT_SYSTEM,
Expand Down Expand Up @@ -175,15 +174,7 @@ protected function get_course_and_cat_sql(\core\event\base $event): string {
$catid = 'null';

if ($record = self::get_course_and_category(CONTEXT_MODULE, $event->objectid)) {
if ($record->contextlevel == CONTEXT_MODULE) {
$courseid = $record->courseid;
} else if ($record->contextlevel == CONTEXT_COURSE) {
$courseid = $record->instanceid;
} else if ($record->contextlevel == CONTEXT_COURSECAT) {
$catid = $record->instanceid;
} else if ($record->contextlevel == CONTEXT_SYSTEM) {
$courseid = 1;
}
$courseid = $record->courseid;
}

return "
Expand All @@ -202,6 +193,10 @@ protected function get_course_and_cat_sql(\core\event\base $event): string {
public static function get_course_and_category($coursemodule, $refid) {
global $DB;

if ($coursemodule !== CONTEXT_MODULE) {
debugging("Invalid contextlevel: ($coursemodule}", DEBUG_DEVELOPER);
}

$sql = 'SELECT ctx.instanceid,
cm.course as courseid,
ctx.contextlevel
Expand All @@ -214,7 +209,7 @@ public static function get_course_and_category($coursemodule, $refid) {
ON qc.id = qbe.questioncategoryid
INNER JOIN {context} ctx
ON ctx.id = qc.contextid
LEFT JOIN {course_modules} cm
INNER JOIN {course_modules} cm
ON cm.id = ctx.instanceid
AND ctx.contextlevel = :coursemodule
WHERE q.id = :refid';
Expand Down
44 changes: 12 additions & 32 deletions admin/tool/brickfield/tests/area_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,51 +93,30 @@ public function test_questiontext(): void {
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$component = 'core_question';

list($category1, $course1, $qcat1, $questions1) = $generator->setup_course_and_questions('course');
list($category2, $course2, $qcat2, $questions2) = $generator->setup_course_and_questions('category');
list($category3, $course3, $qcat3, $questions3) = $generator->setup_course_and_questions('system');
[$category, $course, $qcat, $questions, $qbank] = $generator->setup_course_and_questions();

$c = new \tool_brickfield\local\areas\core_question\questiontext();
// Set up results arrays from the recordset for easier testing.
$course1areas = $this->array_from_recordset($c->find_course_areas($course1->id));
$course2areas = $c->find_course_areas($course2->id);
$course3areas = $c->find_course_areas($course3->id);
$sysareas = $this->array_from_recordset($c->find_system_areas());
$course1areas = $this->array_from_recordset($c->find_course_areas($course->id));

// Assert the core_question area exists for the individual question's context, courseid and categoryid.
// Assert the core_question area exists for the individual question's context, courseid and categoryid.
$this->assert_area_in_array(
$course1areas,
$component,
\context_course::instance($course1->id)->id,
$questions1[0]->id,
$course1->id,
null
);
$this->assert_area_in_array(
$sysareas,
$component,
\context_coursecat::instance($category2->id)->id,
$questions2[0]->id,
SITEID,
$category2->id
);
$this->assert_area_in_array(
$sysareas,
$component,
\context_system::instance()->id,
$questions3[0]->id,
SITEID,
\context_module::instance($qbank->cmid)->id,
$questions[0]->id,
$course->id,
null
);

// Emulate the question_created event.
$event = \core\event\question_created::create_from_question_instance($questions1[1],
\context_course::instance($course1->id));
$event = \core\event\question_created::create_from_question_instance($questions[1],
\context_module::instance($qbank->cmid));
$relevantresults = $this->array_from_recordset($c->find_relevant_areas($event));
$this->assert_area_in_array(
$course1areas,
$relevantresults,
$component,
\context_course::instance($relevantresults[0]->courseid)->id,
$relevantresults[0]->contextid,
$relevantresults[0]->itemid,
$relevantresults[0]->courseid,
$relevantresults[0]->categoryid
Expand All @@ -154,7 +133,8 @@ public function test_questionanswers(): void {
/** @var \core_question_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$course = $this->getDataGenerator()->create_course();
$cat = $generator->create_question_category(['contextid' => \context_course::instance($course->id)->id]);
$qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
$cat = $generator->create_question_category(['contextid' => \context_module::instance($qbank->cmid)->id]);
$question1 = $generator->create_question('multichoice', null,
['name' => 'Example multichoice question', 'category' => $cat->id]);
$question2 = $generator->create_question('numerical', null,
Expand Down
Loading

0 comments on commit 0af9b5c

Please sign in to comment.