Merge branch 'MDL-38821_master' of git://github.com/dmonllao/moodle
[moodle.git] / blocks / comments / lib.php
blob30cca1ee24b49346f2c684fb360dd673d6ff93e7
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.
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/>.
17 /**
18 * The comments block helper functions and callbacks
20 * @package block
21 * @subpackage comments
22 * @copyright 2011 Dongsheng Cai <dongsheng@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 /**
29 * Validate comment parameter before perform other comments actions
31 * @package block_comments
32 * @category comment
34 * @param stdClass $comment_param {
35 * context => context the context object
36 * courseid => int course id
37 * cm => stdClass course module object
38 * commentarea => string comment area
39 * itemid => int itemid
40 * }
41 * @return boolean
43 function block_comments_comment_validate($comment_param) {
44 if ($comment_param->commentarea != 'page_comments') {
45 throw new comment_exception('invalidcommentarea');
47 if ($comment_param->itemid != 0) {
48 throw new comment_exception('invalidcommentitemid');
50 return true;
53 /**
54 * Running addtional permission check on plugins
56 * @package block_comments
57 * @category comment
59 * @param stdClass $args
60 * @return array
62 function block_comments_comment_permissions($args) {
63 return array('post'=>true, 'view'=>true);
66 /**
67 * Validate comment data before displaying comments
69 * @package block_comments
70 * @category comment
72 * @param stdClass $comment
73 * @param stdClass $args
74 * @return boolean
76 function block_comments_comment_display($comments, $args) {
77 if ($args->commentarea != 'page_comments') {
78 throw new comment_exception('invalidcommentarea');
80 if ($args->itemid != 0) {
81 throw new comment_exception('invalidcommentitemid');
83 return $comments;