Proyectos de Subversion Moodle

Rev

| 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
    /**
48
     * An array of renderable feed items
49
     *
50
     * @var array
51
     */
52
    protected $items = array();
53
 
54
    /**
55
     * The channel image
56
     *
57
     * @var channel_image
58
     */
59
    protected $image = null;
60
 
61
    /**
62
     * Whether or not to show the title
63
     *
64
     * @var boolean
65
     */
66
    protected $showtitle;
67
 
68
    /**
69
     * Whether or not to show the channel image
70
     *
71
     * @var boolean
72
     */
73
    protected $showimage;
74
 
75
    /**
76
     * Contructor
77
     *
78
     * @param string $title The title of the RSS feed
79
     * @param boolean $showtitle Whether to show the title
80
     * @param boolean $showimage Whether to show the channel image
81
     */
82
    public function __construct($title, $showtitle = true, $showimage = true) {
83
        $this->title = $title;
84
        $this->showtitle = $showtitle;
85
        $this->showimage = $showimage;
86
    }
87
 
88
    /**
89
     * Export this for use in a mustache template context.
90
     *
91
     * @see templatable::export_for_template()
92
     * @param \renderer_base $output
93
     * @return array
94
     */
95
    public function export_for_template(\renderer_base $output) {
96
        $data = array(
97
            'title' => $this->showtitle ? $this->title : null,
98
            'image' => null,
99
            'items' => array(),
100
        );
101
 
102
        if ($this->showimage && $this->image) {
103
            $data['image'] = $this->image->export_for_template($output);
104
        }
105
 
106
        foreach ($this->items as $item) {
107
            $data['items'][] = $item->export_for_template($output);
108
        }
109
 
110
        return $data;
111
    }
112
 
113
    /**
114
     * Set the feed title
115
     *
116
     * @param string $title
117
     * @return \block_rss_client\output\feed
118
     */
119
    public function set_title($title) {
120
        $this->title = $title;
121
 
122
        return $this;
123
    }
124
 
125
    /**
126
     * Get the feed title
127
     *
128
     * @return string
129
     */
130
    public function get_title() {
131
        return $this->title;
132
    }
133
 
134
    /**
135
     * Add an RSS item
136
     *
137
     * @param \block_rss_client\output\item $item
138
     */
139
    public function add_item(item $item) {
140
        $this->items[] = $item;
141
 
142
        return $this;
143
    }
144
 
145
    /**
146
     * Set the RSS items
147
     *
148
     * @param array $items An array of renderable RSS items
149
     */
150
    public function set_items(array $items) {
151
        $this->items = $items;
152
 
153
        return $this;
154
    }
155
 
156
    /**
157
     * Get the RSS items
158
     *
159
     * @return array An array of renderable RSS items
160
     */
161
    public function get_items() {
162
        return $this->items;
163
    }
164
 
165
    /**
166
     * Set the channel image
167
     *
168
     * @param \block_rss_client\output\channel_image $image
169
     */
170
    public function set_image(channel_image $image) {
171
        $this->image = $image;
172
    }
173
 
174
    /**
175
     * Get the channel image
176
     *
177
     * @return channel_image
178
     */
179
    public function get_image() {
180
        return $this->image;
181
    }
182
 
183
    /**
184
     * Set showtitle
185
     *
186
     * @param boolean $showtitle
187
     * @return \block_rss_client\output\feed
188
     */
189
    public function set_showtitle($showtitle) {
190
        $this->showtitle = boolval($showtitle);
191
 
192
        return $this;
193
    }
194
 
195
    /**
196
     * Get showtitle
197
     *
198
     * @return boolean
199
     */
200
    public function get_showtitle() {
201
        return $this->showtitle;
202
    }
203
 
204
    /**
205
     * Set showimage
206
     *
207
     * @param boolean $showimage
208
     * @return \block_rss_client\output\feed
209
     */
210
    public function set_showimage($showimage) {
211
        $this->showimage = boolval($showimage);
212
 
213
        return $this;
214
    }
215
 
216
    /**
217
     * Get showimage
218
     *
219
     * @return boolean
220
     */
221
    public function get_showimage() {
222
        return $this->showimage;
223
    }
224
}