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 Item
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 item implements \renderable, \templatable {
39
 
40
    /**
41
     * The unique id of the item
42
     *
43
     * @var string
44
     */
45
    protected $id;
46
 
47
    /**
48
     * The link to the item
49
     *
50
     * @var \moodle_url
51
     */
52
    protected $link;
53
 
54
    /**
55
     * The title of the item
56
     *
57
     * @var string
58
     */
59
    protected $title;
60
 
61
    /**
62
     * The description of the item
63
     *
64
     * @var string
65
     */
66
    protected $description;
67
 
68
    /**
69
     * The item's permalink
70
     *
71
     * @var \moodle_url
72
     */
73
    protected $permalink;
74
 
75
    /**
76
     * The publish date of the item in Unix timestamp format
77
     *
78
     * @var int
79
     */
80
    protected $timestamp;
81
 
82
    /**
83
     * Whether or not to show the item's description
84
     *
85
     * @var string
86
     */
87
    protected $showdescription;
88
 
89
    /**
90
     * Contructor
91
     *
92
     * @param string $id The id of the RSS item
93
     * @param \moodle_url $link The URL of the RSS item
94
     * @param string $title The title pf the RSS item
95
     * @param string $description The description of the RSS item
96
     * @param \moodle_url $permalink The permalink of the RSS item
97
     * @param int $timestamp The Unix timestamp that represents the published date
98
     * @param boolean $showdescription Whether or not to show the description
99
     */
100
    public function __construct($id, \moodle_url $link, $title, $description, \moodle_url $permalink, $timestamp,
101
            $showdescription = true) {
102
        $this->id               = $id;
103
        $this->link             = $link;
104
        $this->title            = $title;
105
        $this->description      = $description;
106
        $this->permalink        = $permalink;
107
        $this->timestamp        = $timestamp;
108
        $this->showdescription  = $showdescription;
109
    }
110
 
111
    /**
112
     * Export context for use in mustache templates
113
     *
114
     * @see templatable::export_for_template()
115
     * @param \renderer_base $output
116
     * @return array
117
     */
118
    public function export_for_template(\renderer_base $output) {
119
        $data = array(
120
            'id'            => $this->id,
121
            'permalink'     => clean_param($this->permalink, PARAM_URL),
122
            'datepublished' => $output->format_published_date($this->timestamp),
123
            'link'          => clean_param($this->link, PARAM_URL),
124
        );
125
 
126
        // If the item does not have a title, create one from the description.
127
        $title = $this->title;
128
        if (!$title) {
129
            $title = strip_tags($this->description);
130
            $title = \core_text::substr($title, 0, 20) . '...';
131
        }
132
 
133
        // Allow the renderer to format the title and description.
134
        $data['title']          = strip_tags($output->format_title($title));
135
        $data['description']    = $this->showdescription ? $output->format_description($this->description) : null;
136
 
137
        return $data;
138
    }
139
 
140
    /**
141
     * Set id
142
     *
143
     * @param string $id
144
     * @return \block_rss_client\output\item
145
     */
146
    public function set_id($id) {
147
        $this->id = $id;
148
 
149
        return $this;
150
    }
151
 
152
    /**
153
     * Get id
154
     *
155
     * @return string
156
     */
157
    public function get_id() {
158
        return $this->id;
159
    }
160
 
161
    /**
162
     * Set link
163
     *
164
     * @param \moodle_url $link
165
     * @return \block_rss_client\output\item
166
     */
167
    public function set_link(\moodle_url $link) {
168
        $this->link = $link;
169
 
170
        return $this;
171
    }
172
 
173
    /**
174
     * Get link
175
     *
176
     * @return \moodle_url
177
     */
178
    public function get_link() {
179
        return $this->link;
180
    }
181
 
182
    /**
183
     * Set title
184
     *
185
     * @param string $title
186
     * @return \block_rss_client\output\item
187
     */
188
    public function set_title($title) {
189
        $this->title = $title;
190
 
191
        return $this;
192
    }
193
 
194
    /**
195
     * Get title
196
     *
197
     * @return string
198
     */
199
    public function get_title() {
200
        return $this->title;
201
    }
202
 
203
    /**
204
     * Set description
205
     *
206
     * @param string $description
207
     * @return \block_rss_client\output\item
208
     */
209
    public function set_description($description) {
210
        $this->description = $description;
211
 
212
        return $this;
213
    }
214
 
215
    /**
216
     * Get description
217
     *
218
     * @return string
219
     */
220
    public function get_description() {
221
        return $this->description;
222
    }
223
 
224
    /**
225
     * Set permalink
226
     *
227
     * @param string $permalink
228
     * @return \block_rss_client\output\item
229
     */
230
    public function set_permalink($permalink) {
231
        $this->permalink = $permalink;
232
 
233
        return $this;
234
    }
235
 
236
    /**
237
     * Get permalink
238
     *
239
     * @return string
240
     */
241
    public function get_permalink() {
242
        return $this->permalink;
243
    }
244
 
245
    /**
246
     * Set timestamp
247
     *
248
     * @param int $timestamp
249
     * @return \block_rss_client\output\item
250
     */
251
    public function set_timestamp($timestamp) {
252
        $this->timestamp = $timestamp;
253
 
254
        return $this;
255
    }
256
 
257
    /**
258
     * Get timestamp
259
     *
260
     * @return string
261
     */
262
    public function get_timestamp() {
263
        return $this->timestamp;
264
    }
265
 
266
    /**
267
     * Set showdescription
268
     *
269
     * @param boolean $showdescription
270
     * @return \block_rss_client\output\item
271
     */
272
    public function set_showdescription($showdescription) {
273
        $this->showdescription = boolval($showdescription);
274
 
275
        return $this;
276
    }
277
 
278
    /**
279
     * Get showdescription
280
     *
281
     * @return boolean
282
     */
283
    public function get_showdescription() {
284
        return $this->showdescription;
285
    }
286
}