Jump to content
alp9000

finding comments using pages_id

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.

 

Share this post


Link to post
Share on other sites

Try id instead of pages_id

OK, tried that, but it yields no results at all.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By quickjeff
      Hi Guys, 
      I have been debugging a site for the last 2 hours and cannot solve the issue. 
      I have a site running on 3.0.148. 
      I installed the Kongondo Blog module and was updating the templates to include the website style. 
      Once everything was set and done, I checked the page tree to see an error appear. 
      Template must be assigned a name before 'filename' can be accessed
      The same error appears in templates. 
      Debugging Steps
      I checked the templates in the server to ensure I didnt accidentally delete the namespace.  Deleted cache in browser and server under assets Still no go. 
      Any help is appreciated. 
      Thanks! 
    • By Spyros
      Hello
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      PS 
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
    • By Guy Incognito
      This short script loops through some images from an XML feed and pushes new ones to an image field. It all works perfectly, except for some reason the last image (only) in the loop each time doesn't receive the image description... can everyone spot why? TIA! 🙂 
      foreach ($propertyImages as $img) { $fileName = trim($img[0]); if ( !empty($fileName) ) { $imgPath = '../property_data/'.$fileName; if(file_exists($imgPath) && !in_array(strtolower($fileName),$currentImages)) { $p->property_images->add($imgPath); $p->save(); $newImg = $p->property_images->last(); $newImg->description = $img[1]; $p->save(); } } }  
    • By Anders
      I want to allow full text search on my site. There is a very nice solution that comes right out of the box:
      $selector = "title|body~=$q, limit=50"; This works, but to make it even better I would want to give higher weight to pages where the search term occurs in the title, than if it just occurs in the body. After all, a page with the title "Wine from France" is probably the best match for the search "france wine". How do I accomplish this in ProcessWire?
      I can see three possible paths, but I am not very fond of any of them:
      Do a direct SQL query, circumventing the API, along these lines. But I would prefer to abstract away the database layout if at all possible. Use something like ElasticSearch, but to be honest that would be to complicated to set up and maintain in the long run. Make multiple lookups, first for matches in the title, then for matches in the body, and merge and sort in PHP. My suspicion is that this would get complicated quite quickly. For instance, how do you deal with a page that has two of the three search terms in the title and the third in the body? Is there a magic option four I should look into? Or are any of the above options better than the others? Any input is welcome!
    • By MateThemes
      Hello everyone!
      I am working with Processwire since some time. But some topics are quite hard for me.
      I have a Portfolio (Gallery) Page.
      I am build a template with Portfolio Index and pages with portfolio entries.
      Structure:
      Portfolio Index
      -- Portfolio Entry
      -- Portfolio Entry
      and so on.
      Portfolio Entry has an Image field with max 12 images and are accessible Templates. 
      Now I want to display the single Portfolio Entry on the Portfolio Index and Paginate them. In the index page all images of a single Entry page should be displayed (I should not be organized as albums, where a random image of the portfolio entry should be displayed). 
      I have no clue to achieve this. May someone could give me an advice.
      Thank you in advance!
×
×
  • Create New...