Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Contains class block_rss_client\output\feed
19
 *
20
 * @package   block_rss_client
21
 * @copyright 2015 Howard County Public School System
22
 * @author    Brendan Anderson <brendan_anderson@hcpss.org>
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace block_rss_client\output;
27
 
28
defined('MOODLE_INTERNAL') || die();
29
 
30
/**
31
 * Class to help display an RSS Feed
32
 *
33
 * @package   block_rss_client
34
 * @copyright 2015 Howard County Public School System
35
 * @author    Brendan Anderson <brendan_anderson@hcpss.org>
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class feed implements \renderable, \templatable {
39
 
40
    /**
41
     * The feed's title
42
     *
43
     * @var string
44
     */
45
    protected $title = null;
46
 
47
    /**
1441 ariadna 48
     * The feed's channel link.
49
     *
50
     * @var string|null
51
     */
52
    protected ?string $channellink;
53
 
54
    /**
1 efrain 55
     * An array of renderable feed items
56
     *
57
     * @var array
58
     */
59
    protected $items = array();
60
 
61
    /**
62
     * The channel image
63
     *
64
     * @var channel_image
65
     */
66
    protected $image = null;
67
 
68
    /**
69
     * Whether or not to show the title
70
     *
71
     * @var boolean
72
     */
73
    protected $showtitle;
74
 
75
    /**
76
     * Whether or not to show the channel image
77
     *
78
     * @var boolean
79
     */
80
    protected $showimage;
81
 
82
    /**
83
     * Contructor
84
     *
85
     * @param string $title The title of the RSS feed
86
     * @param boolean $showtitle Whether to show the title
87
     * @param boolean $showimage Whether to show the channel image
1441 ariadna 88
     * @param string|null $channellink The channel link of the RSS feed
1 efrain 89
     */
1441 ariadna 90
    public function __construct($title, $showtitle = true, $showimage = true, ?string $channellink = null) {
1 efrain 91
        $this->title = $title;
92
        $this->showtitle = $showtitle;
93
        $this->showimage = $showimage;
1441 ariadna 94
        $this->channellink = $channellink;
1 efrain 95
    }
96
 
97
    /**
98
     * Export this for use in a mustache template context.
99
     *
100
     * @see templatable::export_for_template()
101
     * @param \renderer_base $output
102
     * @return array
103
     */
104
    public function export_for_template(\renderer_base $output) {
105
        $data = array(
106
            'title' => $this->showtitle ? $this->title : null,
107
            'image' => null,
108
            'items' => array(),
1441 ariadna 109
            'channellink' => $this->channellink ?? null,
1 efrain 110
        );
111
 
112
        if ($this->showimage && $this->image) {
113
            $data['image'] = $this->image->export_for_template($output);
114
        }
115
 
116
        foreach ($this->items as $item) {
117
            $data['items'][] = $item->export_for_template($output);
118
        }
119
 
120
        return $data;
121
    }
122
 
123
    /**
124
     * Set the feed title
125
     *
126
     * @param string $title
127
     * @return \block_rss_client\output\feed
128
     */
129
    public function set_title($title) {
130
        $this->title = $title;
131
 
132
        return $this;
133
    }
134
 
135
    /**
136
     * Get the feed title
137
     *
138
     * @return string
139
     */
140
    public function get_title() {
141
        return $this->title;
142
    }
143
 
144
    /**
1441 ariadna 145
     * Set the feed channel link.
146
     *
147
     * @param \moodle_url|null $channellink the URL to the channel website.
148
     */
149
    public function set_channellink(?\moodle_url $channellink) {
150
        $this->channellink = $channellink;
151
    }
152
 
153
    /**
1 efrain 154
     * Add an RSS item
155
     *
156
     * @param \block_rss_client\output\item $item
157
     */
158
    public function add_item(item $item) {
159
        $this->items[] = $item;
160
 
161
        return $this;
162
    }
163
 
164
    /**
165
     * Set the RSS items
166
     *
167
     * @param array $items An array of renderable RSS items
168
     */
169
    public function set_items(array $items) {
170
        $this->items = $items;
171
 
172
        return $this;
173
    }
174
 
175
    /**
176
     * Get the RSS items
177
     *
178
     * @return array An array of renderable RSS items
179
     */
180
    public function get_items() {
181
        return $this->items;
182
    }
183
 
184
    /**
185
     * Set the channel image
186
     *
187
     * @param \block_rss_client\output\channel_image $image
188
     */
189
    public function set_image(channel_image $image) {
190
        $this->image = $image;
191
    }
192
 
193
    /**
194
     * Get the channel image
195
     *
196
     * @return channel_image
197
     */
198
    public function get_image() {
199
        return $this->image;
200
    }
201
 
202
    /**
203
     * Set showtitle
204
     *
205
     * @param boolean $showtitle
206
     * @return \block_rss_client\output\feed
207
     */
208
    public function set_showtitle($showtitle) {
209
        $this->showtitle = boolval($showtitle);
210
 
211
        return $this;
212
    }
213
 
214
    /**
215
     * Get showtitle
216
     *
217
     * @return boolean
218
     */
219
    public function get_showtitle() {
220
        return $this->showtitle;
221
    }
222
 
223
    /**
224
     * Set showimage
225
     *
226
     * @param boolean $showimage
227
     * @return \block_rss_client\output\feed
228
     */
229
    public function set_showimage($showimage) {
230
        $this->showimage = boolval($showimage);
231
 
232
        return $this;
233
    }
234
 
235
    /**
236
     * Get showimage
237
     *
238
     * @return boolean
239
     */
240
    public function get_showimage() {
241
        return $this->showimage;
242
    }
243
}