[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/grade/report/singleview/classes/local/ui/ -> exclude.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   * Class that represents the exclude checkbox on a grade_grade.
  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  namespace gradereport_singleview\local\ui;
  26  
  27  defined('MOODLE_INTERNAL') || die;
  28  
  29  use grade_grade;
  30  
  31  /**
  32   * Class that represents the exclude checkbox on a grade_grade.
  33   *
  34   * @package   gradereport_singleview
  35   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class exclude extends grade_attribute_format implements be_checked {
  39  
  40      /** @var string $name The name of the input */
  41      public $name = 'exclude';
  42  
  43      /**
  44       * Is it checked?
  45       *
  46       * @return bool
  47       */
  48      public function is_checked() {
  49          return $this->grade->is_excluded();
  50      }
  51  
  52      /**
  53       * Generate the element used to render the UI
  54       *
  55       * @return element
  56       */
  57      public function determine_format() {
  58          return new checkbox_attribute(
  59              $this->get_name(),
  60              $this->get_label(),
  61              $this->is_checked()
  62          );
  63      }
  64  
  65      /**
  66       * Get the label for the form input
  67       *
  68       * @return string
  69       */
  70      public function get_label() {
  71          if (!isset($this->grade->label)) {
  72              $this->grade->label = '';
  73          }
  74          return $this->grade->label;
  75      }
  76  
  77      /**
  78       * Set the value that was changed in the form.
  79       *
  80       * @param string $value The value to set.
  81       * @return mixed string|bool An error message or false.
  82       */
  83      public function set($value) {
  84          if (empty($this->grade->id)) {
  85              if (empty($value)) {
  86                  return false;
  87              }
  88  
  89              $gradeitem = $this->grade->grade_item;
  90  
  91              // Fill in arbitrary grade to be excluded.
  92              $gradeitem->update_final_grade(
  93                  $this->grade->userid, null, 'singleview', null, FORMAT_MOODLE
  94              );
  95  
  96              $gradeparams = array(
  97                  'userid' => $this->grade->userid,
  98                  'itemid' => $this->grade->itemid
  99              );
 100  
 101              $this->grade = grade_grade::fetch($gradeparams);
 102              $this->grade->grade_item = $gradeitem;
 103          }
 104  
 105          $state = $value == 0 ? false : true;
 106  
 107          $this->grade->set_excluded($state);
 108  
 109          $this->grade->grade_item->get_parent_category()->force_regrading();
 110          return false;
 111      }
 112  }


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