FOSCommentBundle
FOSCommentBundle copied to clipboard
Number of thread comments by state.
As there are 4 defined comment states (VISIBLE, DELETED, SPAM, PENDING), I don't find it very useful to include all four states in total comment count displayed to end user.
For example, on my project comments are PENDING by default, and end user shouldn't see them included in total comments number.
I expanded Thread entity to have numVisibleComments
property, and added exactly the same functions as already used for numComments
. Then I attached Event Listeners to listen when VISIBLE comment is created (or already existing one was updated to be VISIBLE) and update it's thread's numVisibleComments
value.
Ofcourse, I updated the template to use numVisibleComments
as comment count.
Also, which states do you think should be included in this number?
Is this desirable behavior? Should I submit a pull request with this?
It depend on your use case. We even have 6 comment states and we simple update the existing numComments
with an event listener but we don't have the need for an extra numVisibleComments
property.
Maybe it would be more suitable to change the ThreadCountersListener to be configurable to what comment states count?
@XWB But you surely don't show end user number of comments which includes comments not visible to him?
@merk I was thinking about that but then you end up with a different problem. If you set ThreadCountersListener to follow only VISIBLE comments for example, admin user who should see PENDING and SPAM comments included in the count wouldn't see them. Thats why I'm suggesting adding another property which would track VISIBLE ones?
I'm expecting the moderation queue, or administrative tools that get added to this bundle to deal with comments marked with non visible flags, so to me it doesnt matter so much that the comment count only matches visible comments.
We also provide extension points so a developer could implement notifications to notify admins when comments are made that dont end up as visible.
so to me it doesnt matter so much that the comment count only matches visible comments.
On the contrary, it shows end user wrong number of comments. Administrator will se it fine.
If I have 5 comments attached on a thread and only 3 are approved ( 2 are still pending ), end user will see :
5 comments
First comment
Second comment
Third comment
Of course, what I meant was I wouldnt have a problem with modifying the intention of the numComments property to only contain the number of comments that match a defined set of states (developers may end up with more than the default 4). I dont see much need in having a second variable. Any admin interface could just run a query to get a real count.
Oh, okay, I can see your point. I just thought this might be a bit more efficient but it probably wouldn't make much difference. I'll modify the ThreadCountersListener in that case.
how did you do to display only comments with STATE_VISIBLE ?
I put STATE_PENDING by default and want ot display only STATE_VISIBLE for all my comments
I've overridden view template comments_comments to only display STATE_VISIBLE {% if comment is fos_comment_in_state(constant('FOS\CommentBundle\Model\CommentInterface::STATE_VISIBLE')) %}
Not sure if its a very good practice though and if there is more elegant way to do it.
ok, need to work on the counter now, to got the right count of state visible
@igorpan ,i'm new to symfony & i'm using foscomment bundle in my project.my question is how we can set another state to our comments? for example setting 'PENDING' for new comments & just show 'VISIBLE' comments to normal users?
thanks :)