mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-82168 badges: Move enable/disable badges to modal
Co-authored-by: Ferran Recio <ferran@moodle.com>
This commit is contained in:
parent
814753e558
commit
8c006300e5
@ -29,9 +29,6 @@ require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
$badgeid = required_param('id', PARAM_INT);
|
||||
$copy = optional_param('copy', 0, PARAM_BOOL);
|
||||
$activate = optional_param('activate', 0, PARAM_BOOL);
|
||||
$deactivate = optional_param('lock', 0, PARAM_BOOL);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$return = optional_param('return', 0, PARAM_LOCALURL);
|
||||
|
||||
require_login();
|
||||
@ -74,64 +71,3 @@ if ($copy) {
|
||||
}
|
||||
redirect(new moodle_url('/badges/overview.php', array('id' => $cloneid)));
|
||||
}
|
||||
|
||||
if ($activate) {
|
||||
require_capability('moodle/badges:configurecriteria', $context);
|
||||
|
||||
$PAGE->url->param('activate', 1);
|
||||
$status = ($badge->status == BADGE_STATUS_INACTIVE) ? BADGE_STATUS_ACTIVE : BADGE_STATUS_ACTIVE_LOCKED;
|
||||
if ($confirm == 1) {
|
||||
require_sesskey();
|
||||
$badge->set_status($status);
|
||||
$returnurl->param('msg', 'activatesuccess');
|
||||
|
||||
if ($badge->type == BADGE_TYPE_SITE) {
|
||||
// Review on cron if there are more than 1000 users who can earn a site-level badge.
|
||||
$sql = 'SELECT COUNT(u.id) as num
|
||||
FROM {user} u
|
||||
LEFT JOIN {badge_issued} bi
|
||||
ON u.id = bi.userid AND bi.badgeid = :badgeid
|
||||
WHERE bi.badgeid IS NULL AND u.id != :guestid AND u.deleted = 0';
|
||||
$toearn = $DB->get_record_sql($sql, array('badgeid' => $badge->id, 'guestid' => $CFG->siteguest));
|
||||
|
||||
if ($toearn->num < 1000) {
|
||||
$awards = $badge->review_all_criteria();
|
||||
$returnurl->param('awards', $awards);
|
||||
} else {
|
||||
$returnurl->param('awards', 'cron');
|
||||
}
|
||||
} else {
|
||||
$awards = $badge->review_all_criteria();
|
||||
$returnurl->param('awards', $awards);
|
||||
}
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
$strheading = get_string('reviewbadge', 'badges');
|
||||
$PAGE->navbar->add($strheading);
|
||||
$PAGE->set_title($strheading);
|
||||
$PAGE->set_heading($heading);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strheading);
|
||||
|
||||
$params = array('id' => $badge->id, 'activate' => 1, 'sesskey' => sesskey(), 'confirm' => 1, 'return' => $return);
|
||||
$url = new moodle_url('/badges/action.php', $params);
|
||||
|
||||
if (!$badge->has_criteria()) {
|
||||
redirect($returnurl, get_string('error:cannotact', 'badges') . get_string('nocriteria', 'badges'), null, \core\output\notification::NOTIFY_ERROR);
|
||||
} else {
|
||||
$message = get_string('reviewconfirm', 'badges', $badge->name);
|
||||
echo $OUTPUT->confirm($message, $url, $returnurl);
|
||||
}
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
}
|
||||
|
||||
if ($deactivate) {
|
||||
require_sesskey();
|
||||
require_capability('moodle/badges:configurecriteria', $context);
|
||||
|
||||
$status = ($badge->status == BADGE_STATUS_ACTIVE) ? BADGE_STATUS_INACTIVE : BADGE_STATUS_INACTIVE_LOCKED;
|
||||
$badge->set_status($status);
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
10
badges/amd/build/actions.min.js
vendored
Normal file
10
badges/amd/build/actions.min.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
define("core_badges/actions",["exports","core_badges/selectors","core/notification","core/prefetch","core/str","core/ajax","core/pending","core/event_dispatcher","core/toast","core_reportbuilder/local/events","core_reportbuilder/local/selectors"],(function(_exports,_selectors,_notification,_prefetch,_str,_ajax,_pending,_event_dispatcher,_toast,reportEvents,reportSelectors){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(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]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
||||
/**
|
||||
* Various actions on badges - enabling, disabling, etc.
|
||||
*
|
||||
* @module core_badges/actions
|
||||
* @copyright 2024 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_selectors=_interopRequireDefault(_selectors),_notification=_interopRequireDefault(_notification),_ajax=_interopRequireDefault(_ajax),_pending=_interopRequireDefault(_pending),reportEvents=_interopRequireWildcard(reportEvents),reportSelectors=_interopRequireWildcard(reportSelectors);_exports.init=()=>{(0,_prefetch.prefetchStrings)("core_badges",["reviewconfirm","activatesuccess","deactivatesuccess","awardoncron","numawardstat"]),(0,_prefetch.prefetchStrings)("core",["confirm","enable"]),registerEventListeners()};const registerEventListeners=()=>{document.addEventListener("click",(event=>{const enableOption=event.target.closest(_selectors.default.actions.enablebadge);if(enableOption){event.preventDefault();const reportElement=event.target.closest(reportSelectors.regions.report),triggerElement=reportElement?enableOption.closest(".dropdown").querySelector(".dropdown-toggle"):null,badgeId=enableOption.dataset.badgeid,badgeName=enableOption.dataset.badgename;_notification.default.saveCancelPromise((0,_str.getString)("confirm","core"),(0,_str.getString)("reviewconfirm","core_badges",badgeName),(0,_str.getString)("enable","core"),{triggerElement:triggerElement}).then((()=>async function(badgeId,badgeName,reportElement){var request={methodname:"core_badges_enable_badges",args:{badgeids:[badgeId]}};const pendingPromise=new _pending.default("core_badges/enable");try{const result=await _ajax.default.call([request])[0];if(reportElement)!function(badgeName,result){var _result$result2;if((null===(_result$result2=result.result)||void 0===_result$result2?void 0:_result$result2.length)>0){var _result$result3;(0,_toast.add)((0,_str.getString)("activatesuccess","core_badges",badgeName),{type:"success"});const awards=null===(_result$result3=result.result)||void 0===_result$result3?void 0:_result$result3.pop().awards;"cron"==awards?(0,_toast.add)((0,_str.getString)("awardoncron","core_badges",{badgename:badgeName})):awards>0&&(0,_toast.add)((0,_str.getString)("numawardstat","core_badges",{badgename:badgeName,awards:awards}))}else result.warnings.length>0&&(0,_toast.add)(result.warnings[0].message,{type:"danger"})}(badgeName,result),(0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{preservePagination:!0},reportElement);else{var _result$result;const awards=null===(_result$result=result.result)||void 0===_result$result?void 0:_result$result.pop().awards;document.location=document.location.pathname+"?id=".concat(badgeId,"&awards=").concat(awards)}}catch(error){_notification.default.exception(error)}pendingPromise.resolve()}(badgeId,badgeName,reportElement))).catch((()=>{}))}const disableOption=event.target.closest(_selectors.default.actions.disablebadge);if(disableOption){event.preventDefault();!async function(badgeId,badgeName,reportElement){var request={methodname:"core_badges_disable_badges",args:{badgeids:[badgeId]}};try{const result=await _ajax.default.call([request])[0];reportElement?(!function(badgeName,result){result.result?(0,_toast.add)((0,_str.getString)("deactivatesuccess","core_badges",badgeName),{type:"success"}):result.warnings.length>0&&(0,_toast.add)(result.warnings[0].message,{type:"danger"})}(badgeName,result),(0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{preservePagination:!0},reportElement)):document.location=document.location.pathname+"?id=".concat(badgeId)}catch(error){_notification.default.exception(error)}}(disableOption.dataset.badgeid,disableOption.dataset.badgename,event.target.closest(reportSelectors.regions.report))}}))}}));
|
||||
|
||||
//# sourceMappingURL=actions.min.js.map
|
1
badges/amd/build/actions.min.js.map
Normal file
1
badges/amd/build/actions.min.js.map
Normal file
File diff suppressed because one or more lines are too long
10
badges/amd/build/selectors.min.js
vendored
10
badges/amd/build/selectors.min.js
vendored
@ -1,3 +1,11 @@
|
||||
define("core_badges/selectors",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var name,value,_default={actions:{deletebackpack:(name="action",value="deletebackpack","[data-".concat(name,'="').concat(value,'"]'))},elements:{clearsearch:".input-group-append .clear-icon",main:"#backpacklist",backpackurl:"[data-backpackurl]"}};return _exports.default=_default,_exports.default}));
|
||||
define("core_badges/selectors",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;
|
||||
/**
|
||||
* Define all of the selectors we will be using on the backpack interface.
|
||||
*
|
||||
* @module core_badges/selectors
|
||||
* @copyright 2020 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
const getDataSelector=(name,value)=>"[data-".concat(name,'="').concat(value,'"]');var _default={actions:{deletebackpack:getDataSelector("action","deletebackpack"),enablebadge:getDataSelector("action","enablebadge"),disablebadge:getDataSelector("action","disablebadge")},elements:{clearsearch:".input-group-append .clear-icon",main:"#backpacklist",backpackurl:"[data-backpackurl]"}};return _exports.default=_default,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=selectors.min.js.map
|
@ -1 +1 @@
|
||||
{"version":3,"file":"selectors.min.js","sources":["../src/selectors.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 * Define all of the selectors we will be using on the backpack interface.\n *\n * @module core_badges/selectors\n * @copyright 2020 Sara Arjona <sara@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * A small helper function to build queryable data selectors.\n *\n * @method getDataSelector\n * @param {String} name\n * @param {String} value\n * @return {string}\n */\nconst getDataSelector = (name, value) => {\n return `[data-${name}=\"${value}\"]`;\n};\n\nexport default {\n actions: {\n deletebackpack: getDataSelector('action', 'deletebackpack'),\n },\n elements: {\n clearsearch: '.input-group-append .clear-icon',\n main: '#backpacklist',\n backpackurl: '[data-backpackurl]',\n },\n};\n"],"names":["name","value","actions","deletebackpack","elements","clearsearch","main","backpackurl"],"mappings":"mJA+ByBA,KAAMC,eAIhB,CACXC,QAAS,CACLC,gBANiBH,KAMe,SANTC,MAMmB,iCAL9BD,kBAASC,cAOzBG,SAAU,CACNC,YAAa,kCACbC,KAAM,gBACNC,YAAa"}
|
||||
{"version":3,"file":"selectors.min.js","sources":["../src/selectors.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 * Define all of the selectors we will be using on the backpack interface.\n *\n * @module core_badges/selectors\n * @copyright 2020 Sara Arjona <sara@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * A small helper function to build queryable data selectors.\n *\n * @method getDataSelector\n * @param {String} name\n * @param {String} value\n * @return {string}\n */\nconst getDataSelector = (name, value) => {\n return `[data-${name}=\"${value}\"]`;\n};\n\nexport default {\n actions: {\n deletebackpack: getDataSelector('action', 'deletebackpack'),\n enablebadge: getDataSelector('action', 'enablebadge'),\n disablebadge: getDataSelector('action', 'disablebadge'),\n },\n elements: {\n clearsearch: '.input-group-append .clear-icon',\n main: '#backpacklist',\n backpackurl: '[data-backpackurl]',\n },\n};\n"],"names":["getDataSelector","name","value","actions","deletebackpack","enablebadge","disablebadge","elements","clearsearch","main","backpackurl"],"mappings":";;;;;;;;MA+BMA,gBAAkB,CAACC,KAAMC,wBACXD,kBAASC,yBAGd,CACXC,QAAS,CACLC,eAAgBJ,gBAAgB,SAAU,kBAC1CK,YAAaL,gBAAgB,SAAU,eACvCM,aAAcN,gBAAgB,SAAU,iBAE5CO,SAAU,CACNC,YAAa,kCACbC,KAAM,gBACNC,YAAa"}
|
194
badges/amd/src/actions.js
Normal file
194
badges/amd/src/actions.js
Normal file
@ -0,0 +1,194 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Various actions on badges - enabling, disabling, etc.
|
||||
*
|
||||
* @module core_badges/actions
|
||||
* @copyright 2024 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import selectors from 'core_badges/selectors';
|
||||
import Notification from 'core/notification';
|
||||
import {prefetchStrings} from 'core/prefetch';
|
||||
import {getString} from 'core/str';
|
||||
import Ajax from 'core/ajax';
|
||||
import Pending from 'core/pending';
|
||||
import {dispatchEvent} from 'core/event_dispatcher';
|
||||
import {add as addToast} from 'core/toast';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
|
||||
/**
|
||||
* Initialize module.
|
||||
*/
|
||||
export const init = () => {
|
||||
prefetchStrings('core_badges', [
|
||||
'reviewconfirm',
|
||||
'activatesuccess',
|
||||
'deactivatesuccess',
|
||||
'awardoncron',
|
||||
'numawardstat',
|
||||
]);
|
||||
prefetchStrings('core', [
|
||||
'confirm',
|
||||
'enable',
|
||||
]);
|
||||
|
||||
registerEventListeners();
|
||||
};
|
||||
|
||||
/**
|
||||
* Register events for delete preset option in action menu.
|
||||
*/
|
||||
const registerEventListeners = () => {
|
||||
document.addEventListener('click', (event) => {
|
||||
const enableOption = event.target.closest(selectors.actions.enablebadge);
|
||||
|
||||
if (enableOption) {
|
||||
event.preventDefault();
|
||||
|
||||
// Use triggerElement to return focus to the action menu toggle.
|
||||
const reportElement = event.target.closest(reportSelectors.regions.report);
|
||||
const triggerElement = reportElement ? enableOption.closest('.dropdown').querySelector('.dropdown-toggle') : null;
|
||||
const badgeId = enableOption.dataset.badgeid;
|
||||
const badgeName = enableOption.dataset.badgename;
|
||||
|
||||
Notification.saveCancelPromise(
|
||||
getString('confirm', 'core'),
|
||||
getString('reviewconfirm', 'core_badges', badgeName),
|
||||
getString('enable', 'core'),
|
||||
{triggerElement}
|
||||
).then(() => {
|
||||
return enableBadge(badgeId, badgeName, reportElement);
|
||||
}).catch(() => {
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
const disableOption = event.target.closest(selectors.actions.disablebadge);
|
||||
if (disableOption) {
|
||||
event.preventDefault();
|
||||
const badgeId = disableOption.dataset.badgeid;
|
||||
const badgeName = disableOption.dataset.badgename;
|
||||
const reportElement = event.target.closest(reportSelectors.regions.report);
|
||||
disableBadge(badgeId, badgeName, reportElement);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable the badge.
|
||||
*
|
||||
* @param {Number} badgeId The id of the badge to enable.
|
||||
* @param {String} badgeName The name of the badge to enable.
|
||||
* @param {HTMLElement} reportElement the report element.
|
||||
*/
|
||||
async function enableBadge(badgeId, badgeName, reportElement) {
|
||||
var request = {
|
||||
methodname: 'core_badges_enable_badges',
|
||||
args: {
|
||||
badgeids: [badgeId],
|
||||
}
|
||||
};
|
||||
|
||||
const pendingPromise = new Pending('core_badges/enable');
|
||||
try {
|
||||
const result = await Ajax.call([request])[0];
|
||||
if (reportElement) {
|
||||
showEnableResultToast(badgeName, result);
|
||||
// Report element is present, reload the table.
|
||||
dispatchEvent(reportEvents.tableReload, {preservePagination: true}, reportElement);
|
||||
} else {
|
||||
// Report element is not present, add the parameters to the current page to display the message.
|
||||
const awards = result.result?.pop().awards;
|
||||
document.location = document.location.pathname + `?id=${badgeId}&awards=${awards}`;
|
||||
}
|
||||
} catch (error) {
|
||||
Notification.exception(error);
|
||||
}
|
||||
pendingPromise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the result of enabling a badge.
|
||||
*
|
||||
* @param {String} badgeName The name of the badge to enable.
|
||||
* @param {Object} result The result of enabling a badge.
|
||||
*/
|
||||
function showEnableResultToast(badgeName, result) {
|
||||
if (result.result?.length > 0) {
|
||||
addToast(getString('activatesuccess', 'core_badges', badgeName), {type: 'success'});
|
||||
const awards = result.result?.pop().awards;
|
||||
if (awards == 'cron') {
|
||||
addToast(getString('awardoncron', 'core_badges', {badgename: badgeName}));
|
||||
} else if (awards > 0) {
|
||||
addToast(getString('numawardstat', 'core_badges', {badgename: badgeName, awards: awards}));
|
||||
}
|
||||
} else if (result.warnings.length > 0) {
|
||||
addToast(result.warnings[0].message, {type: 'danger'});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the badge.
|
||||
*
|
||||
* @param {Number} badgeId The id of the badge to disable.
|
||||
* @param {String} badgeName The name of the badge to enable.
|
||||
* @param {HTMLElement} reportElement the report element.
|
||||
*/
|
||||
async function disableBadge(badgeId, badgeName, reportElement) {
|
||||
var request = {
|
||||
methodname: 'core_badges_disable_badges',
|
||||
args: {
|
||||
badgeids: [badgeId],
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await Ajax.call([request])[0];
|
||||
if (reportElement) {
|
||||
// Report element is present, show the message in a toast and reload the table.
|
||||
showDisableResultToast(badgeName, result);
|
||||
dispatchEvent(reportEvents.tableReload, {preservePagination: true}, reportElement);
|
||||
} else {
|
||||
// Report element is not present, the page should be reloaded.
|
||||
document.location = document.location.pathname + `?id=${badgeId}`;
|
||||
}
|
||||
} catch (error) {
|
||||
Notification.exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the result of disabling a badge.
|
||||
*
|
||||
* @param {String} badgeName The name of the badge to disable.
|
||||
* @param {Object} result The result of disabling a badge.
|
||||
*/
|
||||
function showDisableResultToast(badgeName, result) {
|
||||
if (result.result) {
|
||||
addToast(
|
||||
getString('deactivatesuccess', 'core_badges', badgeName),
|
||||
{type: 'success'}
|
||||
);
|
||||
} else if (result.warnings.length > 0) {
|
||||
addToast(
|
||||
result.warnings[0].message,
|
||||
{type: 'danger'}
|
||||
);
|
||||
}
|
||||
}
|
@ -36,6 +36,8 @@ const getDataSelector = (name, value) => {
|
||||
export default {
|
||||
actions: {
|
||||
deletebackpack: getDataSelector('action', 'deletebackpack'),
|
||||
enablebadge: getDataSelector('action', 'enablebadge'),
|
||||
disablebadge: getDataSelector('action', 'disablebadge'),
|
||||
},
|
||||
elements: {
|
||||
clearsearch: '.input-group-append .clear-icon',
|
||||
|
@ -158,21 +158,19 @@ class badges extends system_report {
|
||||
protected function add_actions(): void {
|
||||
// Activate badge.
|
||||
$this->add_action((new action(
|
||||
new moodle_url('/badges/action.php', [
|
||||
'id' => ':id',
|
||||
'activate' => true,
|
||||
'return' => ':return',
|
||||
]),
|
||||
new moodle_url('#'),
|
||||
new pix_icon('t/show', '', 'core'),
|
||||
[],
|
||||
[
|
||||
'data-action' => 'enablebadge',
|
||||
'data-badgeid' => ':id',
|
||||
'data-badgename' => ':badgename',
|
||||
'data-courseid' => ':courseid',
|
||||
],
|
||||
false,
|
||||
new lang_string('activate', 'badges')
|
||||
))->add_callback(static function(stdclass $row): bool {
|
||||
$badge = new \core_badges\badge($row->id);
|
||||
|
||||
// Populate the return URL.
|
||||
$row->return = (new moodle_url('/badges/index.php',
|
||||
['type' => $badge->type, 'id' => (int) $badge->courseid]))->out_as_local_url(false);
|
||||
$row->badgename = $badge->name;
|
||||
|
||||
return has_capability('moodle/badges:configuredetails', $badge->get_context()) &&
|
||||
$badge->has_criteria() &&
|
||||
@ -182,18 +180,19 @@ class badges extends system_report {
|
||||
|
||||
// Deactivate badge.
|
||||
$this->add_action((new action(
|
||||
new moodle_url('/badges/index.php', [
|
||||
'lock' => ':id',
|
||||
'sesskey' => sesskey(),
|
||||
'type' => ':type',
|
||||
'id' => ':courseid',
|
||||
]),
|
||||
new moodle_url('#'),
|
||||
new pix_icon('t/hide', '', 'core'),
|
||||
[],
|
||||
[
|
||||
'data-action' => 'disablebadge',
|
||||
'data-badgeid' => ':id',
|
||||
'data-badgename' => ':badgename',
|
||||
'data-courseid' => ':courseid',
|
||||
],
|
||||
false,
|
||||
new lang_string('deactivate', 'badges')
|
||||
))->add_callback(static function(stdclass $row): bool {
|
||||
$badge = new \core_badges\badge($row->id);
|
||||
$row->badgename = $badge->name;
|
||||
return has_capability('moodle/badges:configuredetails', $badge->get_context()) &&
|
||||
$badge->has_criteria() &&
|
||||
$row->status != BADGE_STATUS_INACTIVE && $row->status != BADGE_STATUS_INACTIVE_LOCKED;
|
||||
|
@ -161,5 +161,6 @@ $report = system_report_factory::create(badges::class, $PAGE->context);
|
||||
$report->set_default_no_results_notice(new lang_string('nobadges', 'badges'));
|
||||
|
||||
echo $report->output();
|
||||
$PAGE->requires->js_call_amd('core_badges/actions', 'init');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -74,9 +74,9 @@ echo $output->render_tertiary_navigation($actionbar);
|
||||
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
|
||||
|
||||
if ($awards == 'cron') {
|
||||
echo $OUTPUT->notification(get_string('awardoncron', 'badges'), 'notifysuccess');
|
||||
echo $OUTPUT->notification(get_string('awardoncron', 'badges', ['badgename' => $badge->name]), 'info');
|
||||
} else if ((int)$awards > 0) {
|
||||
echo $OUTPUT->notification(get_string('numawardstat', 'badges', $awards), 'notifysuccess');
|
||||
echo $OUTPUT->notification(get_string('numawardstat', 'badges', ['badgename' => $badge->name, 'awards' => $awards]), 'info');
|
||||
}
|
||||
echo $output->print_badge_status_box($badge);
|
||||
echo $output->print_badge_overview($badge, $context);
|
||||
|
@ -242,6 +242,7 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
if ($badge->has_awards()) {
|
||||
$url = new moodle_url('/badges/recipients.php', array('id' => $badge->id));
|
||||
$a = new stdClass();
|
||||
$a->badgename = $badge->name;
|
||||
$a->link = $url->out();
|
||||
$a->count = count($badge->get_awards());
|
||||
$display .= get_string('numawards', 'badges', $a);
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
$string['actions'] = 'Actions';
|
||||
$string['activate'] = 'Enable access';
|
||||
$string['activatesuccess'] = 'Access to the badges was successfully enabled.';
|
||||
$string['activatesuccess'] = 'Access to badge \'{$a}\' enabled.';
|
||||
$string['addalignment'] = 'Add external skill or standard';
|
||||
$string['addbadge'] = 'Add badges';
|
||||
$string['addbadge_help'] = 'Select all badges that should be added to this badge requirement. Hold CTRL key to select multiple items.';
|
||||
@ -78,7 +78,7 @@ $string['attachment_help'] = 'If enabled, an issued badge will be attached to th
|
||||
$string['award'] = 'Award badge';
|
||||
$string['awardedto'] = 'Awarded to {$a}';
|
||||
$string['awardedtoyou'] = 'Issued to me';
|
||||
$string['awardoncron'] = 'Access to the badges was successfully enabled. Too many users can instantly earn this badge. To ensure site performance, this action will take some time to process.';
|
||||
$string['awardoncron'] = 'A high number of users are being awarded the badge \'{$a->badgename}\'. It may take some time for all users to receive it.';
|
||||
$string['awards'] = 'Recipients';
|
||||
$string['backpackavailability'] = 'External badge verification';
|
||||
$string['backpackconnectionok'] = 'Backpack connection successfully established';
|
||||
@ -272,7 +272,7 @@ $string['dateawarded'] = 'Date issued';
|
||||
$string['dateearned'] = 'Date: {$a}';
|
||||
$string['day'] = 'Day(s)';
|
||||
$string['deactivate'] = 'Disable access';
|
||||
$string['deactivatesuccess'] = 'Access to the badges was successfully disabled.';
|
||||
$string['deactivatesuccess'] = 'Access to badge \'{$a}\' disabled.';
|
||||
$string['defaultissuercontact'] = 'Badge issuer email address';
|
||||
$string['defaultissuercontact_desc'] = 'An email address associated with the badge issuer. For an Open Badges v2.0 backpack, this is used for authentication when publishing badges to a backpack.';
|
||||
$string['defaultissuerpassword'] = 'Badge issuer password';
|
||||
@ -296,7 +296,6 @@ $string['error:backpackdatainvalid'] = 'The data return from the backpack was in
|
||||
$string['error:backpackemailnotfound'] = 'The email \'{$a}\' is not associated with a backpack. You need to <a href="http://backpack.openbadges.org">create a backpack</a> for that account or sign in with another email address.';
|
||||
$string['error:badgeawardnotfound'] = 'Cannot verify this awarded badge. This badge may have been revoked.';
|
||||
$string['error:badgenotfound'] = 'Badge not found';
|
||||
$string['error:cannotact'] = 'Cannot activate the badge. ';
|
||||
$string['error:cannotawardbadge'] = 'Cannot award badge to a user.';
|
||||
$string['error:cannotrevokebadge'] = 'Cannot revoke badge from a user.';
|
||||
$string['error:cannotdeletecriterion'] = 'This criterion cannot be deleted. ';
|
||||
@ -461,8 +460,8 @@ $string['notifydaily'] = 'Daily';
|
||||
$string['notifyevery'] = 'Every time';
|
||||
$string['notifymonthly'] = 'Monthly';
|
||||
$string['notifyweekly'] = 'Weekly';
|
||||
$string['numawards'] = 'This badge has been issued to <a href="{$a->link}">{$a->count}</a> user(s).';
|
||||
$string['numawardstat'] = 'This badge has been issued {$a} user(s).';
|
||||
$string['numawards'] = 'Users awarded badge \'{$a->badgename}\': <a href="{$a->link}">{$a->count}</a>.';
|
||||
$string['numawardstat'] = 'Users awarded badge \'{$a->badgename}\': {$a->awards}.';
|
||||
$string['overallcrit'] = 'of the selected criteria are complete.';
|
||||
$string['oauth2issuer'] = 'OAuth 2 services';
|
||||
$string['openbadgesv1'] = 'Open Badges v1.0';
|
||||
@ -516,7 +515,6 @@ $string['requiredcohort'] = 'At least one cohort should be added to the cohort c
|
||||
$string['requiredcompetency'] = 'At least one competency should be added to the competency criterion.';
|
||||
$string['requiredcourse'] = 'At least one course should be added to the courseset criterion.';
|
||||
$string['requiredbadge'] = 'At least one badge should be added to the badge criterion.';
|
||||
$string['reviewbadge'] = 'Changes in badge access';
|
||||
$string['reviewconfirm'] = '<p>This will make your badge visible to users and allow them to start earning it.</p>
|
||||
|
||||
<p>It is possible that some users already meet this badge\'s criteria and will be issued this badge immediately after you enable it.</p>
|
||||
@ -598,4 +596,6 @@ $string['backpackemail'] = 'Email address';
|
||||
$string['backpackemail_help'] = 'The email address associated with your backpack. While you are connected, any badges earned on this site will be associated with this email address.';
|
||||
|
||||
// Deprecated since Moodle 4.5.
|
||||
$string['error:cannotact'] = 'Cannot activate the badge. ';
|
||||
$string['error:duplicatename'] = 'Badge with such name already exists in the system.';
|
||||
$string['reviewbadge'] = 'Changes in badge access';
|
||||
|
@ -117,3 +117,5 @@ importcalendarexternal,core_calendar
|
||||
nocalendarsubscriptions,core_calendar
|
||||
datechanged,core
|
||||
error:duplicatename,core_badges
|
||||
error:cannotact,core_badges
|
||||
reviewbadge,core_badges
|
||||
|
Loading…
x
Reference in New Issue
Block a user