[ Index ]

PHP Cross Reference of moodle-2.8

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 <[email protected]>
  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  
  34  $PAGE->set_pagelayout('report');
  35  $url = new moodle_url('/grade/report/history/index.php', array('id' => $courseid));
  36  $PAGE->set_url($url);
  37  
  38  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  39  require_login($course);
  40  $context = context_course::instance($course->id);
  41  
  42  require_capability('gradereport/history:view', $context);
  43  require_capability('moodle/grade:viewall', $context);
  44  
  45  // Last selected report session tracking.
  46  if (!isset($USER->grade_last_report)) {
  47      $USER->grade_last_report = array();
  48  }
  49  $USER->grade_last_report[$course->id] = 'history';
  50  
  51  $select = "itemtype <> 'course' AND courseid = :courseid AND " . $DB->sql_isnotempty('grade_items', 'itemname', true, true);
  52  $itemids = $DB->get_records_select_menu('grade_items', $select, array('courseid' => $course->id), 'itemname ASC', 'id, itemname');
  53  $itemids = array(0 => get_string('allgradeitems', 'gradereport_history')) + $itemids;
  54  
  55  $output = $PAGE->get_renderer('gradereport_history');
  56  $graders = \gradereport_history\helper::get_graders($course->id);
  57  $params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => null);
  58  $mform = new \gradereport_history\filter_form(null, $params);
  59  $filters = array();
  60  if ($data = $mform->get_data()) {
  61      $filters = (array)$data;
  62  
  63      if (!empty($filters['datetill'])) {
  64          $filters['datetill'] += DAYSECS - 1; // Set to end of the chosen day.
  65      }
  66  } else {
  67      $filters = array(
  68          'id' => $courseid,
  69          'userids' => optional_param('userids', '', PARAM_SEQUENCE),
  70          'itemid' => optional_param('itemid', 0, PARAM_INT),
  71          'grader' => optional_param('grader', 0, PARAM_INT),
  72          'datefrom' => optional_param('datefrom', 0, PARAM_INT),
  73          'datetill' => optional_param('datetill', 0, PARAM_INT),
  74          'revisedonly' => optional_param('revisedonly', 0, PARAM_INT),
  75      );
  76  }
  77  
  78  $table = new \gradereport_history\output\tablelog('gradereport_history', $context, $url, $filters, $download, $page);
  79  
  80  $names = array();
  81  foreach ($table->get_selected_users() as $key => $user) {
  82      $names[$key] = fullname($user);
  83  }
  84  $filters['userfullnames'] = implode(',', $names);
  85  
  86  // Set up js.
  87  \gradereport_history\helper::init_js($course->id, $names);
  88  
  89  // Now that we have the names, reinitialise the button so its able to control them.
  90  $button = new \gradereport_history\output\user_button($PAGE->url, get_string('selectusers', 'gradereport_history'), 'get');
  91  
  92  $userbutton = $output->render($button);
  93  $params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => $userbutton);
  94  $mform = new \gradereport_history\filter_form(null, $params);
  95  $mform->set_data($filters);
  96  
  97  if ($table->is_downloading()) {
  98      // Download file and exit.
  99      echo $output->render($table);
 100      die();
 101  }
 102  
 103  // Print header.
 104  print_grade_page_head($COURSE->id, 'report', 'history', get_string('pluginname', 'gradereport_history'), false, '');
 105  $mform->display();
 106  
 107  // Render table.
 108  echo $output->render($table);
 109  
 110  $event = \gradereport_history\event\grade_report_viewed::create(
 111      array(
 112          'context' => $context,
 113          'courseid' => $courseid
 114      )
 115  );
 116  $event->trigger();
 117  
 118  echo $OUTPUT->footer();


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