MDL-76717 question: Coding style fixes

This commit is contained in:
Andrew Nicols 2023-07-09 21:59:13 +08:00
parent 05a8ac58db
commit 14029657a7
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
6 changed files with 25 additions and 22 deletions

View File

@ -28,10 +28,9 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../../question/tests/behat/behat_question_base.php');
use Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Mink\Exception\ExpectationException as ExpectationException;
use Behat\Mink\Exception\DriverException as DriverException;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Exception\ExpectationException;
use mod_quiz\quiz_attempt;
use mod_quiz\quiz_settings;

View File

@ -6,6 +6,6 @@ define("qbank_usage/usage",["exports","core/fragment","core/modal_factory","core
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_fragment=_interopRequireDefault(_fragment),_modal_factory=_interopRequireDefault(_modal_factory),_notification=_interopRequireDefault(_notification),Str=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str);let modal=null;const usageEvent=async(questionId,contextId,specificVersion)=>{let args={questionid:questionId,specificversion:specificVersion};if(null===modal){try{modal=await _modal_factory.default.create({type:_modal_factory.default.types.CANCEL,title:Str.get_string("usageheader","qbank_usage"),body:_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args),large:!0})}catch(e){_notification.default.exception(e)}modal.show(),modal.getRoot().on("click","a[href].page-link",(function(e){e.preventDefault();let attr=e.target.getAttribute("href");"#"!==attr&&(args.querystring=attr,modal.setBody(_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args)))})),modal.getRoot().on("change","#question_usage_version_dropdown",(function(e){args.questionid=e.target.value,modal.setBody(_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args))}))}else modal.setBody(_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args)),modal.show()};_exports.init=function(questionSelector,contextId){let specificVersion=arguments.length>2&&void 0!==arguments[2]&&arguments[2],target=document.querySelector(questionSelector),questionId=target.getAttribute("data-questionid");target.addEventListener("click",(()=>{usageEvent(questionId,contextId,specificVersion)}))}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_fragment=_interopRequireDefault(_fragment),_modal_factory=_interopRequireDefault(_modal_factory),_notification=_interopRequireDefault(_notification),Str=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str);let modal=null;const usageEvent=async(questionId,contextId,specificVersion)=>{const args={questionid:questionId,specificversion:specificVersion};if(null===modal){try{modal=await _modal_factory.default.create({type:_modal_factory.default.types.CANCEL,title:Str.get_string("usageheader","qbank_usage"),body:_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args),large:!0})}catch(e){return void _notification.default.exception(e)}modal.show(),modal.getRoot().on("click","a[href].page-link",(function(e){e.preventDefault();let attr=e.target.getAttribute("href");"#"!==attr&&(args.querystring=attr,modal.setBody(_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args)))})),modal.getRoot().on("change","#question_usage_version_dropdown",(function(e){args.questionid=e.target.value,modal.setBody(_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args))}))}else modal.setBody(_fragment.default.loadFragment("qbank_usage","question_usage",contextId,args)),modal.show()};_exports.init=function(questionSelector,contextId){let specificVersion=arguments.length>2&&void 0!==arguments[2]&&arguments[2],target=document.querySelector(questionSelector),questionId=target.getAttribute("data-questionid");target.addEventListener("click",(()=>{usageEvent(questionId,contextId,specificVersion)}))}}));
//# sourceMappingURL=usage.min.js.map

View File

