Proyectos de Subversion Moodle

Rev

Rev 275 | Ir a la última revisión | | 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
 
273 ariadna 42
 
115 ariadna 43
    function applicable_formats()
110 ariadna 44
    {
127 ariadna 45
        return array('all' => true);
115 ariadna 46
    }
1 efrain 47
 
116 ariadna 48
    function has_config()
49
    {
50
        return true;
51
    }
52
 
110 ariadna 53
    function instance_allow_multiple()
54
    {
1 efrain 55
        return false;
56
    }
57
 
110 ariadna 58
    function get_content()
59
    {
1 efrain 60
        global $CFG;
61
 
62
        if ($this->content !== NULL) {
63
            return $this->content;
64
        }
65
        if (!$CFG->usecomments) {
66
            $this->content = new stdClass();
67
            $this->content->text = '';
68
            if ($this->page->user_is_editing()) {
69
                $this->content->text = get_string('disabledcomments');
70
            }
71
            return $this->content;
72
        }
73
        $this->content = new stdClass();
74
        $this->content->footer = '';
75
        $this->content->text = '';
76
        if (empty($this->instance)) {
77
            return $this->content;
78
        }
79
        list($context, $course, $cm) = get_context_info_array($this->page->context->id);
80
 
81
        $args = new stdClass;
82
        $args->context   = $this->page->context;
83
        $args->course    = $course;
84
        $args->area      = 'page_comments';
85
        $args->itemid    = 0;
86
        $args->component = 'block_comments';
87
        $args->linktext  = get_string('showcomments');
88
        $args->notoggle  = true;
89
        $args->autostart = true;
90
        $args->displaycancel = false;
91
        $comment = new comment($args);
92
        $comment->set_view_permission(true);
93
        $comment->set_fullwidth();
94
 
95
        $this->content = new stdClass();
96
        $this->content->text = $comment->output(true);
97
        $this->content->footer = '';
98
        return $this->content;
99
    }
100
 
101
    /**
102
     * This block shouldn't be added to a page if the comments advanced feature is disabled.
103
     *
104
     * @param moodle_page $page
105
     * @return bool
106
     */
110 ariadna 107
    public function can_block_be_added(moodle_page $page): bool
108
    {
1 efrain 109
        global $CFG;
110
 
111
        return $CFG->usecomments;
112
    }
113
}