Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 * Displays enrolment LTI instances. 19 * 20 * @package enrol_lti 21 * @copyright 2016 Mark Nelson <markn@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace enrol_lti; 26 27 defined('MOODLE_INTERNAL') || die; 28 29 global $CFG; 30 31 require_once($CFG->libdir . '/tablelib.php'); 32 33 /** 34 * Handles displaying enrolment LTI instances. 35 * 36 * @package enrol_lti 37 * @copyright 2016 Mark Nelson <markn@moodle.com> 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class manage_table extends \table_sql { 41 42 /** 43 * @var \enrol_plugin $ltiplugin 44 */ 45 protected $ltiplugin; 46 47 /** 48 * @var bool $ltienabled 49 */ 50 protected $ltienabled; 51 52 /** 53 * @var bool $canconfig 54 */ 55 protected $canconfig; 56 57 /** 58 * @var int $courseid The course id. 59 */ 60 protected $courseid; 61 62 /** 63 * Sets up the table. 64 * 65 * @param string $courseid The id of the course. 66 */ 67 public function __construct($courseid) { 68 parent::__construct('enrol_lti_manage_table'); 69 70 $this->define_columns(array( 71 'name', 72 'launch', 73 'registration', 74 'edit' 75 )); 76 $this->define_headers(array( 77 get_string('name'), 78 get_string('launchdetails', 'enrol_lti'), 79 get_string('registrationurl', 'enrol_lti'), 80 get_string('edit') 81 )); 82 $this->collapsible(false); 83 $this->sortable(false); 84 85 // Set the variables we need access to. 86 $this->ltiplugin = enrol_get_plugin('lti'); 87 $this->ltienabled = enrol_is_enabled('lti'); 88 $this->canconfig = has_capability('moodle/course:enrolconfig', \context_course::instance($courseid)); 89 $this->courseid = $courseid; 90 91 // Set help icons. 92 $launchicon = new \help_icon('launchdetails', 'enrol_lti'); 93 $regicon = new \help_icon('registrationurl', 'enrol_lti'); 94 $this->define_help_for_headers(['1' => $launchicon, '2' => $regicon]); 95 } 96 97 /** 98 * Generate the name column. 99 * 100 * @param \stdClass $tool event data. 101 * @return string 102 */ 103 public function col_name($tool) { 104 $name = helper::get_name($tool); 105 106 return $this->get_display_text($tool, $name); 107 } 108 109 /** 110 * Generate the launch column. 111 * 112 * @param \stdClass $tool instance data. 113 * @return string 114 */ 115 public function col_launch($tool) { 116 global $OUTPUT; 117 118 $url = helper::get_cartridge_url($tool); 119 120 $cartridgeurllabel = get_string('cartridgeurl', 'enrol_lti'); 121 $cartridgeurl = $url; 122 $secretlabel = get_string('secret', 'enrol_lti'); 123 $secret = $tool->secret; 124 $launchurl = helper::get_launch_url($tool->id); 125 $launchurllabel = get_string('launchurl', 'enrol_lti'); 126 127 $data = [ 128 "rows" => [ 129 [ "label" => $cartridgeurllabel, "text" => $cartridgeurl, "id" => "cartridgeurl", "hidelabel" => false ], 130 [ "label" => $secretlabel, "text" => $secret, "id" => "secret", "hidelabel" => false ], 131 [ "label" => $launchurllabel, "text" => $launchurl, "id" => "launchurl", "hidelabel" => false ], 132 ] 133 ]; 134 135 $return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data); 136 137 return $return; 138 } 139 140 /** 141 * Generate the Registration column. 142 * 143 * @param \stdClass $tool instance data. 144 * @return string 145 */ 146 public function col_registration($tool) { 147 global $OUTPUT; 148 149 $url = helper::get_proxy_url($tool); 150 151 $toolurllabel = get_string("registrationurl", "enrol_lti"); 152 $toolurl = $url; 153 154 $data = [ 155 "rows" => [ 156 [ "label" => $toolurllabel, "text" => $toolurl, "id" => "toolurl" , "hidelabel" => true], 157 ] 158 ]; 159 160 $return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data); 161 return $return; 162 } 163 164 /** 165 * Generate the edit column. 166 * 167 * @param \stdClass $tool event data. 168 * @return string 169 */ 170 public function col_edit($tool) { 171 global $OUTPUT; 172 173 $buttons = array(); 174 175 $instance = new \stdClass(); 176 $instance->id = $tool->enrolid; 177 $instance->courseid = $tool->courseid; 178 $instance->enrol = 'lti'; 179 $instance->status = $tool->status; 180 181 $strdelete = get_string('delete'); 182 $strenable = get_string('enable'); 183 $strdisable = get_string('disable'); 184 185 $url = new \moodle_url('/enrol/lti/index.php', array('sesskey' => sesskey(), 'courseid' => $this->courseid)); 186 187 if ($this->ltiplugin->can_delete_instance($instance)) { 188 $aurl = new \moodle_url($url, array('action' => 'delete', 'instanceid' => $instance->id)); 189 $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/delete', $strdelete, 'core', 190 array('class' => 'iconsmall'))); 191 } 192 193 if ($this->ltienabled && $this->ltiplugin->can_hide_show_instance($instance)) { 194 if ($instance->status == ENROL_INSTANCE_ENABLED) { 195 $aurl = new \moodle_url($url, array('action' => 'disable', 'instanceid' => $instance->id)); 196 $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/hide', $strdisable, 'core', 197 array('class' => 'iconsmall'))); 198 } else if ($instance->status == ENROL_INSTANCE_DISABLED) { 199 $aurl = new \moodle_url($url, array('action' => 'enable', 'instanceid' => $instance->id)); 200 $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/show', $strenable, 'core', 201 array('class' => 'iconsmall'))); 202 } 203 } 204 205 if ($this->ltienabled && $this->canconfig) { 206 $linkparams = array( 207 'courseid' => $instance->courseid, 208 'id' => $instance->id, 'type' => $instance->enrol, 209 'returnurl' => new \moodle_url('/enrol/lti/index.php', array('courseid' => $this->courseid)) 210 ); 211 $editlink = new \moodle_url("/enrol/editinstance.php", $linkparams); 212 $buttons[] = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit'), 'core', 213 array('class' => 'iconsmall'))); 214 } 215 216 return implode(' ', $buttons); 217 } 218 219 /** 220 * Query the reader. Store results in the object for use by build_table. 221 * 222 * @param int $pagesize size of page for paginated displayed table. 223 * @param bool $useinitialsbar do you want to use the initials bar. 224 */ 225 public function query_db($pagesize, $useinitialsbar = true) { 226 $total = \enrol_lti\helper::count_lti_tools(array('courseid' => $this->courseid)); 227 $this->pagesize($pagesize, $total); 228 $tools = \enrol_lti\helper::get_lti_tools(array('courseid' => $this->courseid), $this->get_page_start(), 229 $this->get_page_size()); 230 $this->rawdata = $tools; 231 // Set initial bars. 232 if ($useinitialsbar) { 233 $this->initialbars($total > $pagesize); 234 } 235 } 236 237 /** 238 * Returns text to display in the columns. 239 * 240 * @param \stdClass $tool the tool 241 * @param string $text the text to alter 242 * @return string 243 */ 244 protected function get_display_text($tool, $text) { 245 if ($tool->status != ENROL_INSTANCE_ENABLED) { 246 return \html_writer::tag('span', $text, array('class' => 'dimmed_text')); 247 } 248 249 return $text; 250 } 251 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body