[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/grade/report/singleview/ -> 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   * Displays the Single view
  19   *
  20   * @package   gradereport_singleview
  21   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once('../../../config.php');
  26  require_once($CFG->dirroot.'/lib/gradelib.php');
  27  require_once($CFG->dirroot.'/grade/lib.php');
  28  require_once($CFG->dirroot.'/grade/report/singleview/lib.php');
  29  
  30  $courseid = required_param('id', PARAM_INT);
  31  $groupid  = optional_param('group', null, PARAM_INT);
  32  
  33  // Making this work with profile reports.
  34  $userid   = optional_param('userid', null, PARAM_INT);
  35  
  36  $defaulttype = $userid ? 'user' : 'select';
  37  
  38  $itemid   = optional_param('itemid', $userid, PARAM_INT);
  39  $itemtype = optional_param('item', $defaulttype, PARAM_TEXT);
  40  $page = optional_param('page', 0, PARAM_INT);
  41  $perpage = optional_param('perpage', 100, PARAM_INT);
  42  
  43  $courseparams = array('id' => $courseid);
  44  $PAGE->set_url(new moodle_url('/grade/report/singleview/index.php', $courseparams));
  45  
  46  if (!$course = $DB->get_record('course', $courseparams)) {
  47      print_error('nocourseid');
  48  }
  49  
  50  require_login($course);
  51  
  52  if (!in_array($itemtype, gradereport_singleview::valid_screens())) {
  53      print_error('notvalid', 'gradereport_singleview', '', $itemtype);
  54  }
  55  
  56  $context = context_course::instance($course->id);
  57  
  58  // This is the normal requirements.
  59  require_capability('gradereport/singleview:view', $context);
  60  require_capability('moodle/grade:viewall', $context);
  61  require_capability('moodle/grade:edit', $context);
  62  
  63  $gpr = new grade_plugin_return(array(
  64      'type' => 'report',
  65      'plugin' => 'singleview',
  66      'courseid' => $courseid
  67  ));
  68  
  69  // Last selected report session tracking.
  70  if (!isset($USER->grade_last_report)) {
  71      $USER->grade_last_report = array();
  72  }
  73  $USER->grade_last_report[$course->id] = 'singleview';
  74  
  75  // First make sure we have proper final grades -
  76  // this must be done before constructing of the grade tree.
  77  grade_regrade_final_grades($courseid);
  78  
  79  $report = new gradereport_singleview(
  80      $courseid, $gpr, $context,
  81      $itemtype, $itemid, $groupid
  82  );
  83  
  84  $reportname = $report->screen->heading();
  85  
  86  $pluginname = get_string('pluginname', 'gradereport_singleview');
  87  
  88  $pageparams = array(
  89      'id' => $courseid,
  90      'itemid' => $itemid,
  91      'item' => $itemtype,
  92      'userid' => $userid,
  93      'group' => $groupid,
  94      'page' => $page,
  95      'perpage' => $perpage
  96  );
  97  
  98  $currentpage = new moodle_url('/grade/report/singleview/index.php', $pageparams);
  99  
 100  if ($data = data_submitted()) {
 101      $PAGE->set_pagelayout('redirect');
 102      $PAGE->set_title(get_string('savegrades', 'gradereport_singleview'));
 103      echo $OUTPUT->header();
 104  
 105      require_sesskey(); // Must have a sesskey for all actions.
 106      $result = $report->process_data($data);
 107  
 108      if (!empty($result->warnings)) {
 109          foreach ($result->warnings as $warning) {
 110              echo $OUTPUT->notification($warning);
 111          }
 112      }
 113      echo $OUTPUT->notification(get_string('savegradessuccess', 'gradereport_singleview', count ((array)$result->changecount)));
 114      echo $OUTPUT->continue_button($currentpage);
 115      echo $OUTPUT->footer();
 116      die();
 117  }
 118  
 119  $PAGE->set_pagelayout('report');
 120  print_grade_page_head($course->id, 'report', 'singleview', $reportname);
 121  
 122  $graderrightnav = $graderleftnav = null;
 123  
 124  $options = $report->screen->options();
 125  
 126  if (!empty($options)) {
 127  
 128      $optionkeys = array_keys($options);
 129      $optionitemid = array_shift($optionkeys);
 130  
 131      $relreport = new gradereport_singleview(
 132                  $courseid, $gpr, $context,
 133                  $report->screen->item_type(), $optionitemid, $groupid
 134      );
 135      $reloptions = $relreport->screen->options();
 136      $reloptionssorting = array_keys($relreport->screen->options());
 137  
 138      $i = array_search($itemid, $reloptionssorting);
 139      $navparams = array('item' => $itemtype, 'id' => $courseid, 'group' => $groupid);
 140      if ($i > 0) {
 141          $navparams['itemid'] = $reloptionssorting[$i - 1];
 142          $link = new moodle_url('/grade/report/singleview/index.php', $navparams);
 143          $navprev = html_writer::link($link, $OUTPUT->larrow() . ' ' . $reloptions[$reloptionssorting[$i - 1]]);
 144          $graderleftnav = html_writer::tag('small', $navprev, array('class' => 'itemnav previtem'));
 145      }
 146      if ($i < count($reloptionssorting) - 1) {
 147          $navparams['itemid'] = $reloptionssorting[$i + 1];
 148          $link = new moodle_url('/grade/report/singleview/index.php', $navparams);
 149          $navnext = html_writer::link($link, $reloptions[$reloptionssorting[$i + 1]] . ' ' . $OUTPUT->rarrow());
 150          $graderrightnav = html_writer::tag('small', $navnext, array('class' => 'itemnav nextitem'));
 151      }
 152  }
 153  
 154  if (!is_null($graderleftnav)) {
 155      echo $graderleftnav;
 156  }
 157  if (!is_null($graderrightnav)) {
 158      echo $graderrightnav;
 159  }
 160  
 161  if ($report->screen->supports_paging()) {
 162      echo $report->screen->pager();
 163  }
 164  
 165  if ($report->screen->display_group_selector()) {
 166      echo $report->group_selector;
 167  }
 168  
 169  echo $report->output();
 170  
 171  if ($report->screen->supports_paging()) {
 172      echo $report->screen->pager();
 173  }
 174  
 175  if (!is_null($graderleftnav)) {
 176      echo $graderleftnav;
 177  }
 178  if (!is_null($graderrightnav)) {
 179      echo $graderrightnav;
 180  }
 181  
 182  $event = \gradereport_singleview\event\grade_report_viewed::create(
 183      array(
 184          'context' => $context,
 185          'courseid' => $courseid,
 186          'relateduserid' => $USER->id,
 187      )
 188  );
 189  $event->trigger();
 190  
 191  echo $OUTPUT->footer();


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