[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 simple view - base class for the table 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\screen; 26 27 use html_table; 28 use html_writer; 29 use stdClass; 30 use grade_item; 31 use grade_grade; 32 use gradereport_singleview\local\ui\bulk_insert; 33 34 defined('MOODLE_INTERNAL') || die; 35 36 /** 37 * The gradebook simple view - base class for the table 38 * 39 * @package gradereport_singleview 40 * @copyright 2014 Moodle Pty Ltd (http://moodle.com) 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 abstract class tablelike extends screen { 44 45 /** @var array $headers A list of table headers */ 46 protected $headers = array(); 47 48 /** @var array $initerrors A list of errors that mean we should not show the table */ 49 protected $initerrors = array(); 50 51 /** @var array $definition Describes the columns in the table */ 52 protected $definition = array(); 53 54 /** 55 * Format a row of the table 56 * 57 * @param mixed $item 58 * @return string 59 */ 60 public abstract function format_line($item); 61 62 /** 63 * Get the summary for this table. 64 * 65 * @return string 66 */ 67 public abstract function summary(); 68 69 /** 70 * Get the table headers 71 * 72 * @return array 73 */ 74 public function headers() { 75 return $this->headers; 76 } 77 78 /** 79 * Set the table headers 80 * 81 * @param array $overwrite New headers 82 * @return tablelike This 83 */ 84 public function set_headers($overwrite) { 85 $this->headers = $overwrite; 86 return $this; 87 } 88 89 /** 90 * Get the list of errors 91 * 92 * @return array 93 */ 94 public function init_errors() { 95 return $this->initerrors; 96 } 97 98 /** 99 * Set an error detected while building the page. 100 * 101 * @param string $mesg 102 */ 103 public function set_init_error($mesg) { 104 $this->initerrors[] = $mesg; 105 } 106 107 /** 108 * Get the table definition 109 * 110 * @return array The definition. 111 */ 112 public function definition() { 113 return $this->definition; 114 } 115 116 /** 117 * Set the table definition 118 * 119 * @param array $overwrite New definition 120 * @return tablelike This 121 */ 122 public function set_definition($overwrite) { 123 $this->definition = $overwrite; 124 return $this; 125 } 126 127 /** 128 * Get a element to generate the HTML for this table row 129 * @param array $line This is a list of lines in the table (modified) 130 * @param grade_grade $grade The grade. 131 * @return string 132 */ 133 public function format_definition($line, $grade) { 134 foreach ($this->definition() as $i => $field) { 135 // Table tab index. 136 $tab = ($i * $this->total) + $this->index; 137 $classname = '\\gradereport_singleview\\local\\ui\\' . $field; 138 $html = new $classname($grade, $tab); 139 140 if ($field == 'finalgrade' and !empty($this->structure)) { 141 $html .= $this->structure->get_grade_analysis_icon($grade); 142 } 143 144 // Singleview users without proper permissions should be presented 145 // disabled checkboxes for the Exclude grade attribute. 146 if ($field == 'exclude' && !has_capability('moodle/grade:manage', $this->context)){ 147 $html->disabled = true; 148 } 149 150 $line[] = $html; 151 } 152 return $line; 153 } 154 155 /** 156 * Get the HTML for the whole table 157 * @return string 158 */ 159 public function html() { 160 global $OUTPUT; 161 162 if (!empty($this->initerrors)) { 163 $warnings = ''; 164 foreach ($this->initerrors as $mesg) { 165 $warnings .= $OUTPUT->notification($mesg); 166 } 167 return $warnings; 168 } 169 $table = new html_table(); 170 171 $table->head = $this->headers(); 172 173 $summary = $this->summary(); 174 if (!empty($summary)) { 175 $table->summary = $summary; 176 } 177 178 // To be used for extra formatting. 179 $this->index = 0; 180 $this->total = count($this->items); 181 182 foreach ($this->items as $item) { 183 if ($this->index >= ($this->perpage * $this->page) && 184 $this->index < ($this->perpage * ($this->page + 1))) { 185 $table->data[] = $this->format_line($item); 186 } 187 $this->index++; 188 } 189 190 $underlying = get_class($this); 191 192 $data = new stdClass(); 193 $data->table = $table; 194 $data->instance = $this; 195 196 $buttonattr = array('class' => 'singleview_buttons submit'); 197 $buttonhtml = implode(' ', $this->buttons()); 198 199 $buttons = html_writer::tag('div', $buttonhtml, $buttonattr); 200 $selectview = new select($this->courseid, $this->itemid, $this->groupid); 201 202 $sessionvalidation = html_writer::empty_tag('input', 203 array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); 204 205 $html = $selectview->html(); 206 $html .= html_writer::tag('form', 207 $buttons . html_writer::table($table) . $this->bulk_insert() . $buttons . $sessionvalidation, 208 array('method' => 'POST') 209 ); 210 $html .= $selectview->html(); 211 return $html; 212 } 213 214 /** 215 * Get the HTML for the bulk insert form 216 * 217 * @return string 218 */ 219 public function bulk_insert() { 220 return html_writer::tag( 221 'div', 222 (new bulk_insert($this->item))->html(), 223 array('class' => 'singleview_bulk') 224 ); 225 } 226 227 /** 228 * Get the buttons for saving changes. 229 * 230 * @return array 231 */ 232 public function buttons() { 233 $save = html_writer::empty_tag('input', array( 234 'type' => 'submit', 235 'value' => get_string('save', 'gradereport_singleview'), 236 )); 237 238 return array($save); 239 } 240 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |