[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/grade/report/history/ -> index.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   * The gradebook grade history report
  19   *
  20   * @package    gradereport_history
  21   * @copyright  2013 NetSpot Pty Ltd (https://www.netspot.com.au)
  22   * @author     Adam Olley <adam.olley@netspot.com.au>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once(__DIR__ . '/../../../config.php');
  27  require_once($CFG->libdir.'/gradelib.php');
  28  require_once($CFG->dirroot.'/grade/lib.php');
  29  
  30  $download      = optional_param('download', '', PARAM_ALPHA);
  31  $courseid      = required_param('id', PARAM_INT);        // Course id.
  32  $page          = optional_param('page', 0, PARAM_INT);   // Active page.
  33  $showreport    = optional_param('showreport', 0, PARAM_INT);
  34  
  35  $PAGE->set_pagelayout('report');
  36  $url = new moodle_url('/grade/report/history/index.php', array('id' => $courseid, 'showreport' => 1));
  37  $PAGE->set_url($url);
  38  
  39  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  40  require_login($course);
  41  $context = context_course::instance($course->id);
  42  
  43  require_capability('gradereport/history:view', $context);
  44  require_capability('moodle/grade:viewall', $context);
  45  
  46  // Last selected report session tracking.
  47  if (!isset($USER->grade_last_report)) {
  48      $USER->grade_last_report = array();
  49  }
  50  $USER->grade_last_report[$course->id] = 'history';
  51  
  52  $select = "itemtype <> 'course' AND courseid = :courseid AND " . $DB->sql_isnotempty('grade_items', 'itemname', true, true);
  53  $itemids = $DB->get_records_select_menu('grade_items', $select, array('courseid' => $course->id), 'itemname ASC', 'id, itemname');
  54  $itemids = array(0 => get_string('allgradeitems', 'gradereport_history')) + $itemids;
  55  
  56  $output = $PAGE->get_renderer('gradereport_history');
  57  $graders = \gradereport_history\helper::get_graders($course->id);
  58  $params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => null);
  59  $mform = new \gradereport_history\filter_form(null, $params);
  60  $filters = array();
  61  if ($data = $mform->get_data()) {
  62      $filters = (array)$data;
  63  
  64      if (!empty($filters['datetill'])) {
  65          $filters['datetill'] += DAYSECS - 1; // Set to end of the chosen day.
  66      }
  67  } else {
  68      $filters = array(
  69          'id' => $courseid,
  70          'userids' => optional_param('userids', '', PARAM_SEQUENCE),
  71          'itemid' => optional_param('itemid', 0, PARAM_INT),
  72          'grader' => optional_param('grader', 0, PARAM_INT),
  73          'datefrom' => optional_param('datefrom', 0, PARAM_INT),
  74          'datetill' => optional_param('datetill', 0, PARAM_INT),
  75          'revisedonly' => optional_param('revisedonly', 0, PARAM_INT),
  76      );
  77  }
  78  
  79  $table = new \gradereport_history\output\tablelog('gradereport_history', $context, $url, $filters, $download, $page);
  80  
  81  $names = array();
  82  foreach ($table->get_selected_users() as $key => $user) {
  83      $names[$key] = fullname($user);
  84  }
  85  $filters['userfullnames'] = implode(',', $names);
  86  
  87  // Set up js.
  88  \gradereport_history\helper::init_js($course->id, $names);
  89  
  90  // Now that we have the names, reinitialise the button so its able to control them.
  91  $button = new \gradereport_history\output\user_button($PAGE->url, get_string('selectusers', 'gradereport_history'), 'get');
  92  
  93  $userbutton = $output->render($button);
  94  $params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => $userbutton);
  95  $mform = new \gradereport_history\filter_form(null, $params);
  96  $mform->set_data($filters);
  97  
  98  if ($table->is_downloading()) {
  99      // Download file and exit.
 100      \core\session\manager::write_close();
 101      echo $output->render($table);
 102      die();
 103  }
 104  
 105  // Print header.
 106  print_grade_page_head($COURSE->id, 'report', 'history', get_string('pluginname', 'gradereport_history'), false, '');
 107  $mform->display();
 108  
 109  if ($showreport) {
 110      // Only display report after form has been submitted.
 111      echo $output->render($table);
 112  
 113      $event = \gradereport_history\event\grade_report_viewed::create(
 114          array(
 115              'context' => $context,
 116              'courseid' => $courseid
 117          )
 118      );
 119      $event->trigger();
 120  }
 121  
 122  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1