[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/assignmentupgrade/ -> upgradableassignmentstable.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   * This file contains the definition for the grading table which subclassses easy_table
  19   *
  20   * @package   tool_assignmentupgrade
  21   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir.'/tablelib.php');
  28  require_once($CFG->libdir.'/gradelib.php');
  29  require_once($CFG->dirroot.'/mod/assign/locallib.php');
  30  
  31  /**
  32   * Extends table_sql to provide a table of assignment submissions
  33   *
  34   * @package   tool_assignmentupgrade
  35   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class tool_assignmentupgrade_assignments_table extends table_sql implements renderable {
  39  
  40      /** @var int $perpage */
  41      private $perpage = 10;
  42      /** @var int $rownum (global index of current row in table) */
  43      private $rownum = -1;
  44      /** @var renderer_base for getting output */
  45      private $output = null;
  46      /** @var boolean anyupgradableassignments - True if there is one or more assignments that can upgraded */
  47      public $anyupgradableassignments = false;
  48  
  49      /**
  50       * This table loads a list of the old assignment instances and tests them to see
  51       * if they can be upgraded
  52       *
  53       * @param int $perpage How many per page
  54       * @param int $rowoffset The starting row for pagination
  55       */
  56      public function __construct($perpage, $rowoffset=0) {
  57          global $PAGE;
  58          parent::__construct('tool_assignmentupgrade_assignments');
  59          $this->perpage = $perpage;
  60          $this->output = $PAGE->get_renderer('tool_assignmentupgrade');
  61  
  62          $this->define_baseurl(new moodle_url('/admin/tool/assignmentupgrade/listnotupgraded.php'));
  63  
  64          $this->anyupgradableassignments = tool_assignmentupgrade_any_upgradable_assignments();
  65  
  66          // Do some business - then set the sql.
  67          if ($rowoffset) {
  68              $this->rownum = $rowoffset - 1;
  69          }
  70  
  71          $fields = 'a.id as id,
  72                     a.name as name,
  73                     a.assignmenttype as type,
  74                     c.shortname as courseshortname,
  75                     c.id as courseid,
  76                     COUNT(s.id) as submissioncount';
  77          $from = '{assignment} a JOIN {course} c ON a.course = c.id ' .
  78                          ' LEFT JOIN {assignment_submissions} s ON a.id = s.assignment';
  79  
  80          $where = '1 = 1';
  81          $where .= ' GROUP BY a.id, a.name, a.assignmenttype, c.shortname, c.id ';
  82  
  83          $this->set_sql($fields, $from, $where, array());
  84          $this->set_count_sql('SELECT COUNT(*) FROM {assignment} a JOIN {course} c ON a.course = c.id', array());
  85  
  86          $columns = array();
  87          $headers = array();
  88  
  89          $columns[] = 'select';
  90          $headers[] = get_string('select', 'tool_assignmentupgrade') .
  91                       '<div class="selectall">' .
  92                       '<input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/>' .
  93                       '</div>';
  94          $columns[] = 'upgradable';
  95          $headers[] = get_string('upgradable', 'tool_assignmentupgrade');
  96          $columns[] = 'id';
  97          $headers[] = get_string('assignmentid', 'tool_assignmentupgrade');
  98          $columns[] = 'courseshortname';
  99          $headers[] = get_string('course');
 100          $columns[] = 'name';
 101          $headers[] = get_string('name');
 102          $columns[] = 'type';
 103          $headers[] = get_string('assignmenttype', 'tool_assignmentupgrade');
 104          $columns[] = 'submissioncount';
 105          $headers[] = get_string('submissions', 'tool_assignmentupgrade');
 106  
 107          // Set the columns.
 108          $this->define_columns($columns);
 109          $this->define_headers($headers);
 110          $this->no_sorting('upgradable');
 111          $this->no_sorting('select');
 112      }
 113  
 114      /**
 115       * Return the number of rows to display on a single page
 116       *
 117       * @return int The number of rows per page
 118       */
 119      public function get_rows_per_page() {
 120          return $this->perpage;
 121      }
 122  
 123      /**
 124       * Format a link to the assignment instance
 125       *
 126       * @param stdClass $row
 127       * @return string
 128       */
 129      public function col_name(stdClass $row) {
 130          $url = new moodle_url('/mod/assignment/view.php', array('a' => $row->id));
 131          return html_writer::link($url, $row->name);
 132      }
 133  
 134  
 135      /**
 136       * Format a link to the upgrade single tool
 137       *
 138       * @param stdClass $row (contains cached result from previous upgradable check)
 139       * @return string
 140       */
 141      public function col_upgradable(stdClass $row) {
 142          if ($row->upgradable) {
 143              $urlparams = array('id' => $row->id, 'sesskey' => sesskey());
 144              $url = new moodle_url('/admin/tool/assignmentupgrade/upgradesingleconfirm.php', $urlparams);
 145              return html_writer::link($url, get_string('supported', 'tool_assignmentupgrade'));
 146          } else {
 147              return get_string('notsupported', 'tool_assignmentupgrade');
 148          }
 149      }
 150  
 151      /**
 152       * Insert a checkbox for selecting the current row for batch operations
 153       *
 154       * @param stdClass $row
 155       * @return string
 156       */
 157      public function col_select(stdClass $row) {
 158          global $CFG;
 159          $version = get_config('assignment_' . $row->type, 'version');
 160          require_once($CFG->dirroot . '/mod/assign/locallib.php');
 161          if (assign::can_upgrade_assignment($row->type, $version)) {
 162              $row->upgradable = true;
 163              return '<input type="checkbox" name="selectedassignment" value="' . $row->id . '"/>';
 164          }
 165          $row->upgradable = false;
 166          return '';
 167      }
 168  
 169      /**
 170       * Override the table show_hide_link to not show for select column
 171       *
 172       * @param string $column the column name, index into various names.
 173       * @param int $index numerical index of the column.
 174       * @return string HTML fragment.
 175       */
 176      protected function show_hide_link($column, $index) {
 177          if ($index > 0) {
 178              return parent::show_hide_link($column, $index);
 179          }
 180          return '';
 181      }
 182  }


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