3 require_once($CFG->dirroot . '/comment/lib.php');
5 class block_comments extends block_base {
8 $this->title = get_string('pluginname', 'block_comments');
11 function specialization() {
12 // require js for commenting
15 function applicable_formats() {
16 return array('all' => true);
19 function instance_allow_multiple() {
23 function get_content() {
25 if (!$CFG->usecomments) {
26 $this->content->text = '';
27 if ($this->page->user_is_editing()) {
28 $this->content->text = get_string('disabledcomments');
30 return $this->content;
32 if ($this->content !== NULL) {
33 return $this->content;
35 if (empty($this->instance)) {
38 $this->content->footer = '';
39 $this->content->text = '';
40 list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
42 $args->context = $PAGE->context;
43 $args->course = $course;
44 $args->area = 'page_comments';
46 // set 'env' to tell moodle tweak ui for this block
47 $args->env = 'block_comments';
48 $args->component = 'block_comments';
49 $args->linktext = get_string('showcomments');
50 $comment = new comment($args);
51 $comment->set_view_permission(true);
53 $this->content = new stdClass;
54 $this->content->text = $comment->output(true);
55 $this->content->footer = '';
56 return $this->content;
58 function instance_delete() {
60 //delete orphan records
61 $DB->delete_records('comments', array('contextid'=>$PAGE->context->id, 'commentarea'=>'page_comments', 'itemid'=>0));