MDL-72354 badges: Show always issuer details when creating badges
Co-author: Huynh Nguyen
This commit is contained in:
@@ -168,14 +168,6 @@ class badge {
|
||||
}
|
||||
}
|
||||
|
||||
if (badges_open_badges_backpack_api() != OPEN_BADGES_V1) {
|
||||
// For Open Badges 2 we need to use a single site issuer with no exceptions.
|
||||
$issuer = badges_get_default_issuer();
|
||||
$this->issuername = $issuer['name'];
|
||||
$this->issuercontact = $issuer['email'];
|
||||
$this->issuerurl = $issuer['url'];
|
||||
}
|
||||
|
||||
$this->criteria = self::get_criteria();
|
||||
}
|
||||
|
||||
@@ -1020,17 +1012,9 @@ class badge {
|
||||
$fordb->timemodified = $now;
|
||||
$fordb->usercreated = $USER->id;
|
||||
$fordb->usermodified = $USER->id;
|
||||
|
||||
if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
|
||||
$fordb->issuername = $data->issuername;
|
||||
$fordb->issuerurl = $data->issuerurl;
|
||||
$fordb->issuercontact = $data->issuercontact;
|
||||
} else {
|
||||
$url = parse_url($CFG->wwwroot);
|
||||
$fordb->issuerurl = $url['scheme'] . '://' . $url['host'];
|
||||
$fordb->issuername = $CFG->badges_defaultissuername;
|
||||
$fordb->issuercontact = $CFG->badges_defaultissuercontact;
|
||||
}
|
||||
$fordb->issuername = $data->issuername;
|
||||
$fordb->issuerurl = $data->issuerurl;
|
||||
$fordb->issuercontact = $data->issuercontact;
|
||||
|
||||
if (!property_exists($data, 'expiry')) {
|
||||
$data->expiry = 0;
|
||||
@@ -1087,11 +1071,9 @@ class badge {
|
||||
$this->imageauthorurl = $data->imageauthorurl;
|
||||
$this->imagecaption = $data->imagecaption;
|
||||
$this->usermodified = $USER->id;
|
||||
if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
|
||||
$this->issuername = $data->issuername;
|
||||
$this->issuerurl = $data->issuerurl;
|
||||
$this->issuercontact = $data->issuercontact;
|
||||
}
|
||||
$this->issuername = $data->issuername;
|
||||
$this->issuerurl = $data->issuerurl;
|
||||
$this->issuercontact = $data->issuercontact;
|
||||
$this->expiredate = ($data->expiry == 1) ? $data->expiredate : null;
|
||||
$this->expireperiod = ($data->expiry == 2) ? $data->expireperiod : null;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class badge extends moodleform {
|
||||
* Defines the form
|
||||
*/
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
global $CFG, $SITE;
|
||||
|
||||
$mform = $this->_form;
|
||||
$badge = (isset($this->_customdata['badge'])) ? $this->_customdata['badge'] : false;
|
||||
@@ -97,29 +97,28 @@ class badge extends moodleform {
|
||||
$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'));
|
||||
$mform->addElement('header', 'issuerdetails', get_string('issuerdetails', 'badges'));
|
||||
|
||||
$mform->addElement('text', 'issuername', get_string('name'), ['size' => '70']);
|
||||
$mform->setType('issuername', PARAM_NOTAGS);
|
||||
$mform->addRule('issuername', null, 'required');
|
||||
if (isset($CFG->badges_defaultissuername)) {
|
||||
$mform->setDefault('issuername', $CFG->badges_defaultissuername);
|
||||
}
|
||||
$mform->addHelpButton('issuername', 'issuername', 'badges');
|
||||
$mform->addElement('text', 'issuername', get_string('issuername', 'badges'), ['size' => '70']);
|
||||
$mform->setType('issuername', PARAM_NOTAGS);
|
||||
$mform->addRule('issuername', null, 'required');
|
||||
$site = get_site();
|
||||
$issuername = $CFG->badges_defaultissuername ?: $site->fullname;
|
||||
$mform->setDefault('issuername', $issuername);
|
||||
$mform->addHelpButton('issuername', 'issuername', 'badges');
|
||||
|
||||
$mform->addElement('text', 'issuercontact', get_string('contact', 'badges'), ['size' => '70']);
|
||||
if (isset($CFG->badges_defaultissuercontact)) {
|
||||
$mform->setDefault('issuercontact', $CFG->badges_defaultissuercontact);
|
||||
}
|
||||
$mform->setType('issuercontact', PARAM_RAW);
|
||||
$mform->addHelpButton('issuercontact', 'contact', 'badges');
|
||||
// Set issuer URL.
|
||||
// Have to parse URL because badge issuer origin cannot be a subfolder in wwwroot.
|
||||
$url = parse_url($CFG->wwwroot);
|
||||
$mform->addElement('hidden', 'issuerurl', $url['scheme'] . '://' . $url['host']);
|
||||
$mform->setType('issuerurl', PARAM_URL);
|
||||
$mform->addElement('text', 'issuercontact', get_string('contact', 'badges'), ['size' => '70']);
|
||||
if (isset($CFG->badges_defaultissuercontact)) {
|
||||
$mform->setDefault('issuercontact', $CFG->badges_defaultissuercontact);
|
||||
}
|
||||
$mform->setType('issuercontact', PARAM_RAW);
|
||||
$mform->addRule('issuercontact', null, 'email');
|
||||
$mform->addHelpButton('issuercontact', 'contact', 'badges');
|
||||
// Set issuer URL.
|
||||
// Have to parse URL because badge issuer origin cannot be a subfolder in wwwroot.
|
||||
$url = parse_url($CFG->wwwroot);
|
||||
$mform->addElement('hidden', 'issuerurl', $url['scheme'] . '://' . $url['host']);
|
||||
$mform->setType('issuerurl', PARAM_URL);
|
||||
|
||||
$mform->addElement('header', 'issuancedetails', get_string('issuancedetails', 'badges'));
|
||||
|
||||
@@ -211,12 +210,6 @@ class badge extends moodleform {
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
|
||||
if (!empty($data['issuercontact']) && !validate_email($data['issuercontact'])) {
|
||||
$errors['issuercontact'] = get_string('invalidemail');
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['expiry'] == 2 && $data['expireperiod'] <= 0) {
|
||||
$errors['expirydategr'] = get_string('error:invalidexpireperiod', 'badges');
|
||||
}
|
||||
|
||||
@@ -201,6 +201,11 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
$dl = array();
|
||||
$dl[get_string('issuername', 'badges')] = $badge->issuername;
|
||||
$dl[get_string('contact', 'badges')] = html_writer::tag('a', $badge->issuercontact, array('href' => 'mailto:' . $badge->issuercontact));
|
||||
$dl[get_string('issuerurl', 'badges')] = html_writer::tag(
|
||||
'a',
|
||||
$badge->issuerurl,
|
||||
['href' => $badge->issuerurl, 'target' => '_blank'],
|
||||
);
|
||||
$display .= $this->definition_list($dl);
|
||||
|
||||
// Issuance details if any.
|
||||
|
||||
@@ -20,20 +20,22 @@ Feature: Add badges to the system
|
||||
Then I should see "There are currently no badges available for users to earn."
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Add a badge
|
||||
Given I navigate to "Badges > Badges settings" in site administration
|
||||
And I set the field "Badge issuer name" to "Test Badge Site"
|
||||
And I set the field "Badge issuer email address" to "testuser@example.com"
|
||||
And I press "Save changes"
|
||||
Scenario: Add a site badge
|
||||
Given the following config values are set as admin:
|
||||
| badges_defaultissuername | Test Badge Site |
|
||||
| badges_defaultissuercontact | testuser@example.com |
|
||||
And I navigate to "Badges > Add a new badge" in site administration
|
||||
And the field "Issuer name" matches value "Test Badge Site"
|
||||
And the field "Issuer contact" matches value "testuser@example.com"
|
||||
And I set the following fields to these values:
|
||||
| Name | Test badge with 'apostrophe' and other friends (<>&@#) |
|
||||
| Version | v1 |
|
||||
| Language | English |
|
||||
| Description | Test badge description |
|
||||
| Image author | http://author.example.com |
|
||||
| Image caption | Test caption image |
|
||||
| Tags | Math, Physics |
|
||||
| Name | Test badge with 'apostrophe' and other friends (<>&@#) |
|
||||
| Version | v1 |
|
||||
| Language | English |
|
||||
| Description | Test badge description |
|
||||
| Image author | http://author.example.com |
|
||||
| Image caption | Test caption image |
|
||||
| Tags | Math, Physics |
|
||||
| Issuer contact | issuer@example.com |
|
||||
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
|
||||
When I press "Create badge"
|
||||
Then I should see "Edit details"
|
||||
@@ -42,11 +44,11 @@ Feature: Add badges to the system
|
||||
And I should see "Related badges (0)"
|
||||
And I should see "Alignments (0)"
|
||||
And I should not see "Create badge"
|
||||
And I should not see "Issuer details"
|
||||
And I select "Overview" from the "jump" singleselect
|
||||
And I should see "Issuer details"
|
||||
And I should see "Test Badge Site"
|
||||
And I should see "testuser@example.com"
|
||||
And I should see "issuer@example.com"
|
||||
And I should not see "testuser@example.com"
|
||||
And I should see "Tags"
|
||||
And I should see "Math"
|
||||
And I should see "Physics"
|
||||
@@ -172,37 +174,49 @@ Feature: Add badges to the system
|
||||
And I should see "Add a new badge"
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Edit a badge
|
||||
Given I navigate to "Badges > Badges settings" in site administration
|
||||
And I set the field "Badge issuer name" to "Test Badge Site"
|
||||
And I set the field "Badge issuer email address" to "testuser@example.com"
|
||||
And I press "Save changes"
|
||||
And I navigate to "Badges > Add a new badge" in site administration
|
||||
Scenario: Edit a site badge
|
||||
Given the following "core_badges > Badge" exists:
|
||||
| name | Site badge |
|
||||
| status | inactive |
|
||||
| version | 1 |
|
||||
| language | ca |
|
||||
| description | Test badge description |
|
||||
| image | badges/tests/behat/badge.png |
|
||||
| imageauthorurl | http://imtheauthor.example.com |
|
||||
| imagecaption | My caption image |
|
||||
| issuercontact | testuser@example.com |
|
||||
And the following "core_badges > Criterias" exist:
|
||||
| badge | role |
|
||||
| Site badge | editingteacher |
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
When I press "Edit" action in the "Site badge" report row
|
||||
And I should see "Site badge"
|
||||
And the field "Issuer contact" matches value "testuser@example.com"
|
||||
And I set the following fields to these values:
|
||||
| Name | Test badge with 'apostrophe' and other friends (<>&@#) |
|
||||
| Version | firstversion |
|
||||
| Language | English |
|
||||
| Description | Test badge description |
|
||||
| Image author | http://author.example.com |
|
||||
| Image caption | Test caption image |
|
||||
| Tags | Math, Physics |
|
||||
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
|
||||
And I press "Create badge"
|
||||
When I select "Edit details" from the "jump" singleselect
|
||||
And I should see "Test badge with 'apostrophe' and other friends (&@#)"
|
||||
And I should not see "Issuer details"
|
||||
And I should see "Math"
|
||||
And I should see "Physics"
|
||||
And I set the following fields to these values:
|
||||
| Name | Test badge renamed |
|
||||
| Version | secondversion |
|
||||
| Tags | Math, History |
|
||||
| Name | Test badge with 'apostrophe' and other friends (<>&@#) |
|
||||
| Version | secondversion |
|
||||
| Language | English |
|
||||
| Description | Modified test badge description |
|
||||
| Image author | http://author.example.com |
|
||||
| Image caption | Test caption image |
|
||||
| Tags | Math, History |
|
||||
| Issuer contact | issuer@invalid.cat |
|
||||
And I press "Save changes"
|
||||
And I select "Overview" from the "jump" singleselect
|
||||
Then I should not see "Test badge with 'apostrophe' and other friends (&@#)"
|
||||
And I should not see "firstversion"
|
||||
And I should not see "Math, Physics"
|
||||
And I should see "Test badge renamed"
|
||||
And I expand all fieldsets
|
||||
Then I should see "Test badge with 'apostrophe' and other friends (&@#)"
|
||||
And I should not see "Site badge"
|
||||
And I should see "secondversion"
|
||||
And I should not see "firstversion"
|
||||
And I should see "Math"
|
||||
And I should see "History"
|
||||
And I should see "issuer@invalid.cat"
|
||||
And I should not see "testuser@example.com"
|
||||
|
||||
Scenario: Default value for issuer name
|
||||
When I navigate to "Badges > Add a new badge" in site administration
|
||||
Then the field "Issuer name" matches value "Acceptance test site"
|
||||
But the following config values are set as admin:
|
||||
| badges_defaultissuername | Test Badge Site |
|
||||
And I navigate to "Badges > Add a new badge" in site administration
|
||||
And the field "Issuer name" matches value "Test Badge Site"
|
||||
|
||||
+1
-1
@@ -191,7 +191,7 @@ $string['configuremessage'] = 'Badge message';
|
||||
$string['connect'] = 'Connect';
|
||||
$string['connected'] = 'Connected';
|
||||
$string['connecting'] = 'Connecting...';
|
||||
$string['contact'] = 'Contact';
|
||||
$string['contact'] = 'Issuer contact';
|
||||
$string['contact_help'] = 'An email address associated with the badge issuer.';
|
||||
$string['copy'] = 'Copy';
|
||||
$string['copyof'] = 'Copy of {$a}';
|
||||
|
||||
Reference in New Issue
Block a user