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
defined('MOODLE_INTERNAL') || die();
18
 
19
// Forum.
20
require_once($CFG->dirroot . "/mod/forum/renderer.php");
21
class theme_universe_mod_forum_renderer extends plugin_renderer_base {
22
    /**
23
     * Returns the navigation to the previous and next discussion.
24
     *
25
     * @param mixed $prev Previous discussion record, or false.
26
     * @param mixed $next Next discussion record, or false.
27
     * @return string The output.
28
     */
29
    public function neighbouring_discussion_navigation($prev, $next) {
30
        $html = '';
31
        if ($prev || $next) {
32
            $html .= html_writer::start_tag('div', array('class' => 'discussion-nav clearfix border p-2 rounded'));
33
            $html .= html_writer::start_tag('ul');
34
            if ($prev) {
35
                $url = new moodle_url('/mod/forum/discuss.php', array('d' => $prev->id));
36
                $html .= html_writer::start_tag('li', array('class' => 'prev-discussion'));
37
                $html .= html_writer::link(
38
                    $url,
39
                    '<svg class="mr-2" width="16" height="16" stroke-width="2" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor">
40
                    <path d="M18.5 12H6m0 0l6-6m-6 6l6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
41
                    </svg>' . format_string($prev->name),
42
                    array(
43
                        'aria-label' => get_string('prevdiscussiona', 'mod_forum', format_string($prev->name)),
44
                        'class' => 'btn btn-xs btn-secondary text-truncate'
45
                    )
46
                );
47
                $html .= html_writer::end_tag('li');
48
            }
49
            if ($next) {
50
                $url = new moodle_url('/mod/forum/discuss.php', array('d' => $next->id));
51
                $html .= html_writer::start_tag('li', array('class' => 'next-discussion'));
52
                $html .= html_writer::link(
53
                    $url,
54
                    format_string($next->name) . '<svg class="ml-2" width="16" height="16" stroke-width="2" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor">
55
                            <path d="M6 12h12.5m0 0l-6-6m6 6l-6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
56
                        </svg>',
57
                    array(
58
                        'aria-label' => get_string('nextdiscussiona', 'mod_forum', format_string($next->name)),
59
                        'class' => 'btn btn-xs btn-secondary text-truncate'
60
                    )
61
                );
62
                $html .= html_writer::end_tag('li');
63
            }
64
            $html .= html_writer::end_tag('ul');
65
            $html .= html_writer::end_tag('div');
66
        }
67
        return $html;
68
    }
69
 
70
    /**
71
     * This method is used to generate HTML for a subscriber selection form that
72
     * uses two user_selector controls
73
     *
74
     * @param user_selector_base $existinguc
75
     * @param user_selector_base $potentialuc
76
     * @return string
77
     */
78
    public function subscriber_selection_form(user_selector_base $existinguc, user_selector_base $potentialuc) {
79
        $output = '';
80
        $formattributes = array();
81
        $formattributes['id'] = 'subscriberform';
82
        $formattributes['action'] = '';
83
        $formattributes['method'] = 'post';
84
        $output .= html_writer::start_tag('form', $formattributes);
85
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
86
 
87
        $existingcell = new html_table_cell();
88
        $existingcell->text = $existinguc->display(true);
89
        $existingcell->attributes['class'] = 'existing';
90
        $actioncell = new html_table_cell();
91
        $actioncell->text = html_writer::start_tag('div', array());
92
        $actioncell->text .= html_writer::empty_tag('input',
93
            array('type' => 'submit',
94
                  'name' => 'subscribe',
95
                  'value' => get_string('add'),
96
                  'class' => 'actionbutton btn btn-success')
97
        );
98
        $actioncell->text .= html_writer::empty_tag('input',
99
            array('type' => 'submit',
100
                  'name' => 'unsubscribe',
101
                  'value' => get_string('remove'),
102
                  'class' => 'actionbutton btn btn-danger')
103
        );
104
        $actioncell->text .= html_writer::end_tag('div', array());
105
        $actioncell->attributes['class'] = 'actions px-3';
106
        $potentialcell = new html_table_cell();
107
        $potentialcell->text = $potentialuc->display(true);
108
        $potentialcell->attributes['class'] = 'potential';
109
 
110
        $output .= html_writer::start_tag('fieldset', array('class' => 'w-100'));
111
        $table = new html_table();
112
        $table->attributes['class'] = 'subscribertable boxaligncenter mb-2 border-bottom';
113
        $table->data = array(new html_table_row(array($existingcell, $actioncell, $potentialcell)));
114
        $output .= html_writer::table($table);
115
        $output .= html_writer::end_tag('fieldset');
116
 
117
        $output .= html_writer::end_tag('form');
118
        return $output;
119
    }
120
 
121
    /**
122
     * This function generates HTML to display a subscriber overview, primarily used on
123
     * the subscribers page if editing was turned off
124
     *
125
     * @param array $users
126
     * @param object $forum
127
     * @param object $course
128
     * @return string
129
     */
130
    public function subscriber_overview($users, $forum, $course) {
131
        $output = '';
132
        $modinfo = get_fast_modinfo($course);
133
        if (!$users || !is_array($users) || count($users) === 0) {
134
            $output .= $this->output->notification(
135
                get_string("nosubscribers", "forum"),
136
                \core\output\notification::NOTIFY_INFO,
137
                false
138
            );
139
        } else if (!isset($modinfo->instances['forum'][$forum->id])) {
140
            $output .= $this->output->heading(get_string("invalidmodule", "error"));
141
        } else {
142
            $cm = $modinfo->instances['forum'][$forum->id];
143
            // TODO Does not support custom user profile fields (MDL-70456).
144
            $canviewemail = in_array('email', \core_user\fields::get_identity_fields(context_module::instance($cm->id), false));
145
            $strparams = new stdclass();
146
            $strparams->name = format_string($forum->name);
147
            $strparams->count = count($users);
148
            $output .= $this->output->heading(get_string("subscriberstowithcount", "forum", $strparams));
149
            $table = new html_table();
150
            $table->cellpadding = 5;
151
            $table->cellspacing = 5;
152
            $table->tablealign = 'center';
153
            $table->data = array();
154
            foreach ($users as $user) {
155
                $info = array($this->output->user_picture($user, array('courseid' => $course->id)), fullname($user));
156
                if ($canviewemail) {
157
                    array_push($info, $user->email);
158
                }
159
                $table->data[] = $info;
160
            }
161
            $output .= html_writer::table($table);
162
        }
163
        return $output;
164
    }
165
 
166
    /**
167
     * This is used to display a control containing all of the subscribed users so that
168
     * it can be searched
169
     *
170
     * @param user_selector_base $existingusers
171
     * @return string
172
     */
173
    public function subscribed_users(user_selector_base $existingusers) {
174
        $output = $this->output->box_start('subscriberdiv boxaligncenter');
175
        $output .= html_writer::tag('p', get_string('forcesubscribed', 'forum'));
176
        $output .= $existingusers->display(true);
177
        $output .= $this->output->box_end();
178
        return $output;
179
    }
180
 
181
    /**
182
     * Generate the HTML for an icon to be displayed beside the subject of a timed discussion.
183
     *
184
     * @param object $discussion
185
     * @param bool $visiblenow Indicicates that the discussion is currently
186
     * visible to all users.
187
     * @return string
188
     */
189
    public function timed_discussion_tooltip($discussion, $visiblenow) {
190
        $dates = array();
191
        if ($discussion->timestart) {
192
            $dates[] = get_string('displaystart', 'mod_forum') . ': ' . userdate($discussion->timestart);
193
        }
194
        if ($discussion->timeend) {
195
            $dates[] = get_string('displayend', 'mod_forum') . ': ' . userdate($discussion->timeend);
196
        }
197
 
198
        $str = $visiblenow ? 'timedvisible' : 'timedhidden';
199
        $dates[] = get_string($str, 'mod_forum');
200
 
201
        $tooltip = implode("\n", $dates);
202
        return $this->pix_icon('i/calendar', $tooltip, 'moodle', array('class' => 'smallicon timedpost'));
203
    }
204
 
205
    /**
206
     * Display a forum post in the relevant context.
207
     *
208
     * @param \mod_forum\output\forum_post $post The post to display.
209
     * @return string
210
     */
211
    public function render_forum_post_email(\mod_forum\output\forum_post_email $post) {
212
        $data = $post->export_for_template($this, $this->target === RENDERER_TARGET_TEXTEMAIL);
213
        return $this->render_from_template('mod_forum/' . $this->forum_post_template(), $data);
214
    }
215
 
216
    /**
217
     * The template name for this renderer.
218
     *
219
     * @return string
220
     */
221
    public function forum_post_template() {
222
        return 'forum_post';
223
    }
224
 
225
    /**
226
     * Create the inplace_editable used to select forum digest options.
227
     *
228
     * @param   stdClass    $forum  The forum to create the editable for.
229
     * @param   int         $value  The current value for this user
230
     * @return  inplace_editable
231
     */
232
    public function render_digest_options($forum, $value) {
233
        $options = forum_get_user_digest_options();
234
        $editable = new \core\output\inplace_editable(
235
            'mod_forum',
236
            'digestoptions',
237
            $forum->id,
238
            true,
239
            $options[$value],
240
            $value
241
        );
242
 
243
        $editable->set_type_select($options);
244
 
245
        return $editable;
246
    }
247
 
248
    /**
249
     * Render quick search form.
250
     *
251
     * @param \mod_forum\output\quick_search_form $form The renderable.
252
     * @return string rendered HTML string from the template.
253
     */
254
    public function render_quick_search_form(\mod_forum\output\quick_search_form $form) {
255
        if (strpos($this->page->url->get_path(), "index.php")) {
256
            return $this->render_from_template('mod_forum/quick_search_form', $form->export_for_template($this));
257
        }
258
 
259
        return $this->render_from_template('mod_forum/forum_new_discussion_actionbar', $form->export_for_template($this));
260
    }
261
 
262
    /**
263
     * Render the view action area.
264
     *
265
     * @param \mod_forum\output\forum_actionbar $actionbar forum_actionbar object.
266
     * @return string rendered HTML string
267
     */
268
    public function render_activity_actionbar(\mod_forum\output\forum_actionbar $actionbar): string {
269
        return $this->render_from_template('mod_forum/forum_actionbar', $actionbar->export_for_template($this));
270
    }
271
 
272
    /**
273
     * Render the subscription action area.
274
     *
275
     * @param \mod_forum\output\subscription_actionbar $subscriptionactionbar subscription_actionbar object.
276
     * @return bool|string rendered HTML string.
277
     */
278
    public function subscription_actionbar(\mod_forum\output\subscription_actionbar $subscriptionactionbar): string {
279
        return $this->render_from_template(
280
            'mod_forum/forum_subscription_action',
281
            $subscriptionactionbar->export_for_template($this)
282
        );
283
    }
284
 
285
    /**
286
     * Render big search form.
287
     *
288
     * @param \mod_forum\output\big_search_form $form The renderable.
289
     * @return string
290
     */
291
    public function render_big_search_form(\mod_forum\output\big_search_form $form) {
292
        return $this->render_from_template('mod_forum/big_search_form', $form->export_for_template($this));
293
    }
294
}