Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
reordering comments in a discussion - passing data to themes/comments.php
Hi everyone,
I'm trying to figure out how I could reorder comments for a possible Threaded Discussions addon. I need to put a child comment under its parent comment.
I realised that it can only be done with tweaking the db query since the control CommentGrid sends themes/comments.php the data through $this->CommentData that is a db resource.
That's quite annoying because I don't have a way to reorder this $this->CommentData thing. What would have been easy is to send themes/comments.php an array with the comments data, because an array is sortable.
Any idea on this?
I'm trying to figure out how I could reorder comments for a possible Threaded Discussions addon. I need to put a child comment under its parent comment.
I realised that it can only be done with tweaking the db query since the control CommentGrid sends themes/comments.php the data through $this->CommentData that is a db resource.
That's quite annoying because I don't have a way to reorder this $this->CommentData thing. What would have been easy is to send themes/comments.php an array with the comments data, because an array is sortable.
Any idea on this?
0
This discussion has been closed.
Comments
First, I must tell you a bit about the data structure. I read MySchizoBuddy's docs and choosed to add a field for each comment to know its parent comment (I could give you my reasons to do so, not here). Knowing this, there's no simple way to retrieve the tree of comments with a single query.
What I did in my draft is a new query, distinct from the original one. Then its result is post-processed with php.
After that I wanted to save some processing and try to grab results from the original one.
After a better understanding of the framework, I realise that the result of the query stays in its black box until the theme file analyses it. So I can't act on it. I'm a bit stuck here.
1) I understand it yet a bit better. This morning I had a revelation. Well, I know, it's "basic Vanilla" internals, but that was not clear to me until today.
You know what: Theme files have their delegates too, but the delegation class is the class that includes them,and that's why we have
// Note: This file is included from the library/Vanilla/Vanilla.Control...
The first example in the docs uses this fact but I thought it could deserve a section.
2) so my reordering problem could be solved inserting a new delegate call in themes/comments.php
replace
while ($Row = $this->Context->Database->GetRow($this->CommentData)) {
with
$Result = array(); while ($Row = $this->Context->Database->GetRow($this->CommentData)) { $Result[] = $Row; } $this->DelegateParameters['CommentResult'] = &$Result; $this->CallDelegate('PreCommentLoop'); foreach ( $Result as $Row ) { //...
This works well for me, I'll try to benchmark a bit if someone asks me.
3) But I realised that there's a pagination problem too. I need to scan every
posts in a discussion to build my tree. I'm gonna investigate to see if I can
force the query to fetch every post.
Then, during my array processing, I'll try 'paginate-back' excluding the posts I don't need in the page.
When your extension is working, give use the list of delegation you have added.
If delegations can't help you, that there is too much changed, remember that Vanilla can use a modified CommentGrid class instead of the default one:
http://lussumo.com/docs/doku.php?id=vanilla:development:objectfactory
I guess I cannot override what is coded in the theme file with a modified CommentGrid class, am I wrong ?
I'd like to make my extension theme independant. That's why I thought about this transformation from a MySQL result to an array. If not possible, I'll bundle a modified themes/comments.php file and a way to update a custom themes/comments.php file in my addon.
Thanks.
Thanks.
It seems that I needed precautions for using ObjectFactory->SetReference. Are they really needed? Did I miss something?
if ( ! class_exists( 'CommentGrid' )) include( $Context->Configuration['LIBRARY_PATH'] . 'Vanilla/Vanilla.Control.CommentGrid.php' ); if ( ! class_exists( 'ThreadedCommentGrid' )) include('inc/ThreadedCommentGrid.class.php'); $Context->ObjectFactory->SetReference( 'CommentGrid', 'ThreadedCommentGrid' );
Thanks "mountains-man".
if(!defined('IN_VANILLA')) exit(); require_once($Context->Configuration['LIBRARY_PATH'] . 'Vanilla/Vanilla.Control.CommentGrid.php'); class ThreadedCommentGrid extends CommentGrid { ... }
Then in default.php:
include('inc/ThreadedCommentGrid.class.php'); $Context->ObjectFactory->SetReference( 'CommentGrid', 'ThreadedCommentGrid' );