1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * Output rendering for the plugin. 20 * 21 * @package tool_installaddon 22 * @category output 23 * @copyright 2013 David Mudrak <david@moodle.com> 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 /** 30 * Implements the plugin renderer 31 * 32 * @copyright 2013 David Mudrak <david@moodle.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class tool_installaddon_renderer extends plugin_renderer_base { 36 37 /** @var tool_installaddon_installer */ 38 protected $installer = null; 39 40 /** 41 * Sets the tool_installaddon_installer instance being used. 42 * 43 * @throws coding_exception if the installer has been already set 44 * @param tool_installaddon_installer $installer 45 */ 46 public function set_installer_instance(tool_installaddon_installer $installer) { 47 if (is_null($this->installer)) { 48 $this->installer = $installer; 49 } else { 50 throw new coding_exception('Attempting to reset the installer instance.'); 51 } 52 } 53 54 /** 55 * Defines the index page layout 56 * 57 * @return string 58 */ 59 public function index_page() { 60 61 if (is_null($this->installer)) { 62 throw new coding_exception('Installer instance has not been set.'); 63 } 64 65 $permcheckurl = new moodle_url('/admin/tool/installaddon/permcheck.php'); 66 $this->page->requires->yui_module('moodle-tool_installaddon-permcheck', 'M.tool_installaddon.permcheck.init', 67 array(array('permcheckurl' => $permcheckurl->out()))); 68 $this->page->requires->strings_for_js( 69 array('permcheckprogress', 'permcheckresultno', 'permcheckresultyes', 'permcheckerror', 'permcheckrepeat'), 70 'tool_installaddon'); 71 72 $out = $this->output->header(); 73 $out .= $this->index_page_heading(); 74 $out .= $this->index_page_repository(); 75 $out .= $this->index_page_upload(); 76 $out .= $this->output->footer(); 77 78 return $out; 79 } 80 81 /** 82 * Inform the user that the ZIP is not a valid plugin package file. 83 * 84 * @param moodle_url $continueurl 85 * @return string 86 */ 87 public function zip_not_valid_plugin_package_page(moodle_url $continueurl) { 88 89 $out = $this->output->header(); 90 $out .= $this->output->heading(get_string('installfromzip', 'tool_installaddon')); 91 $out .= $this->output->box(get_string('installfromzipinvalid', 'tool_installaddon'), 'generalbox', 'notice'); 92 $out .= $this->output->continue_button($continueurl, 'get'); 93 $out .= $this->output->footer(); 94 95 return $out; 96 } 97 98 /** 99 * Inform the user about invalid remote installation request. 100 * 101 * @param moodle_url $continueurl 102 * @return string 103 */ 104 public function remote_request_invalid_page(moodle_url $continueurl) { 105 106 $out = $this->output->header(); 107 $out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon')); 108 $out .= $this->output->box(get_string('remoterequestinvalid', 'tool_installaddon'), 'generalbox', 'notice'); 109 $out .= $this->output->continue_button($continueurl, 'get'); 110 $out .= $this->output->footer(); 111 112 return $out; 113 } 114 115 /** 116 * Inform the user that such plugin is already installed 117 * 118 * @param stdClass $data decoded request data 119 * @param moodle_url $continueurl 120 * @return string 121 */ 122 public function remote_request_alreadyinstalled_page(stdClass $data, moodle_url $continueurl) { 123 124 $out = $this->output->header(); 125 $out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon')); 126 $out .= $this->output->box(get_string('remoterequestalreadyinstalled', 'tool_installaddon', $data), 'generalbox', 'notice'); 127 $out .= $this->output->continue_button($continueurl, 'get'); 128 $out .= $this->output->footer(); 129 130 return $out; 131 } 132 133 /** 134 * Let the user confirm the remote installation request. 135 * 136 * @param stdClass $data decoded request data 137 * @param moodle_url $continueurl 138 * @param moodle_url $cancelurl 139 * @return string 140 */ 141 public function remote_request_confirm_page(stdClass $data, moodle_url $continueurl, moodle_url $cancelurl) { 142 143 $out = $this->output->header(); 144 $out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon')); 145 $out .= $this->output->confirm(get_string('remoterequestconfirm', 'tool_installaddon', $data), $continueurl, $cancelurl); 146 $out .= $this->output->footer(); 147 148 return $out; 149 } 150 151 /** 152 * Inform the user that the target plugin type location is not writable. 153 * 154 * @param stdClass $data decoded request data 155 * @param string $plugintypepath full path to the plugin type location 156 * @param moodle_url $continueurl to repeat the write permission check 157 * @param moodle_url $cancelurl to cancel the installation 158 * @return string 159 */ 160 public function remote_request_permcheck_page(stdClass $data, $plugintypepath, moodle_url $continueurl, moodle_url $cancelurl) { 161 162 $data->typepath = $plugintypepath; 163 164 $out = $this->output->header(); 165 $out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon')); 166 $out .= $this->output->confirm(get_string('remoterequestpermcheck', 'tool_installaddon', $data), $continueurl, $cancelurl); 167 $out .= $this->output->footer(); 168 169 return $out; 170 } 171 172 /** 173 * Inform the user that the requested remote plugin is not installable. 174 * 175 * @param stdClass $data decoded request data with ->reason property added 176 * @param moodle_url $continueurl 177 * @return string 178 */ 179 public function remote_request_non_installable_page(stdClass $data, moodle_url $continueurl) { 180 181 $out = $this->output->header(); 182 $out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon')); 183 $out .= $this->output->box(get_string('remoterequestnoninstallable', 'tool_installaddon', $data), 'generalbox', 'notice'); 184 $out .= $this->output->continue_button($continueurl, 'get'); 185 $out .= $this->output->footer(); 186 187 return $out; 188 } 189 190 // End of the external API ///////////////////////////////////////////////// 191 192 /** 193 * Renders the index page heading 194 * 195 * @return string 196 */ 197 protected function index_page_heading() { 198 return $this->output->heading(get_string('pluginname', 'tool_installaddon')); 199 } 200 201 /** 202 * Renders the widget for browsing the add-on repository 203 * 204 * @return string 205 */ 206 protected function index_page_repository() { 207 208 $url = $this->installer->get_addons_repository_url(); 209 210 $out = $this->box( 211 $this->output->single_button($url, get_string('installfromrepo', 'tool_installaddon'), 'get'). 212 $this->output->help_icon('installfromrepo', 'tool_installaddon'), 213 'generalbox', 'installfromrepobox' 214 ); 215 216 return $out; 217 } 218 219 /** 220 * Renders the widget for uploading the add-on ZIP package 221 * 222 * @return string 223 */ 224 protected function index_page_upload() { 225 226 $form = $this->installer->get_installfromzip_form(); 227 228 ob_start(); 229 $form->display(); 230 $out = ob_get_clean(); 231 232 $out = $this->box($out, 'generalbox', 'installfromzipbox'); 233 234 return $out; 235 } 236 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body