Lars282 Posted June 5, 2012 Share Posted June 5, 2012 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 More sharing options...
diogo Posted June 5, 2012 Share Posted June 5, 2012 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. 1 Link to comment Share on other sites More sharing options...
Lars282 Posted June 5, 2012 Author Share Posted June 5, 2012 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 More sharing options...
diogo Posted June 6, 2012 Share Posted June 6, 2012 (edited) 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 June 6, 2012 by diogo 1 Link to comment Share on other sites More sharing options...
Lars282 Posted June 6, 2012 Author Share Posted June 6, 2012 (edited) 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 June 6, 2012 by Lars282 Link to comment Share on other sites More sharing options...
diogo Posted June 6, 2012 Share Posted June 6, 2012 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 More sharing options...
Lars282 Posted June 6, 2012 Author Share Posted June 6, 2012 (edited) 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 June 6, 2012 by Lars282 Link to comment Share on other sites More sharing options...
Soma Posted June 6, 2012 Share Posted June 6, 2012 I'd guess your pages are hidden or unpublished (not likely)... I would try making it $p = wire('pages')->find("$field.status=0, include=all"); Link to comment Share on other sites More sharing options...
Lars282 Posted June 6, 2012 Author Share Posted June 6, 2012 No, doesn't work either. The pages are definitely not hidden ... But somehow find("$field.status=0") does not get any pages ... ? Link to comment Share on other sites More sharing options...
diogo Posted June 6, 2012 Share Posted June 6, 2012 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 More sharing options...
Soma Posted June 6, 2012 Share Posted June 6, 2012 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 More sharing options...
ryan Posted June 6, 2012 Share Posted June 6, 2012 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 More sharing options...
Lars282 Posted June 6, 2012 Author Share Posted June 6, 2012 Hm, this is how it appears in the admin/fields page: Is that the correct one to use? Link to comment Share on other sites More sharing options...
diogo Posted June 6, 2012 Share Posted June 6, 2012 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 More sharing options...
Soma Posted June 6, 2012 Share Posted June 6, 2012 Hm, this is how it appears in the admin/fields page: Is that the correct one to use? .... and show us a screen shot of the module' config screen... Link to comment Share on other sites More sharing options...
Lars282 Posted June 6, 2012 Author Share Posted June 6, 2012 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 More sharing options...
diogo Posted June 6, 2012 Share Posted June 6, 2012 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 More sharing options...
Lars282 Posted June 6, 2012 Author Share Posted June 6, 2012 What are the possibilities for the status of a comment? 0 for pending, 1 for approved ... -1 for spam? Link to comment Share on other sites More sharing options...
Soma Posted June 6, 2012 Share Posted June 6, 2012 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; 1 Link to comment Share on other sites More sharing options...
Lars282 Posted June 7, 2012 Author Share Posted June 7, 2012 Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now