Proyectos de Subversion Moodle

Rev

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