Jump to content

finding comments using pages_id


alp9000
 Share

Recommended Posts

I'm trying to find all comments for a small group of pages using the API.  The pages, in this case, all have the same author.  I'm extending ProcessCommentsManager to accomplish this, by adding the following code at line 167 of ProcessCommentsManager.module (inside ___executeList()):

$posts = $this->pages->find("template=post,author=" . $this->author);
$selector .= ", pages_id=" . $posts;
 $selector, at this point, has the following value:
start=0, limit=10, sort=-created, status=1, pages_id=4287|4304|4307|4314
And then we resume with the existing code at line 168:
$comments = $field->type->find($field, $selector); 

However, I'm only getting comments for page #4287, the first one in the list.  I've tried this with several data sets and it's always the same.  Is there something about pages_id that doesn't like the usual pipe format for multiple values?  Is there a better way to solve this problem?

I'd also welcome feedback about whether this is generally a good approach to displaying comments only for certain pages.

 
Link to comment
Share on other sites

Sorry, I didn't read properly. I am still not exactly sure the scenario you have, but if I understand correctly, it is easy to get all the comments for a series of pages like this, without needing to hack core code:

$selectedPages = $pages->find("id=4287|4304|4307|4314");

foreach($selectedPages as $p) {
    foreach($p->comments as $c) echo $c->text;
}

Maybe that isn't exactly what you need, but maybe it will be helpful.

If not, can you explain a little more about how and where you want to output the comments.

Link to comment
Share on other sites

If not, can you explain a little more about how and where you want to output the comments.

Thanks, Adrian.  That is helpful and I could probably make that work, but I'll explain what I'm up to.  I have a bunch of occasional bloggers who need to be able to 1) submit blog posts, and 2) moderate comments on those posts.   I'm not giving them access to the Pages admin, but rather am building a couple of process modules to give them a very limited admin interface.  For the comments moderation piece, I'm trying to extend ProcessCommentsManager, which has a nice user interface that sorts them into "All","Pending", etc. and provides pagination.  I thought I could just add one more element to the selector, which would be "pages_id", where pages_id equals the pages the user created.  It would be a two-line solution to my problem if it worked, but it doesn't, so maybe I need to do something closer to what you suggested.

Plan B would be to include the comment moderation on each page, as in the Pages admin, but I really like the way ProcessCommentsManager does it as a big batch.

Link to comment
Share on other sites

  • 9 months later...

I'm striking the same problem. I'm using Ryan's findRecentComments function (which in turn uses FieldtypeComments::findComments). This works well if you want the latest comments from any page. But I want to limit the list of latest comments to pages with a particular property. I think the only way to do this is to use the pages_id value of a comment, which stores the ID of the page the comment is on.

First I was hopeful that pages_id would support sub-selectors but no joy there. So then I figured I'll build a PageArray of pages I want to limit my latest comments list to and give that to pages_id in the selector, but that doesn't work either. Even manually entering a set of bar-separated page IDs doesn't work. Is there some trick to getting pages_id to accept anything apart from a single page id?

Edit: This line explains why the problem exists. I have submitted a GitHub issue / feature request.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...