[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/badges/ -> mybadges.php (source)

   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   * Displays user badges for badges management in own profile
  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 <[email protected]>
  25   */
  26  
  27  require_once(dirname(dirname(__FILE__)) . '/config.php');
  28  require_once($CFG->libdir . '/badgeslib.php');
  29  
  30  $page        = optional_param('page', 0, PARAM_INT);
  31  $search      = optional_param('search', '', PARAM_CLEAN);
  32  $clearsearch = optional_param('clearsearch', '', PARAM_TEXT);
  33  $download    = optional_param('download', 0, PARAM_INT);
  34  $hash        = optional_param('hash', '', PARAM_ALPHANUM);
  35  $downloadall = optional_param('downloadall', false, PARAM_BOOL);
  36  $hide        = optional_param('hide', 0, PARAM_INT);
  37  $show        = optional_param('show', 0, PARAM_INT);
  38  
  39  require_login();
  40  
  41  if (empty($CFG->enablebadges)) {
  42      print_error('badgesdisabled', 'badges');
  43  }
  44  
  45  $url = new moodle_url('/badges/mybadges.php');
  46  $PAGE->set_url($url);
  47  
  48  if (isguestuser()) {
  49      $PAGE->set_context(context_system::instance());
  50      echo $OUTPUT->header();
  51      echo $OUTPUT->box(get_string('error:guestuseraccess', 'badges'), 'notifyproblem');
  52      echo $OUTPUT->footer();
  53      die();
  54  }
  55  
  56  if ($page < 0) {
  57      $page = 0;
  58  }
  59  
  60  if ($clearsearch) {
  61      $search = '';
  62  }
  63  
  64  if ($hide) {
  65      require_sesskey();
  66      $DB->set_field('badge_issued', 'visible', 0, array('id' => $hide, 'userid' => $USER->id));
  67  } else if ($show) {
  68      require_sesskey();
  69      $DB->set_field('badge_issued', 'visible', 1, array('id' => $show, 'userid' => $USER->id));
  70  } else if ($download && $hash) {
  71      require_sesskey();
  72      $badge = new badge($download);
  73      $name = str_replace(' ', '_', $badge->name) . '.png';
  74      ob_start();
  75      $file = badges_bake($hash, $download);
  76      header('Content-Type: image/png');
  77      header('Content-Disposition: attachment; filename="'. $name .'"');
  78      readfile($file);
  79      ob_flush();
  80  } else if ($downloadall) {
  81      require_sesskey();
  82      ob_start();
  83      badges_download($USER->id);
  84      ob_flush();
  85  }
  86  
  87  $context = context_user::instance($USER->id);
  88  require_capability('moodle/badges:manageownbadges', $context);
  89  
  90  $PAGE->set_context($context);
  91  
  92  $title = get_string('mybadges', 'badges');
  93  $PAGE->set_title($title);
  94  $PAGE->set_heading($title);
  95  $PAGE->set_pagelayout('mydashboard');
  96  
  97  // Include JS files for backpack support.
  98  badges_setup_backpack_js();
  99  
 100  $output = $PAGE->get_renderer('core', 'badges');
 101  $badges = badges_get_user_badges($USER->id);
 102  
 103  echo $OUTPUT->header();
 104  $totalcount = count($badges);
 105  $records = badges_get_user_badges($USER->id, null, $page, BADGE_PERPAGE, $search);
 106  
 107  $userbadges             = new badge_user_collection($records, $USER->id);
 108  $userbadges->sort       = 'dateissued';
 109  $userbadges->dir        = 'DESC';
 110  $userbadges->page       = $page;
 111  $userbadges->perpage    = BADGE_PERPAGE;
 112  $userbadges->totalcount = $totalcount;
 113  $userbadges->search     = $search;
 114  
 115  echo $output->render($userbadges);
 116  
 117  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1