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 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!
    • By ngrmm
      I have a page with a table. Each table row has a page-reference field and a checkbox.
      The Page sends emails to all users (page-refrence->email-field) and change the value of the checkbox in a row to 1.
      It works with this:
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?> But i have to use a variable in my emailbody.inc which i'm able to get in the table-loop.
      So i do the including of the body inside my loop. But this doesn't work anymore. Page sends out the emails but is unable to change the value of the checkbox.
      I get no errors!
      I'm using ProTable
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?>  
    • By Vigilante
      In general, is there an easy way to know which method should be used to access the API?
      For example, when _ini.php is used in the theme, it would seem you have to use wire()->addHookBefore(...). But on other sites where they used ready.php, I've seen it go straight to just doing $this->addHookAfter() even though there is no class or namespace set up in the ready.php file.
      So how do I know when I can do $this, or $wire, or wire() to access things? And any other variables I'm not aware of.
      Thanks!
×
×
  • Create New...