@ -1 +1 @@
{"version":3,"file":"usage.min.js","sources":["../src/usage.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Usage column selector js.\n *\n * @module qbank_usage/usage\n * @copyright 2021 Catalyst IT Australia Pty Ltd\n * @author Safat Shahin <safatshahin@catalyst-au.net>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Fragment from 'core/fragment';\nimport ModalFactory from 'core/modal_factory';\nimport Notification from 'core/notification';\nimport * as Str from 'core/str';\n\nlet modal = null;\n\n/**\n * Event listeners for the module.\n *\n * @method clickEvent\n * @param {int} questionId\n * @param {int} contextId\n * @param {boolean} specificVersion Is the view listing specific question versions?\n */\nconst usageEvent = async(questionId, contextId, specificVersion) => {\n let args = {\n questionid: questionId,\n specificversion: specificVersion,\n };\n if (modal === null) {\n try {\n modal = await ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n title: Str.get_string('usageheader', 'qbank_usage'),\n body: Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args),\n large: true,\n });\n } catch (e) {\n Notification.exception(e);\n }\n\n modal.show();\n modal.getRoot().on('click', 'a[href].page-link', function(e) {\n e.preventDefault();\n let attr = e.target.getAttribute(\"href\");\n if (attr !== '#') {\n args.querystring = attr;\n modal.setBody(Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args));\n }\n });\n // Version selection event.\n modal.getRoot().on('change', '#question_usage_version_dropdown', function(e) {\n args.questionid = e.target.value;\n modal.setBody(Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args));\n });\n } else {\n modal.setBody(Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args));\n modal.show();\n }\n\n};\n\n/**\n * Entrypoint of the js.\n *\n * @method init\n * @param {string} questionSelector the question usage identifier.\n * @param {int} contextId the question context id.\n * @param {boolean} specificVersion Is the view listing specific question versions?\n */\nexport const init = (questionSelector, contextId, specificVersion = false) => {\n let target = document.querySelector(questionSelector);\n let questionId = target.getAttribute('data-questionid');\n target.addEventListener('click', () => {\n // Call for the event listener to listed for clicks in any usage count row.\n usageEvent(questionId, contextId, specificVersion);\n });\n};\n"],"names":["modal","usageEvent","async","questionId","contextId","specificVersion","args","questionid","specificversion","ModalFactory","create","type","types","CANCEL","title","Str","get_string","body","Fragment","loadFragment","large","e","exception","show","getRoot","on","preventDefault","attr","target","getAttribute","querystring","setBody","value","questionSelector","document","querySelector","addEventListener"],"mappings":";;;;;;;;k4BA6BIA,MAAQ,WAUNC,WAAaC,MAAMC,WAAYC,UAAWC,uBACxCC,KAAO,CACPC,WAAYJ,WACZK,gBAAiBH,oBAEP,OAAVL,MAAgB,KAEZA,YAAcS,uBAAaC,OAAO,CAC9BC,KAAMF,uBAAaG,MAAMC,OACzBC,MAAOC,IAAIC,WAAW,cAAe,eACrCC,KAAMC,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,MACxEc,OAAO,IAEb,MAAOC,yBACQC,UAAUD,GAG3BrB,MAAMuB,OACNvB,MAAMwB,UAAUC,GAAG,QAAS,qBAAqB,SAASJ,GACtDA,EAAEK,qBACEC,KAAON,EAAEO,OAAOC,aAAa,QACpB,MAATF,OACArB,KAAKwB,YAAcH,KACnB3B,MAAM+B,QAAQb,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,WAIxFN,MAAMwB,UAAUC,GAAG,SAAU,oCAAoC,SAASJ,GACtEf,KAAKC,WAAac,EAAEO,OAAOI,MAC3BhC,MAAM+B,QAAQb,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,eAGpFN,MAAM+B,QAAQb,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,OAChFN,MAAMuB,sBAaM,SAACU,iBAAkB7B,eAAWC,wEAC1CuB,OAASM,SAASC,cAAcF,kBAChC9B,WAAayB,OAAOC,aAAa,mBACrCD,OAAOQ,iBAAiB,SAAS,KAE7BnC,WAAWE,WAAYC,UAAWC"}
{"version":3,"file":"usage.min.js","sources":["../src/usage.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Usage column selector js.\n *\n * @module qbank_usage/usage\n * @copyright 2021 Catalyst IT Australia Pty Ltd\n * @author Safat Shahin <safatshahin@catalyst-au.net>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Fragment from 'core/fragment';\nimport ModalFactory from 'core/modal_factory';\nimport Notification from 'core/notification';\nimport * as Str from 'core/str';\n\nlet modal = null;\n\n/**\n * Event listeners for the module.\n *\n * @method clickEvent\n * @param {int} questionId\n * @param {int} contextId\n * @param {boolean} specificVersion Is the view listing specific question versions?\n */\nconst usageEvent = async(questionId, contextId, specificVersion) => {\n const args = {\n questionid: questionId,\n specificversion: specificVersion,\n };\n if (modal === null) {\n try {\n modal = await ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n title: Str.get_string('usageheader', 'qbank_usage'),\n body: Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args),\n large: true,\n });\n } catch (e) {\n Notification.exception(e);\n return;\n }\n\n modal.show();\n modal.getRoot().on('click', 'a[href].page-link', function(e) {\n e.preventDefault();\n let attr = e.target.getAttribute(\"href\");\n if (attr !== '#') {\n args.querystring = attr;\n modal.setBody(Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args));\n }\n });\n // Version selection event.\n modal.getRoot().on('change', '#question_usage_version_dropdown', function(e) {\n args.questionid = e.target.value;\n modal.setBody(Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args));\n });\n } else {\n modal.setBody(Fragment.loadFragment('qbank_usage', 'question_usage', contextId, args));\n modal.show();\n }\n\n};\n\n/**\n * Entrypoint of the js.\n *\n * @method init\n * @param {string} questionSelector the question usage identifier.\n * @param {int} contextId the question context id.\n * @param {boolean} specificVersion Is the view listing specific question versions?\n */\nexport const init = (questionSelector, contextId, specificVersion = false) => {\n let target = document.querySelector(questionSelector);\n let questionId = target.getAttribute('data-questionid');\n target.addEventListener('click', () => {\n // Call for the event listener to listed for clicks in any usage count row.\n usageEvent(questionId, contextId, specificVersion);\n });\n};\n"],"names":["modal","usageEvent","async","questionId","contextId","specificVersion","args","questionid","specificversion","ModalFactory","create","type","types","CANCEL","title","Str","get_string","body","Fragment","loadFragment","large","e","exception","show","getRoot","on","preventDefault","attr","target","getAttribute","querystring","setBody","value","questionSelector","document","querySelector","addEventListener"],"mappings":";;;;;;;;k4BA6BIA,MAAQ,WAUNC,WAAaC,MAAMC,WAAYC,UAAWC,yBACtCC,KAAO,CACTC,WAAYJ,WACZK,gBAAiBH,oBAEP,OAAVL,MAAgB,KAEZA,YAAcS,uBAAaC,OAAO,CAC9BC,KAAMF,uBAAaG,MAAMC,OACzBC,MAAOC,IAAIC,WAAW,cAAe,eACrCC,KAAMC,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,MACxEc,OAAO,IAEb,MAAOC,qCACQC,UAAUD,GAI3BrB,MAAMuB,OACNvB,MAAMwB,UAAUC,GAAG,QAAS,qBAAqB,SAASJ,GACtDA,EAAEK,qBACEC,KAAON,EAAEO,OAAOC,aAAa,QACpB,MAATF,OACArB,KAAKwB,YAAcH,KACnB3B,MAAM+B,QAAQb,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,WAIxFN,MAAMwB,UAAUC,GAAG,SAAU,oCAAoC,SAASJ,GACtEf,KAAKC,WAAac,EAAEO,OAAOI,MAC3BhC,MAAM+B,QAAQb,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,eAGpFN,MAAM+B,QAAQb,kBAASC,aAAa,cAAe,iBAAkBf,UAAWE,OAChFN,MAAMuB,sBAaM,SAACU,iBAAkB7B,eAAWC,wEAC1CuB,OAASM,SAASC,cAAcF,kBAChC9B,WAAayB,OAAOC,aAAa,mBACrCD,OAAOQ,iBAAiB,SAAS,KAE7BnC,WAAWE,WAAYC,UAAWC"}

View File

@ -38,7 +38,7 @@ let modal = null;
* @param {boolean} specificVersion Is the view listing specific question versions?
*/
const usageEvent = async(questionId, contextId, specificVersion) => {
let args = {
const args = {
questionid: questionId,
specificversion: specificVersion,
};
@ -52,6 +52,7 @@ const usageEvent = async(questionId, contextId, specificVersion) => {
});
} catch (e) {
Notification.exception(e);
return;
}
modal.show();

View File

@ -54,8 +54,8 @@ class helper {
*/
public static function question_usage_sql(bool $specificversion = false): string {
$sqlset = "(". self::get_question_attempt_usage_sql($specificversion) .")".
"UNION".
"(". self::get_question_bank_usage_sql($specificversion) .")";
"UNION".
"(". self::get_question_bank_usage_sql($specificversion) .")";
return $sqlset;
}
@ -122,15 +122,15 @@ class helper {
// or the question ID that's requested is the latest version, and the reference is set to null (always latest version).
$sql .= " AND qv.questionid = ?
AND (
qv.version = qr.version
OR (
qr.version IS NULL
AND qv.version = (
SELECT MAX(qv1.version)
FROM {question_versions} qv1
WHERE qv1.questionbankentryid = qbe.id
)
)
qv.version = qr.version
OR (
qr.version IS NULL
AND qv.version = (
SELECT MAX(qv1.version)
FROM {question_versions} qv1
WHERE qv1.questionbankentryid = qbe.id
)
)
)";
}
return $sql;
@ -158,13 +158,13 @@ class helper {
$sql .= "
JOIN {question} q ON q.id = qatt.questionid
WHERE qa.preview = 0
AND q.id = ?";
AND q.id = ?";
} else {
$sql .= "
JOIN {question_versions} qv ON qv.questionid = qatt.questionid
JOIN {question_versions} qv2 ON qv.questionbankentryid = qv2.questionbankentryid
WHERE qa.preview = 0
AND qv2.questionid = ?";
AND qv2.questionid = ?";
}
return $sql;
}

View File

@ -47,8 +47,11 @@ class question_usage_column extends column_base {
if (question_has_capability_on($question, 'view')) {
$target = 'questionusagepreview_' . $question->id;
$datatarget = '[data-target="' . $target . '"]';
$PAGE->requires->js_call_amd('qbank_usage/usage', 'init',
[$datatarget, $question->contextid, $this->qbank->is_listing_specific_versions()]);
$PAGE->requires->js_call_amd('qbank_usage/usage', 'init', [
$datatarget,
$question->contextid,
$this->qbank->is_listing_specific_versions(),
]);
$attributes = [
'href' => '#',
'data-target' => $target,