示例#1
0
 protected function render_issued_badge(issued_badge $ibadge)
 {
     global $USER, $CFG, $DB;
     $issued = $ibadge->issued;
     $badge = new badge($ibadge->badgeid);
     $today_date = date('Y-m-d');
     $today = strtotime($today_date);
     $table = new html_table();
     $imagetable = new html_table();
     $imagetable->attributes = array('class' => 'clearfix badgeissuedimage');
     $imagetable->data[] = array(html_writer::empty_tag('img', array('src' => $issued['badge']['image'])));
     if ($USER->id == $ibadge->recipient && !empty($CFG->enablebadges)) {
         $imagetable->data[] = array($this->output->single_button(new moodle_url('/badges/badge.php', array('hash' => $ibadge->hash, '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));
             $attributes = array('type' => 'button', 'value' => get_string('addtobackpack', 'badges'), 'onclick' => 'OpenBadges.issue(["' . $assertion->out(false) . '"], function(errors, successes) { })');
             $tobackpack = html_writer::tag('input', '', $attributes);
             $imagetable->data[] = array($tobackpack);
         }
     }
     $datatable = new html_table();
     $datatable->attributes = array('class' => 'badgeissuedinfo');
     $datatable->colclasses = array('bfield', 'bvalue');
     $datatable->data[] = array($this->output->heading(get_string('issuerdetails', 'badges'), 3), '');
     $datatable->data[] = array(get_string('issuername', 'badges'), $badge->issuername);
     if (isset($badge->issuercontact) && !empty($badge->issuercontact)) {
         $datatable->data[] = array(get_string('contact', 'badges'), html_writer::tag('a', $badge->issuercontact, array('href' => 'mailto:' . $badge->issuercontact)));
     }
     $datatable->data[] = array($this->output->heading(get_string('badgedetails', 'badges'), 3), '');
     $datatable->data[] = array(get_string('name'), $badge->name);
     $datatable->data[] = array(get_string('description', 'badges'), $badge->description);
     if ($badge->type == BADGE_TYPE_COURSE && isset($badge->courseid)) {
         $coursename = $DB->get_field('course', 'fullname', array('id' => $badge->courseid));
         $datatable->data[] = array(get_string('course'), $coursename);
     }
     $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']);
     if (isset($issued['expires'])) {
         $expiration = strtotime($issued['expires']);
         if ($expiration < $today) {
             $cell = new html_table_cell($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 .= $this->output->pix_icon('i/expired', get_string('expireddate', 'badges', $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']);
         }
     }
     // Print evidence.
     $agg = $badge->get_aggregation_methods();
     $evidence = $badge->get_criteria_completions($ibadge->recipient);
     $eids = array_map(create_function('$o', 'return $o->critid;'), $evidence);
     unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
     $items = array();
     foreach ($badge->criteria as $type => $c) {
         if (in_array($c->id, $eids)) {
             if (count($c->params) == 1) {
                 $items[] = get_string('criteria_descr_single_' . $type, 'badges') . $c->get_details();
             } else {
                 $items[] = get_string('criteria_descr_' . $type, 'badges', strtoupper($agg[$badge->get_aggregation_method($type)])) . $c->get_details();
             }
         }
     }
     $datatable->data[] = array(get_string('evidence', 'badges'), get_string('completioninfo', 'badges') . html_writer::alist($items, array(), 'ul'));
     $table->attributes = array('class' => 'generalbox boxaligncenter issuedbadgebox');
     $table->data[] = array(html_writer::table($imagetable), html_writer::table($datatable));
     $htmlbadge = html_writer::table($table);
     return $htmlbadge;
 }
示例#2
0
 protected function render_issued_badge(issued_badge $ibadge)
 {
     global $USER, $CFG, $DB, $SITE;
     $issued = $ibadge->issued;
     $userinfo = $ibadge->recipient;
     $badgeclass = $ibadge->badgeclass;
     $badge = new badge($ibadge->badgeid);
     $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' => $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' => $issued['uid'], 'bake' => true)), get_string('download'), 'POST'));
         $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', 'id' => 'addbutton', 'value' => get_string('addtobackpack', 'badges'));
             $tobackpack = html_writer::tag('input', '', $attributes);
             $this->output->add_action_handler($action, 'addbutton');
             $imagetable->data[] = array($tobackpack);
         }
     }
     $datatable = new html_table();
     $datatable->attributes = array('class' => 'badgeissuedinfo');
     $datatable->colclasses = array('bfield', 'bvalue');
     // Recipient information.
     $datatable->data[] = array($this->output->heading(get_string('recipientdetails', 'badges'), 3), '');
     if ($userinfo->deleted) {
         $strdata = new stdClass();
         $strdata->user = fullname($userinfo);
         $strdata->site = format_string($SITE->fullname, true, array('context' => context_system::instance()));
         $datatable->data[] = array(get_string('name'), get_string('error:userdeleted', 'badges', $strdata));
     } else {
         $datatable->data[] = array(get_string('name'), fullname($userinfo));
     }
     $datatable->data[] = array($this->output->heading(get_string('issuerdetails', 'badges'), 3), '');
     $datatable->data[] = array(get_string('issuername', 'badges'), $badge->issuername);
     if (isset($badge->issuercontact) && !empty($badge->issuercontact)) {
         $datatable->data[] = array(get_string('contact', 'badges'), obfuscate_mailto($badge->issuercontact));
     }
     $datatable->data[] = array($this->output->heading(get_string('badgedetails', 'badges'), 3), '');
     $datatable->data[] = array(get_string('name'), $badge->name);
     $datatable->data[] = array(get_string('description', 'badges'), $badge->description);
     if ($badge->type == BADGE_TYPE_COURSE && isset($badge->courseid)) {
         $coursename = $DB->get_field('course', 'fullname', array('id' => $badge->courseid));
         $datatable->data[] = array(get_string('course'), $coursename);
     }
     $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'), userdate($issued['issuedOn']));
     if (isset($issued['expires'])) {
         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' => $badgeclass['image']));
             $image .= $this->output->pix_icon('i/expired', 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'), userdate($issued['expires']));
         }
     }
     // Print evidence.
     $agg = $badge->get_aggregation_methods();
     $evidence = $badge->get_criteria_completions($userinfo->id);
     $eids = array_map(create_function('$o', 'return $o->critid;'), $evidence);
     unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
     $items = array();
     foreach ($badge->criteria as $type => $c) {
         if (in_array($c->id, $eids)) {
             if (count($c->params) == 1) {
                 $items[] = get_string('criteria_descr_single_' . $type, 'badges') . $c->get_details();
             } else {
                 $items[] = get_string('criteria_descr_' . $type, 'badges', core_text::strtoupper($agg[$badge->get_aggregation_method($type)])) . $c->get_details();
             }
         }
     }
     $datatable->data[] = array(get_string('evidence', 'badges'), get_string('completioninfo', 'badges') . html_writer::alist($items, array(), 'ul'));
     $table->attributes = array('class' => 'generalbox boxaligncenter issuedbadgebox');
     $table->data[] = array(html_writer::table($imagetable), html_writer::table($datatable));
     $htmlbadge = html_writer::table($table);
     return $htmlbadge;
 }