MDL-73325 core_badges: Add tags field to BadgeClass
This commit is contained in:
@@ -161,6 +161,10 @@ class core_badges_assertion {
|
||||
if (!empty($this->_data->dateexpire)) {
|
||||
$assertion['expires'] = $this->_data->dateexpire;
|
||||
}
|
||||
$tags = $this->get_tags();
|
||||
if (is_array($tags) && count($tags) > 0) {
|
||||
$assertion['tags'] = $tags;
|
||||
}
|
||||
$this->embed_data_badge_version2($assertion, OPEN_BADGES_V2_TYPE_ASSERTION);
|
||||
}
|
||||
return $assertion;
|
||||
@@ -205,6 +209,10 @@ class core_badges_assertion {
|
||||
$issuerurl = new moodle_url('/badges/issuer_json.php', $params);
|
||||
$class['issuer'] = $issuerurl->out(false);
|
||||
}
|
||||
$tags = $this->get_tags();
|
||||
if (is_array($tags) && count($tags) > 0) {
|
||||
$class['tags'] = $tags;
|
||||
}
|
||||
$this->embed_data_badge_version2($class, OPEN_BADGES_V2_TYPE_BADGE);
|
||||
if (!$issued) {
|
||||
unset($class['issuer']);
|
||||
@@ -404,4 +412,13 @@ class core_badges_assertion {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tags of the badge.
|
||||
*
|
||||
* @return array tags.
|
||||
*/
|
||||
public function get_tags(): array {
|
||||
return array_values(\core_tag_tag::get_item_tags_array('core_badges', 'badge', $this->get_badge_id()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +302,7 @@ class badge {
|
||||
$fordb->usermodified = $USER->id;
|
||||
$fordb->timecreated = time();
|
||||
$fordb->timemodified = time();
|
||||
$tags = $this->get_badge_tags();
|
||||
unset($fordb->id);
|
||||
|
||||
if ($fordb->notification > 1) {
|
||||
@@ -313,6 +314,8 @@ class badge {
|
||||
|
||||
if ($new = $DB->insert_record('badge', $fordb, true)) {
|
||||
$newbadge = new badge($new);
|
||||
// Copy badge tags.
|
||||
\core_tag_tag::set_item_tags('core_badges', 'badge', $newbadge->id, $this->get_context(), $tags);
|
||||
|
||||
// Copy badge image.
|
||||
$fs = get_file_storage();
|
||||
@@ -745,6 +748,9 @@ class badge {
|
||||
$DB->delete_records_select('badge_related', $relatedsql, $relatedparams);
|
||||
$DB->delete_records('badge_alignment', array('badgeid' => $this->id));
|
||||
|
||||
// Delete all tags.
|
||||
\core_tag_tag::remove_all_item_tags('core_badges', 'badge', $this->id);
|
||||
|
||||
// Finally, remove badge itself.
|
||||
$DB->delete_records('badge', array('id' => $this->id));
|
||||
|
||||
@@ -976,4 +982,13 @@ class badge {
|
||||
|
||||
return $issuer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tags of badge.
|
||||
*
|
||||
* @return array Badge tags.
|
||||
*/
|
||||
public function get_badge_tags(): array {
|
||||
return array_values(\core_tag_tag::get_item_tags_array('core_badges', 'badge', $this->id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class badge extends moodleform {
|
||||
$mform->addElement('text', 'imagecaption', get_string('imagecaption', 'badges'), array('size' => '70'));
|
||||
$mform->setType('imagecaption', PARAM_TEXT);
|
||||
$mform->addHelpButton('imagecaption', 'imagecaption', 'badges');
|
||||
|
||||
$mform->addElement('tags', 'tags', get_string('tags', 'badges'), ['itemtype' => 'badge', 'component' => 'core_badges']);
|
||||
|
||||
if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
|
||||
$mform->addElement('header', 'issuerdetails', get_string('issuerdetails', 'badges'));
|
||||
@@ -173,22 +173,23 @@ class badge extends moodleform {
|
||||
/**
|
||||
* Load in existing data as form defaults
|
||||
*
|
||||
* @param stdClass|array $default_values object or array of default values
|
||||
* @param stdClass|array $badge object or array of default values
|
||||
*/
|
||||
public function set_data($badge) {
|
||||
$default_values = array();
|
||||
$defaultvalues = [];
|
||||
parent::set_data($badge);
|
||||
|
||||
if (!empty($badge->expiredate)) {
|
||||
$default_values['expiry'] = 1;
|
||||
$default_values['expiredate'] = $badge->expiredate;
|
||||
$defaultvalues['expiry'] = 1;
|
||||
$defaultvalues['expiredate'] = $badge->expiredate;
|
||||
} else if (!empty($badge->expireperiod)) {
|
||||
$default_values['expiry'] = 2;
|
||||
$default_values['expireperiod'] = $badge->expireperiod;
|
||||
$defaultvalues['expiry'] = 2;
|
||||
$defaultvalues['expireperiod'] = $badge->expireperiod;
|
||||
}
|
||||
$default_values['currentimage'] = print_badge_image($badge, $badge->get_context(), 'large');
|
||||
$defaultvalues['tags'] = \core_tag_tag::get_item_tags_array('core_badges', 'badge', $badge->id);
|
||||
$defaultvalues['currentimage'] = print_badge_image($badge, $badge->get_context(), 'large');
|
||||
|
||||
parent::set_data($default_values);
|
||||
parent::set_data($defaultvalues);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -170,6 +170,11 @@ class badgeclass implements renderable {
|
||||
}
|
||||
}
|
||||
|
||||
// Field: Tags.
|
||||
$tags = \core_tag_tag::get_item_tags('core_badges', 'badge', $this->badgeid);
|
||||
$taglist = new \core_tag\output\taglist($tags);
|
||||
$data->badgetag = $taglist->export_for_template($output);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +242,11 @@ class issued_badge implements renderable {
|
||||
}
|
||||
}
|
||||
|
||||
// Field: Tags.
|
||||
$tags = \core_tag_tag::get_item_tags('core_badges', 'badge', $this->badgeid);
|
||||
$taglist = new \core_tag\output\taglist($tags);
|
||||
$data->badgetag = $taglist->export_for_template($output);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user