Proyectos de Subversion Moodle

Rev

Rev 276 | | 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
 
17
/**
18
 * The comments block
19
 *
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
23
 */
110 ariadna 24
class block_comments extends block_base
25
{
1 efrain 26
 
110 ariadna 27
    function init()
28
    {
1 efrain 29
        global $CFG;
30
 
31
        require_once($CFG->dirroot . '/comment/lib.php');
32
 
33
        $this->title = get_string('pluginname', 'block_comments');
34
    }
35
 
110 ariadna 36
    function specialization()
37
    {
276 ariadna 38
        $this->title = get_string('pluginname', 'block_comments');
122 ariadna 39
        comment::init();
1 efrain 40
    }
111 ariadna 41
 
115 ariadna 42
    function applicable_formats()
110 ariadna 43
    {
127 ariadna 44
        return array('all' => true);
115 ariadna 45
    }
1 efrain 46
 
116 ariadna 47
    function has_config()
48
    {
49
        return true;
50
    }
51
 
110 ariadna 52
    function instance_allow_multiple()
53
    {
1 efrain 54
        return false;
55
    }
56
 
110 ariadna 57
    function get_content()
58
    {
1 efrain 59
        global $CFG;
60
 
61
        if ($this->content !== NULL) {
62
            return $this->content;
63
        }
64
        if (!$CFG->usecomments) {
65
            $this->content = new stdClass();
66
            $this->content->text = '';
67
            if ($this->page->user_is_editing()) {
68
                $this->content->text = get_string('disabledcomments');
69
            }
70
            return $this->content;
71
        }
72
        $this->content = new stdClass();
73
        $this->content->footer = '';
74
        $this->content->text = '';
75
        if (empty($this->instance)) {
76
            return $this->content;
77
        }
78
        list($context, $course, $cm) = get_context_info_array($this->page->context->id);
79
 
80
        $args = new stdClass;
81
        $args->context   = $this->page->context;
82
        $args->course    = $course;
83
        $args->area      = 'page_comments';
84
        $args->itemid    = 0;
85
        $args->component = 'block_comments';
86
        $args->linktext  = get_string('showcomments');
87
        $args->notoggle  = true;
88
        $args->autostart = true;
89
        $args->displaycancel = false;
90
        $comment = new comment($args);
91
        $comment->set_view_permission(true);
92
        $comment->set_fullwidth();
93
 
94
        $this->content = new stdClass();
95
        $this->content->text = $comment->output(true);
96
        $this->content->footer = '';
97
        return $this->content;
98
    }
99
 
100
    /**
101
     * This block shouldn't be added to a page if the comments advanced feature is disabled.
102
     *
103
     * @param moodle_page $page
104
     * @return bool
105
     */
110 ariadna 106
    public function can_block_be_added(moodle_page $page): bool
107
    {
1 efrain 108
        global $CFG;
109
 
110
        return $CFG->usecomments;
111
    }
112
}