| Línea 51... |
Línea 51... |
| 51 |
|
51 |
|
| 52 |
/**
|
52 |
/**
|
| 53 |
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
|
53 |
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
|
| 54 |
*
|
54 |
*
|
| 55 |
* Recognised page names are:
|
55 |
* Recognised page names are:
|
| 56 |
* | pagetype | name meaning | description |
|
56 |
* | pagetype | name meaning | description |
|
| 57 |
* | course question bank | Course name | The question bank for a course |
|
57 |
* | course question bank | Course name | The default question bank for a course |
|
| 58 |
* | course question import | Course name | The import questions screen for a course |
|
58 |
* | course question import | Course name | The import questions screen for a course default bank |
|
| - |
|
59 |
* | course question export | Course name | The export questions screen for a course default bank |
|
| - |
|
60 |
* | question bank | Question bank name | The question bank module |
|
| - |
|
61 |
* | question import | Question bank name | The import questions screen for a question bank |
|
| 59 |
* | course question export | Course name | The export questions screen for a course |
|
62 |
* | question export | Question bank name | The export questions screen for a question bank |
|
| 60 |
* | preview | Question name | The screen to preview a question |
|
63 |
* | preview | Question name | The screen to preview a question |
|
| 61 |
* | edit | Question name | The screen to edit a question |
|
64 |
* | edit | Question name | The screen to edit a question |
|
| 62 |
*
|
65 |
*
|
| 63 |
* @param string $type identifies which type of page this is, e.g. 'Preview'.
|
66 |
* @param string $type identifies which type of page this is, e.g. 'Preview'.
|
| 64 |
* @param string $identifier identifies the particular page, e.g. 'My question'.
|
67 |
* @param string $identifier identifies the particular page, e.g. 'My question'.
|
| 65 |
* @return moodle_url the corresponding URL.
|
68 |
* @return moodle_url the corresponding URL.
|
| Línea 69... |
Línea 72... |
| 69 |
switch (strtolower($type)) {
|
72 |
switch (strtolower($type)) {
|
| 70 |
case 'course question bank':
|
73 |
case 'course question bank':
|
| 71 |
// The question bank does not handle fields at the edge of the viewport well.
|
74 |
// The question bank does not handle fields at the edge of the viewport well.
|
| 72 |
// Increase the size to avoid this.
|
75 |
// Increase the size to avoid this.
|
| 73 |
$this->execute('behat_general::i_change_window_size_to', ['window', 'large']);
|
76 |
$this->execute('behat_general::i_change_window_size_to', ['window', 'large']);
|
| - |
|
77 |
$qbank = $this->get_default_bank_for_course_identifier($identifier);
|
| 74 |
return new moodle_url('/question/edit.php', [
|
78 |
return new moodle_url('/question/edit.php', [
|
| 75 |
'courseid' => $this->get_course_id($identifier),
|
79 |
'cmid' => $qbank->id,
|
| 76 |
]);
|
80 |
]);
|
| Línea -... |
Línea 81... |
| - |
|
81 |
|
| - |
|
82 |
case 'question bank':
|
| - |
|
83 |
// The question bank does not handle fields at the edge of the viewport well.
|
| - |
|
84 |
// Increase the size to avoid this.
|
| - |
|
85 |
$this->execute('behat_general::i_change_window_size_to', ['window', 'large']);
|
| - |
|
86 |
return new moodle_url('/question/edit.php',
|
| - |
|
87 |
['cmid' => $this->get_cm_by_activity_name('qbank', $identifier)->id]
|
| - |
|
88 |
);
|
| 77 |
|
89 |
|
| - |
|
90 |
case 'course question categories':
|
| 78 |
case 'course question categories':
|
91 |
$qbank = $this->get_default_bank_for_course_identifier($identifier);
|
| - |
|
92 |
return new moodle_url('/question/bank/managecategories/category.php',
|
| - |
|
93 |
['cmid' => $qbank->id]
|
| - |
|
94 |
);
|
| - |
|
95 |
|
| - |
|
96 |
case 'question categories':
|
| 79 |
return new moodle_url('/question/bank/managecategories/category.php',
|
97 |
return new moodle_url('/question/bank/managecategories/category.php',
|
| - |
|
98 |
['cmid' => $this->get_cm_by_activity_name('qbank', $identifier)->id]
|
| Línea 80... |
Línea 99... |
| 80 |
['courseid' => $this->get_course_id($identifier)]);
|
99 |
);
|
| - |
|
100 |
|
| 81 |
|
101 |
case 'course question import':
|
| - |
|
102 |
$qbank = $this->get_default_bank_for_course_identifier($identifier);
|
| - |
|
103 |
return new moodle_url('/question/bank/importquestions/import.php',
|
| - |
|
104 |
['cmid' => $qbank->id]
|
| - |
|
105 |
);
|
| - |
|
106 |
|
| 82 |
case 'course question import':
|
107 |
case 'question import':
|
| - |
|
108 |
return new moodle_url('/question/bank/importquestions/import.php',
|
| Línea 83... |
Línea 109... |
| 83 |
return new moodle_url('/question/bank/importquestions/import.php',
|
109 |
['cmid' => $this->get_cm_by_activity_name('qbank', $identifier)->id]
|
| - |
|
110 |
);
|
| - |
|
111 |
|
| - |
|
112 |
case 'course question export':
|
| - |
|
113 |
$qbank = $this->get_default_bank_for_course_identifier($identifier);
|
| - |
|
114 |
return new moodle_url('/question/bank/exportquestions/export.php',
|
| - |
|
115 |
['cmid' => $qbank->id]
|
| 84 |
['courseid' => $this->get_course_id($identifier)]);
|
116 |
);
|
| 85 |
|
117 |
|
| - |
|
118 |
case 'question export':
|
| Línea 86... |
Línea 119... |
| 86 |
case 'course question export':
|
119 |
return new moodle_url('/question/bank/exportquestions/export.php',
|
| 87 |
return new moodle_url('/question/bank/exportquestions/export.php',
|
120 |
['cmid' => $this->get_cm_by_activity_name('qbank', $identifier)->id]
|
| 88 |
['courseid' => $this->get_course_id($identifier)]);
|
121 |
);
|
| 89 |
|
122 |
|
| Línea 101... |
Línea 134... |
| 101 |
throw new Exception('Unrecognised core_question page type "' . $type . '."');
|
134 |
throw new Exception('Unrecognised core_question page type "' . $type . '."');
|
| 102 |
}
|
135 |
}
|
| 103 |
}
|
136 |
}
|
| Línea 104... |
Línea 137... |
| 104 |
|
137 |
|
| - |
|
138 |
/**
|
| - |
|
139 |
* Get the course default question bank, creating it if it doesn't yet exist
|
| - |
|
140 |
*
|
| - |
|
141 |
* @param string $identifier The name of the course to add a default bank to.
|
| - |
|
142 |
* @return cm_info The newly created default question bank.
|
| - |
|
143 |
*/
|
| - |
|
144 |
private function get_default_bank_for_course_identifier(string $identifier): cm_info {
|
| - |
|
145 |
$course = get_course($this->get_course_id($identifier));
|
| - |
|
146 |
return \core_question\local\bank\question_bank_helper::get_default_open_instance_system_type($course, true);
|
| - |
|
147 |
}
|
| - |
|
148 |
|
| 105 |
/**
|
149 |
/**
|
| 106 |
* Find a question, and where it is, from the question name.
|
150 |
* Find a question, and where it is, from the question name.
|
| 107 |
*
|
151 |
*
|
| 108 |
* This is a helper used by resolve_page_instance_url.
|
152 |
* This is a helper used by resolve_page_instance_url.
|
| 109 |
*
|
153 |
*
|
| Línea 362... |
Línea 406... |
| 362 |
]);
|
406 |
]);
|
| Línea 363... |
Línea 407... |
| 363 |
|
407 |
|
| 364 |
// Apply filters.
|
408 |
// Apply filters.
|
| 365 |
$this->execute("behat_forms::press_button", [get_string('applyfilters')]);
|
409 |
$this->execute("behat_forms::press_button", [get_string('applyfilters')]);
|
| - |
|
410 |
}
|
| - |
|
411 |
|
| - |
|
412 |
/**
|
| - |
|
413 |
* Record that a user has recently accessed the question bank related to a particular activity.
|
| - |
|
414 |
*
|
| - |
|
415 |
* @Given :user has recently viewed the :activityname :activitytype question bank
|
| - |
|
416 |
* @param string $useridentifier The user's username or email.
|
| - |
|
417 |
* @param string $activityname name of an activity.
|
| - |
|
418 |
* @param string $activitytype type of an activity, e.g. 'quiz' or 'qbank'.
|
| - |
|
419 |
*/
|
| - |
|
420 |
public function user_has_recently_viewed_question_bank(
|
| - |
|
421 |
string $useridentifier,
|
| - |
|
422 |
string $activityname,
|
| - |
|
423 |
string $activitytype,
|
| - |
|
424 |
): void {
|
| - |
|
425 |
global $USER;
|
| - |
|
426 |
$originaluser = $USER;
|
| - |
|
427 |
|
| - |
|
428 |
if (!plugin_supports('mod', $activitytype, FEATURE_USES_QUESTIONS)) {
|
| - |
|
429 |
throw new Exception($activitytype . ' do not have a question bank.');
|
| - |
|
430 |
}
|
| - |
|
431 |
|
| - |
|
432 |
$user = $this->get_user_by_identifier($useridentifier);
|
| - |
|
433 |
if (!$user) {
|
| - |
|
434 |
throw new Exception('Unknow user ' . $useridentifier . '.');
|
| - |
|
435 |
}
|
| - |
|
436 |
$USER = $user;
|
| - |
|
437 |
|
| - |
|
438 |
$cm = $this->get_cm_by_activity_name($activitytype, $activityname);
|
| - |
|
439 |
\core_question\local\bank\question_bank_helper::add_bank_context_to_recently_viewed($cm->context);
|
| - |
|
440 |
|
| - |
|
441 |
$USER = $originaluser;
|
| 366 |
}
|
442 |
}
|