Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * The gradebook simple view - base class for the table
 *
 * @package   gradereport_singleview
 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace gradereport_singleview\local\screen;

> use gradereport_singleview\local\ui\be_readonly;
use html_table; use html_writer; use stdClass;
< use grade_item;
use grade_grade; use gradereport_singleview\local\ui\bulk_insert; defined('MOODLE_INTERNAL') || die; /** * The gradebook simple view - base class for the table * * @package gradereport_singleview * @copyright 2014 Moodle Pty Ltd (http://moodle.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */
< abstract class tablelike extends screen {
> abstract class tablelike extends screen implements be_readonly {
< /** @var array $headers A list of table headers */ < protected $headers = array();
> /** > * A list of table headers > * @var array $headers > */ > protected $headers = []; > > /** > * A list of errors that mean we should not show the table > * @var array $initerrors > */ > protected $initerrors = []; > > /** > * Describes the columns in the table > * @var array $definition > */ > protected $definition = [];
< /** @var array $initerrors A list of errors that mean we should not show the table */ < protected $initerrors = array();
> /** > * Total items > * @var int $total > */ > protected $total; > > /** > * Table tab index > * @var int $index > */ > protected $index;
< /** @var array $definition Describes the columns in the table */ < protected $definition = array();
> /** > * The grade item or user. > * @var mixed $item > */ > protected $item;
/** * Format a row of the table *
< * @param mixed $item < * @return string
> * @var mixed $item > * @return array
*/
< public abstract function format_line($item);
> abstract public function format_line($item): array;
/** * Get the summary for this table. * * @return string */
< public abstract function summary();
> abstract public function summary(): string;
/** * Get the table headers * * @return array */
< public function headers() {
> public function headers(): array {
return $this->headers; } /** * Set the table headers * * @param array $overwrite New headers * @return tablelike This */
< public function set_headers($overwrite) {
> public function set_headers(array $overwrite): tablelike {
$this->headers = $overwrite; return $this; } /** * Get the list of errors * * @return array */
< public function init_errors() {
> public function init_errors(): array {
return $this->initerrors; } /** * Set an error detected while building the page. * * @param string $mesg */
< public function set_init_error($mesg) {
> public function set_init_error(string $mesg) {
$this->initerrors[] = $mesg; } /** * Get the table definition * * @return array The definition. */
< public function definition() {
> public function definition(): array {
return $this->definition; } /** * Set the table definition * * @param array $overwrite New definition * @return tablelike This */
< public function set_definition($overwrite) {
> public function set_definition(array $overwrite): tablelike {
$this->definition = $overwrite; return $this; } /** * Get a element to generate the HTML for this table row
< * @param array $line This is a list of lines in the table (modified)
* @param grade_grade $grade The grade.
< * @return string
> * @return array
*/
< public function format_definition($line, $grade) {
> public function format_definition(grade_grade $grade): array { > $line = [];
foreach ($this->definition() as $i => $field) { // Table tab index. $tab = ($i * $this->total) + $this->index; $classname = '\\gradereport_singleview\\local\\ui\\' . $field; $html = new $classname($grade, $tab); if ($field == 'finalgrade' and !empty($this->structure)) {
< $html .= $this->structure->get_grade_analysis_icon($grade);
> $html .= $this->structure->get_grade_action_menu($grade);
} // Singleview users without proper permissions should be presented // disabled checkboxes for the Exclude grade attribute. if ($field == 'exclude' && !has_capability('moodle/grade:manage', $this->context)){ $html->disabled = true; }
< $line[] = $html;
> $line[$field] = $html;
} return $line; } /** * Get the HTML for the whole table * @return string */
< public function html() {
> public function html(): string {
global $OUTPUT; if (!empty($this->initerrors)) { $warnings = ''; foreach ($this->initerrors as $mesg) { $warnings .= $OUTPUT->notification($mesg); } return $warnings; } $table = new html_table();
> $table->id = 'singleview-grades';
$table->head = $this->headers(); $summary = $this->summary(); if (!empty($summary)) { $table->caption = $summary; $table->captionhide = true; } // To be used for extra formatting. $this->index = 0; $this->total = count($this->items); foreach ($this->items as $item) { if ($this->index >= ($this->perpage * $this->page) && $this->index < ($this->perpage * ($this->page + 1))) { $table->data[] = $this->format_line($item); } $this->index++; }
< $underlying = get_class($this); <
$data = new stdClass(); $data->table = $table; $data->instance = $this;
< $buttonattr = array('class' => 'singleview_buttons submit'); < $buttonhtml = implode(' ', $this->buttons());
> $html = html_writer::table($table);
< $buttons = html_writer::tag('div', $buttonhtml, $buttonattr); < $selectview = new select($this->courseid, $this->itemid, $this->groupid); < < $sessionvalidation = html_writer::empty_tag('input', < array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); < < $html = $selectview->html(); < $html .= html_writer::tag('form', < $buttons . html_writer::table($table) . $this->bulk_insert() . $buttons . $sessionvalidation, < array('method' => 'POST') < ); < $html .= $selectview->html(); < return $html;
> return html_writer::div($html, 'reporttable position-relative');
} /** * Get the HTML for the bulk insert form * * @return string */ public function bulk_insert() { return html_writer::tag( 'div', (new bulk_insert($this->item))->html(),
< array('class' => 'singleview_bulk')
> ['class' => 'singleview_bulk', 'hidden' => 'hidden']
); } /**
> * Return true if this is read-only. * Get the buttons for saving changes. > * * > * @return bool * @return array > */ */ > public function is_readonly(): bool { public function buttons() { > global $USER; global $OUTPUT; > return empty($USER->editing); > } $save = $OUTPUT->render_from_template('gradereport_singleview/button', [ > 'type' => 'submit', > /**
'value' => get_string('save', 'gradereport_singleview'),
> * @param bool $disabled If button is disabled
< public function buttons() {
> public function buttons(bool $disabled = false): array {
< < $save = $OUTPUT->render_from_template('gradereport_singleview/button', [ < 'type' => 'submit', < 'value' => get_string('save', 'gradereport_singleview'), < ]); < < return array($save);
> $params = ['type' => 'submit', 'value' => get_string('save', 'gradereport_singleview')]; > if ($disabled) { > $params['disabled'] = 'disabled'; > } > return [$OUTPUT->render_from_template('gradereport_singleview/button', $params)];