lib.php 3.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
/**
 *
 * @package    mahara
 * @subpackage blocktype-comment
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

defined ('INTERNAL') || die();

14
class PluginBlocktypeComment extends MaharaCoreBlocktype {
Aaron Wells's avatar
Aaron Wells committed
15
16
17
18
19
    public static function should_ajaxify() {
        // TinyMCE doesn't play well with loading by ajax
        return false;
    }

20
21
22
23
24
    public static function single_only() {
        return true;
    }

    public static function get_title() {
25

26
27
28
29
30
31
32
33
        return get_string('title', 'blocktype.comment/comment');
    }

    public static function get_description() {
        return get_string('description', 'blocktype.comment/comment');
    }

    public static function get_categories() {
34
        return array("general" => 14000);
35
36
37
38
39
40
    }

    public static function get_viewtypes() {
        return array('portfolio');
    }

41
    public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
42
43
        global $USER;

Pat Kira's avatar
Pat Kira committed
44
45
46
47
48
49
50
        if ($editing) {
            $smarty = smarty_core();
            $smarty->assign('editing', get_string('ineditordescription1', 'blocktype.comment/comment'));
            $html = $smarty->fetch('blocktype:comment:comment.tpl');
            return $html;
        }

51
        // Comment list pagination requires limit/offset params
52
53
54
        $limit       = param_integer('limit', 10);
        $offset      = param_integer('offset', 0);
        $showcomment = param_integer('showcomment', null);
55
        // Create the "make comment private form" now if it's been submitted
56
        if (param_exists('make_public_submit')) {
57
58
            pieform(ArtefactTypeComment::make_public_form(param_integer('comment')));
        }
59
        else if (param_exists('delete_comment_submit')) {
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
            pieform(ArtefactTypeComment::delete_comment_form(param_integer('comment')));
        }
        $view = new View($instance->get('view'));
        $submittedgroup = (int)$view->get('submittedgroup');
        if ($USER->is_logged_in() && $submittedgroup && group_user_can_assess_submitted_views($submittedgroup, $USER->get('id'))) {
            $releaseform = true;
        }
        else {
            $releaseform = false;
        }
        // If the view has comments turned off, tutors can still leave
        // comments if the view is submitted to their group.
        if (!empty($releaseform) || ($view->user_comments_allowed($USER))) {
            $addfeedbackpopup = true;
        }
        safe_require('artefact', 'comment');
76
77
78
79
80
81
        $commentoptions = ArtefactTypeComment::get_comment_options();
        $commentoptions->limit = $limit;
        $commentoptions->offset = $offset;
        $commentoptions->showcomment = $showcomment;
        $commentoptions->view = $instance->get_view();
        $feedback = ArtefactTypeComment::get_comments($commentoptions);
82
83
84
85
86
87
        $smarty = smarty_core();
        $smarty->assign('feedback', $feedback);
        if (isset($addfeedbackpopup)) {
            $smarty->assign('enablecomments', 1);
            $smarty->assign('addfeedbackpopup', $addfeedbackpopup);
        }
88

89
90
91
92
93
94
95
        $html = $smarty->fetch('blocktype:comment:comment.tpl');
        return $html;
    }

    public static function has_instance_config() {
        return false;
    }
96
97
98
99
100
101
102
103
104
105

    /**
     * Shouldn't be linked to any artefacts via the view_artefacts table.
     *
     * @param BlockInstance $instance
     * @return multitype:
     */
    public static function get_artefacts(BlockInstance $instance) {
        return array();
    }
106
}