Proyectos de Subversion Moodle

Rev

Rev 1 | | 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 helper functions and callbacks
19
 *
20
 * @package   block_comments
21
 * @copyright 2011 Dongsheng Cai <dongsheng@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
/**
28
 * Validate comment parameter before perform other comments actions
29
 *
30
 * @package  block_comments
31
 * @category comment
32
 *
33
 * @param stdClass $comment_param {
34
 *              context  => context the context object
35
 *              courseid => int course id
36
 *              cm       => stdClass course module object
37
 *              commentarea => string comment area
38
 *              itemid      => int itemid
39
 * }
40
 * @return boolean
41
 */
118 ariadna 42
function block_comments_comment_validate($comment_param)
43
{
1 efrain 44
    if ($comment_param->commentarea != 'page_comments') {
45
        throw new comment_exception('invalidcommentarea');
46
    }
47
    if ($comment_param->itemid != 0) {
48
        throw new comment_exception('invalidcommentitemid');
49
    }
50
    return true;
51
}
52
 
53
/**
54
 * Running addtional permission check on plugins
55
 *
56
 * @package  block_comments
57
 * @category comment
58
 *
59
 * @param stdClass $args
60
 * @return array
61
 */
118 ariadna 62
function block_comments_comment_permissions($args)
63
{
1 efrain 64
    global $DB, $USER;
65
    // By default, anyone can post and view comments.
66
    $canpost = $canview = true;
67
    // Check if it's the user context and not the owner's profile.
68
    if ($args->context->contextlevel == CONTEXT_USER && $USER->id != $args->context->instanceid) {
69
        // Check whether the context owner has a comment block in the user's profile.
70
        $sqlparam = [
71
            'blockname' => 'comments',
72
            'parentcontextid' => $args->context->id,
73
            'pagetypepattern' => 'user-profile',
74
        ];
75
        // If the comment block is not present at the target user's profile,
76
        // then the logged-in user cannot post or view comments.
77
        $canpost = $canview = $DB->record_exists_select(
78
            'block_instances',
79
            'blockname = :blockname AND parentcontextid = :parentcontextid AND pagetypepattern = :pagetypepattern',
80
            $sqlparam,
81
        );
82
    }
83
    return ['post' => $canpost, 'view' => $canview];
84
}
85
 
86
/**
87
 * Validate comment data before displaying comments
88
 *
89
 * @package  block_comments
90
 * @category comment
91
 *
92
 * @param stdClass $comment
93
 * @param stdClass $args
94
 * @return boolean
95
 */
118 ariadna 96
function block_comments_comment_display($comments, $args)
97
{
1 efrain 98
    if ($args->commentarea != 'page_comments') {
99
        throw new comment_exception('invalidcommentarea');
100
    }
101
    if ($args->itemid != 0) {
102
        throw new comment_exception('invalidcommentitemid');
103
    }
104
    return $comments;
105
}