From dda00c54529467c1c1eecce8f9710d3156e8ffe5 Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Sun, 16 Dec 2012 17:24:58 +1300 Subject: [PATCH] Update to use filter() instead of where() --- code/controllers/CommentingController.php | 30 +++++++++++------------ code/dataobjects/Comment.php | 2 +- code/extensions/CommentsExtension.php | 17 +++++++------ 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index ee1fb4c..5bb0278 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -79,38 +79,36 @@ class CommentingController extends Controller { $class = $request->param('ID'); $id = $request->param('OtherID'); - if(isset($_GET['pageid'])) { - $id = Convert::raw2sql($_GET['pageid']); + $comments = Comment::get()->filter(array( + 'Moderated' => 1, + 'IsSpam' => 0, + )); - $comments = Comment::get()->where(sprintf( - "BaseClass = 'SiteTree' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0", $id + if($request->getVar('pageid')) { + $comments = $comments->filter(array( + 'BaseClass' => 'SiteTree', + 'ParentID' => $request->getVar('pageid'), )); $link = $this->Link('rss', 'SiteTree', $id); - } else if($class && $id) { + } elseif($class && $id) { if(Commenting::has_commenting($class)) { - $comments = Comment::get()->where(sprintf( - "BaseClass = '%s' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0", - Convert::raw2sql($class), - Convert::raw2sql($id) + $comments = $comments->filter(array( + 'BaseClass' => $class, + 'ParentID' => $id, )); $link = $this->Link('rss', Convert::raw2xml($class), (int) $id); } else { return $this->httpError(404); } - } else if($class) { + } elseif($class) { if(Commenting::has_commenting($class)) { - $comments = Comment::get()->where(sprintf( - "BaseClass = '%s' AND Moderated = 1 AND IsSpam = 0", - Convert::raw2sql($class) - )); + $comments = $comments->filter('BaseClass', $class); } else { return $this->httpError(404); } - } else { - $comments = Comment::get()->where("Moderated = 1 AND IsSpam = 0"); } $title = _t('CommentingController.RSSTITLE', "Comments RSS Feed"); diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index d2cad8a..c5dfe1f 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -22,7 +22,7 @@ class Comment extends DataObject { "Author" => "Member" ); - public static $default_sort = "Created DESC"; + public static $default_sort = '"Created" DESC'; public static $has_many = array(); diff --git a/code/extensions/CommentsExtension.php b/code/extensions/CommentsExtension.php index e2bdb5f..be6885b 100644 --- a/code/extensions/CommentsExtension.php +++ b/code/extensions/CommentsExtension.php @@ -56,19 +56,20 @@ class CommentsExtension extends DataExtension { $order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by'); - // has moderation been turned on if it has amend the sql query - $moderation = ''; + $list = Comment::get()->filter(array( + 'ParentID' => $this->owner->ID, + 'BaseClass' => $this->ownerBaseClass + ))->sort($order); + + // has moderation been turned on if it has amend the DataList if (Commenting::get_config_value($this->ownerBaseClass, 'require_moderation')) { - $member = new Member(); - if ($member->currentUser() == false) { - $moderation = 'Moderated = 1 AND '; + if (Member::currentUser() == false) { + $list = $list->filter('Moderated', 1); } } - $list = new PaginatedList(Comment::get()->where(sprintf( - $moderation . "ParentID = '%s' AND BaseClass = '%s'", $this->owner->ID, $this->ownerBaseClass - ))->sort($order)); + $list = new PaginatedList($list); $list->setPageLength(Commenting::get_config_value( $this->ownerBaseClass, 'comments_per_page'