MDL-38509 Mark the new installaddon admin tool as the standard plugin
[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
61 $out = $this->output->header();
62 $out .= $this->index_page_heading();
63 $out .= $this->index_page_repository();
64 $out .= $this->index_page_upload();
65 $out .= $this->output->footer();
66
67 return $out;
68 }
69
70 /**
71 * Renders the index page heading
72 *
73 * @return string
74 */
75 protected function index_page_heading() {
76 return $this->output->heading(get_string('pluginname', 'tool_installaddon'));
77 }
78
79 /**
80 * Renders the widget for browsing the add-on repository
81 *
82 * @return string
83 */
84 protected function index_page_repository() {
85
86 $url = $this->installer->get_addons_repository_url();
87
88 $out = $this->box(
89 $this->output->single_button($url, get_string('installfromrepo', 'tool_installaddon'), 'get').
90 $this->output->help_icon('installfromrepo', 'tool_installaddon'),
91 'generalbox', 'installfromrepobox'
92 );
93
94 return $out;
95 }
96
97 /**
98 * Renders the widget for uploading the add-on ZIP package
99 *
100 * @return string
101 */
102 protected function index_page_upload() {
103
104 $form = $this->installer->get_installfromzip_form();
105
106 ob_start();
107 $form->display();
108 $out = ob_get_clean();
109
110 $out = $this->box($out, 'generalbox', 'installfromzipbox');
111
112 return $out;
113 }
114}