Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       1  <?php
       2  // This file is part of Moodle - http://moodle.org/
       3  //
       4  // Moodle is free software: you can redistribute it and/or modify
       5  // it under the terms of the GNU General Public License as published by
       6  // the Free Software Foundation, either version 3 of the License, or
       7  // (at your option) any later version.
       8  //
       9  // Moodle is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License
      15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
      16  
      17  /**
      18   * Badge awards information
      19   *
      20   * @package    core
      21   * @subpackage badges
      22   * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
      23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      24   * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
      25   */
      26  
      27  require_once(dirname(dirname(__FILE__)) . '/config.php');
      28  require_once($CFG->libdir . '/badgeslib.php');
      29  
      30  $badgeid    = required_param('id', PARAM_INT);
      31  $sortby     = optional_param('sort', 'dateissued', PARAM_ALPHA);
      32  $sorthow    = optional_param('dir', 'DESC', PARAM_ALPHA);
      33  $page       = optional_param('page', 0, PARAM_INT);
      34  
      35  require_login();
      36  
      37  if (empty($CFG->enablebadges)) {
      38      print_error('badgesdisabled', 'badges');
      39  }
      40  
      41  if (!in_array($sortby, array('firstname', 'lastname', 'dateissued'))) {
      42      $sortby = 'dateissued';
      43  }
      44  
      45  if ($sorthow != 'ASC' and $sorthow != 'DESC') {
      46      $sorthow = 'DESC';
      47  }
      48  
      49  if ($page < 0) {
      50      $page = 0;
      51  }
      52  
      53  $badge = new badge($badgeid);
      54  $context = $badge->get_context();
      55  $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
      56  
      57  if ($badge->type == BADGE_TYPE_COURSE) {
      58      if (empty($CFG->badges_allowcoursebadges)) {
      59          print_error('coursebadgesdisabled', 'badges');
      60      }
      61      require_login($badge->courseid);
      62      $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
      63      $PAGE->set_pagelayout('standard');
      64      navigation_node::override_active_url($navurl);
      65  } else {
      66      $PAGE->set_pagelayout('admin');
      67      navigation_node::override_active_url($navurl, true);
      68  }
      69  
      70  $PAGE->set_context($context);
      71  $PAGE->set_url('/badges/recipients.php', array('id' => $badgeid, 'sort' => $sortby, 'dir' => $sorthow));
      72  $PAGE->set_heading($badge->name);
      73  $PAGE->set_title($badge->name);
      74  $PAGE->navbar->add($badge->name);
      75  
      76  $output = $PAGE->get_renderer('core', 'badges');
      77  
      78  echo $output->header();
      79  echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
      80  
      81  echo $output->print_badge_status_box($badge);
      82  $output->print_badge_tabs($badgeid, $context, 'awards');
      83  
      84  // Add button for badge manual award.
      85  if ($badge->has_manual_award_criteria() && has_capability('moodle/badges:awardbadge', $context) && $badge->is_active()) {
      86      $url = new moodle_url('/badges/award.php', array('id' => $badge->id));
      87      echo $OUTPUT->box($OUTPUT->single_button($url, get_string('award', 'badges')), 'clearfix mdl-align');
      88  }
      89  
      90  $namefields = get_all_user_name_fields(true, 'u');
      91  $sql = "SELECT b.userid, b.dateissued, b.uniquehash, $namefields
      92      FROM {badge_issued} b INNER JOIN {user} u
      93          ON b.userid = u.id
      94      WHERE b.badgeid = :badgeid AND u.deleted = 0
      95      ORDER BY $sortby $sorthow";
      96  
      97  $totalcount = $DB->count_records('badge_issued', array('badgeid' => $badge->id));
      98  
      99  if ($badge->has_awards()) {
     100      $users = $DB->get_records_sql($sql, array('badgeid' => $badge->id), $page * BADGE_PERPAGE, BADGE_PERPAGE);
     101      $recipients             = new badge_recipients($users);
     102      $recipients->sort       = $sortby;
     103      $recipients->dir        = $sorthow;
     104      $recipients->page       = $page;
     105      $recipients->perpage    = BADGE_PERPAGE;
     106      $recipients->totalcount = $totalcount;
     107  
     108      echo $output->render($recipients);
     109  } else {
     110      echo $output->notification(get_string('noawards', 'badges'));
     111  }
     112  
     113  echo $output->footer();
    

    Search This Site: