Skip to content

Commit

Permalink
Merge branch 'MDL-76757-fixup' of https://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Jul 13, 2023
2 parents 2e78301 + 3ea0bdf commit 8ecebfc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
39 changes: 22 additions & 17 deletions question/bank/deletequestion/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,48 @@ public static function get_delete_confirmation_message(array $questionids, bool
global $DB;
$questionnames = '';
$inuse = false;
$hasmutipleversions = false;
$questionversions = [];
$countselectedquestion = count($questionids);

if ($deleteallversions) {
$listofquestions = \question_bank::get_all_versions_of_questions($questionids);
foreach ($listofquestions as $questionbankentry) {
if (count($questionbankentry) > 1 && !$hasmutipleversions) {
$hasmutipleversions = true;
}
// Flip the array to list question by question id. [ qid => qversion ].
$questionversions += array_flip($questionbankentry);
$versionsofeachquestionbankentry = \question_bank::get_all_versions_of_questions($questionids);
foreach ($versionsofeachquestionbankentry as $entryid => $versions) {
// Re-order to oldest first.
$versionsofeachquestionbankentry[$entryid] = array_reverse($versions, true);
// Flip the array to list question by question id. [ qid => version ].
$questionversions += array_flip($versions);
}
// Flatten an array.
$questionids = array_merge(...$listofquestions);
$questionids = array_merge(...$versionsofeachquestionbankentry);
}
[$questionsql, $params] = $DB->get_in_or_equal($questionids, SQL_PARAMS_NAMED);
$questions = $DB->get_records_select('question', 'id ' . $questionsql, $params,
'name ASC', 'id, name');
foreach ($questions as $question) {
if (questions_in_use([$question->id])) {

// Get the names of all the questions.
$questions = $DB->get_records_list('question', 'id', $questionids, '', 'id, name');

// Build the message.
foreach ($questionids as $questionid) {
if (questions_in_use([$questionid])) {
$questionnames .= '* ';
$inuse = true;
}
$questionname = format_string($question->name);
if (isset($questionversions[$question->id])) {
$questionname = format_string($questions[$questionid]->name);
if (isset($questionversions[$questionid])) {
$a = new \stdClass();
$a->name = $questionname;
$a->version = $questionversions[$question->id];
$a->version = $questionversions[$questionid];
$questionnames .= get_string('questionnameandquestionversion',
'question', $a) . '<br />';
} else {
$questionnames .= $questionname . '<br />';
}
}

// Add the in-use message if required.
if ($inuse) {
$questionnames .= '<br />'.get_string('questionsinuse', 'question');
}

// Add in the right tile and message text.
$confirmtitle = [
'confirmtitle' => $countselectedquestion > 1 ? get_string('deleteversiontitle_plural',
'question') : get_string('deleteversiontitle', 'question'),
Expand Down
3 changes: 2 additions & 1 deletion question/engine/bank.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ public static function get_all_versions_of_question(int $questionid): array {
* Get all the versions of questions.
*
* @param array $questionids Array of question ids.
* @return array List of versions of questions.
* @return array two dimensional array question_bank_entries.id => version number => question.id.
* Versions in descending order.
*/
public static function get_all_versions_of_questions(array $questionids): array {
global $DB;
Expand Down

0 comments on commit 8ecebfc

Please sign in to comment.