Merge branch 'MDL-41659_master' of https://github.com/totara/openbadges
authorDamyon Wiese <damyon@moodle.com>
Wed, 9 Oct 2013 05:30:40 +0000 (13:30 +0800)
committerDamyon Wiese <damyon@moodle.com>
Wed, 9 Oct 2013 05:30:40 +0000 (13:30 +0800)
1  2 
badges/renderer.php

diff --combined badges/renderer.php
@@@ -282,24 -282,24 +282,24 @@@ class core_badges_renderer extends plug
          global $USER, $CFG, $DB;
          $issued = $ibadge->issued;
          $userinfo = $ibadge->recipient;
 +        $badgeclass = $ibadge->badgeclass;
          $badge = new badge($ibadge->badgeid);
 -        $today_date = date('Y-m-d');
 -        $today = strtotime($today_date);
 +        $now = time();
  
          $table = new html_table();
          $table->id = 'issued-badge-table';
  
          $imagetable = new html_table();
          $imagetable->attributes = array('class' => 'clearfix badgeissuedimage');
 -        $imagetable->data[] = array(html_writer::empty_tag('img', array('src' => $issued['badge']['image'])));
 +        $imagetable->data[] = array(html_writer::empty_tag('img', array('src' => $badgeclass['image'])));
          if ($USER->id == $userinfo->id && !empty($CFG->enablebadges)) {
              $imagetable->data[] = array($this->output->single_button(
 -                        new moodle_url('/badges/badge.php', array('hash' => $ibadge->hash, 'bake' => true)),
 +                        new moodle_url('/badges/badge.php', array('hash' => $issued['uid'], 'bake' => true)),
                          get_string('download'),
                          'POST'));
 -            $expiration = isset($issued['expires']) ? strtotime($issued['expires']) : $today + 1;
 -            if (!empty($CFG->badges_allowexternalbackpack) && ($expiration > $today) && badges_user_has_backpack($USER->id)) {
 -                $assertion = new moodle_url('/badges/assertion.php', array('b' => $ibadge->hash));
 +            $expiration = isset($issued['expires']) ? $issued['expires'] : $now + 86400;
 +            if (!empty($CFG->badges_allowexternalbackpack) && ($expiration > $now) && badges_user_has_backpack($USER->id)) {
 +                $assertion = new moodle_url('/badges/assertion.php', array('b' => $issued['uid']));
                  $action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false)));
                  $attributes = array(
                          'type'  => 'button',
  
          $datatable->data[] = array(get_string('bcriteria', 'badges'), self::print_badge_criteria($badge));
          $datatable->data[] = array($this->output->heading(get_string('issuancedetails', 'badges'), 3), '');
 -        $datatable->data[] = array(get_string('dateawarded', 'badges'), $issued['issued_on']);
 +        $datatable->data[] = array(get_string('dateawarded', 'badges'), userdate($issued['issuedOn']));
          if (isset($issued['expires'])) {
 -            $expiration = strtotime($issued['expires']);
 -            if ($expiration < $today) {
 -                $cell = new html_table_cell($issued['expires'] . get_string('warnexpired', 'badges'));
 +            if ($issued['expires'] < $now) {
 +                $cell = new html_table_cell(userdate($issued['expires']) . get_string('warnexpired', 'badges'));
                  $cell->attributes = array('class' => 'notifyproblem warning');
                  $datatable->data[] = array(get_string('expirydate', 'badges'), $cell);
  
                  $image = html_writer::start_tag('div', array('class' => 'badge'));
 -                $image .= html_writer::empty_tag('img', array('src' => $issued['badge']['image']));
 +                $image .= html_writer::empty_tag('img', array('src' => $badgeclass['image']));
                  $image .= $this->output->pix_icon('i/expired',
 -                                get_string('expireddate', 'badges', $issued['expires']),
 +                                get_string('expireddate', 'badges', userdate($issued['expires'])),
                                  'moodle',
                                  array('class' => 'expireimage'));
                  $image .= html_writer::end_tag('div');
                  $imagetable->data[0] = array($image);
              } else {
 -                $datatable->data[] = array(get_string('expirydate', 'badges'), $issued['expires']);
 +                $datatable->data[] = array(get_string('expirydate', 'badges'), userdate($issued['expires']));
              }
          }
  
  
          // Local badges.
          $localhtml = html_writer::start_tag('fieldset', array('id' => 'issued-badge-table', 'class' => 'generalbox'));
-         $localhtml .= html_writer::tag('legend',
-                     $this->output->heading_with_help(get_string('localbadges', 'badges', $SITE->fullname), 'localbadgesh', 'badges'));
+         $heading = get_string('localbadges', 'badges', format_string($SITE->fullname, true, array('context' => context_system::instance())));
+         $localhtml .= html_writer::tag('legend', $this->output->heading_with_help($heading, 'localbadgesh', 'badges'));
          if ($badges->badges) {
              $table = new html_table();
              $table->attributes['class'] = 'statustable';
@@@ -908,15 -909,15 +908,15 @@@ class issued_badge implements renderabl
      /** @var badge recipient */
      public $recipient;
  
 +    /** @var badge class */
 +    public $badgeclass;
 +
      /** @var badge visibility to others */
      public $visible = 0;
  
      /** @var badge class */
      public $badgeid = 0;
  
 -    /** @var issued badge unique hash */
 -    public $hash = "";
 -
      /**
       * Initializes the badge to display
       *
       */
      public function __construct($hash) {
          global $DB;
 -        $this->issued = badges_get_issued_badge_info($hash);
 -        $this->hash = $hash;
 +
 +        $assertion = new core_badges_assertion($hash);
 +        $this->issued = $assertion->get_badge_assertion();
 +        $this->badgeclass = $assertion->get_badge_class();
  
          $rec = $DB->get_record_sql('SELECT userid, visible, badgeid
                  FROM {badge_issued}