Proyectos de Subversion Moodle

Rev

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