MDL-38509 Add new tool_installaddon_installer::extract_installfromzip_file() method
[moodle.git] / admin / tool / installaddon / renderer.php
CommitLineData
0056f2a3
DM
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
27defined('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 */
35class 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
ddab904b
DM
61 $permcheckurl = new moodle_url('/admin/tool/installaddon/permcheck.php');
62 $this->page->requires->yui_module('moodle-tool_installaddon-permcheck', 'M.tool_installaddon.permcheck.init',
63 array(array('permcheckurl' => $permcheckurl->out())));
64 $this->page->requires->strings_for_js(
65 array('permcheckprogress', 'permcheckresultno', 'permcheckresultyes', 'permcheckerror'), 'tool_installaddon');
66
0056f2a3
DM
67 $out = $this->output->header();
68 $out .= $this->index_page_heading();
69 $out .= $this->index_page_repository();
70 $out .= $this->index_page_upload();
71 $out .= $this->output->footer();
72
73 return $out;
74 }
75
76 /**
77 * Renders the index page heading
78 *
79 * @return string
80 */
81 protected function index_page_heading() {
82 return $this->output->heading(get_string('pluginname', 'tool_installaddon'));
83 }
84
85 /**
86 * Renders the widget for browsing the add-on repository
87 *
88 * @return string
89 */
90 protected function index_page_repository() {
91
92 $url = $this->installer->get_addons_repository_url();
93
94 $out = $this->box(
95 $this->output->single_button($url, get_string('installfromrepo', 'tool_installaddon'), 'get').
96 $this->output->help_icon('installfromrepo', 'tool_installaddon'),
97 'generalbox', 'installfromrepobox'
98 );
99
100 return $out;
101 }
102
103 /**
104 * Renders the widget for uploading the add-on ZIP package
105 *
106 * @return string
107 */
108 protected function index_page_upload() {
109
110 $form = $this->installer->get_installfromzip_form();
111
112 ob_start();
113 $form->display();
114 $out = ob_get_clean();
115
116 $out = $this->box($out, 'generalbox', 'installfromzipbox');
117
118 return $out;
119 }
120}