Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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   * Endorsement information
  18   *
  19   * @package    core
  20   * @subpackage badges
  21   * @copyright  2018 Tung Thai
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   * @author     Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
  24   */
  25  require_once(__DIR__ . '/../config.php');
  26  require_once($CFG->libdir . '/badgeslib.php');
  27  require_once($CFG->dirroot . '/badges/endorsement_form.php');
  28  
  29  $badgeid = required_param('id', PARAM_INT);
  30  
  31  require_login();
  32  
  33  if (empty($CFG->enablebadges)) {
  34      print_error('badgesdisabled', 'badges');
  35  }
  36  
  37  $badge = new badge($badgeid);
  38  $context = $badge->get_context();
  39  $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
  40  require_capability('moodle/badges:configuredetails', $context);
  41  
  42  if ($badge->type == BADGE_TYPE_COURSE) {
  43      if (empty($CFG->badges_allowcoursebadges)) {
  44          print_error('coursebadgesdisabled', 'badges');
  45      }
  46      require_login($badge->courseid);
  47      $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
  48      $PAGE->set_pagelayout('standard');
  49      navigation_node::override_active_url($navurl);
  50  } else {
  51      $PAGE->set_pagelayout('admin');
  52      navigation_node::override_active_url($navurl, true);
  53  }
  54  
  55  $currenturl = new moodle_url('/badges/endorsement.php', array('id' => $badgeid));
  56  $PAGE->set_context($context);
  57  $PAGE->set_url($currenturl);
  58  $PAGE->set_heading($badge->name);
  59  $PAGE->set_title($badge->name);
  60  $PAGE->navbar->add($badge->name);
  61  
  62  $output = $PAGE->get_renderer('core', 'badges');
  63  $msg = optional_param('msg', '', PARAM_TEXT);
  64  $emsg = optional_param('emsg', '', PARAM_TEXT);
  65  
  66  if ($msg !== '') {
  67      $msg = get_string($msg, 'badges');
  68  }
  69  
  70  echo $OUTPUT->header();
  71  echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
  72  
  73  echo $output->print_badge_status_box($badge);
  74  $output->print_badge_tabs($badgeid, $context, 'bendorsement');
  75  
  76  $form = new endorsement_form($currenturl, array('badge' => $badge));
  77  if ($form->is_cancelled()) {
  78      redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
  79  } else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
  80      $endorsement = new stdClass();
  81      $endorsement->badgeid = $badgeid;
  82      $endorsement->issuername = $data->issuername;
  83      $endorsement->issueremail = $data->issueremail;
  84      $endorsement->issuerurl = $data->issuerurl;
  85      $endorsement->claimid = $data->claimid;
  86      $endorsement->claimcomment = strip_tags($data->claimcomment);
  87      $endorsement->dateissued = $data->dateissued;
  88  
  89      if ($badge->save_endorsement($endorsement)) {
  90          $msg = get_string('changessaved');
  91      } else {
  92          $emsg = get_string('error:save', 'badges');
  93      }
  94  }
  95  
  96  if ($emsg !== '') {
  97      echo $OUTPUT->notification($emsg);
  98  
  99  } else if ($msg !== '') {
 100      echo $OUTPUT->notification($msg, 'notifysuccess');
 101  }
 102  echo $output->notification(get_string('noteendorsement', 'badges'), 'info');
 103  $form->display();
 104  echo $OUTPUT->footer();