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 * Renderer class for manage subscriptions page.
19 *
20 * @package    tool_monitor
21 * @copyright  2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25namespace tool_monitor\output\managesubs;
26
27defined('MOODLE_INTERNAL') || die;
28
29/**
30 * Renderer class for manage subscriptions page.
31 *
32 * @since      Moodle 2.8
33 * @package    tool_monitor
34 * @copyright  2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
35 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class renderer extends \plugin_renderer_base {
38
39    /**
40     * Get html to display on the page.
41     *
42     * @param subs $renderable renderable widget
43     *
44     * @return string to display on the mangesubs page.
45     */
46    protected function render_subs(subs $renderable) {
47        $o = $this->render_table($renderable);
48        return $o;
49    }
50
51    /**
52     * Get html to display on the page.
53     *
54     * @param rules $renderable renderable widget
55     *
56     * @return string to display on the mangesubs page.
57     */
58    protected function render_rules(rules $renderable) {
59        $o = '';
60        if (!empty($renderable->totalcount)) {
61            $o .= $this->render_table($renderable);
62        }
63        return $o;
64    }
65
66    /**
67     * Get html to display on the page for select dropdown..
68     *
69     * @param rules $renderable renderable widget
70     *
71     * @return string to display on the mangesubs page.
72     */
73    protected function render_course_select(rules $renderable) {
74        if ($select = $renderable->get_user_courses_select()) {
75            return $this->render($select);
76        }
77    }
78
79    /**
80     * Get html to display on the page.
81     *
82     * @param rules|subs $renderable renderable widget
83     *
84     * @return string to display on the mangesubs page.
85     */
86    protected function render_table($renderable) {
87        $o = '';
88        ob_start();
89        $renderable->out($renderable->pagesize, true);
90        $o = ob_get_contents();
91        ob_end_clean();
92
93        return $o;
94    }
95
96    /**
97     * Html to add a link to go to the rule manager page.
98     *
99     * @param moodle_url $ruleurl The url of the rule manager page.
100     *
101     * @return string html for the link to the rule manager page.
102     */
103    public function render_rules_link($ruleurl) {
104        echo \html_writer::start_div();
105        $a = \html_writer::link($ruleurl, get_string('managerules', 'tool_monitor'));
106        $link = \html_writer::tag('span', get_string('manageruleslink', 'tool_monitor', $a));
107        echo $link;
108        echo \html_writer::end_div();
109    }
110}
111