Update to use filter() instead of where()

This commit is contained in:
Simon Welsh 2012-12-16 17:24:58 +13:00
parent e87963baae
commit 5a837216d9
3 changed files with 24 additions and 25 deletions

View File

@ -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");

View File

@ -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();

View File

@ -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'