Merge branch 'MDL-65191-master' of git://github.com/lameze/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 8 Apr 2019 22:46:47 +0000 (00:46 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 8 Apr 2019 22:46:47 +0000 (00:46 +0200)
1  2 
lang/en/admin.php
lib/badgeslib.php
lib/db/tasks.php
version.php

Simple merge
@@@ -1555,59 -1533,49 +1555,106 @@@ function badges_setup_backpack_js() 
      }
  }
  
 +/**
 + * Return all the enabled criteria types for this site.
 + *
 + * @param boolean $enabled
 + * @return array
 + */
 +function badges_list_criteria($enabled = true) {
 +    global $CFG;
 +
 +    $types = array(
 +        BADGE_CRITERIA_TYPE_OVERALL    => 'overall',
 +        BADGE_CRITERIA_TYPE_ACTIVITY   => 'activity',
 +        BADGE_CRITERIA_TYPE_MANUAL     => 'manual',
 +        BADGE_CRITERIA_TYPE_SOCIAL     => 'social',
 +        BADGE_CRITERIA_TYPE_COURSE     => 'course',
 +        BADGE_CRITERIA_TYPE_COURSESET  => 'courseset',
 +        BADGE_CRITERIA_TYPE_PROFILE    => 'profile',
 +        BADGE_CRITERIA_TYPE_BADGE      => 'badge',
 +        BADGE_CRITERIA_TYPE_COHORT     => 'cohort',
 +        BADGE_CRITERIA_TYPE_COMPETENCY => 'competency',
 +    );
 +    if ($enabled) {
 +        foreach ($types as $key => $type) {
 +            $class = 'award_criteria_' . $type;
 +            $file = $CFG->dirroot . '/badges/criteria/' . $class . '.php';
 +            if (file_exists($file)) {
 +                require_once($file);
 +
 +                if (!$class::is_enabled()) {
 +                    unset($types[$key]);
 +                }
 +            }
 +        }
 +    }
 +    return $types;
 +}
 +
 +/**
 + * Check if any badge has records for competencies.
 + *
 + * @param array $competencyids Array of competencies ids.
 + * @return boolean Return true if competencies were found in any badge.
 + */
 +function badge_award_criteria_competency_has_records_for_competencies($competencyids) {
 +    global $DB;
 +
 +    list($insql, $params) = $DB->get_in_or_equal($competencyids, SQL_PARAMS_NAMED);
 +
 +    $sql = "SELECT DISTINCT bc.badgeid
 +                FROM {badge_criteria} bc
 +                JOIN {badge_criteria_param} bcp ON bc.id = bcp.critid
 +                WHERE bc.criteriatype = :criteriatype AND bcp.value $insql";
 +    $params['criteriatype'] = BADGE_CRITERIA_TYPE_COMPETENCY;
 +
 +    return $DB->record_exists_sql($sql, $params);
 +}
++
+ /**
+  * Creates single message for all notification and sends it out
+  *
+  * @param object $badge A badge which is notified about.
+  */
+ function badge_assemble_notification(stdClass $badge) {
+     global $DB;
+     $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))) {
+         // Get badge creator.
+         $creator = $DB->get_record('user', array('id' => $badge->creator), '*', MUST_EXIST);
+         $creatorsubject = get_string('creatorsubject', 'badges', $badge->name);
+         $creatormessage = '';
+         // Put all messages in one digest.
+         foreach ($msgs as $msg) {
+             $issuedlink = html_writer::link(new moodle_url('/badges/badge.php', array('hash' => $msg->uniquehash)), $badge->name);
+             $recipient = $DB->get_record('user', array('id' => $msg->userid), '*', MUST_EXIST);
+             $a = new stdClass();
+             $a->user = fullname($recipient);
+             $a->link = $issuedlink;
+             $creatormessage .= get_string('creatorbody', 'badges', $a);
+             $DB->set_field('badge_issued', 'issuernotified', time(), array('badgeid' => $msg->badgeid, 'userid' => $msg->userid));
+         }
+         // Create a message object.
+         $eventdata = new \core\message\message();
+         $eventdata->courseid          = SITEID;
+         $eventdata->component         = 'moodle';
+         $eventdata->name              = 'badgecreatornotice';
+         $eventdata->userfrom          = $userfrom;
+         $eventdata->userto            = $creator;
+         $eventdata->notification      = 1;
+         $eventdata->subject           = $creatorsubject;
+         $eventdata->fullmessage       = format_text_email($creatormessage, FORMAT_HTML);
+         $eventdata->fullmessageformat = FORMAT_PLAIN;
+         $eventdata->fullmessagehtml   = $creatormessage;
+         $eventdata->smallmessage      = $creatorsubject;
+         message_send($eventdata);
+     }
+ }
Simple merge
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2019040600.02;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2019032200.01;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2019040600.03;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.