first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+98
View File
@@ -0,0 +1,98 @@
<?php
// 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/>.
/**
* Contains alignment class for displaying a badge alignment.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying a badge alignment.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class alignment_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => [
'type' => PARAM_INT,
'description' => 'Alignment id',
'optional' => true,
],
'badgeid' => [
'type' => PARAM_INT,
'description' => 'Badge id',
'optional' => true,
],
'targetName' => [
'type' => PARAM_TEXT,
'description' => 'Target name',
'optional' => true,
],
'targetUrl' => [
'type' => PARAM_URL,
'description' => 'Target URL',
'optional' => true,
],
'targetDescription' => [
'type' => PARAM_TEXT,
'description' => 'Target description',
'null' => NULL_ALLOWED,
'optional' => true,
],
'targetFramework' => [
'type' => PARAM_TEXT,
'description' => 'Target framework',
'null' => NULL_ALLOWED,
'optional' => true,
],
'targetCode' => [
'type' => PARAM_TEXT,
'description' => 'Target code',
'null' => NULL_ALLOWED,
'optional' => true,
]
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
);
}
}
+182
View File
@@ -0,0 +1,182 @@
<?php
// 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/>.
/**
* Contains class for displaying a assertion.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use stdClass;
/**
* Class for displaying a badge competency.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assertion_exporter extends exporter {
/**
* Constructor - saves the persistent object, and the related objects.
*
* @param mixed $data - Either an stdClass or an array of values.
* @param array $related - An optional list of pre-loaded objects related to this object.
*/
public function __construct($data, $related = array()) {
// Having mixed $data is causing some issues. As this class is treating $data as an object everywhere, it can be converted
// to object at this point, to avoid errors and get the expected behaviour always.
// $data is an array when this class is a request exporter in backpack_api_mapping, but it is an object when this is
// used as a response exporter.
parent::__construct((object) $data, $related);
}
/**
* Map from a request response data to the internal structure.
*
* @param stdClass $data The remote data.
* @param string $apiversion The backpack version used to communicate remotely.
* @return stdClass
*/
public static function map_external_data($data, $apiversion) {
$mapped = new \stdClass();
if (isset($data->entityType)) {
$mapped->type = $data->entityType;
} else {
$mapped->type = $data->type;
}
if (isset($data->entityId)) {
$mapped->id = $data->entityId;
} else {
$mapped->id = $data->id;
}
if (isset($data->issuedOn)) {
$mapped->issuedOn = $data->issuedOn;
}
if (isset($data->recipient)) {
$mapped->recipient = $data->recipient;
}
if (isset($data->badgeclass)) {
$mapped->badgeclass = $data->badgeclass;
}
$propname = '@context';
$mapped->$propname = 'https://w3id.org/openbadges/v2';
return $mapped;
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return array(
'badge' => array(
'type' => badgeclass_exporter::read_properties_definition(),
'optional' => true
),
'recipient' => array(
'type' => recipient_exporter::read_properties_definition(),
'optional' => true
),
'verification' => array(
'type' => verification_exporter::read_properties_definition(),
'optional' => true
)
);
}
/**
* We map from related data passed as data to this exporter to clean exportable values.
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output) {
global $DB;
$result = [];
if (property_exists($this->data, 'related_badge')) {
$exporter = new badgeclass_exporter($this->data->related_badge, $this->related);
$result['badge'] = $exporter->export($output);
}
if (property_exists($this->data, 'related_recipient')) {
$exporter = new recipient_exporter($this->data->related_recipient, $this->related);
$result['recipient'] = $exporter->export($output);
}
if (property_exists($this->data, 'related_verify')) {
$exporter = new verification_exporter($this->data->related_verify, $this->related);
$result['verification'] = $exporter->export($output);
}
return $result;
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'type' => [
'type' => PARAM_ALPHA,
'description' => 'Issuer',
],
'id' => [
'type' => PARAM_URL,
'description' => 'Unique identifier for this assertion',
],
'badgeclass' => [
'type' => PARAM_RAW,
'description' => 'Identifier of the badge for this assertion',
'optional' => true,
],
'issuedOn' => [
'type' => PARAM_RAW,
'description' => 'Date this badge was issued',
],
'expires' => [
'type' => PARAM_RAW,
'description' => 'Date this badge will expire',
'optional' => true,
],
'@context' => [
'type' => PARAM_URL,
'description' => 'Badge version',
],
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context'
);
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
// 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/>.
/**
* Contains competency class for displaying a badge backpack.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying a badge competency.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backpack_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => [
'type' => PARAM_INT,
'description' => 'Backpack id',
],
'backpackapiurl' => [
'type' => PARAM_URL,
'description' => 'Backpack API URL',
],
'backpackweburl' => [
'type' => PARAM_URL,
'description' => 'Backpack Website URL',
],
'sitebackpack' => [
'type' => PARAM_BOOL,
'description' => 'Is this the current site backpack',
],
'apiversion' => [
'type' => PARAM_FLOAT,
'description' => 'API version supported',
],
'sortorder' => [
'type' => PARAM_INT,
'description' => 'Sort order'
]
];
}
}
+238
View File
@@ -0,0 +1,238 @@
<?php
// 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/>.
/**
* Contains class for displaying a badgeclass.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
/**
* Class for displaying a badge competency.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class badgeclass_exporter extends exporter {
/**
* Constructor - saves the persistent object, and the related objects.
*
* @param mixed $data - Either an stdClass or an array of values.
* @param array $related - An optional list of pre-loaded objects related to this object.
*/
public function __construct($data, $related = array()) {
// Having mixed $data is causing some issues. As this class is treating $data as an object everywhere, it can be converted
// to object at this point, to avoid errors and get the expected behaviour always.
// $data is an array when this class is a request exporter in backpack_api_mapping, but it is an object when this is
// used as a response exporter.
$data = (object) $data;
$pick = $this->pick_related();
foreach ($pick as $one) {
$isarray = false;
// Allow [] to mean an array of values.
if (substr($one, -2) === '[]') {
$one = substr($one, 0, -2);
$isarray = true;
}
$prefixed = 'related_' . $one;
if (property_exists($data, $one) && !array_key_exists($one, $related)) {
if ($isarray) {
$newrelated = [];
foreach ($data->$one as $item) {
$newrelated[] = (object) $item;
}
$related[$one] = $newrelated;
} else {
$related[$one] = (object) $data->$one;
}
unset($data->$one);
} else if (property_exists($data, $prefixed) && !array_key_exists($one, $related)) {
if ($isarray) {
$newrelated = [];
foreach ($data->$prefixed as $item) {
$newrelated[] = (object) $item;
}
$related[$one] = $newrelated;
} else {
$related[$one] = (object) $data->$prefixed;
}
unset($data->$prefixed);
} else if (!array_key_exists($one, $related)) {
$related[$one] = null;
}
}
parent::__construct($data, $related);
}
/**
* List properties passed in $data that should be moved to $related in the constructor.
*
* @return array A list of properties to move from $data to $related.
*/
public static function pick_related() {
return ['alignment[]', 'criteria'];
}
/**
* Map data from a request response to the internal structure.
*
* @param stdClass $data The remote data.
* @param string $apiversion The backpack version used to communicate remotely.
* @return stdClass
*/
public static function map_external_data($data, $apiversion) {
$mapped = new \stdClass();
if (isset($data->entityType)) {
$mapped->type = $data->entityType;
} else {
$mapped->type = $data->type;
}
if (isset($data->entityId)) {
$mapped->id = $data->entityId;
} else {
$mapped->id = $data->id;
}
$mapped->name = $data->name;
$mapped->image = $data->image;
$mapped->issuer = $data->issuer;
$mapped->description = $data->description;
if (isset($data->openBadgeId)) {
$mapped->hostedUrl = $data->openBadgeId;
} else {
$mapped->hostedUrl = $data->id;
}
return $mapped;
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'type' => [
'type' => PARAM_ALPHA,
'description' => 'BadgeClass',
],
'id' => [
'type' => PARAM_RAW,
'description' => 'Unique identifier for this badgeclass',
],
'issuer' => [
'type' => PARAM_RAW,
'description' => 'Unique identifier for this badgeclass',
'optional' => true,
],
'name' => [
'type' => PARAM_TEXT,
'description' => 'Name of the badgeclass',
],
'image' => [
'type' => PARAM_URL,
'description' => 'URL to the image.',
],
'description' => [
'type' => PARAM_TEXT,
'description' => 'Description of the badge class.',
],
'hostedUrl' => [
'type' => PARAM_RAW,
'description' => 'Identifier of the open badge for this assertion',
'optional' => true,
],
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
'alignment' => 'stdClass[]?',
'criteria' => 'stdClass?',
);
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return array(
'alignment' => array(
'type' => alignment_exporter::read_properties_definition(),
'optional' => true,
'multiple' => true
),
'criteriaUrl' => array(
'type' => PARAM_URL,
'optional' => true
),
'criteriaNarrative' => array(
'type' => PARAM_TEXT,
'optional' => true
)
);
}
/**
* We map from related data passed as data to this exporter to clean exportable values.
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output) {
global $DB;
$result = [];
if (array_key_exists('alignment', $this->related) && $this->related['alignment'] !== null) {
$alignment = [];
foreach ($this->related['alignment'] as $alignment) {
$exporter = new alignment_exporter($alignment, $this->related);
$alignments[] = $exporter->export($output);
}
$result['alignment'] = $alignments;
}
if (array_key_exists('criteria', $this->related) && $this->related['criteria'] !== null) {
if (property_exists($this->related['criteria'], 'id') && $this->related['criteria']->id !== null) {
$result['criteriaUrl'] = $this->related['criteria']->id;
}
if (property_exists($this->related['criteria'], 'narrative') && $this->related['criteria']->narrative !== null) {
$result['criteriaNarrative'] = $this->related['criteria']->narrative;
}
}
return $result;
}
}
+110
View File
@@ -0,0 +1,110 @@
<?php
// 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/>.
/**
* Contains class for displaying a collection.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use stdClass;
/**
* Class for displaying a badge competency.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class collection_exporter extends exporter {
/**
* Either map version 1 data to version 2 or return it untouched.
*
* @param stdClass $data The remote data.
* @param string $apiversion The backpack version used to communicate remotely.
* @return stdClass
*/
public static function map_external_data($data, $apiversion) {
if ($apiversion == OPEN_BADGES_V1) {
$result = new stdClass();
$result->entityType = 'BackpackCollection';
$result->entityId = $data->groupId;
$result->name = $data->name;
$result->description = $data->description;
$result->assertions = [];
return $result;
}
return $data;
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'entityType' => [
'type' => PARAM_ALPHA,
'description' => 'BackpackCollection',
],
'entityId' => [
'type' => PARAM_RAW,
'description' => 'Unique identifier for this collection',
],
'name' => [
'type' => PARAM_TEXT,
'description' => 'Collection name',
],
'description' => [
'type' => PARAM_TEXT,
'description' => 'Collection description',
],
'share_url' => [
'type' => PARAM_URL,
'description' => 'Url to view this collection',
],
'published' => [
'type' => PARAM_BOOL,
'description' => 'True means this collection is public.',
],
'assertions' => [
'type' => PARAM_RAW,
'description' => 'List of assertion ids in this collection',
'multiple' => true,
],
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
);
}
}
+95
View File
@@ -0,0 +1,95 @@
<?php
// 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/>.
/**
* Contains endorsement class for displaying a badge endorsement.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying a badge endorsement.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class endorsement_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => [
'type' => PARAM_INT,
'description' => 'Endorsement id',
],
'badgeid' => [
'type' => PARAM_INT,
'description' => 'Badge id',
],
'issuername' => [
'type' => PARAM_TEXT,
'description' => 'Endorsement issuer name',
],
'issuerurl' => [
'type' => PARAM_URL,
'description' => 'Endorsement issuer URL',
],
'issueremail' => [
'type' => PARAM_RAW,
'description' => 'Endorsement issuer email',
],
'claimid' => [
'type' => PARAM_URL,
'description' => 'Claim URL',
'null' => NULL_ALLOWED,
],
'claimcomment' => [
'type' => PARAM_NOTAGS,
'description' => 'Claim comment',
'null' => NULL_ALLOWED,
],
'dateissued' => [
'type' => PARAM_INT,
'description' => 'Date issued',
'default' => 0,
]
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
);
}
}
+114
View File
@@ -0,0 +1,114 @@
<?php
// 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/>.
namespace core_badges\external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_multiple_structure;
use core_external\external_value;
use core_external\external_warnings;
use moodle_exception;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/badgeslib.php');
/**
* External service to get user badge.
*
* This is mainly used by the mobile application.
*
* @package core_badges
* @category external
* @copyright 2023 Rodrigo Mady <rodrigo.mady@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 4.3
*/
class get_user_badge_by_hash extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'hash' => new external_value(PARAM_ALPHANUM, 'Badge issued hash', VALUE_REQUIRED),
]);
}
/**
* Execute the get user badge.
*
* @param string $hash
* @return array
* @throws \restricted_context_exception
*/
public static function execute(string $hash): array {
global $CFG;
// Initialize return variables.
$warnings = [];
$result = [];
// Validate the hash.
[
'hash' => $hash,
] = self::validate_parameters(self::execute_parameters(), [
'hash' => $hash,
]);
if (empty($CFG->enablebadges)) {
throw new moodle_exception('badgesdisabled', 'badges');
}
// Get the badge by hash.
$badge = badges_get_badge_by_hash($hash);
if (!empty($badge)) {
// Get the user that issued the badge.
$user = \core_user::get_user($badge->userid, '*', MUST_EXIST);
$result[] = badges_prepare_badge_for_external($badge, $user);
} else {
$warnings[] = [
'item' => $hash,
'warningcode' => 'badgeawardnotfound',
'message' => get_string('error:badgeawardnotfound', 'badges')
];
}
return [
'badge' => $result,
'warnings' => $warnings
];
}
/**
* Describe the return structure of the external service.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'badge' => new external_multiple_structure(
user_badge_exporter::get_read_structure()
),
'warnings' => new external_warnings()
]);
}
}
+109
View File
@@ -0,0 +1,109 @@
<?php
// 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/>.
/**
* Contains class for displaying a issuer.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying a badge competency.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class issuer_exporter extends exporter {
/**
* Either map version 1 data to version 2 or return it untouched.
*
* @param stdClass $data The remote data.
* @param string $apiversion The backpack version used to communicate remotely.
* @return stdClass
*/
public static function map_external_data($data, $apiversion) {
if ($apiversion == OPEN_BADGES_V1) {
$result = new \stdClass();
return $result;
}
$mapped = new \stdClass();
if (isset($data->entityType)) {
$mapped->type = $data->entityType;
} else {
$mapped->type = $data->type;
}
if (isset($data->entityId)) {
$mapped->id = $data->entityId;
} else {
$mapped->id = $data->id;
}
$mapped->name = $data->name;
$mapped->email = $data->email;
$mapped->url = $data->url;
return $mapped;
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'type' => [
'type' => PARAM_ALPHA,
'description' => 'Issuer',
],
'id' => [
'type' => PARAM_RAW,
'description' => 'Unique identifier for this issuer',
],
'name' => [
'type' => PARAM_TEXT,
'description' => 'Name of the issuer',
],
'email' => [
'type' => PARAM_EMAIL,
'description' => 'Email of the issuer',
],
'url' => [
'type' => PARAM_URL,
'description' => 'URL for this issuer',
],
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
);
}
}
+82
View File
@@ -0,0 +1,82 @@
<?php
// 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/>.
/**
* Contains class for displaying a recipient.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying a badge competency.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class recipient_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'identity' => [
'type' => PARAM_RAW,
'description' => 'Hashed email address to issue badge to.',
],
'plaintextIdentity' => [
'type' => PARAM_RAW,
'description' => 'Email address to issue badge to.',
'optional' => true,
],
'salt' => [
'type' => PARAM_RAW,
'description' => 'Salt used to hash email.',
'optional' => true,
],
'type' => [
'type' => PARAM_ALPHA,
'description' => 'Email',
],
'hashed' => [
'type' => PARAM_BOOL,
'description' => 'Should be true',
],
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
);
}
}
+85
View File
@@ -0,0 +1,85 @@
<?php
// 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/>.
/**
* Contains related class for displaying information of a related badge.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying information of a related badge.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class related_info_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => [
'type' => PARAM_INT,
'description' => 'Badge id',
],
'name' => [
'type' => PARAM_TEXT,
'description' => 'Badge name',
],
'version' => [
'type' => PARAM_TEXT,
'description' => 'Version',
'optional' => true,
'null' => NULL_ALLOWED,
],
'language' => [
'type' => PARAM_NOTAGS,
'description' => 'Language',
'optional' => true,
'null' => NULL_ALLOWED,
],
'type' => [
'type' => PARAM_INT,
'description' => 'Type',
'optional' => true,
],
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
);
}
}
+311
View File
@@ -0,0 +1,311 @@
<?php
// 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/>.
/**
* Contains user badge class for displaying a badge issued to a user.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use moodle_url;
use core_badges\external\endorsement_exporter;
use core_badges\external\alignment_exporter;
use core_badges\external\related_info_exporter;
/**
* Class for displaying a badge issued to a user.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_badge_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => [
'type' => PARAM_INT,
'description' => 'Badge id',
'optional' => true,
],
'name' => [
'type' => PARAM_TEXT,
'description' => 'Badge name',
],
'description' => [
'type' => PARAM_NOTAGS,
'description' => 'Badge description',
'null' => NULL_ALLOWED,
],
'timecreated' => [
'type' => PARAM_INT,
'description' => 'Time created',
'optional' => true,
'default' => 0,
],
'timemodified' => [
'type' => PARAM_INT,
'description' => 'Time modified',
'optional' => true,
'default' => 0,
],
'usercreated' => [
'type' => PARAM_INT,
'description' => 'User created',
'optional' => true,
],
'usermodified' => [
'type' => PARAM_INT,
'description' => 'User modified',
'optional' => true,
],
'issuername' => [
'type' => PARAM_TEXT,
'description' => 'Issuer name',
],
'issuerurl' => [
'type' => PARAM_URL,
'description' => 'Issuer URL',
],
'issuercontact' => [
'type' => PARAM_RAW,
'description' => 'Issuer contact',
'null' => NULL_ALLOWED,
],
'expiredate' => [
'type' => PARAM_INT,
'description' => 'Expire date',
'optional' => true,
'null' => NULL_ALLOWED,
],
'expireperiod' => [
'type' => PARAM_INT,
'description' => 'Expire period',
'optional' => true,
'null' => NULL_ALLOWED,
],
'type' => [
'type' => PARAM_INT,
'description' => 'Type',
'optional' => true,
'default' => 1,
],
'courseid' => [
'type' => PARAM_INT,
'description' => 'Course id',
'optional' => true,
'null' => NULL_ALLOWED,
],
'message' => [
'type' => PARAM_RAW,
'description' => 'Message',
'optional' => true,
],
'messagesubject' => [
'type' => PARAM_TEXT,
'description' => 'Message subject',
'optional' => true,
],
'attachment' => [
'type' => PARAM_INT,
'description' => 'Attachment',
'optional' => true,
'default' => 1,
],
'notification' => [
'type' => PARAM_INT,
'description' => 'Whether to notify when badge is awarded',
'optional' => true,
'default' => 1,
],
'nextcron' => [
'type' => PARAM_INT,
'description' => 'Next cron',
'optional' => true,
'null' => NULL_ALLOWED,
],
'status' => [
'type' => PARAM_INT,
'description' => 'Status',
'optional' => true,
'default' => 0,
],
'issuedid' => [
'type' => PARAM_INT,
'description' => 'Issued id',
'optional' => true,
],
'uniquehash' => [
'type' => PARAM_ALPHANUM,
'description' => 'Unique hash',
],
'dateissued' => [
'type' => PARAM_INT,
'description' => 'Date issued',
'default' => 0,
],
'dateexpire' => [
'type' => PARAM_INT,
'description' => 'Date expire',
'null' => NULL_ALLOWED,
],
'visible' => [
'type' => PARAM_INT,
'description' => 'Visible',
'optional' => true,
'default' => 0,
],
'email' => [
'type' => PARAM_TEXT,
'description' => 'User email',
'optional' => true,
],
'version' => [
'type' => PARAM_TEXT,
'description' => 'Version',
'optional' => true,
'null' => NULL_ALLOWED,
],
'language' => [
'type' => PARAM_NOTAGS,
'description' => 'Language',
'optional' => true,
'null' => NULL_ALLOWED,
],
'imageauthorname' => [
'type' => PARAM_TEXT,
'description' => 'Name of the image author',
'optional' => true,
'null' => NULL_ALLOWED,
],
'imageauthoremail' => [
'type' => PARAM_TEXT,
'description' => 'Email of the image author',
'optional' => true,
'null' => NULL_ALLOWED,
],
'imageauthorurl' => [
'type' => PARAM_URL,
'description' => 'URL of the image author',
'optional' => true,
'null' => NULL_ALLOWED,
],
'imagecaption' => [
'type' => PARAM_TEXT,
'description' => 'Caption of the image',
'optional' => true,
'null' => NULL_ALLOWED,
],
];
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return array(
'context' => 'context',
'endorsement' => 'stdClass?',
'alignment' => 'stdClass[]',
'relatedbadges' => 'stdClass[]',
);
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return [
'badgeurl' => [
'type' => PARAM_URL,
'description' => 'Badge URL',
],
'endorsement' => [
'type' => endorsement_exporter::read_properties_definition(),
'description' => 'Badge endorsement',
'optional' => true,
],
'alignment' => [
'type' => alignment_exporter::read_properties_definition(),
'description' => 'Badge alignments',
'multiple' => true,
],
'relatedbadges' => [
'type' => related_info_exporter::read_properties_definition(),
'description' => 'Related badges',
'multiple' => true,
]
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$context = $this->related['context'];
$endorsement = $this->related['endorsement'];
$alignments = $this->related['alignment'];
$relatedbadges = $this->related['relatedbadges'];
$values = array(
'badgeurl' => moodle_url::make_webservice_pluginfile_url($context->id, 'badges', 'badgeimage', $this->data->id, '/',
'f3')->out(false),
'alignment' => array(),
'relatedbadges' => array(),
);
if ($endorsement) {
$endorsementexporter = new endorsement_exporter($endorsement, array('context' => $context));
$values['endorsement'] = $endorsementexporter->export($output);
}
if (!empty($alignments)) {
foreach ($alignments as $alignment) {
$alignmentexporter = new alignment_exporter($alignment, array('context' => $context));
$values['alignment'][] = $alignmentexporter->export($output);
}
}
if (!empty($relatedbadges)) {
foreach ($relatedbadges as $badge) {
$relatedexporter = new related_info_exporter($badge, array('context' => $context));
$values['relatedbadges'][] = $relatedexporter->export($output);
}
}
return $values;
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
// 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/>.
/**
* Contains class for displaying a recipient.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_badges\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying a badge competency.
*
* @package core_badges
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class verification_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'type' => [
'type' => PARAM_ALPHA,
'description' => 'Type of verification.',
]
];
}
}