Proyectos de Subversion Moodle

Rev

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