mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Merge branch 'MDL-72141-master' of https://github.com/sarjona/moodle
This commit is contained in:
commit
91a76566c9
@ -31,6 +31,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
use renderable;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* An external badges for external.php page
|
||||
@ -39,19 +41,19 @@ use renderable;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class external_badge implements renderable {
|
||||
/** @var issued badge */
|
||||
/** @var stdClass Issued badge */
|
||||
public $issued;
|
||||
|
||||
/** @var User ID */
|
||||
/** @var int User ID */
|
||||
public $recipient;
|
||||
|
||||
/** @var validation of external badge */
|
||||
/** @var bool Validation of external badge */
|
||||
public $valid = true;
|
||||
|
||||
/**
|
||||
* Initializes the badge to display
|
||||
*
|
||||
* @param object $badge External badge information.
|
||||
* @param stdClass $badge External badge information.
|
||||
* @param int $recipient User id.
|
||||
*/
|
||||
public function __construct($badge, $recipient) {
|
||||
@ -97,5 +99,78 @@ class external_badge implements renderable {
|
||||
$this->valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export this data so it can be used as the context for a mustache template.
|
||||
*
|
||||
* @param renderer_base $output Renderer base.
|
||||
* @return stdClass
|
||||
*/
|
||||
public function export_for_template(renderer_base $output): stdClass {
|
||||
$data = new stdClass();
|
||||
|
||||
$now = time();
|
||||
if (isset($this->issued->assertion->expires)) {
|
||||
if (!is_numeric($this->issued->assertion->expires)) {
|
||||
$this->issued->assertion->expires = strtotime($this->issued->assertion->expires);
|
||||
}
|
||||
$expiration = $this->issued->assertion->expires;
|
||||
} else {
|
||||
$expiration = $now + 86400;
|
||||
}
|
||||
|
||||
// Field: Image.
|
||||
if (isset($this->issued->imageUrl)) {
|
||||
$this->issued->image = $this->issued->imageUrl;
|
||||
}
|
||||
$data->badgeimage = $this->issued->image;
|
||||
|
||||
// Field: Expiration date.
|
||||
if (isset($this->issued->assertion->expires)) {
|
||||
if ($expiration < $now) {
|
||||
$data->expireddate = $this->issued->assertion->expires;
|
||||
$data->expireddateformatted = userdate(
|
||||
$this->issued->assertion->expires,
|
||||
get_string('strftimedatetime', 'langconfig')
|
||||
);
|
||||
} else {
|
||||
$data->expiredate = $this->issued->assertion->expires;
|
||||
}
|
||||
}
|
||||
|
||||
// Fields: Name, description, issuedOn.
|
||||
$data->badgename = $this->issued->assertion->badge->name;
|
||||
$data->badgedescription = $this->issued->assertion->badge->description;
|
||||
if (isset($this->issued->assertion->issued_on)) {
|
||||
if (!is_numeric($this->issued->assertion->issued_on)) {
|
||||
$this->issued->assertion->issued_on = strtotime($this->issued->assertion->issued_on);
|
||||
}
|
||||
$data->badgeissuedon = $this->issued->assertion->issued_on;
|
||||
}
|
||||
|
||||
// Field: Recipient (the badge was awarded to this person).
|
||||
$data->recipientname = fullname($this->recipient);
|
||||
if (!$this->valid) {
|
||||
$data->recipientnotification = new stdClass();
|
||||
$data->recipientnotification->message = get_string('recipientvalidationproblem', 'badges');
|
||||
}
|
||||
|
||||
// Field: Criteria.
|
||||
if (isset($this->issued->assertion->badgeclass->criteria->narrative)) {
|
||||
$data->criteria = $this->issued->assertion->badgeclass->criteria->narrative;
|
||||
}
|
||||
|
||||
// Field: Issuer.
|
||||
$data->issuedby = $this->issued->issuer->name;
|
||||
if (isset($this->issued->issuer->contact) && !empty($this->issued->issuer->contact)) {
|
||||
$data->issuedbyemailobfuscated = obfuscate_mailto($this->issued->issuer->contact, $data->issuedby);
|
||||
}
|
||||
|
||||
// Field: Hosted URL.
|
||||
if (isset($this->issued->hostedUrl) && !empty($this->issued->hostedUrl)) {
|
||||
$data->hostedurl = $this->issued->hostedUrl;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -325,101 +325,8 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
* @return string
|
||||
*/
|
||||
protected function render_external_badge(\core_badges\output\external_badge $ibadge) {
|
||||
$issued = $ibadge->issued;
|
||||
$assertion = $issued->assertion;
|
||||
$issuer = $assertion->badge->issuer;
|
||||
$userinfo = $ibadge->recipient;
|
||||
$table = new html_table();
|
||||
$today = strtotime(date('Y-m-d'));
|
||||
|
||||
$output = '';
|
||||
$output .= html_writer::start_tag('div', array('id' => 'badge'));
|
||||
$output .= html_writer::start_tag('div', array('id' => 'badge-image'));
|
||||
if (isset($issued->imageUrl)) {
|
||||
$issued->image = $issued->imageUrl;
|
||||
}
|
||||
$output .= html_writer::empty_tag('img', array('src' => $issued->image, 'width' => '100'));
|
||||
if (isset($assertion->expires)) {
|
||||
$expiration = is_numeric($assertion->expires) ? $assertion->expires : strtotime($assertion->expires);
|
||||
if ($expiration < $today) {
|
||||
$output .= $this->output->pix_icon('i/expired',
|
||||
get_string('expireddate', 'badges', userdate($expiration)),
|
||||
'moodle',
|
||||
array('class' => 'expireimage'));
|
||||
}
|
||||
}
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
$output .= html_writer::start_tag('div', array('id' => 'badge-details'));
|
||||
|
||||
// Recipient information.
|
||||
$output .= $this->output->heading(get_string('recipientdetails', 'badges'), 3);
|
||||
$dl = array();
|
||||
// Technically, we should alway have a user at this point, but added an extra check just in case.
|
||||
if ($userinfo) {
|
||||
if (!$ibadge->valid) {
|
||||
$notify = $this->output->notification(get_string('recipientvalidationproblem', 'badges'), 'notifynotice');
|
||||
$dl[get_string('name')] = fullname($userinfo) . $notify;
|
||||
} else {
|
||||
$dl[get_string('name')] = fullname($userinfo);
|
||||
}
|
||||
} else {
|
||||
$notify = $this->output->notification(get_string('recipientidentificationproblem', 'badges'), 'notifynotice');
|
||||
$dl[get_string('name')] = $notify;
|
||||
}
|
||||
$output .= $this->definition_list($dl);
|
||||
|
||||
$output .= $this->output->heading(get_string('issuerdetails', 'badges'), 3);
|
||||
$dl = array();
|
||||
$dl[get_string('issuername', 'badges')] = s($issuer->name);
|
||||
if (isset($issuer->origin)) {
|
||||
$dl[get_string('issuerurl', 'badges')] = html_writer::tag('a', $issuer->origin, array('href' => $issuer->origin));
|
||||
}
|
||||
|
||||
if (isset($issuer->contact)) {
|
||||
$dl[get_string('contact', 'badges')] = obfuscate_mailto($issuer->contact);
|
||||
}
|
||||
$output .= $this->definition_list($dl);
|
||||
|
||||
$output .= $this->output->heading(get_string('badgedetails', 'badges'), 3);
|
||||
$dl = array();
|
||||
$dl[get_string('name')] = s($assertion->badge->name);
|
||||
$dl[get_string('description', 'badges')] = s($assertion->badge->description);
|
||||
if (isset($assertion->badge->criteria)) {
|
||||
$dl[get_string('bcriteria', 'badges')] = html_writer::tag(
|
||||
'a',
|
||||
s($assertion->badge->criteria),
|
||||
array('href' => $assertion->badge->criteria)
|
||||
);
|
||||
}
|
||||
$output .= $this->definition_list($dl);
|
||||
|
||||
$dl = array();
|
||||
if (isset($assertion->issued_on)) {
|
||||
$issuedate = is_numeric($assertion->issued_on) ? $assertion->issued_on : strtotime($assertion->issued_on);
|
||||
$dl[get_string('dateawarded', 'badges')] = userdate($issuedate);
|
||||
}
|
||||
if (isset($assertion->expires)) {
|
||||
if ($expiration < $today) {
|
||||
$dl[get_string('expirydate', 'badges')] = userdate($expiration) . get_string('warnexpired', 'badges');
|
||||
} else {
|
||||
$dl[get_string('expirydate', 'badges')] = userdate($expiration);
|
||||
}
|
||||
}
|
||||
if (isset($assertion->evidence)) {
|
||||
$dl[get_string('evidence', 'badges')] = html_writer::tag(
|
||||
'a',
|
||||
s($assertion->evidence),
|
||||
array('href' => $assertion->evidence)
|
||||
);
|
||||
}
|
||||
if (!empty($dl)) {
|
||||
$output .= $this->output->heading(get_string('issuancedetails', 'badges'), 3);
|
||||
$output .= $this->definition_list($dl);
|
||||
}
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
return $output;
|
||||
$data = $ibadge->export_for_template($this);
|
||||
return parent::render_from_template('core_badges/issued_badge', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,7 @@
|
||||
* badgedescription - Badge description.
|
||||
* badgeissuedon - Date where the badge was issued on by the user.
|
||||
* recipientname - User awarded with the badge.
|
||||
* recipientnotification.message - Message to be displayed if there is some issue with the recipient.
|
||||
* criteria - HTML code with the criteria to display.
|
||||
* issuedby - Badge issuer.
|
||||
* issuedbyemailobfuscated - Badge issuer email link obfuscated.
|
||||
@ -45,6 +46,7 @@
|
||||
* relatedbadges - Array of related badges (if hasrelatedbadges is set to true).
|
||||
* hasalignments - Whether the badge has alignments or not.
|
||||
* alignments - Array of alignments (if hasalignments is set to true).
|
||||
* hostedurl - The URL where the badge is hosted [optional].
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
@ -55,7 +57,10 @@
|
||||
"badgedescription":"This badge is awarded to people who have provided outstanding support to other participants in the MOOC",
|
||||
"badgeissuedon": 1625491897,
|
||||
"recipientname": "Judit Cortes",
|
||||
"criteria": "Complete <strong>ALL</strong> of the listed requirements.<ul><li>This badge has to be awarded by a user with the following role:<ul><li>Teacher</li></ul></li><li>The following activity has to be completed:<ul><li><strong>View video</strong></li></ul></li><li>The following badge has to be earned:<ul><li><strong>Lean Moodle 3.11 Basics participant</strong></li></ul></li></ul>;",
|
||||
"recipientnotification": {
|
||||
"message": "This user cannot be verified as a recipient of this badge."
|
||||
},
|
||||
"criteria": "Complete <strong>ALL</strong> of the listed requirements.<ul><li>This badge has to be awarded by a user with the following role:<ul><li>Teacher</li></ul></li><li>The following activity has to be completed:<ul><li><strong>View video</strong></li></ul></li><li>The following badge has to be earned:<ul><li><strong>Lean Moodle 3.11 Basics participant</strong></li></ul></li></ul>",
|
||||
"issuedby": "Moodle HQ",
|
||||
"issuedbyemailobfuscated": "<a href=\"mailto:xxxxx\">Moodle HQ</a>",
|
||||
"hasotherfields": true,
|
||||
@ -106,7 +111,8 @@
|
||||
"targetframework": "Framework name",
|
||||
"targetcode": "A1001"
|
||||
}
|
||||
]
|
||||
],
|
||||
"hostedurl": "http://externalbackpack/badge?id=ABC"
|
||||
}
|
||||
}}
|
||||
|
||||
@ -134,6 +140,9 @@
|
||||
<div id="badge-details-col" class="col">
|
||||
<h2>{{badgename}}</h2>
|
||||
<div id="badge-awardedto" class="pt-1 pb-2">
|
||||
{{#recipientnotification}}
|
||||
{{> core/notification_warning}}
|
||||
{{/recipientnotification}}
|
||||
{{#str}}awardedto, core_badges, {{recipientname}}{{/str}}
|
||||
</div>
|
||||
|
||||
@ -179,6 +188,14 @@
|
||||
</div>
|
||||
{{/issuedby}}
|
||||
|
||||
{{#hostedurl}}
|
||||
<div class="pb-2">
|
||||
<a href="{{.}}" target="_blank" aria-label="{{#str}}hostedurldescription, core_badges{{/str}}">
|
||||
{{#str}}hostedurl, core_badges{{/str}}
|
||||
</a>
|
||||
</div>
|
||||
{{/hostedurl}}
|
||||
|
||||
{{#coursefullname}}
|
||||
<div class="pb-2">
|
||||
{{#str}}
|
||||
|
@ -338,7 +338,6 @@ $string['eventbadgelistingviewed'] = 'Badge listing viewed';
|
||||
$string['eventbadgerevoked'] = 'Badge revoked';
|
||||
$string['eventbadgeupdated'] = 'Badge updated';
|
||||
$string['eventbadgeviewed'] = 'Badge viewed';
|
||||
$string['evidence'] = 'Evidence';
|
||||
$string['existingrecipients'] = 'Existing badge recipients';
|
||||
$string['expired'] = 'Expired';
|
||||
$string['expiredate'] = 'This badge expires on {$a}.';
|
||||
@ -359,6 +358,8 @@ $string['externalbadges_help'] = 'This area displays badges from your external b
|
||||
$string['fixed'] = 'Fixed date';
|
||||
$string['hidden'] = 'Hidden';
|
||||
$string['hiddenbadge'] = 'Unfortunately, the badge owner has not made this information available.';
|
||||
$string['hostedurl'] = 'External URL';
|
||||
$string['hostedurldescription'] = 'External URL where the badge is hosted';
|
||||
$string['imageauthoremail'] = 'Image author\'s email';
|
||||
$string['imageauthoremail_help'] = 'If specified, the email address of the badge image author is displayed on the badge page.';
|
||||
$string['imageauthorname'] = 'Image author\'s name';
|
||||
@ -492,9 +493,7 @@ $string['privacy:metadata:manualaward:issuerid'] = 'The ID of the user awarding
|
||||
$string['privacy:metadata:manualaward:issuerrole'] = 'The role of the user awarding the badge';
|
||||
$string['privacy:metadata:manualaward:recipientid'] = 'The ID of the user who is manually awarded a badge';
|
||||
$string['recipients'] = 'Badge recipients';
|
||||
$string['recipientdetails'] = 'Recipient details';
|
||||
$string['recipientidentificationproblem'] = 'Cannot find a recipient of this badge among the existing users.';
|
||||
$string['recipientvalidationproblem'] = 'Current user cannot be verified as a recipient of this badge.';
|
||||
$string['recipientvalidationproblem'] = 'This user cannot be verified as a recipient of this badge.';
|
||||
$string['relative'] = 'Relative date';
|
||||
$string['relatedbages'] = 'Related badges';
|
||||
$string['revoke'] = 'Revoke badge';
|
||||
@ -588,3 +587,8 @@ $string['error:backpacknotavailable'] = 'Your site is not accessible from the In
|
||||
$string['error:backpackproblem'] = 'There was a problem connecting to your backpack service provider. Please try again later.';
|
||||
$string['sitebackpack'] = 'Active external backpack';
|
||||
$string['sitebackpack_help'] = 'The external backpack that users can connect to from this site. Note that changing this setting after users have connected their backpacks will require each user to go to their backpack settings page and disconnect then reconnect.';
|
||||
|
||||
// Deprecated since Moodle 4.0.
|
||||
$string['evidence'] = 'Evidence';
|
||||
$string['recipientdetails'] = 'Recipient details';
|
||||
$string['recipientidentificationproblem'] = 'Cannot find a recipient of this badge among the existing users.';
|
||||
|
@ -164,3 +164,6 @@ mediapluginswfnote,core_admin
|
||||
createuserandpass,core
|
||||
supplyinfo,core
|
||||
monthlyview,core_calendar
|
||||
evidence,core_badges
|
||||
recipientdetails,core_badges
|
||||
recipientidentificationproblem,core_badges
|
||||
|
Loading…
x
Reference in New Issue
Block a user