Proyectos de Subversion Moodle

Rev

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