Home » Documentation » What is PeoplePods? » SDK Documentation » Object Definitions » Comment Object

Comment Object

The comment object is a pretty simple object with only a few fields. Each comment is linked to a person object representing the author of the comment, and a content object representing the piece of content upon which the comment was left.

Fields

id the unique id of this comment
contentId reference to the piece of content the comment is attached to
profileId reference to the person profile the comment is attached to
userId reference to the comment's author
id the unique id of this comment
comment the text of the comment
date timestamp of when the comment was posted
type short string, used to create multiple types of comment - ie review vs comment
permalink url for this comment
minutes minutes since the comment was posted

Relationships

You can access the author of the comment using the $comment->author() function, which returns a person object.

// access person object member functions
echo "Comment by: ";
$comment->author()->permalink();

// output the author using a special template
$comment->author()->output('avatar');

You can also access the content upon which the comment was left, using the handy $comment->parent() function.

// access content values
$comment->parent()->write('headline');

// is this comment by the original poster?
if ($comment->get('userId')==$comment->parent()->get('userId')) { 
  // do something
}

Loading Comments

The vast majority of the time, you'll probably be displaying the comments that are attached to the piece of content you are viewing. To do this, simply use the $content->comments() function, which returns a list of the comments in chronological order.

You can also load a specific comment by it's id using the $POD->getComment() function.

If you need to query the comment database on any of the comment fields or fields in the related tables, use the $POD->getComments() function.

// output the comments from a piece of content
$content->comments()->output();

// load a specific comment (for editing, etc)
$comment = $POD->getComment(array('id'=>1));

// load all comments from a user
$comments = $POD->getComments(array('userId'=>1));

// load all comments from any piece of content in a specific group
$group_comments = $POD->getComments(array('d.groupId'=>5));

Adding and Removing Commments

The best way to add a comment is to use the $content->addComment() function, which handles all the nitty gritty details.

To delete comments, call $comment->delete().

Relationships

Each comment has a set of predefined relationships to people and other pieces of content within the site. These relationships are represented by cleverly named functions that return other objects or stacks of objects.

  • $Comment->parent() - returns either a content object or a person object defined by $comments contentId or profileId field.
  • $Comment->author() - returns a person object defined by $Comment's userId field.

And don't forget, every content object inherits all the functions from the $Obj object. These functions include:

  • Discuss This Document

No comments have been posted yet.

Download Download the latest version of PeoplePods!

0.9 Latest Version:
Release Notes

Join the PeoplePods developer network and get direct access to documentation, additional plugins, and our forums!

  Already Registered? Login

Recent Posts from Our Blog

Version 0.9 is here!

The latest version of PeoplePods is now available for download! This version features a drastically revamped theme which is now valid HTML5, a completely rewritten JSON-powered API, many...

Ben Brown on how running a community is like throwing a giant, never-ending party

An interview I did with OpenSource.com is now online!  Read it here. In it, I discuss how running an online community is like throwing a giant, never-ending party, how open source techniques...