FIX: use pagination on comments

This commit is contained in:
Will Rossiter 2012-07-22 13:44:30 +12:00
parent c50740846c
commit 8819fb8381
2 changed files with 15 additions and 12 deletions

View File

@ -62,18 +62,22 @@ class CommentsExtension extends DataExtension {
/** /**
* Returns a list of all the comments attached to this record. * Returns a list of all the comments attached to this record.
* *
* @todo pagination * @return PaginatedList
*
* @return DataObjectSet
*/ */
public function Comments() { public function Comments() {
$order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by'); $order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by');
return DataObject::get( $list = new PaginatedList(Comment::get()->where(sprintf(
'Comment', "ParentID = '%s' AND BaseClass = '%s'", $this->owner->ID, $this->ownerBaseClass
"\"ParentID\" = '". $this->owner->ID ."' AND \"BaseClass\" = '". $this->ownerBaseClass ."'", ))->sort($order));
$order
); $list->setPageLength(Commenting::get_config_value(
$this->ownerBaseClass, 'comments_per_page'
));
$list->setPaginationGetVar("commentsstart". $this->owner->ID);
return $list;
} }
@ -84,7 +88,7 @@ class CommentsExtension extends DataExtension {
* To customize the html see templates/CommentInterface.ss or extend this function with * To customize the html see templates/CommentInterface.ss or extend this function with
* your own extension. * your own extension.
* *
* @todo Cleanup the passing of all this state based functionality * @todo Cleanup the passing of all this configuration based functionality
* *
* @see docs/en/Extending * @see docs/en/Extending
*/ */

View File

@ -1,6 +1,5 @@
<% if CommentsEnabled %> <% if CommentsEnabled %>
<div id="$CommentHolderID" class="comments-holder-container"> <div id="$CommentHolderID" class="comments-holder-container">
<h4><% _t('POSTCOM','Post your comment') %></h4> <h4><% _t('POSTCOM','Post your comment') %></h4>
<% if AddCommentForm %> <% if AddCommentForm %>
@ -20,11 +19,11 @@
<div class="comments-holder"> <div class="comments-holder">
<% if Comments %> <% if Comments %>
<ul class="comments-list"> <ul class="comments-list">
<% control Comments %> <% loop Comments %>
<li class="comment $EvenOdd<% if FirstLast %> $FirstLast <% end_if %> $SpamClass"> <li class="comment $EvenOdd<% if FirstLast %> $FirstLast <% end_if %> $SpamClass">
<% include CommentsInterface_singlecomment %> <% include CommentsInterface_singlecomment %>
</li> </li>
<% end_control %> <% end_loop %>
</ul> </ul>
<% if Comments.MoreThanOnePage %> <% if Comments.MoreThanOnePage %>