Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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      throw new \moodle_exception('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          throw new \moodle_exception('coursebadgesdisabled', 'badges');
  45      }
  46      require_login($badge->courseid);
  47      $course = get_course($badge->courseid);
  48      $heading = format_string($course->fullname, true, ['context' => $context]);
  49      $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
  50      $PAGE->set_pagelayout('standard');
  51      navigation_node::override_active_url($navurl);
  52  } else {
  53      $PAGE->set_pagelayout('admin');
  54      $heading = get_string('administrationsite');
  55      navigation_node::override_active_url($navurl, true);
  56  }
  57  
  58  $currenturl = new moodle_url('/badges/endorsement.php', array('id' => $badgeid));
  59  $PAGE->set_context($context);
  60  $PAGE->set_url($currenturl);
  61  $PAGE->set_heading($heading);
  62  $PAGE->set_title($badge->name);
  63  $PAGE->navbar->add($badge->name);
  64  
  65  $output = $PAGE->get_renderer('core', 'badges');
  66  $msg = optional_param('msg', '', PARAM_TEXT);
  67  $emsg = optional_param('emsg', '', PARAM_TEXT);
  68  
  69  if ($msg !== '') {
  70      $msg = get_string($msg, 'badges');
  71  }
  72  
  73  echo $OUTPUT->header();
  74  
  75  $actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
  76  echo $output->render_tertiary_navigation($actionbar);
  77  
  78  echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
  79  echo $output->print_badge_status_box($badge);
  80  
  81  $form = new endorsement_form($currenturl, array('badge' => $badge));
  82  if ($form->is_cancelled()) {
  83      redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
  84  } else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
  85      $endorsement = new stdClass();
  86      $endorsement->badgeid = $badgeid;
  87      $endorsement->issuername = $data->issuername;
  88      $endorsement->issueremail = $data->issueremail;
  89      $endorsement->issuerurl = $data->issuerurl;
  90      $endorsement->claimid = $data->claimid;
  91      $endorsement->claimcomment = strip_tags($data->claimcomment);
  92      $endorsement->dateissued = $data->dateissued;
  93  
  94      if ($badge->save_endorsement($endorsement)) {
  95          $msg = get_string('changessaved');
  96      } else {
  97          $emsg = get_string('error:save', 'badges');
  98      }
  99  }
 100  
 101  if ($emsg !== '') {
 102      echo $OUTPUT->notification($emsg);
 103  
 104  } else if ($msg !== '') {
 105      echo $OUTPUT->notification($msg, 'notifysuccess');
 106  }
 107  echo $output->notification(get_string('noteendorsement', 'badges'), 'info');
 108  $form->display();
 109  echo $OUTPUT->footer();