Reordering a block of variables

Discussion forum for Extension Writers regarding Extension Development.
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Reordering a block of variables

Post by javiexin »

Hi,

I would like to reorder a set of entries in a blockvar block. Is this possible without recreating it from scratch?

What I would like to do is something like this (pseudocode):

Code: Select all

$block_vars=$template->get_block_vars('block_name');
usort($block_vars, "order_array_func");
$template->destroy_block_vars('block_name');
$template->assign_block_vars('block_name',$block_vars);
Any hint as to how? The part that is not in the interface (as far as I can tell) is the GET part... interesting.

Thanks in advance,
-javiexin
User avatar
david63
Registered User
Posts: 18437
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Reordering a block of variables

Post by david63 »

Why do you need to sort them? You can control the order they are displayed from within the template.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Reordering a block of variables

Post by javiexin »

How?

In any case, I believe you cannot do that, as it would require modifying a standard template.

Thanks
-javiexin
User avatar
david63
Registered User
Posts: 18437
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Reordering a block of variables

Post by david63 »

I am not sure what you are trying to do but reordering a block will not normally have any affect on how they are displayed on a core template as each element of the block is defined in the template.

Take a look at any of the templates that contain blocks to see how they work.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Reordering a block of variables

Post by javiexin »

This is a working 3.0 mod being ported to 3.1, it works as expected in 3.0, but in 3.1 there is no way to modify the array that is put in the block var, so I am stuck with modifying the block in place.

For the record, I am trying to reorder the presentation of poll options, to show them ordered by number of votes.

Thanks,
-javiexin
User avatar
david63
Registered User
Posts: 18437
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Reordering a block of variables

Post by david63 »

Which event are you using?

Not knowing exactly where you are working I would have thought that you could manipulate the poll data before it is sent to the template.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Reordering a block of variables

Post by javiexin »

core.viewtopic_get_post_data

No other event after calculating poll option data, and no event before sending the data to the template.
brunoais
Registered User
Posts: 438
Joined: Wed Jun 18, 2008 10:50 am

Re: Reordering a block of variables

Post by brunoais »

What do you need to reorder?
I still didn't get that.
User avatar
david63
Registered User
Posts: 18437
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Reordering a block of variables

Post by david63 »

javiexin wrote:core.viewtopic_get_post_data

No other event after calculating poll option data, and no event before sending the data to the template.
In any case you do not have block variables in that event
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Reordering a block of variables

Post by javiexin »

brunoais wrote:What do you need to reorder?
I still didn't get that.
Ok, let's be precise. In 3.0, I had the following code inserted in what is now (3.1) line 939 of viewtopic.php:

Code: Select all

	if ($s_display_results && $topic_data['poll_sort_results'])
	{
		function order_by_votes($a, $b) { return (($a['poll_option_total'] < $b['poll_option_total']) ? 1 : (($a['poll_option_total'] > $b['poll_option_total']) ? -1 : (($a['poll_option_id'] > $b['poll_option_id']) ? 1 : -1))); }
		usort($poll_info, "order_by_votes");
	}
I want to achieve exactly the same...
david63 wrote:
javiexin wrote:core.viewtopic_get_post_data
No other event after calculating poll option data, and no event before sending the data to the template.
In any case you do not have block variables in that event
Not as parameters of the event, but they are available through the $template variable. In this case, it is the 'poll_option' block array that I want to manipulate.

Please, help me out...
Thanks a lot.
-javiexin
rxu
Extensions Development Team
Posts: 3400
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Reordering a block of variables

Post by rxu »

javiexin wrote:Please, help me out...
I believe the best option here would be adding new event to the viewtopic.php to access the poll data ($poll_info and some others I guess). say, around line 940.
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Reordering a block of variables

Post by javiexin »

Yes, that is what I wanted to avoid, to ask for a new event. But I guess there is no better option.

Anyhow, and back to the original question: any way to query the $template to get the current status/content of a block?

Thanks,
-javiexin
brunoais
Registered User
Posts: 438
Joined: Wed Jun 18, 2008 10:50 am

Re: Reordering a block of variables

Post by brunoais »

There is none.
You can only delete and send the block again
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Reordering a block of variables

Post by javiexin »

brunoais wrote:There is none.
You can only delete and send the block again
Which would require recalculating everything again, additional DB queries, etc. Not nice.
But thanks for the response...
-javiexin
rxu
Extensions Development Team
Posts: 3400
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Reordering a block of variables

Post by rxu »

javiexin wrote:that is what I wanted to avoid, to ask for a new event
Why not? It's not a big deal, although you won't get it prior to 3.1.5 if merged currently.
Also, it would be nice to know what variables are needed to access in the event listener.
Post Reply

Return to “Extension Writers Discussion”