]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-19839, comments block"
authordongsheng <dongsheng>
Fri, 24 Jul 2009 02:52:09 +0000 (02:52 +0000)
committerdongsheng <dongsheng>
Fri, 24 Jul 2009 02:52:09 +0000 (02:52 +0000)
blocks/comments/block_comments.php [new file with mode: 0644]

diff --git a/blocks/comments/block_comments.php b/blocks/comments/block_comments.php
new file mode 100644 (file)
index 0000000..8f107b6
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+require_once($CFG->libdir . '/commentlib.php');
+
+class block_comments extends block_base {
+
+    function init() {
+        $this->title = get_string('comments');
+        $this->version = 2009072000;
+    }
+
+    function specialization() {
+        // require js for commenting
+        comment::js();
+    }
+    function applicable_formats() {
+        return array('all' => true);
+    }
+
+    function instance_allow_multiple() {
+        return false;
+    }
+
+    function get_content() {
+        if ($this->content !== NULL) {
+            return $this->content;
+        }
+        if (empty($this->instance)) {
+            return null;
+        }
+        $this->content->footer = '';
+        $this->content->text = '';
+        if (isloggedin() && !isguestuser()) {   // Show the block
+            $cmt = new stdclass;
+            $cmt->context   = $this->instance->context;
+            $cmt->area      = 'block_comments';
+            $cmt->itemid    = $this->instance->id;
+            $cmt->course    = $this->page->course;
+            // this is a hack to adjust commenting UI
+            // in block_comments 
+            $cmt->env       = 'block_comments';
+            $cmt->linktext  = get_string('showcomments');
+            $comment = new comment($cmt);
+            $this->content = new stdClass;
+            $this->content->text = $comment->init(true);
+            $this->content->footer = '';
+
+        }
+        return $this->content;
+    }
+}