Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]
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 * Renderable for display of license manager table. 19 * 20 * @package tool_licensemanager 21 * @copyright 2020 Tom Dickman <tomdickman@catalyst-au.net> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace tool_licensemanager\output; 25 26 use html_table; 27 use html_table_cell; 28 use html_table_row; 29 use html_writer; 30 use license_manager; 31 32 defined('MOODLE_INTERNAL') || die(); 33 34 /** 35 * Renderable for display of license manager table. 36 * 37 * @package tool_licensemanager 38 * @copyright 2020 Tom Dickman <tomdickman@catalyst-au.net> 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class table implements \renderable { 42 43 /** 44 * 'Create License' link. 45 * 46 * @return string HTML string. 47 */ 48 public function create_license_link() { 49 $link = html_writer::link(\tool_licensemanager\helper::get_create_license_url(), 50 get_string('createlicensebuttontext', 'tool_licensemanager'), 51 ['class' => 'btn btn-secondary mb-3']); 52 53 return $link; 54 } 55 56 /** 57 * Create the HTML table for license management. 58 * 59 * @param array $licenses 60 * @param \renderer_base $output 61 * 62 * @return string HTML for license manager table. 63 */ 64 public function create_license_manager_table(array $licenses, \renderer_base $output) { 65 $table = new html_table(); 66 $table->head = [ 67 get_string('enable'), 68 get_string('license', 'tool_licensemanager'), 69 get_string('version'), 70 get_string('order'), 71 get_string('edit'), 72 get_string('delete'), 73 ]; 74 $table->colclasses = [ 75 'text-center', 76 'text-left', 77 'text-left', 78 'text-center', 79 'text-center', 80 'text-center', 81 ]; 82 $table->id = 'manage-licenses'; 83 $table->attributes['class'] = 'admintable generaltable'; 84 $table->data = []; 85 86 $rownumber = 0; 87 $rowcount = count($licenses); 88 89 foreach ($licenses as $key => $value) { 90 $canmoveup = $rownumber > 0; 91 $canmovedown = $rownumber < $rowcount - 1; 92 $table->data[] = $this->get_license_table_row_data($value, $canmoveup, $canmovedown, $output); 93 $rownumber++; 94 } 95 96 $html = html_writer::table($table); 97 98 return $html; 99 } 100 101 /** 102 * Get table row data for a license. 103 * 104 * @param object $license the license to populate row data for. 105 * @param bool $canmoveup can this row move up. 106 * @param bool $canmovedown can this row move down. 107 * @param \renderer_base $output the renderer 108 * 109 * @return \html_table_row of columns values for row. 110 */ 111 protected function get_license_table_row_data($license, bool $canmoveup, bool $canmovedown, \renderer_base $output) { 112 global $CFG; 113 114 $summary = $license->fullname . ' ('. $license->shortname . ')'; 115 if (!empty($license->source)) { 116 $summary .= html_writer::empty_tag('br'); 117 $summary .= html_writer::link($license->source, $license->source, ['target' => '_blank']); 118 } 119 $summarycell = new html_table_cell($summary); 120 $summarycell->attributes['class'] = 'license-summary'; 121 $versioncell = new html_table_cell($license->version); 122 $versioncell->attributes['class'] = 'license-version'; 123 124 $deletelicense = ''; 125 if ($license->shortname == $CFG->sitedefaultlicense) { 126 $hideshow = $output->pix_icon('t/locked', get_string('sitedefaultlicenselock', 'tool_licensemanager')); 127 } else { 128 if ($license->enabled == license_manager::LICENSE_ENABLED) { 129 $hideshow = html_writer::link(\tool_licensemanager\helper::get_disable_license_url($license->shortname), 130 $output->pix_icon('t/hide', get_string('disablelicensename', 'tool_licensemanager', $license->fullname))); 131 } else { 132 $hideshow = html_writer::link(\tool_licensemanager\helper::get_enable_license_url($license->shortname), 133 $output->pix_icon('t/show', get_string('enablelicensename', 'tool_licensemanager', $license->fullname))); 134 } 135 136 if ($license->custom == license_manager::CUSTOM_LICENSE) { 137 $deletelink = new \moodle_url('/admin/tool/licensemanager/index.php', [ 138 'action' => 'delete', 139 'license' => $license->shortname, 140 'sesskey' => sesskey(), 141 ]); 142 $deletelicense = html_writer::link( 143 url: '#', 144 text: $output->pix_icon('i/trash', get_string('deletelicensename', 'tool_licensemanager', $license->fullname)), 145 attributes: [ 146 'class' => 'delete-license', 147 'data-modal' => 'confirmation', 148 'data-modal-title-str' => json_encode(['deletelicense', 'tool_licensemanager']), 149 'data-modal-content-str' => json_encode(['deletelicenseconfirmmessage', 'tool_licensemanager']), 150 'data-modal-destination' => $deletelink->out(false), 151 ], 152 ); 153 } 154 } 155 $hideshowcell = new html_table_cell($hideshow); 156 $hideshowcell->attributes['class'] = 'license-status'; 157 158 if ($license->custom == license_manager::CUSTOM_LICENSE) { 159 $editlicense = html_writer::link(\tool_licensemanager\helper::get_update_license_url($license->shortname), 160 $output->pix_icon('t/editinline', get_string('editlicensename', 'tool_licensemanager', $license->fullname)), 161 ['class' => 'edit-license']); 162 } else { 163 $editlicense = ''; 164 } 165 $editlicensecell = new html_table_cell($editlicense); 166 $editlicensecell->attributes['class'] = 'edit-license'; 167 168 $spacer = $output->pix_icon('spacer', '', 'moodle', ['class' => 'iconsmall']); 169 $updown = ''; 170 if ($canmoveup) { 171 $updown .= html_writer::link(\tool_licensemanager\helper::get_moveup_license_url($license->shortname), 172 $output->pix_icon('t/up', get_string('movelicenseupname', 'tool_licensemanager', $license->fullname), 173 'moodle', ['class' => 'iconsmall']), 174 ['class' => 'move-up']) . ''; 175 } else { 176 $updown .= $spacer; 177 } 178 179 if ($canmovedown) { 180 $updown .= ' '.html_writer::link(\tool_licensemanager\helper::get_movedown_license_url($license->shortname), 181 $output->pix_icon('t/down', get_string('movelicensedownname', 'tool_licensemanager', $license->fullname), 182 'moodle', ['class' => 'iconsmall']), 183 ['class' => 'move-down']); 184 } else { 185 $updown .= $spacer; 186 } 187 $updowncell = new html_table_cell($updown); 188 $updowncell->attributes['class'] = 'license-order'; 189 190 $row = new html_table_row([$hideshowcell, $summarycell, $versioncell, $updowncell, $editlicensecell, $deletelicense]); 191 $row->attributes['data-license'] = $license->shortname; 192 $row->attributes['class'] = strtolower(get_string('license', 'tool_licensemanager')); 193 194 return $row; 195 } 196 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body