entry_groupdata and dategroup troubles

Creating and modifying plugins.
Post Reply
karel
Posts: 4
Joined: Thu Nov 08, 2007 3:02 am

entry_groupdata and dategroup troubles

Post by karel »

Hey,

I have already spent quite a bit of time getting s9y to do what I want it to do. Looks good so far. However I have one problem:

I would like to manipulate the output of serendipity_printEntries. I have already almost acomplished what I needed in the entry_display hook, but I do not want s9y to apply any sorting afterwards. Alternatively I can do it more properly and use entry_groupdata.

function_entries.inc.php indicates the routines should use $dategroup =& $entries; but this does not work for me.

I am not an expert on these references, but to me it seems clearly different to the foreach() { $dategroup[$key]['entries'][] = &$entries[$x]; } loop in the sort mechanism.

If the code is correct, can somebody explain how to write a simple plugin for entry_groupdata. (just the event hook function, without doing anything)

Thanks for your help
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: entry_groupdata and dategroup troubles

Post by garvinhicking »

Hi!

I'd like to help you, but I might not have understand your intention correctly. What exactly do you want to do?

Do you want to pass a custom sorted array of entry data form the plugin to the output?

That would be something like:

Code: Select all

case 'entry_groupdata':
  $eventData = array();
  $entries = ... your entries here, using the format like serendipity_fetchEntries does
  $eventData[] = array('entries' => $entries);
I think what you're missing is that the hook_event call puts the original $entries into the plugin, but there it is accessed via $eventData and NOT $entries. That's a usual PHP thing, because it uses variables with the name you declared in the function scope, not with the name you pass a variable.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
karel
Posts: 4
Joined: Thu Nov 08, 2007 3:02 am

Post by karel »

Hey Garvin,

no I am not making the $eventData / $entries mistake.

Let me try to explain another way, I just want to know if I understand it correctly.

Following situation, no plugins, no hooks, just looking at functions_entries.inc.php, serendipity_printEntries

Assume

Code: Select all

$entries['use_grouped_array']="something";
Then I think, that following has to be changed

Code: Select all

    // A plugin executed in entry_display should be able to change the way of ordering entries. Forward-Thinking. ;)
    if (isset($entries['use_grouped_array'])) {
        $use_grouped_array = $entries['use_grouped_array'];
--> unset( $entries['use_grouped_array']);
    }

    if ($use_grouped_array === false) {
...
    } elseif ($use_grouped_array === 'plugin') {
        // Let a plugin do the grouping
        serendipity_plugin_api::hook_event('entry_groupdata', $entries);
--> $entries=array(array('entries'=>$entries));
        $dategroup =& $entries;
    } else {
--> $entries=array(array('entries'=>$entries));
        $dategroup =& $entries;
    }

    foreach($dategroup as $properties) {
        foreach($properties['entries'] as $x => $_entry) {
            $entry = &$properties['entries'][$x]; // PHP4 Compat
?>
karel
Posts: 4
Joined: Thu Nov 08, 2007 3:02 am

Re: entry_groupdata and dategroup troubles

Post by karel »

garvinhicking wrote:case 'entry_groupdata':
$eventData = array();
$entries = ... your entries here, using the format like serendipity_fetchEntries does
$eventData[] = array('entries' => $entries);
[/code]
Just to make the point: I understand your solution and it would probably work. But it does not seem logical to me, to do this transformation within the plugin, because it would break as soon as I would be using two or more plugins for the same event? (whether it makes sense or not in case).
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: entry_groupdata and dategroup troubles

Post by garvinhicking »

Hi!

Please, you'll need to explain me what you want to achieve. I don't see a reason for your patch, because a plugin must decide on its own how ordering is done (using my code example).

Of course this disturbs other possible plugins, but in reality this should never happen: Either you use a plugin that puts custom ordering into the entry list, or you don't. But you can't use two plugins where one orders the entries in way A, and the other plugin orders them in way B. What's the right order? Only the user can decide, by configuring the plugin. Since such a plugin does not exist yet, it's in your responsibility to add that configuration option ;)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
karel
Posts: 4
Joined: Thu Nov 08, 2007 3:02 am

Post by karel »

First of all: My solution posted above is not suffient, as the absence of the date fields breaks some output functions. Couple of more lines needed. (I can solve this easily)


Just for discussion: (my problem is solved, thank you very much for your help)
Of course it does not make sense to have multiple sorting plugins. But usually you would split up your plugins by feature, so it can happen that several of them would like to have an influence on their position. If the is_sticky variable were not hardcoded in all the templates and s9y, you could not make any additional sorting.

As far as this function is concerned, my view of the logic was:
Default: Sort by date
OR: let a plugin do the work
ELSE: leave the data as it is.

But the else function will not work this way. The output is a different array structure than the output sorted by date and thus all subsequent functions won't work.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Glad to hear your problem was solved. However I still don't get what you want to achieve so I can't comment on your Default/Or/Else-logic question/idea.

With more precise examples, I might be able to understand what you need and could see how it could be modified.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply