Пример #1
0
 * @subpackage badges
 * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @author     Yuliya Bozhko <*****@*****.**>
 */
require_once dirname(dirname(__FILE__)) . '/config.php';
require_once $CFG->libdir . '/badgeslib.php';
$id = required_param('hash', PARAM_ALPHANUM);
$bake = optional_param('bake', 0, PARAM_BOOL);
$PAGE->set_context(context_system::instance());
$output = $PAGE->get_renderer('core', 'badges');
$badge = new issued_badge($id);
if ($bake && $badge->recipient->id == $USER->id) {
    $name = str_replace(' ', '_', $badge->badgeclass['name']) . '.png';
    ob_start();
    $file = badges_bake($id, $badge->badgeid);
    header('Content-Type: image/png');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    readfile($file);
    ob_flush();
}
$PAGE->set_url('/badges/badge.php', array('hash' => $id));
$PAGE->set_pagelayout('base');
$PAGE->set_title(get_string('issuedbadge', 'badges'));
if (isloggedin()) {
    $PAGE->set_heading($badge->badgeclass['name']);
    $PAGE->navbar->add($badge->badgeclass['name']);
    if ($badge->recipient->id == $USER->id) {
        $url = new moodle_url('/badges/mybadges.php');
    } else {
        $url = new moodle_url($CFG->wwwroot);
Пример #2
0
if ($clearsearch) {
    $search = '';
}
if ($hide) {
    require_sesskey();
    $DB->set_field('badge_issued', 'visible', 0, array('id' => $hide, 'userid' => $USER->id));
} else {
    if ($show) {
        require_sesskey();
        $DB->set_field('badge_issued', 'visible', 1, array('id' => $show, 'userid' => $USER->id));
    } else {
        if ($download && $hash) {
            require_sesskey();
            $badge = new badge($download);
            $name = str_replace(' ', '_', $badge->name) . '.png';
            $filehash = badges_bake($hash, $download, $USER->id, true);
            $fs = get_file_storage();
            $file = $fs->get_file_by_hash($filehash);
            send_stored_file($file, 0, 0, true, array('filename' => $name));
        } else {
            if ($downloadall) {
                require_sesskey();
                badges_download($USER->id);
            }
        }
    }
}
$context = context_user::instance($USER->id);
require_capability('moodle/badges:manageownbadges', $context);
$PAGE->set_context($context);
$title = get_string('mybadges', 'badges');
Пример #3
0
 * @subpackage badges
 * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @author     Yuliya Bozhko <*****@*****.**>
 */
require_once __DIR__ . '/../config.php';
require_once $CFG->libdir . '/badgeslib.php';
require_once $CFG->libdir . '/filelib.php';
$id = required_param('hash', PARAM_ALPHANUM);
$bake = optional_param('bake', 0, PARAM_BOOL);
$PAGE->set_context(context_system::instance());
$output = $PAGE->get_renderer('core', 'badges');
$badge = new issued_badge($id);
if ($bake && $badge->recipient->id == $USER->id) {
    $name = str_replace(' ', '_', $badge->badgeclass['name']) . '.png';
    $filehash = badges_bake($id, $badge->badgeid, $USER->id, true);
    $fs = get_file_storage();
    $file = $fs->get_file_by_hash($filehash);
    send_stored_file($file, 0, 0, true, array('filename' => $name));
}
$PAGE->set_url('/badges/badge.php', array('hash' => $id));
$PAGE->set_pagelayout('base');
$PAGE->set_title(get_string('issuedbadge', 'badges'));
if (isloggedin()) {
    $PAGE->set_heading($badge->badgeclass['name']);
    $PAGE->navbar->add($badge->badgeclass['name']);
    if ($badge->recipient->id == $USER->id) {
        $url = new moodle_url('/badges/mybadges.php');
    } else {
        $url = new moodle_url($CFG->wwwroot);
    }
Пример #4
0
    $search = '';
}
if ($hide) {
    require_sesskey();
    $DB->set_field('badge_issued', 'visible', 0, array('id' => $hide));
} else {
    if ($show) {
        require_sesskey();
        $DB->set_field('badge_issued', 'visible', 1, array('id' => $show));
    } else {
        if ($download && $hash) {
            require_sesskey();
            $badge = new badge($download);
            $name = str_replace(' ', '_', $badge->name) . '.png';
            ob_start();
            $file = badges_bake($hash, $download);
            header('Content-Type: image/png');
            header('Content-Disposition: attachment; filename="' . $name . '"');
            readfile($file);
            ob_flush();
        } else {
            if ($downloadall) {
                require_sesskey();
                ob_start();
                badges_download($USER->id);
                ob_flush();
            }
        }
    }
}
$context = context_user::instance($USER->id);
Пример #5
0
 /**
  * Issue a badge to user.
  *
  * @param int $userid User who earned the badge
  * @param bool $nobake Not baking actual badges (for testing purposes)
  */
 public function issue($userid, $nobake = false)
 {
     global $DB, $CFG;
     $now = time();
     $issued = new stdClass();
     $issued->badgeid = $this->id;
     $issued->userid = $userid;
     $issued->uniquehash = sha1(rand() . $userid . $this->id . $now);
     $issued->dateissued = $now;
     if ($this->can_expire()) {
         $issued->dateexpire = $this->calculate_expiry($now);
     } else {
         $issued->dateexpire = null;
     }
     // Take into account user badges privacy settings.
     // If none set, badges default visibility is set to public.
     $issued->visible = get_user_preferences('badgeprivacysetting', 1, $userid);
     $result = $DB->insert_record('badge_issued', $issued, true);
     if ($result) {
         // Trigger badge awarded event.
         $eventdata = array('context' => $this->get_context(), 'objectid' => $this->id, 'relateduserid' => $userid, 'other' => array('dateexpire' => $issued->dateexpire, 'badgeissuedid' => $result));
         \core\event\badge_awarded::create($eventdata)->trigger();
         // Lock the badge, so that its criteria could not be changed any more.
         if ($this->status == BADGE_STATUS_ACTIVE) {
             $this->set_status(BADGE_STATUS_ACTIVE_LOCKED);
         }
         // Update details in criteria_met table.
         $compl = $this->get_criteria_completions($userid);
         foreach ($compl as $c) {
             $obj = new stdClass();
             $obj->id = $c->id;
             $obj->issuedid = $result;
             $DB->update_record('badge_criteria_met', $obj, true);
         }
         if (!$nobake) {
             // Bake a badge image.
             $pathhash = badges_bake($issued->uniquehash, $this->id, $userid, true);
             // Notify recipients and badge creators.
             badges_notify_badge_award($this, $userid, $issued->uniquehash, $pathhash);
         }
     }
 }
Пример #6
0
 /**
  * Get user information
  *
  * @param string $username EBS username, could be 8-digit int or string.
  * @return array An array describing targets (and metadata) for that user for all leapcore_* courses.
  */
 public static function get_badges_by_username($username)
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::get_badges_by_username_parameters(), array('username' => $username));
     if ($params['username'] == '') {
         header($_SERVER["SERVER_PROTOCOL"] . ' 422 Unprocessable Entity ($params[\'username\'] empty.)', true, 422);
         exit(1);
     }
     // Could do with knowing what this user's {user}.id is.
     $sql = "SELECT id from {user} WHERE username LIKE ?;";
     if (!($user = $DB->get_record_sql($sql, array($params['username'] . '%')))) {
         header($_SERVER["SERVER_PROTOCOL"] . ' 422 Unprocessable Entity ($params[\'username\'] could not be matched against a valid user.)', true, 422);
         exit(1);
     }
     require_once $CFG->libdir . '/badgeslib.php';
     // Get the user's badges.
     $userbadges = badges_get_user_badges($user->id);
     $output = array();
     if (!$userbadges) {
         return $output;
     } else {
         $output = array();
         $count = 0;
         foreach ($userbadges as $hash => $ubadge) {
             $count++;
             $output[$count]['course_id'] = $ubadge->courseid;
             $output[$count]['date_issued'] = $ubadge->dateissued;
             $output[$count]['description'] = $ubadge->description;
             $output[$count]['details_link'] = (string) new moodle_url('/badges/badge.php', array('hash' => $hash));
             $output[$count]['image_url'] = (string) badges_bake($hash, $ubadge->id);
             $output[$count]['name'] = $ubadge->name;
         }
     }
     return $output;
 }