Proyectos de Subversion Moodle

Rev

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