Development:Comments 2.0: Difference between revisions
mNo edit summary |
m (→Comments API) |
||
Line 72: | Line 72: | ||
==Comments API== | ==Comments API== | ||
lib/weblib.php | lib/weblib.php | ||
===function format_text_with_comments($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=null, $cmt_options)=== | |||
Use this function format text will add a comment icon automatically at the end of the text: | |||
For example, use following code in format module will add comment icon to every post: | |||
<code php> | |||
$cmt = new stdclass; | |||
$cmt->contextid = $modcontext->id; | |||
$cmt->area = 'format_post'; | |||
$cmt->itemid = $post->id; | |||
$cmt->summary = substr(strip_tags($post->message), 0 ,10); | |||
echo format_text_with_comments($post->message, $post->messageformat, $options, $course->id, $cmt)."<hr />"; | |||
</code> | |||
lib/commentlib.php | |||
===class comments()=== | ===class comments()=== | ||
====__construct($contextid, $comment_area, $itemid))==== | ====__construct($contextid, $comment_area, $itemid))==== | ||
====print_comment_link()==== | ====print_comment_link($return = false)==== | ||
Will print a comment | Will print a comment icon, click it you will get commenting interface | ||
====print_comments($params = array())==== | ====print_comments($params = array())==== | ||
print | print comments | ||
====add($content, $parent_id)==== | ====add($content, $parent_id)==== | ||
Line 91: | Line 108: | ||
====edit($id, $content)==== | ====edit($id, $content)==== | ||
Edit a comment | Edit a comment | ||
==Javascript API== | ==Javascript API== |
Revision as of 07:49, 25 May 2009
Objectives
The goals of comments 2.0:
- Manage comments centrally
- Use a consistent approach for all comments throughout Moodle
- Easily integrate comments 2.0 with existing modules
Overview
The comments 2.0 provides APIs to:
- Add comments
- Update comments
And provides an ajax interface to allow adding comments on a floating DIV.
Comments database table
Field | Type | Default | Info |
---|---|---|---|
id | int(10) | auto-incrementing | The unique ID for this comment. |
user_id | int(10) | who wrote this comment | |
parent_id | int(10) | the ID for parent comment | |
contextid | int(10) | The context id defined in context table - identifies the instance of plugin owning the comment. | |
itemid | int(10) | Some plugin specific item id (eg. forum post, blog entry or assignment submission) | |
comment_area | int(10) | a comment should belong to a comment area | |
timecreated | int(10) | ||
timemodified | int(10) | ||
content | text | content of comment |
Comments API
lib/weblib.php
function format_text_with_comments($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=null, $cmt_options)
Use this function format text will add a comment icon automatically at the end of the text:
For example, use following code in format module will add comment icon to every post:
$cmt = new stdclass;
$cmt->contextid = $modcontext->id;
$cmt->area = 'format_post';
$cmt->itemid = $post->id;
$cmt->summary = substr(strip_tags($post->message), 0 ,10);
echo format_text_with_comments($post->message, $post->messageformat, $options, $course->id, $cmt)."
";
lib/commentlib.php
class comments()
__construct($contextid, $comment_area, $itemid))
print_comment_link($return = false)
Will print a comment icon, click it you will get commenting interface
print_comments($params = array())
print comments
add($content, $parent_id)
Add comment to database
delete($id)
delete a comment
edit($id, $content)
Edit a comment
Javascript API
Can be found in lib/javascript-static.js
do_comment(html_id, contextid, comment_area, itemid)
Create a new comment
reply_comment(html_id, contextid, comment_area, itemid, parent_id)
Reply a existed comment
submit_comment
Using AJAX to submit a comment or a reply
comment_callback
Mockup
Interface
See also
- MDL-19118 - Comments 2.0 issue