mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Update to use filter() instead of where()
This commit is contained in:
parent
e87963baae
commit
5a837216d9
@ -79,38 +79,36 @@ class CommentingController extends Controller {
|
|||||||
$class = $request->param('ID');
|
$class = $request->param('ID');
|
||||||
$id = $request->param('OtherID');
|
$id = $request->param('OtherID');
|
||||||
|
|
||||||
if(isset($_GET['pageid'])) {
|
$comments = Comment::get()->filter(array(
|
||||||
$id = Convert::raw2sql($_GET['pageid']);
|
'Moderated' => 1,
|
||||||
|
'IsSpam' => 0,
|
||||||
|
));
|
||||||
|
|
||||||
$comments = Comment::get()->where(sprintf(
|
if($request->getVar('pageid')) {
|
||||||
"BaseClass = 'SiteTree' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0", $id
|
$comments = $comments->filter(array(
|
||||||
|
'BaseClass' => 'SiteTree',
|
||||||
|
'ParentID' => $request->getVar('pageid'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$link = $this->Link('rss', 'SiteTree', $id);
|
$link = $this->Link('rss', 'SiteTree', $id);
|
||||||
|
|
||||||
} else if($class && $id) {
|
} elseif($class && $id) {
|
||||||
if(Commenting::has_commenting($class)) {
|
if(Commenting::has_commenting($class)) {
|
||||||
$comments = Comment::get()->where(sprintf(
|
$comments = $comments->filter(array(
|
||||||
"BaseClass = '%s' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0",
|
'BaseClass' => $class,
|
||||||
Convert::raw2sql($class),
|
'ParentID' => $id,
|
||||||
Convert::raw2sql($id)
|
|
||||||
));
|
));
|
||||||
|
|
||||||
$link = $this->Link('rss', Convert::raw2xml($class), (int) $id);
|
$link = $this->Link('rss', Convert::raw2xml($class), (int) $id);
|
||||||
} else {
|
} else {
|
||||||
return $this->httpError(404);
|
return $this->httpError(404);
|
||||||
}
|
}
|
||||||
} else if($class) {
|
} elseif($class) {
|
||||||
if(Commenting::has_commenting($class)) {
|
if(Commenting::has_commenting($class)) {
|
||||||
$comments = Comment::get()->where(sprintf(
|
$comments = $comments->filter('BaseClass', $class);
|
||||||
"BaseClass = '%s' AND Moderated = 1 AND IsSpam = 0",
|
|
||||||
Convert::raw2sql($class)
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
return $this->httpError(404);
|
return $this->httpError(404);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$comments = Comment::get()->where("Moderated = 1 AND IsSpam = 0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = _t('CommentingController.RSSTITLE', "Comments RSS Feed");
|
$title = _t('CommentingController.RSSTITLE', "Comments RSS Feed");
|
||||||
|
@ -22,7 +22,7 @@ class Comment extends DataObject {
|
|||||||
"Author" => "Member"
|
"Author" => "Member"
|
||||||
);
|
);
|
||||||
|
|
||||||
public static $default_sort = "Created DESC";
|
public static $default_sort = '"Created" DESC';
|
||||||
|
|
||||||
public static $has_many = array();
|
public static $has_many = array();
|
||||||
|
|
||||||
|
@ -56,19 +56,20 @@ class CommentsExtension extends DataExtension {
|
|||||||
|
|
||||||
$order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by');
|
$order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by');
|
||||||
|
|
||||||
// has moderation been turned on if it has amend the sql query
|
$list = Comment::get()->filter(array(
|
||||||
$moderation = '';
|
'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')) {
|
if (Commenting::get_config_value($this->ownerBaseClass, 'require_moderation')) {
|
||||||
|
|
||||||
$member = new Member();
|
if (Member::currentUser() == false) {
|
||||||
if ($member->currentUser() == false) {
|
$list = $list->filter('Moderated', 1);
|
||||||
$moderation = 'Moderated = 1 AND ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = new PaginatedList(Comment::get()->where(sprintf(
|
$list = new PaginatedList($list);
|
||||||
$moderation . "ParentID = '%s' AND BaseClass = '%s'", $this->owner->ID, $this->ownerBaseClass
|
|
||||||
))->sort($order));
|
|
||||||
|
|
||||||
$list->setPageLength(Commenting::get_config_value(
|
$list->setPageLength(Commenting::get_config_value(
|
||||||
$this->ownerBaseClass, 'comments_per_page'
|
$this->ownerBaseClass, 'comments_per_page'
|
||||||
|
Loading…
Reference in New Issue
Block a user