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