lib.php 3.81 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
    public static function single_only() {
        return true;
    }

Lisa Seeto's avatar
Lisa Seeto committed
24 25 26 27
    public static function single_artefact_per_block() {
        return false;
    }

28
    public static function get_title() {
29

30 31 32 33 34 35 36 37
        return get_string('title', 'blocktype.comment/comment');
    }

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

    public static function get_categories() {
38
        return array("general" => 14000);
39 40 41 42 43 44
    }

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

45
    public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
46 47
        global $USER;

Pat Kira's avatar
Pat Kira committed
48 49 50
        if ($editing) {
            $smarty = smarty_core();
            $smarty->assign('editing', get_string('ineditordescription1', 'blocktype.comment/comment'));
51
            $smarty->assign('blockid', $instance->get('id'));
Pat Kira's avatar
Pat Kira committed
52 53 54 55
            $html = $smarty->fetch('blocktype:comment:comment.tpl');
            return $html;
        }

56
        // Comment list pagination requires limit/offset params
57 58 59
        $limit       = param_integer('limit', 10);
        $offset      = param_integer('offset', 0);
        $showcomment = param_integer('showcomment', null);
60
        // Create the "make comment private form" now if it's been submitted
61
        if (param_exists('make_public_submit')) {
62 63
            pieform(ArtefactTypeComment::make_public_form(param_integer('comment')));
        }
64
        else if (param_exists('delete_comment_submit')) {
65 66 67 68 69 70 71 72 73 74 75 76
            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.
77
        if ((!empty($releaseform) || ($view->user_comments_allowed($USER))) && !$versioning) {
78 79 80
            $addfeedbackpopup = true;
        }
        safe_require('artefact', 'comment');
81 82 83 84
        $commentoptions = ArtefactTypeComment::get_comment_options();
        $commentoptions->limit = $limit;
        $commentoptions->offset = $offset;
        $commentoptions->showcomment = $showcomment;
85
        $commentoptions->versioning = $versioning;
86 87
        $commentoptions->view = $instance->get_view();
        $feedback = ArtefactTypeComment::get_comments($commentoptions);
88 89 90 91 92 93
        $smarty = smarty_core();
        $smarty->assign('feedback', $feedback);
        if (isset($addfeedbackpopup)) {
            $smarty->assign('enablecomments', 1);
            $smarty->assign('addfeedbackpopup', $addfeedbackpopup);
        }
94

95 96 97 98 99 100 101
        $html = $smarty->fetch('blocktype:comment:comment.tpl');
        return $html;
    }

    public static function has_instance_config() {
        return false;
    }
102 103 104 105 106 107 108 109 110 111

    /**
     * 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();
    }
112
}