Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to pass additional data to events json #51

Closed
juho-jaakkola opened this issue Jun 5, 2013 · 15 comments
Closed

Make it possible to pass additional data to events json #51

juho-jaakkola opened this issue Jun 5, 2013 · 15 comments

Comments

@juho-jaakkola
Copy link

I have the need to pass additional data (backgroundColor in particular) to the events json returned by event_calendar_get_page_content_fullcalendar_events(). I wonder what would be the best way to achieve this?

I suppose the full calendar view is the only one that has any use for backgroundColor and similar data, correct? So maybe the function could trigger a plugin hook?

Or would it be too excessive to attach all metadata (available to the current user) to the json? If this option was used other plugins could add metadata using events and plugin hooks, and all the added data would then be immediately available in the json on the client side.

How much metadata is there in a single event_calendar object? Is the latter one a bad idea?

@kevinjardine
Copy link
Owner

I think the json approach sounds like a good one. More options to configure the appearance or behaviour of the calendar would be great.

@juho-jaakkola
Copy link
Author

So... the latter one? All metadata would be automatically available on the client side without the need to add them to the json using a plugin hook handler?

@kevinjardine
Copy link
Owner

Sorry, I'm not sure what you mean by "all metadata". I meant that adding additional fields to the json object was fine. I don't think it would be necessary to store these in the database would it?

@juho-jaakkola
Copy link
Author

Yes, I would need to save them to database.

In my use case the events would be color coded. User could pick a color in create/edit form for each event. (I believe this was a default feature in Elgg 1.7 version?)

@kevinjardine
Copy link
Owner

No, colour coding was not a previous feature in this plugin.

The event calendar has no actual concept of a calendar. It is just a collection of events contained by a user or group.

Perhaps you could create a new "calendar configuration" object to store configuration metadata? Then when displaying the events associated with a container object, the code could also check to see if the container also contains a calendar configuration object and use it to customise the calendar if it exists by passing its metadata via JSON?.

@kevinjardine
Copy link
Owner

Or did you really want to have the information associated with just one event? If so, I'm not sure I like the idea of automatically copying all the event metadata to JSON as some of it may not be relevant to the display.

@juho-jaakkola
Copy link
Author

Or did you really want to have the information associated with just one event?

Yes!

I can add a colorpicker to the event edit form using elgg_extend_view(). Then I can save the color as metadata to the database using a plugin hook handler.

The only problem is to get the additional metadata to the json returned by event_calendar_get_page_content_fullcalendar_events().

I'm not sure I like the idea of automatically copying all the event metadata to JSON as some of it may not be relevant to the display.

This is understandable. So how about triggering a plugin hook in event_calendar_get_page_content_fullcalendar_events()? Something like:

// Allow other plugins to add/delete/modify the event data
$event_item = elgg_trigger_plugin_hook('prepare:json', 'event_calendar', $event, $event_item);

I could then make a plugin hook handler that adds e.g. the backgroundColor to the event item:

function myplugin_event_data_handler($hook, $type, $event_item, $entity) {
    if ($entity->backgroundColor) {
        $event_item['backgroundColor'] = $entity->backgroundColor;
    }

    return $event_item;
}

At least I can't think of any better idea than a plugin hook at the moment...

@juho-jaakkola
Copy link
Author

Just as a curiosity, here's a screenshot of the Elgg 1.7 version I'm supposed to upgrade. Apparently someone has made their own version that allows defining the background color for each event:
event_calendar_colorpicker

Here's what the calendar is supposed to look like in the 1.8 version once I get the color feature implemented:

event_calendar_colored

@kevinjardine
Copy link
Owner

Interesting. The colour picker isn't my code. Sounds like a good idea though.

I like your JSON solution. Should be useful for a number of things.

@kevinjardine
Copy link
Owner

By the way, I would be fine in this case if you added the colour picker to the main code. Just make it a plugin configurable option (toggled off by default).

Please do that if you have the time and your client/employer is OK with it.

@juho-jaakkola
Copy link
Author

I like your JSON solution. Should be useful for a number of things.

Any preferences for the name of the hook? The 'prepare:json', 'event_calendar' was just the first thing that came to my mind.

By the way, I would be fine in this case if you added the colour picker to the main code

Great! I'll open a separate issue for that.

@kevinjardine
Copy link
Owner

prepare:json seems fine to me and comparable to other similar Elgg plugin hooks.

@juho-jaakkola
Copy link
Author

Hm... or 'prepare', 'event_calendar:json' in comparison to 'prepare', 'menu:site' in Elgg core? I'm not really sure.

@kevinjardine
Copy link
Owner

Yes, you're right. Best to make it specific or we may run into collisions with other plugins.

kevinjardine pushed a commit that referenced this issue Jun 6, 2013
Fixes #51 - Make it possible to pass additional data to events json
@juho-jaakkola
Copy link
Author

Closed by #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants