Jump to content

List of Pending Comments?


Lars282
 Share

Recommended Posts

Hey!

I was wondering whether it is possible to display a list of all pending comments somewhere? I have hundreds of pages where visitors can comment and checking them all in the admin page is not really an option.

... of course there's the email notification, but would be great if that's not the only way ...

Thanks,

Lars

Link to comment
Share on other sites

You can easily list all pages that have pending comments and link to their admin pages like this:

foreach ($pages->find("comments.status=0") as $c){ // status 0 means pending
  echo "<li><a target='_blank' href='{$config->urls->admin}page/edit/?id={$c->id}'>{$c->title}</a></li>";
}

If I have time tomorrow, I can try to make a process module with this, so you can have the list on an admin page.

  • Like 1
Link to comment
Share on other sites

Thanks, comments.status=0 helps!

It would be really great to have it on the admin page - if you have time, it would be amazing.

Or maybe you could give me brief outline on how to write this module and I can give it a try myself? The hello world module only shows how to add hooks ... but how to add an admin page?

Thanks again,

Lars

Link to comment
Share on other sites

Here is the module :)

Just install it and create a page as child of "admin" with the "admin" template, and assign the process "ProcessCommentsList" to it.

Edit: changed some details on the module

Edit2: added some options to the module settings

Edit3: updated the module with some changes suggested by Ryan

Edit4: minor change -- replaced the word "Sentence" by "Message" on the options

Edit5: No need for a title when outputting the link to the page. If it is not there, the name is used instead

ProcessCommentsList.module

Edited by diogo
  • Like 1
Link to comment
Share on other sites

Thanks a million!

I adjusted it slightly by finding pages with the comments field name as the one I am using instead of 'comments':

find("article_comments.status=0")

Unfortunately, it now only shows an empty page as if it is not finding anything - there are pending comments though.

When I do something like find("template=xyz") it works fine ... ?

Thanks,

Lars

Edited by Lars282
Link to comment
Share on other sites

I did some changes to the module. Now it supports three options on the settings of the module:

  • Name of the field
  • Sentence for when there are no pending comments
  • Sentence for when there are pending comments

Can you test it?

Link to comment
Share on other sites

Thanks diogo!

It is the same problem as before: It displays the message for when there are pending comments, but then does not list any pages ...

Again, if I replace find("$field.status=0") with something like find("template=xyz"), where xyz is a template I am using, then it displays some pages ...

Edited by Lars282
Link to comment
Share on other sites

Strange. I uninstalled the module and erased the page, and then installed it again and created a new page with the process. Then I created a comments field named "article_comments" and changed the field name option to this name. Added the field to a template, and changed from "comments->renderForm()" to "article_comments->renderForm()" on the template file. Then I added some dummy comments to some pages, and I got the expected list with those pages. Then I went through those pages and Approved all the comments. I get the no comments message as expected.

Link to comment
Share on other sites

Then your comments field is named different. Double check if the comments field is named same as what is set in the module configuration screen.

I just installed and works well diogo. Nice work here. Could be improved to maybe even approve them directly on the admin page. :)

Link to comment
Share on other sites

Great module Diogo! Tested here and seems to work well. I did have to change the selector to "$field.status<1, include=all". I did "<1" rather than "=0" so that it would catch comments marked as spam as pending too. In your getModuleConfigInputfields I recommend removing the "size=200" attribute, as that's causing an overflow issue in Chrome/Mac at least. I would just leave off the size attribute there (unless you need it small), as it'll automatically size to the screen width if you leave it out.

Link to comment
Share on other sites

Ryan, I did the changes you suggested and all is working. Updated the file already.

Lars, it seems to be correct. Anyone knows what might be happening?

Link to comment
Share on other sites

Found where it went wrong: the pages in question have an empty title field, due to their nature ... so the <a></a> were created properly but just invisible.

Thanks so much diogo! I might try to extend this module to include more functionality, and upload here once I do.

Thanks again for your help!

Link to comment
Share on other sites

the pages in question have an empty title field, due to their nature ... so the <a></a> were created properly but just invisible

Updated the module to prevent this to happen. Now it checks for the title, and if it isn't there, it outputs the name

$out .= $c->title ? $c->title : $c->name;
Link to comment
Share on other sites

copied from the wire/modules/Fieldtype/FieldtypeComments/Comment.php

/**

* Status for Comment identified as spam

*

*/

const statusSpam = -2;

/**

* Status for Comment pending review

*

*/

const statusPending = 0;

/**

* Status for Comment that's been approved

*

*/

const statusApproved = 1;

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...