2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
20 * @package block_comments
21 * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 class block_comments
extends block_base
{
29 require_once($CFG->dirroot
. '/comment/lib.php');
31 $this->title
= get_string('pluginname', 'block_comments');
34 function specialization() {
35 // require js for commenting
38 function applicable_formats() {
39 return array('all' => true);
42 function instance_allow_multiple() {
46 function get_content() {
49 if ($this->content
!== NULL) {
50 return $this->content
;
52 if (!$CFG->usecomments
) {
53 $this->content
= new stdClass();
54 $this->content
->text
= '';
55 if ($this->page
->user_is_editing()) {
56 $this->content
->text
= get_string('disabledcomments');
58 return $this->content
;
60 $this->content
= new stdClass();
61 $this->content
->footer
= '';
62 $this->content
->text
= '';
63 if (empty($this->instance
)) {
64 return $this->content
;
66 list($context, $course, $cm) = get_context_info_array($this->page
->context
->id
);
69 $args->context
= $this->page
->context
;
70 $args->course
= $course;
71 $args->area
= 'page_comments';
73 $args->component
= 'block_comments';
74 $args->linktext
= get_string('showcomments');
75 $args->notoggle
= true;
76 $args->autostart
= true;
77 $args->displaycancel
= false;
78 $comment = new comment($args);
79 $comment->set_view_permission(true);
80 $comment->set_fullwidth();
82 $this->content
= new stdClass();
83 $this->content
->text
= $comment->output(true);
84 $this->content
->footer
= '';
85 return $this->content
;
89 * This block shouldn't be added to a page if the comments advanced feature is disabled.
91 * @param moodle_page $page
94 public function can_block_be_added(moodle_page
$page): bool {
97 return $CFG->usecomments
;