Proyectos de Subversion Moodle

Rev

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