| Línea 77... |
Línea 77... |
| 77 |
* Load a {@link question_usage_by_activity} from the database, based on its id.
|
77 |
* Load a {@link question_usage_by_activity} from the database, based on its id.
|
| 78 |
* @param int $qubaid the id of the usage to load.
|
78 |
* @param int $qubaid the id of the usage to load.
|
| 79 |
* @param moodle_database $db a database connectoin. Defaults to global $DB.
|
79 |
* @param moodle_database $db a database connectoin. Defaults to global $DB.
|
| 80 |
* @return question_usage_by_activity loaded from the database.
|
80 |
* @return question_usage_by_activity loaded from the database.
|
| 81 |
*/
|
81 |
*/
|
| 82 |
public static function load_questions_usage_by_activity($qubaid, moodle_database $db = null) {
|
82 |
public static function load_questions_usage_by_activity($qubaid, ?moodle_database $db = null) {
|
| 83 |
$dm = new question_engine_data_mapper($db);
|
83 |
$dm = new question_engine_data_mapper($db);
|
| 84 |
return $dm->load_questions_usage_by_activity($qubaid);
|
84 |
return $dm->load_questions_usage_by_activity($qubaid);
|
| 85 |
}
|
85 |
}
|
| Línea 86... |
Línea 86... |
| 86 |
|
86 |
|
| Línea 89... |
Línea 89... |
| 89 |
* if the usage was newly created by {@link make_questions_usage_by_activity()}
|
89 |
* if the usage was newly created by {@link make_questions_usage_by_activity()}
|
| 90 |
* or loaded from the database using {@link load_questions_usage_by_activity()}
|
90 |
* or loaded from the database using {@link load_questions_usage_by_activity()}
|
| 91 |
* @param question_usage_by_activity the usage to save.
|
91 |
* @param question_usage_by_activity the usage to save.
|
| 92 |
* @param moodle_database $db a database connectoin. Defaults to global $DB.
|
92 |
* @param moodle_database $db a database connectoin. Defaults to global $DB.
|
| 93 |
*/
|
93 |
*/
|
| 94 |
public static function save_questions_usage_by_activity(question_usage_by_activity $quba, moodle_database $db = null) {
|
94 |
public static function save_questions_usage_by_activity(question_usage_by_activity $quba, ?moodle_database $db = null) {
|
| 95 |
$dm = new question_engine_data_mapper($db);
|
95 |
$dm = new question_engine_data_mapper($db);
|
| 96 |
$observer = $quba->get_observer();
|
96 |
$observer = $quba->get_observer();
|
| 97 |
if ($observer instanceof question_engine_unit_of_work) {
|
97 |
if ($observer instanceof question_engine_unit_of_work) {
|
| 98 |
$observer->save($dm);
|
98 |
$observer->save($dm);
|
| 99 |
} else {
|
99 |
} else {
|
| Línea 152... |
Línea 152... |
| 152 |
* @param array $questionids of question ids.
|
152 |
* @param array $questionids of question ids.
|
| 153 |
* @param qubaid_condition $qubaids ids of the usages to consider.
|
153 |
* @param qubaid_condition $qubaids ids of the usages to consider.
|
| 154 |
* @return boolean whether any of these questions are being used by any of
|
154 |
* @return boolean whether any of these questions are being used by any of
|
| 155 |
* those usages.
|
155 |
* those usages.
|
| 156 |
*/
|
156 |
*/
|
| 157 |
public static function questions_in_use(array $questionids, qubaid_condition $qubaids = null) {
|
157 |
public static function questions_in_use(array $questionids, ?qubaid_condition $qubaids = null) {
|
| 158 |
if (is_null($qubaids)) {
|
158 |
if (is_null($qubaids)) {
|
| 159 |
return false;
|
159 |
return false;
|
| 160 |
}
|
160 |
}
|
| 161 |
$dm = new question_engine_data_mapper();
|
161 |
$dm = new question_engine_data_mapper();
|
| 162 |
return $dm->questions_in_use($questionids, $qubaids);
|
162 |
return $dm->questions_in_use($questionids, $qubaids);
|
| Línea 701... |
Línea 701... |
| 701 |
|
701 |
|
| 702 |
/**
|
702 |
/**
|
| 703 |
* Helper to add the question identify (if there is one) to the label of an input field in a question.
|
703 |
* Helper to add the question identify (if there is one) to the label of an input field in a question.
|
| 704 |
*
|
704 |
*
|
| 705 |
* @param string $label The plain field label. E.g. 'Answer 1'
|
705 |
* @param string $label The plain field label. E.g. 'Answer 1'
|
| 706 |
* @param bool $sridentifier If true, the question identifier, if added, will be wrapped in a sr-only span. Default false.
|
706 |
* @param bool $sridentifier If true, the question identifier, if added, will be wrapped in a visually-hidden. Default false.
|
| 707 |
* @param bool $addbefore If true, the question identifier will be added before the label.
|
707 |
* @param bool $addbefore If true, the question identifier will be added before the label.
|
| 708 |
* @return string The amended label. For example 'Answer 1, Question 1'.
|
708 |
* @return string The amended label. For example 'Answer 1, Question 1'.
|
| 709 |
*/
|
709 |
*/
|
| 710 |
public function add_question_identifier_to_label(string $label, bool $sridentifier = false, bool $addbefore = false): string {
|
710 |
public function add_question_identifier_to_label(string $label, bool $sridentifier = false, bool $addbefore = false): string {
|
| 711 |
if (!$this->has_question_identifier()) {
|
711 |
if (!$this->has_question_identifier()) {
|
| 712 |
return $label;
|
712 |
return $label;
|
| 713 |
}
|
713 |
}
|
| 714 |
$identifier = $this->questionidentifier;
|
714 |
$identifier = $this->questionidentifier;
|
| 715 |
if ($sridentifier) {
|
715 |
if ($sridentifier) {
|
| 716 |
$identifier = html_writer::span($identifier, 'sr-only');
|
716 |
$identifier = html_writer::span($identifier, 'visually-hidden');
|
| 717 |
}
|
717 |
}
|
| 718 |
$fieldlang = 'fieldinquestion';
|
718 |
$fieldlang = 'fieldinquestion';
|
| 719 |
if ($addbefore) {
|
719 |
if ($addbefore) {
|
| 720 |
$fieldlang = 'fieldinquestionpre';
|
720 |
$fieldlang = 'fieldinquestionpre';
|
| Línea 1132... |
Línea 1132... |
| 1132 |
'autosave' => false
|
1132 |
'autosave' => false
|
| 1133 |
];
|
1133 |
];
|
| Línea 1134... |
Línea 1134... |
| 1134 |
|
1134 |
|
| 1135 |
return $editoroptions;
|
1135 |
return $editoroptions;
|
| - |
|
1136 |
}
|
| - |
|
1137 |
|
| - |
|
1138 |
/**
|
| - |
|
1139 |
* Format question fragment string and apply filtering,
|
| - |
|
1140 |
*
|
| - |
|
1141 |
* @param string $text current text that we want to be apply filters.
|
| - |
|
1142 |
* @param context $context of the page question are in.
|
| - |
|
1143 |
* @return string result has been modified by filters.
|
| - |
|
1144 |
*/
|
| - |
|
1145 |
public static function format_question_fragment(string $text, context $context): string {
|
| - |
|
1146 |
global $PAGE;
|
| - |
|
1147 |
$filtermanager = \filter_manager::instance();
|
| - |
|
1148 |
$filtermanager->setup_page_for_filters($PAGE, $context);
|
| - |
|
1149 |
return $filtermanager->filter_string($text, $context);
|
| 1136 |
}
|
1150 |
}
|
| Línea 1137... |
Línea 1151... |
| 1137 |
}
|
1151 |
}
|
| 1138 |
|
1152 |
|