first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,263 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Big search form.
*
* @package mod_forum
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output;
defined('MOODLE_INTERNAL') || die();
use html_writer;
use moodle_url;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* Big search form class.
*
* @package mod_forum
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class big_search_form implements renderable, templatable {
public $course;
public $datefrom;
public $dateto;
public $forumoptions;
public $fullwords;
public $notwords;
public $phrase;
public $showfullwords;
public $subject;
public $user;
public $words;
public $tags;
/** @var string The URL of the search form. */
public $actionurl;
/** @var bool Is the user a guest user? */
public $guestuser;
/** @var bool Whether the include starredonly checkbox is checked. */
public $starredonly;
/** @var int forum ID. */
public $forumid;
/**
* Constructor.
*
* @param object $course The course.
* @param object $user The user.
*/
public function __construct($course) {
global $DB, $USER;
$this->course = $course;
$this->tags = [];
$this->guestuser = !isloggedin() || isguestuser($USER);
$this->showfullwords = $DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres';
$this->actionurl = new moodle_url('/mod/forum/search.php');
$forumoptions = ['' => get_string('allforums', 'forum')] + forum_menu_list($course);
$this->forumoptions = array_map(function($option) use ($forumoptions) {
return [
'value' => $option,
'name' => $forumoptions[$option]
];
}, array_keys($forumoptions));
}
/**
* Set date from.
*
* @param mixed $value Date from.
*/
public function set_datefrom($value) {
$this->datefrom = $value;
}
/**
* Set date to.
*
* @param mixed $value Date to.
*/
public function set_dateto($value) {
$this->dateto = $value;
}
/**
* Set full words.
*
* @param mixed $value Full words.
*/
public function set_fullwords($value) {
$this->fullwords = $value;
}
/**
* Set not words.
*
* @param mixed $value Not words.
*/
public function set_notwords($value) {
$this->notwords = $value;
}
/**
* Set phrase.
*
* @param mixed $value Phrase.
*/
public function set_phrase($value) {
$this->phrase = $value;
}
/**
* Set subject.
*
* @param mixed $value Subject.
*/
public function set_subject($value) {
$this->subject = $value;
}
/**
* Set user.
*
* @param mixed $value User.
*/
public function set_user($value) {
$this->user = $value;
}
/**
* Set words.
*
* @param mixed $value Words.
*/
public function set_words($value) {
$this->words = $value;
}
/**
* Set tags.
*
* @param mixed $value Tags.
*/
public function set_tags($value) {
$this->tags = $value;
}
/**
* Set starred only value.
*
* @param mixed $value Bool.
*/
public function set_starredonly($value) {
$this->starredonly = $value;
}
/**
* Forum ID setter search criteria.
*
* @param int $forumid The forum ID.
*/
public function set_forumid($forumid) {
$this->forumid = $forumid;
}
public function export_for_template(renderer_base $output) {
global $DB, $CFG, $PAGE;
$data = new stdClass();
$data->courseid = $this->course->id;
$data->words = $this->words;
$data->phrase = $this->phrase;
$data->notwords = $this->notwords;
$data->fullwords = $this->fullwords;
$data->datefromchecked = !empty($this->datefrom);
$data->datetochecked = !empty($this->dateto);
$data->subject = $this->subject;
$data->user = $this->user;
$data->showfullwords = $this->showfullwords;
$data->guestuser = $this->guestuser;
$data->starredonly = $this->starredonly;
$data->actionurl = $this->actionurl->out(false);
$tagtypestoshow = \core_tag_area::get_showstandard('mod_forum', 'forum_posts');
$showstandard = ($tagtypestoshow != \core_tag_tag::HIDE_STANDARD);
$typenewtags = ($tagtypestoshow != \core_tag_tag::STANDARD_ONLY);
$PAGE->requires->js_call_amd('core/form-autocomplete', 'enhance', $params = array('#tags', $typenewtags, '',
get_string('entertags', 'tag'), false, $showstandard, get_string('noselection', 'form')));
$data->tagsenabled = \core_tag_tag::is_enabled('mod_forum', 'forum_posts');
$namefield = empty($CFG->keeptagnamecase) ? 'name' : 'rawname';
$tags = $DB->get_records('tag',
array('isstandard' => 1, 'tagcollid' => \core_tag_area::get_collection('mod_forum', 'forum_posts')),
$namefield, 'rawname,' . $namefield . ' as fieldname');
$data->tags = [];
foreach ($tags as $tag) {
$data->tagoptions[] = ['value' => $tag->rawname,
'text' => $tag->fieldname,
'selected' => in_array($tag->rawname, $this->tags)
];
}
$datefrom = $this->datefrom;
if (empty($datefrom)) {
$datefrom = make_timestamp(2000, 1, 1, 0, 0, 0);
}
$dateto = $this->dateto;
if (empty($dateto)) {
$dateto = time() + HOURSECS;
}
$data->datefromfields = html_writer::div(html_writer::select_time('days', 'fromday', $datefrom), 'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('months', 'frommonth', $datefrom),
'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('years', 'fromyear', $datefrom), 'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('hours', 'fromhour', $datefrom), 'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('minutes', 'fromminute', $datefrom),
'mb-3 fitem ml-2');
$data->datetofields = html_writer::div(html_writer::select_time('days', 'today', $dateto), 'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('months', 'tomonth', $dateto), 'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('years', 'toyear', $dateto), 'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('hours', 'tohour', $dateto), 'mb-3 fitem ml-2')
. html_writer::div(html_writer::select_time('minutes', 'tominute', $dateto), 'mb-3 fitem ml-2');
if ($this->forumid && !empty($this->forumoptions)) {
foreach ($this->forumoptions as $index => $option) {
if ($option['value'] == $this->forumid) {
$this->forumoptions[$index]['selected'] = true;
} else {
$this->forumoptions[$index]['selected'] = false;
}
}
}
$data->forumoptions = $this->forumoptions;
return $data;
}
}
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_forum\output\courseformat;
/**
* Activity badge forum class, used for rendering unread messages.
*
* @package mod_forum
* @copyright 2023 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activitybadge extends \core_courseformat\output\activitybadge {
/**
* This method will be called before exporting the template.
*/
protected function update_content(): void {
global $CFG;
require_once($CFG->dirroot . '/mod/forum/lib.php');
if (forum_tp_can_track_forums()) {
if ($unread = forum_tp_count_forum_unread_posts($this->cminfo, $this->cminfo->get_course())) {
if ($unread == 1) {
$this->content = get_string('unreadpostsone', 'forum');
} else {
$this->content = get_string('unreadpostsnumber', 'forum', $unread);
}
$this->style = self::STYLES['dark'];
}
}
}
}
@@ -0,0 +1,85 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output\email;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../../../renderer.php');
/**
* Forum post renderable.
*
* @since Moodle 3.0
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \mod_forum_renderer {
/**
* The template name for this renderer.
*
* @return string
*/
public function forum_post_template() {
return 'forum_post_email_htmlemail';
}
/**
* The HTML version of the e-mail message.
*
* @param \stdClass $cm
* @param \stdClass $post
* @return string
*/
public function format_message_text($cm, $post) {
$context = \context_module::instance($cm->id);
$message = file_rewrite_pluginfile_urls(
$post->message,
'pluginfile.php',
$context->id,
'mod_forum',
'post',
$post->id,
[
'includetoken' => true,
]);
$options = new \stdClass();
$options->para = true;
$options->context = $context;
return format_text($message, $post->messageformat, $options);
}
/**
* The HTML version of the attachments list.
*
* @param \stdClass $cm
* @param \stdClass $post
* @return string
*/
public function format_message_attachments($cm, $post) {
return forum_print_attachments($post, $cm, "html");
}
}
@@ -0,0 +1,72 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output\email;
defined('MOODLE_INTERNAL') || die();
/**
* Forum post renderable.
*
* @since Moodle 3.0
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer_textemail extends renderer {
/**
* The template name for this renderer.
*
* @return string
*/
public function forum_post_template() {
return 'forum_post_email_textemail';
}
/**
* The plaintext version of the e-mail message.
*
* @param \stdClass $cm
* @param \stdClass $post
* @return string
*/
public function format_message_text($cm, $post) {
$message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php',
\context_module::instance($cm->id)->id,
'mod_forum', 'post', $post->id);
return format_text_email($message, $post->messageformat);
}
/**
* The plaintext version of the attachments list.
*
* @param \stdClass $cm
* @param \stdClass $post
* @return string
*/
public function format_message_attachments($cm, $post) {
return forum_print_attachments($post, $cm, "text");
}
}
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output\emaildigestbasic;
defined('MOODLE_INTERNAL') || die();
/**
* Forum post renderable.
*
* @since Moodle 3.0
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \mod_forum\output\email\renderer {
/**
* The template name for this renderer.
*
* @return string
*/
public function forum_post_template() {
return 'forum_post_emaildigestbasic_htmlemail';
}
}
@@ -0,0 +1,69 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output\emaildigestbasic;
defined('MOODLE_INTERNAL') || die();
/**
* Forum post renderable.
*
* @since Moodle 3.0
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer_textemail extends \mod_forum\output\email\renderer_textemail {
/**
* The template name for this renderer.
*
* @return string
*/
public function forum_post_template() {
return 'forum_post_emaildigestbasic_textemail';
}
/**
* The plaintext version of the e-mail message.
*
* @param \stdClass $cm
* @param \stdClass $post
* @return string
*/
public function format_message_text($cm, $post) {
$context = \context_module::instance($cm->id);
$message = file_rewrite_pluginfile_urls(
$post->message,
'pluginfile.php',
$context->id,
'mod_forum',
'post',
$post->id,
[
'includetoken' => true,
]);
return format_text_email($message, $post->messageformat);
}
}
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output\emaildigestfull;
defined('MOODLE_INTERNAL') || die();
/**
* Forum post renderable.
*
* @since Moodle 3.0
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \mod_forum\output\email\renderer {
/**
* The template name for this renderer.
*
* @return string
*/
public function forum_post_template() {
return 'forum_post_emaildigestfull_htmlemail';
}
}
@@ -0,0 +1,69 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output\emaildigestfull;
defined('MOODLE_INTERNAL') || die();
/**
* Forum post renderable.
*
* @since Moodle 3.0
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer_textemail extends \mod_forum\output\email\renderer_textemail {
/**
* The template name for this renderer.
*
* @return string
*/
public function forum_post_template() {
return 'forum_post_emaildigestfull_textemail';
}
/**
* The plaintext version of the e-mail message.
*
* @param \stdClass $cm
* @param \stdClass $post
* @return string
*/
public function format_message_text($cm, $post) {
$context = \context_module::instance($cm->id);
$message = file_rewrite_pluginfile_urls(
$post->message,
'pluginfile.php',
$context->id,
'mod_forum',
'post',
$post->id,
[
'includetoken' => true,
]);
return format_text_email($message, $post->messageformat);
}
}
@@ -0,0 +1,135 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_forum\output;
use renderable;
use renderer_base;
use templatable;
use moodle_url;
use help_icon;
use mod_forum\local\entities\forum as forum_entity;
/**
* Render activity page for tertiary nav
*
* Render elements search forum, add new discussion button and subscribe all
* to the page action.
*
* @package mod_forum
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class forum_actionbar implements renderable, templatable {
/**
* @var forum_entity $forum
*/
private $forum;
/**
* @var \stdClass $course
*/
private $course;
/**
* @var mixed $groupid
*/
private $groupid;
/**
* @var string $search
*/
private $search;
/**
* forum_actionbar constructor.
*
* @param forum_entity $forum The forum object.
* @param \stdClass $course The course object.
* @param int|null $groupid The group id.
* @param string $search The search string.
*/
public function __construct(forum_entity $forum, \stdClass $course, ?int $groupid, string $search) {
$this->forum = $forum;
$this->course = $course;
$this->groupid = $groupid;
$this->search = $search;
}
/**
* Render the new discussion button.
*
* @return string HTML button
*/
private function get_new_discussion_topic_button(): string {
global $USER;
$renderfactory = \mod_forum\local\container::get_renderer_factory();
$discussionrenderer = $renderfactory->get_discussion_list_renderer($this->forum);
return $discussionrenderer->render_new_discussion($USER, $this->groupid);
}
/**
* Data for the template.
*
* @param renderer_base $output The render_base object.
* @return array data for the template
*/
public function export_for_template(renderer_base $output): array {
global $USER;
$actionurl = (new moodle_url('/mod/forum/search.php'))->out(false);
$helpicon = new help_icon('search', 'core');
$hiddenfields = [
(object) ['name' => 'id', 'value' => $this->course->id],
];
$shownewdiscussionbtn = '';
if ($this->forum->get_type() !== 'single') {
$shownewdiscussionbtn = $this->get_new_discussion_topic_button();
}
$data = [
'action' => $actionurl,
'hiddenfields' => $hiddenfields,
'query' => $this->search,
'helpicon' => $helpicon->export_for_template($output),
'inputname' => 'search',
'searchstring' => get_string('searchforums', 'mod_forum'),
'newdiscussionbtn' => $shownewdiscussionbtn,
];
$legacydatamapperfactory = \mod_forum\local\container::get_legacy_data_mapper_factory();
$forumobject = $legacydatamapperfactory->get_forum_data_mapper()->to_legacy_object($this->forum);
$context = $this->forum->get_context();
$activeenrolled = is_enrolled($context, $USER, '', true);
$canmanage = has_capability('mod/forum:managesubscriptions', $context);
$cansubscribe = $activeenrolled && !($this->forum->get_subscription_mode() === FORUM_FORCESUBSCRIBE) &&
(!($this->forum->get_subscription_mode() === FORUM_DISALLOWSUBSCRIBE) || $canmanage);
if ($cansubscribe) {
$returnurl =
(new moodle_url('/mod/forum/view.php', ['id' => $this->forum->get_course_module_record()->id]))->out(false);
if (!\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject, null, $this->forum->get_course_module_record())) {
$data['subscribetoforum'] = (new moodle_url(
'/mod/forum/subscribe.php',
['id' => $forumobject->id, 'sesskey' => sesskey(), 'returnurl' => $returnurl]
))->out(false);
} else {
$data['unsubscribefromforum'] = (new moodle_url(
'/mod/forum/subscribe.php',
['id' => $forumobject->id, 'sesskey' => sesskey(), 'returnurl' => $returnurl]
))->out(false);
}
}
return $data;
}
}
+587
View File
@@ -0,0 +1,587 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output;
defined('MOODLE_INTERNAL') || die();
/**
* Forum post renderable.
*
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @property boolean $viewfullnames Whether to override fullname()
*/
class forum_post implements \renderable, \templatable {
/**
* The course that the forum post is in.
*
* @var object $course
*/
protected $course = null;
/**
* The course module for the forum.
*
* @var object $cm
*/
protected $cm = null;
/**
* The forum that the post is in.
*
* @var object $forum
*/
protected $forum = null;
/**
* The discussion that the forum post is in.
*
* @var object $discussion
*/
protected $discussion = null;
/**
* The forum post being displayed.
*
* @var object $post
*/
protected $post = null;
/**
* Whether the user can reply to this post.
*
* @var boolean $canreply
*/
protected $canreply = false;
/**
* Whether to override forum display when displaying usernames.
* @var boolean $viewfullnames
*/
protected $viewfullnames = false;
/**
* The user that is reading the post.
*
* @var object $userto
*/
protected $userto = null;
/**
* The user that wrote the post.
*
* @var object $author
*/
protected $author = null;
/**
* An associative array indicating which keys on this object should be writeable.
*
* @var array $writablekeys
*/
protected $writablekeys = array(
'viewfullnames' => true,
);
/** @var \stdClass user record. */
protected $userfrom;
/**
* Builds a renderable forum post
*
* @param object $course Course of the forum
* @param object $cm Course Module of the forum
* @param object $forum The forum of the post
* @param object $discussion Discussion thread in which the post appears
* @param object $post The post
* @param object $author Author of the post
* @param object $recipient Recipient of the email
* @param bool $canreply True if the user can reply to the post
*/
public function __construct($course, $cm, $forum, $discussion, $post, $author, $recipient, $canreply) {
$this->course = $course;
$this->cm = $cm;
$this->forum = $forum;
$this->discussion = $discussion;
$this->post = $post;
$this->author = $author;
$this->userto = $recipient;
$this->canreply = $canreply;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \mod_forum_renderer $renderer The render to be used for formatting the message and attachments
* @param bool $plaintext Whethe the target is a plaintext target
* @return array Data ready for use in a mustache template
*/
public function export_for_template(\renderer_base $renderer, $plaintext = false) {
if ($plaintext) {
return $this->export_for_template_text($renderer);
} else {
return $this->export_for_template_html($renderer);
}
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \mod_forum_renderer $renderer The render to be used for formatting the message and attachments
* @return array Data ready for use in a mustache template
*/
protected function export_for_template_text(\mod_forum_renderer $renderer) {
$data = $this->export_for_template_shared($renderer);
return $data + array(
'id' => html_entity_decode($this->post->id, ENT_COMPAT),
'coursename' => html_entity_decode($this->get_coursename(), ENT_COMPAT),
'courselink' => html_entity_decode($this->get_courselink(), ENT_COMPAT),
'forumname' => html_entity_decode($this->get_forumname(), ENT_COMPAT),
'showdiscussionname' => html_entity_decode($this->get_showdiscussionname(), ENT_COMPAT),
'discussionname' => html_entity_decode($this->get_discussionname(), ENT_COMPAT),
'subject' => html_entity_decode($this->get_subject(), ENT_COMPAT),
'authorfullname' => html_entity_decode($this->get_author_fullname(), ENT_COMPAT),
'postdate' => html_entity_decode($this->get_postdate(), ENT_COMPAT),
// Format some components according to the renderer.
'message' => html_entity_decode($renderer->format_message_text($this->cm, $this->post), ENT_COMPAT),
'attachments' => html_entity_decode($renderer->format_message_attachments($this->cm, $this->post), ENT_COMPAT),
'canreply' => $this->canreply,
'permalink' => $this->get_permalink(),
'firstpost' => $this->get_is_firstpost(),
'replylink' => $this->get_replylink(),
'unsubscribediscussionlink' => $this->get_unsubscribediscussionlink(),
'unsubscribeforumlink' => $this->get_unsubscribeforumlink(),
'parentpostlink' => $this->get_parentpostlink(),
'forumindexlink' => $this->get_forumindexlink(),
'forumviewlink' => $this->get_forumviewlink(),
'discussionlink' => $this->get_discussionlink(),
'authorlink' => $this->get_authorlink(),
'authorpicture' => $this->get_author_picture($renderer),
'grouppicture' => $this->get_group_picture($renderer),
);
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \mod_forum_renderer $renderer The render to be used for formatting the message and attachments
* @return array Data ready for use in a mustache template
*/
protected function export_for_template_html(\mod_forum_renderer $renderer) {
$data = $this->export_for_template_shared($renderer);
return $data + array(
'id' => $this->post->id,
'coursename' => $this->get_coursename(),
'courselink' => $this->get_courselink(),
'forumname' => $this->get_forumname(),
'showdiscussionname' => $this->get_showdiscussionname(),
'discussionname' => $this->get_discussionname(),
'subject' => $this->get_subject(),
'authorfullname' => $this->get_author_fullname(),
'postdate' => $this->get_postdate(),
// Format some components according to the renderer.
'message' => $renderer->format_message_text($this->cm, $this->post),
'attachments' => $renderer->format_message_attachments($this->cm, $this->post),
);
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \mod_forum_renderer $renderer The render to be used for formatting the message and attachments
* @return stdClass Data ready for use in a mustache template
*/
protected function export_for_template_shared(\mod_forum_renderer $renderer) {
return array(
'canreply' => $this->canreply,
'permalink' => $this->get_permalink(),
'firstpost' => $this->get_is_firstpost(),
'replylink' => $this->get_replylink(),
'unsubscribediscussionlink' => $this->get_unsubscribediscussionlink(),
'unsubscribeforumlink' => $this->get_unsubscribeforumlink(),
'parentpostlink' => $this->get_parentpostlink(),
'forumindexlink' => $this->get_forumindexlink(),
'forumviewlink' => $this->get_forumviewlink(),
'discussionlink' => $this->get_discussionlink(),
'authorlink' => $this->get_authorlink(),
'authorpicture' => $this->get_author_picture($renderer),
'grouppicture' => $this->get_group_picture($renderer),
'isprivatereply' => !empty($this->post->privatereplyto),
);
}
/**
* Magically sets a property against this object.
*
* @param string $key
* @param mixed $value
*/
public function __set($key, $value) {
// First attempt to use the setter function.
$methodname = 'set_' . $key;
if (method_exists($this, $methodname)) {
return $this->{$methodname}($value);
}
// Fall back to the writable keys list.
if (isset($this->writablekeys[$key]) && $this->writablekeys[$key]) {
return $this->{$key} = $value;
}
// Throw an error rather than fail silently.
throw new \coding_exception('Tried to set unknown property "' . $key . '"');
}
/**
* Whether this is the first post.
*
* @return boolean
*/
public function get_is_firstpost() {
return empty($this->post->parent);
}
/**
* Get the link to the course.
*
* @return string
*/
public function get_courselink() {
$link = new \moodle_url(
// Posts are viewed on the topic.
'/course/view.php', array(
'id' => $this->course->id,
)
);
return $link->out(false);
}
/**
* Get the link to the forum index for this course.
*
* @return string
*/
public function get_forumindexlink() {
$link = new \moodle_url(
// Posts are viewed on the topic.
'/mod/forum/index.php', array(
'id' => $this->course->id,
)
);
return $link->out(false);
}
/**
* Get the link to the view page for this forum.
*
* @return string
*/
public function get_forumviewlink() {
$link = new \moodle_url(
// Posts are viewed on the topic.
'/mod/forum/view.php', array(
'f' => $this->forum->id,
)
);
return $link->out(false);
}
/**
* Get the link to the current discussion.
*
* @return string
*/
protected function _get_discussionlink() {
return new \moodle_url(
// Posts are viewed on the topic.
'/mod/forum/discuss.php', array(
// Within a discussion.
'd' => $this->discussion->id,
)
);
}
/**
* Get the link to the current discussion.
*
* @return string
*/
public function get_discussionlink() {
$link = $this->_get_discussionlink();
return $link->out(false);
}
/**
* Get the link to the current post, including post anchor.
*
* @return string
*/
public function get_permalink() {
$link = $this->_get_discussionlink();
$link->set_anchor($this->get_postanchor());
return $link->out(false);
}
/**
* Get the link to the parent post.
*
* @return string
*/
public function get_parentpostlink() {
$link = $this->_get_discussionlink();
$link->param('parent', $this->post->parent);
return $link->out(false);
}
/**
* Get the link to the author's profile page.
*
* @return string
*/
public function get_authorlink() {
$link = new \moodle_url(
'/user/view.php', array(
'id' => $this->post->userid,
'course' => $this->course->id,
)
);
return $link->out(false);
}
/**
* Get the link to unsubscribe from the forum.
*
* @return string
*/
public function get_unsubscribeforumlink() {
if (!\mod_forum\subscriptions::is_subscribable($this->forum)) {
return null;
}
$link = new \moodle_url(
'/mod/forum/subscribe.php', array(
'id' => $this->forum->id,
)
);
return $link->out(false);
}
/**
* Get the link to unsubscribe from the discussion.
*
* @return string
*/
public function get_unsubscribediscussionlink() {
if (!\mod_forum\subscriptions::is_subscribable($this->forum)) {
return null;
}
$link = new \moodle_url(
'/mod/forum/subscribe.php', array(
'id' => $this->forum->id,
'd' => $this->discussion->id,
)
);
return $link->out(false);
}
/**
* Get the link to reply to the current post.
*
* @return string
*/
public function get_replylink() {
return new \moodle_url(
'/mod/forum/post.php', array(
'reply' => $this->post->id,
)
);
}
/**
* The formatted subject for the current post.
*
* @return string
*/
public function get_subject() {
return format_string($this->post->subject, true);
}
/**
* The plaintext anchor id for the current post.
*
* @return string
*/
public function get_postanchor() {
return 'p' . $this->post->id;
}
/**
* ID number of the course that the forum is in.
*
* @return string
*/
public function get_courseidnumber() {
return s($this->course->idnumber);
}
/**
* The full name of the course that the forum is in.
*
* @return string
*/
public function get_coursefullname() {
return format_string($this->course->fullname, true, array(
'context' => \context_course::instance($this->course->id),
));
}
/**
* The name of the course that the forum is in.
*
* @return string
*/
public function get_coursename() {
return format_string($this->course->shortname, true, array(
'context' => \context_course::instance($this->course->id),
));
}
/**
* The name of the forum.
*
* @return string
*/
public function get_forumname() {
return format_string($this->forum->name, true);
}
/**
* The name of the current discussion.
*
* @return string
*/
public function get_discussionname() {
return format_string($this->discussion->name, true);
}
/**
* Whether to show the discussion name.
* If the forum name matches the discussion name, the discussion name
* is not typically displayed.
*
* @return boolean
*/
public function get_showdiscussionname() {
return ($this->forum->name !== $this->discussion->name);
}
/**
* The fullname of the post author.
*
* @return string
*/
public function get_author_fullname() {
return fullname($this->author, $this->viewfullnames);
}
/**
* The recipient of the post.
*
* @return string
*/
protected function get_postto() {
global $USER;
if (null === $this->userto) {
return $USER;
}
return $this->userto;
}
/**
* The date of the post, formatted according to the postto user's
* preferences.
*
* @return string
*/
public function get_postdate() {
global $CFG;
$postmodified = $this->post->modified;
if (!empty($CFG->forum_enabletimedposts) && ($this->discussion->timestart > $postmodified)) {
$postmodified = $this->discussion->timestart;
}
return userdate($postmodified, "", \core_date::get_user_timezone($this->get_postto()));
}
/**
* The HTML for the author's user picture.
*
* @param \renderer_base $renderer
* @return string
*/
public function get_author_picture(\renderer_base $renderer) {
return $renderer->user_picture($this->author, array('courseid' => $this->course->id));
}
/**
* The HTML for a group picture.
*
* @param \renderer_base $renderer
* @return string
*/
public function get_group_picture(\renderer_base $renderer) {
if (isset($this->userfrom->groups)) {
$groups = $this->userfrom->groups[$this->forum->id];
} else {
$groups = groups_get_all_groups($this->course->id, $this->author->id, $this->cm->groupingid);
}
if ($this->get_is_firstpost()) {
return print_group_picture($groups, $this->course->id, false, true, true, true);
}
}
}
@@ -0,0 +1,36 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Forum post renderable for e-mail.
*
* @package mod_forum
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output;
defined('MOODLE_INTERNAL') || die();
/**
* Forum post renderable for use in e-mail.
*
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class forum_post_email extends forum_post {
}
@@ -0,0 +1,80 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Quick search form renderable.
*
* @package mod_forum
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\output;
defined('MOODLE_INTERNAL') || die();
use help_icon;
use moodle_url;
use renderable;
use renderer_base;
use templatable;
/**
* Quick search form renderable class.
*
* @package mod_forum
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quick_search_form implements renderable, templatable {
/** @var int The course ID. */
protected $courseid;
/** @var string Current query. */
protected $query;
/** @var moodle_url The form action URL. */
protected $actionurl;
/** @var help_icon The help icon. */
protected $helpicon;
/**
* Constructor.
*
* @param int $courseid The course ID.
* @param string $query The current query.
*/
public function __construct($courseid, $query = '') {
$this->courseid = $courseid;
$this->query = $query;
$this->actionurl = new moodle_url('/mod/forum/search.php');
$this->helpicon = new help_icon('search', 'core');
}
public function export_for_template(renderer_base $output) {
$hiddenfields = [
(object) ['name' => 'id', 'value' => $this->courseid],
];
$data = [
'action' => $this->actionurl->out(false),
'hiddenfields' => $hiddenfields,
'query' => $this->query,
'helpicon' => $this->helpicon->export_for_template($output),
'inputname' => 'search',
'searchstring' => get_string('searchforums', 'mod_forum')
];
return $data;
}
}
@@ -0,0 +1,166 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_forum\output;
use moodle_url;
use renderer_base;
use url_select;
use renderable;
use templatable;
/**
* Renders the subscribers page for this activity.
*
* @package mod_forum
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class subscription_actionbar implements renderable, templatable {
/** @var int course id */
private $id;
/** @var moodle_url */
private $currenturl;
/** @var \stdClass */
private $forum;
/** @var int */
private $edit;
/**
* subscription_actionbar constructor.
*
* @param int $id The forum id.
* @param moodle_url $currenturl Current URL.
* @param \stdClass $forum The forum object.
* @param int $edit This argument decides to show view/manage subscribers view.
*/
public function __construct(int $id, moodle_url $currenturl, \stdClass $forum, int $edit) {
$this->id = $id;
$this->currenturl = $currenturl;
$this->forum = $forum;
$this->edit = $edit;
}
/**
* Create url select menu for subscription option
*
* @return url_select|null the url_select object
*/
private function create_subscription_menu(): ?url_select {
// When user is on manage subscription, we don't have to show the subscription selector.
if ($this->edit === 1 && !\mod_forum\subscriptions::is_forcesubscribed($this->forum)) {
return null;
}
$sesskey = sesskey();
$modeset = \mod_forum\subscriptions::get_subscription_mode($this->forum);
$optionallink = new moodle_url('/mod/forum/subscribe.php',
['id' => $this->id, 'mode' => FORUM_CHOOSESUBSCRIBE, 'sesskey' => $sesskey, 'edit' => $this->edit]);
$forcedlink = new moodle_url('/mod/forum/subscribe.php',
['id' => $this->id, 'mode' => FORUM_FORCESUBSCRIBE, 'sesskey' => $sesskey, 'edit' => $this->edit]);
$autolink = new moodle_url('/mod/forum/subscribe.php',
['id' => $this->id, 'mode' => FORUM_INITIALSUBSCRIBE, 'sesskey' => $sesskey, 'edit' => $this->edit]);
$disabledlink = new moodle_url('/mod/forum/subscribe.php',
['id' => $this->id, 'mode' => FORUM_DISALLOWSUBSCRIBE, 'sesskey' => $sesskey, 'edit' => $this->edit]);
$menu = [
$optionallink->out(false) => get_string('subscriptionoptional', 'forum'),
$forcedlink->out(false) => get_string('subscriptionforced', 'forum'),
$autolink->out(false) => get_string('subscriptionauto', 'forum'),
$disabledlink->out(false) => get_string('subscriptiondisabled', 'forum'),
];
switch ($modeset) {
case FORUM_CHOOSESUBSCRIBE:
$set = get_string('subscriptionoptional', 'forum');
break;
case FORUM_FORCESUBSCRIBE:
$set = get_string('subscriptionforced', 'forum');
break;
case FORUM_INITIALSUBSCRIBE:
$set = get_string('subscriptionauto', 'forum');
break;
case FORUM_DISALLOWSUBSCRIBE:
$set = get_string('subscriptiondisabled', 'forum');
break;
default:
throw new \moodle_exception(get_string('invalidforcesubscribe', 'forum'));
}
$menu = array_filter($menu, function($key) use ($set) {
if ($key !== $set) {
return true;
}
});
$urlselect = new url_select($menu, $this->currenturl, ['' => $set], 'selectsubscriptionoptions');
$urlselect->set_label(get_string('subscriptionmode', 'mod_forum'), ['class' => 'mr-1']);
$urlselect->set_help_icon('subscriptionmode', 'mod_forum');
$urlselect->class .= ' float-right';
return $urlselect;
}
/**
* Create view and manage subscribers select menu.
*
* @return url_select|null get url_select object.
*/
private function create_view_manage_menu(): ?url_select {
// If forced subscription is used then no need to show the view.
if (\mod_forum\subscriptions::is_forcesubscribed($this->forum)) {
return null;
}
$viewlink = new moodle_url('/mod/forum/subscribers.php', ['id' => $this->id, 'edit' => 'off']);
$managelink = new moodle_url('/mod/forum/subscribers.php', ['id' => $this->id, 'edit' => 'on']);
$menu = [
$viewlink->out(false) => get_string('forum:viewsubscribers', 'forum'),
$managelink->out(false) => get_string('managesubscriptionson', 'forum'),
];
if ($this->edit === 0) {
$this->currenturl = $viewlink;
} else {
$this->currenturl = $managelink;
}
$urlselect = new url_select($menu, $this->currenturl->out(false), null, 'selectviewandmanagesubscribers');
$urlselect->set_label(get_string('subscribers', 'forum'), ['class' => 'accesshide']);
return $urlselect;
}
/**
* Data for the template.
*
* @param renderer_base $output The render_base object.
* @return array data for template
*/
public function export_for_template(renderer_base $output): array {
$data = [];
$subscribeoptionselect = $this->create_subscription_menu();
$viewmanageselect = $this->create_view_manage_menu();
if ($subscribeoptionselect) {
$data ['subscriptionoptions'] = $subscribeoptionselect->export_for_template($output);
}
if ($viewmanageselect) {
$data['viewandmanageselect'] = $viewmanageselect->export_for_template($output);
}
return $data;
}
}