mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-77147' of https://github.com/timhunt/moodle
This commit is contained in:
commit
77c4493a11
1 changed files with 20 additions and 28 deletions
|
@ -24,6 +24,7 @@
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use core_question\local\bank\question_version_status;
|
||||||
|
|
||||||
require_once(__DIR__ . '/../config.php');
|
require_once(__DIR__ . '/../config.php');
|
||||||
require_once($CFG->libdir . '/questionlib.php');
|
require_once($CFG->libdir . '/questionlib.php');
|
||||||
|
@ -42,36 +43,27 @@ $qtypes = question_bank::get_all_qtypes();
|
||||||
$pluginmanager = core_plugin_manager::instance();
|
$pluginmanager = core_plugin_manager::instance();
|
||||||
|
|
||||||
// Get some data we will need - question counts and which types are needed.
|
// Get some data we will need - question counts and which types are needed.
|
||||||
$hiddenstatus = \core_question\local\bank\question_version_status::QUESTION_STATUS_HIDDEN;
|
$counts = $DB->get_records_sql("
|
||||||
$draftstatus = \core_question\local\bank\question_version_status::QUESTION_STATUS_DRAFT;
|
SELECT q.qtype,
|
||||||
|
COUNT(qv.id) AS numquestions,
|
||||||
|
SUM(CASE WHEN qv.status = :hiddenstatus THEN 1 ELSE 0 END) AS numhidden,
|
||||||
|
SUM(CASE WHEN qv.status = :draftstatus THEN 1 ELSE 0 END) AS numdraft
|
||||||
|
|
||||||
$sql = "SELECT result.qtype,
|
FROM {question_bank_entries} qbe
|
||||||
SUM(result.numquestions) AS numquestions,
|
JOIN {question_versions} qv ON qv.questionbankentryid = qbe.id
|
||||||
SUM(result.numhidden) AS numhidden,
|
AND qv.version = (
|
||||||
SUM(result.numdraft) AS numdraft
|
SELECT MAX(version)
|
||||||
FROM (SELECT data.qtype,
|
FROM {question_versions}
|
||||||
data.versionid,
|
WHERE questionbankentryid = qbe.id
|
||||||
COUNT(data.numquestions) AS numquestions,
|
)
|
||||||
(SELECT COUNT(qv.id)
|
JOIN {question} q ON q.id = qv.questionid
|
||||||
FROM {question_versions} qv
|
|
||||||
WHERE qv.id = data.versionid
|
GROUP BY q.qtype
|
||||||
AND qv.status = :hiddenstatus) AS numhidden,
|
", [
|
||||||
(SELECT COUNT(qv.id)
|
'hiddenstatus' => question_version_status::QUESTION_STATUS_HIDDEN,
|
||||||
FROM {question_versions} qv
|
'draftstatus' => question_version_status::QUESTION_STATUS_DRAFT,
|
||||||
WHERE qv.id = data.versionid
|
]);
|
||||||
AND qv.status = :draftstatus) AS numdraft
|
|
||||||
FROM (SELECT q.qtype, qv.id AS versionid, 1 AS numquestions
|
|
||||||
FROM {question} q
|
|
||||||
JOIN {question_versions} qv ON qv.questionid = q.id
|
|
||||||
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
|
|
||||||
AND qv.version = (SELECT MAX(v.version)
|
|
||||||
FROM {question_versions} v
|
|
||||||
JOIN {question_bank_entries} be ON be.id = v.questionbankentryid
|
|
||||||
WHERE be.id = qbe.id)) data
|
|
||||||
GROUP BY data.qtype, data.versionid) result
|
|
||||||
GROUP BY result.qtype";
|
|
||||||
|
|
||||||
$counts = $DB->get_records_sql($sql, ['hiddenstatus' => $hiddenstatus, 'draftstatus' => $draftstatus]);
|
|
||||||
$needed = [];
|
$needed = [];
|
||||||
foreach ($qtypes as $qtypename => $qtype) {
|
foreach ($qtypes as $qtypename => $qtype) {
|
||||||
if (!isset($counts[$qtypename])) {
|
if (!isset($counts[$qtypename])) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue