mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 13:33:52 +02:00
Merge branch 'MDL-39923_master' of https://github.com/totara/openbadges
Conflicts: version.php
This commit is contained in:
commit
d5c0f0453c
@ -116,14 +116,9 @@ function badge_message_cron() {
|
||||
* @param object $badge A badge which is notified about.
|
||||
*/
|
||||
function badge_assemble_notification(stdClass $badge) {
|
||||
global $CFG, $DB;
|
||||
global $DB;
|
||||
|
||||
$admin = get_admin();
|
||||
$userfrom = new stdClass();
|
||||
$userfrom->id = $admin->id;
|
||||
$userfrom->email = !empty($CFG->badges_defaultissuercontact) ? $CFG->badges_defaultissuercontact : $admin->email;
|
||||
$userfrom->firstname = !empty($CFG->badges_defaultissuername) ? $CFG->badges_defaultissuername : $admin->firstname;
|
||||
$userfrom->lastname = !empty($CFG->badges_defaultissuername) ? '' : $admin->lastname;
|
||||
$userfrom = core_user::get_noreply_user();
|
||||
$userfrom->maildisplay = true;
|
||||
|
||||
if ($msgs = $DB->get_records_select('badge_issued', 'issuernotified IS NULL AND badgeid = ?', array($badge->id))) {
|
||||
@ -147,15 +142,15 @@ function badge_assemble_notification(stdClass $badge) {
|
||||
// Create a message object.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->component = 'moodle';
|
||||
$eventdata->name = 'instantmessage';
|
||||
$eventdata->name = 'badgecreatornotice';
|
||||
$eventdata->userfrom = $userfrom;
|
||||
$eventdata->userto = $creator;
|
||||
$eventdata->notification = 1;
|
||||
$eventdata->subject = $creatorsubject;
|
||||
$eventdata->fullmessage = $creatormessage;
|
||||
$eventdata->fullmessage = format_text_email($creatormessage, FORMAT_HTML);
|
||||
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
||||
$eventdata->fullmessagehtml = format_text($creatormessage, FORMAT_HTML);
|
||||
$eventdata->smallmessage = '';
|
||||
$eventdata->fullmessagehtml = $creatormessage;
|
||||
$eventdata->smallmessage = $creatorsubject;
|
||||
|
||||
message_send($eventdata);
|
||||
}
|
||||
|
@ -225,6 +225,9 @@ class edit_message_form extends moodleform {
|
||||
|
||||
$mform->addElement('advcheckbox', 'attachment', get_string('attachment', 'badges'), '', null, array(0, 1));
|
||||
$mform->addHelpButton('attachment', 'attachment', 'badges');
|
||||
if (empty($CFG->allowattachments)) {
|
||||
$mform->freeze('attachment');
|
||||
}
|
||||
|
||||
$options = array(
|
||||
BADGE_MESSAGE_NEVER => get_string('never'),
|
||||
|
@ -166,6 +166,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_badge_awards() {
|
||||
$this->preventResetByRollback(); // Messaging is not compatible with transactions.
|
||||
$badge = new badge($this->badgeid);
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
|
||||
@ -225,6 +226,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
* Test badges observer when course module completion event id fired.
|
||||
*/
|
||||
public function test_badges_observer_course_module_criteria_review() {
|
||||
$this->preventResetByRollback(); // Messaging is not compatible with transactions.
|
||||
$badge = new badge($this->coursebadge);
|
||||
$this->assertFalse($badge->is_issued($this->user->id));
|
||||
|
||||
@ -257,6 +259,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
* Test badges observer when course_completed event is fired.
|
||||
*/
|
||||
public function test_badges_observer_course_criteria_review() {
|
||||
$this->preventResetByRollback(); // Messaging is not compatible with transactions.
|
||||
$badge = new badge($this->coursebadge);
|
||||
$this->assertFalse($badge->is_issued($this->user->id));
|
||||
|
||||
@ -282,6 +285,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
* Test badges observer when user_updated event is fired.
|
||||
*/
|
||||
public function test_badges_observer_profile_criteria_review() {
|
||||
$this->preventResetByRollback(); // Messaging is not compatible with transactions.
|
||||
$badge = new badge($this->coursebadge);
|
||||
$this->assertFalse($badge->is_issued($this->user->id));
|
||||
|
||||
@ -304,6 +308,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
* Test badges assertion generated when a badge is issued.
|
||||
*/
|
||||
public function test_badges_assertion() {
|
||||
$this->preventResetByRollback(); // Messaging is not compatible with transactions.
|
||||
$badge = new badge($this->coursebadge);
|
||||
$this->assertFalse($badge->is_issued($this->user->id));
|
||||
|
||||
|
@ -56,7 +56,7 @@ $string['anymethodcourseset'] = 'Any of the selected courses is complete';
|
||||
$string['anymethodmanual'] = 'Any of the selected roles awards the badge';
|
||||
$string['anymethodprofile'] = 'Any of the selected profile fields has been completed';
|
||||
$string['attachment'] = 'Attach badge to message';
|
||||
$string['attachment_help'] = 'If checked, an issued badge will be attached to the recepient\'s email for download';
|
||||
$string['attachment_help'] = 'If checked, an issued badge file will be attached to the recepient\'s email for download. Email attachments must be enabled in site settings to use this option.';
|
||||
$string['award'] = 'Award badge';
|
||||
$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.';
|
||||
|
@ -1087,6 +1087,8 @@ $string['messagedselectedusers'] = 'Selected users have been messaged and the re
|
||||
$string['messagedselectedusersfailed'] = 'Something went wrong while messaging selected users. Some may have received the email.';
|
||||
$string['messageprovider:availableupdate'] = 'Available update notifications';
|
||||
$string['messageprovider:backup'] = 'Backup notifications';
|
||||
$string['messageprovider:badgecreatornotice'] = 'Badge creator notifications';
|
||||
$string['messageprovider:badgerecipientnotice'] = 'Badge recipient notifications';
|
||||
$string['messageprovider:courserequestapproved'] = 'Course creation request approval notification';
|
||||
$string['messageprovider:courserequested'] = 'Course creation request notification';
|
||||
$string['messageprovider:courserequestrejected'] = 'Course creation request rejection notification';
|
||||
|
@ -632,27 +632,36 @@ function badges_notify_badge_award(badge $badge, $userid, $issued, $filepathhash
|
||||
$message = badge_message_from_template($badge->message, $params);
|
||||
$plaintext = format_text_email($message, FORMAT_HTML);
|
||||
|
||||
// TODO: $filepathhash may be moodle_url instance too...
|
||||
// Notify recipient.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->component = 'moodle';
|
||||
$eventdata->name = 'badgerecipientnotice';
|
||||
$eventdata->userfrom = $userfrom;
|
||||
$eventdata->userto = $userto;
|
||||
$eventdata->notification = 1;
|
||||
$eventdata->subject = $badge->messagesubject;
|
||||
$eventdata->fullmessage = $plaintext;
|
||||
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
||||
$eventdata->fullmessagehtml = $message;
|
||||
$eventdata->smallmessage = $plaintext;
|
||||
|
||||
if ($badge->attachment && is_string($filepathhash)) {
|
||||
// Attach badge image if possible.
|
||||
if (!empty($CFG->allowattachments) && $badge->attachment && is_string($filepathhash)) {
|
||||
$fs = get_file_storage();
|
||||
$file = $fs->get_file_by_hash($filepathhash);
|
||||
$attachment = $file->copy_content_to_temp();
|
||||
email_to_user($userto,
|
||||
$userfrom,
|
||||
$badge->messagesubject,
|
||||
$plaintext,
|
||||
$message,
|
||||
str_replace($CFG->dataroot, '', $attachment),
|
||||
str_replace(' ', '_', $badge->name) . ".png"
|
||||
);
|
||||
@unlink($attachment);
|
||||
$eventdata->attachment = $file;
|
||||
$eventdata->attachname = str_replace(' ', '_', $badge->name) . ".png";
|
||||
|
||||
message_send($eventdata);
|
||||
} else {
|
||||
email_to_user($userto, $userfrom, $badge->messagesubject, $plaintext, $message);
|
||||
message_send($eventdata);
|
||||
}
|
||||
|
||||
// Notify badge creator about the award if they receive notifications every time.
|
||||
if ($badge->notification == 1) {
|
||||
$userfrom = core_user::get_noreply_user();
|
||||
$userfrom->maildisplay = true;
|
||||
|
||||
$creator = $DB->get_record('user', array('id' => $badge->usercreated), '*', MUST_EXIST);
|
||||
$a = new stdClass();
|
||||
$a->user = fullname($userto);
|
||||
@ -662,15 +671,15 @@ function badges_notify_badge_award(badge $badge, $userid, $issued, $filepathhash
|
||||
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->component = 'moodle';
|
||||
$eventdata->name = 'instantmessage';
|
||||
$eventdata->name = 'badgecreatornotice';
|
||||
$eventdata->userfrom = $userfrom;
|
||||
$eventdata->userto = $creator;
|
||||
$eventdata->notification = 1;
|
||||
$eventdata->subject = $creatorsubject;
|
||||
$eventdata->fullmessage = $creatormessage;
|
||||
$eventdata->fullmessage = format_text_email($creatormessage, FORMAT_HTML);
|
||||
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
||||
$eventdata->fullmessagehtml = format_text($creatormessage, FORMAT_HTML);
|
||||
$eventdata->smallmessage = '';
|
||||
$eventdata->fullmessagehtml = $creatormessage;
|
||||
$eventdata->smallmessage = $creatorsubject;
|
||||
|
||||
message_send($eventdata);
|
||||
$DB->set_field('badge_issued', 'issuernotified', time(), array('badgeid' => $badge->id, 'userid' => $userid));
|
||||
@ -969,10 +978,17 @@ function badges_bake($hash, $badgeid, $userid = 0, $pathhash = false) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debugging('Error baking badge image!');
|
||||
debugging('Error baking badge image!', DEBUG_DEVELOPER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If file exists and we just need its path hash, return it.
|
||||
if ($pathhash) {
|
||||
$file = $fs->get_file($user_context->id, 'badges', 'userbadge', $badge->id, '/', $hash . '.png');
|
||||
return $file->get_pathnamehash();
|
||||
}
|
||||
|
||||
$fileurl = moodle_url::make_pluginfile_url($user_context->id, 'badges', 'userbadge', $badge->id, '/', $hash, true);
|
||||
return $fileurl;
|
||||
}
|
||||
|
@ -78,6 +78,21 @@ $messageproviders = array (
|
||||
// Course request rejection notification
|
||||
'courserequestrejected' => array (
|
||||
'capability' => 'moodle/course:request'
|
||||
)
|
||||
),
|
||||
|
||||
// Badge award notification to a badge recipient.
|
||||
'badgerecipientnotice' => array (
|
||||
'defaults' => array(
|
||||
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
|
||||
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDOFF,
|
||||
),
|
||||
'capability' => 'moodle/badges:earnbadge'
|
||||
),
|
||||
|
||||
// Badge award notification to a badge creator (mostly cron-based).
|
||||
'badgecreatornotice' => array (
|
||||
'defaults' => array(
|
||||
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDOFF,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2013110600.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2013111100.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user