Sonntag, 30. Oktober 2016

Semantic MediaWiki - Making multiday calender events

I just introduced a calendar in my semantic media wiki using the calendar format of the Semantic Result Formats extension. This format works quite straight forward: You define which attribute (must be of date format) shall be used, and each entry having it is displayed in the calender with its page name as a link. You can also restrict the selection by category.
{{#ask:
[[date::>{{CURRENTYEAR}}-1-1]]
|?date
|format=calendar
|limit=400
|sort=date
|order=ascending,ascending
}}

Shows all entries with a date attribute since the first of this year (max 400 entries).

The only problem is that the calendar can just handle single day events. It does not anticipate an end date. In the web I found no easy solution, so I came up with my own. I used the recurring event functionality.

Recurring events are often used in combination with the calendar format for meet ups, birthdays, etc.. They create sub events for each date, instead of forcing you to create a separate page for every event. Of course the parent page is used as the page label and as link target.
{{#set_recurring_event:
property=date
|start=August 9, 2016 8:00 pm
|unit=month
|period=1
|week number=2
}}

This creates an event taking place every second Tuesday each month. That it is a Tuesday is defined by the start date.
So what I did was creating a template, which would create a page which is a recurring event.
The template looked like this:
{|
|-
! Titel
| [[title::{{{Titel|}}}]]
|-
! Termin
| [[date::{{{Termin|}}}]] - [[dateEnd::{{{TerminEnde|}}}]]
|-
! Ort
| [[location::{{{Ort|}}}]]
|-
|}
and I added this recurring event definition to the end:
{{#set_recurring_event:
property=date
|start={{{Termin|}}}
|end={{{TerminEnde|}}}
|unit=day
|period=1
}}
Therewith for each event a sub event for each day of the event was created.

BUT...since the main page had a date attribute, it was listed as a single day event in the calendar, as well as the sub event for the first day.
So how to solve this? Since I did not find a solution to tinker with the date (like adding one day), I did a little hack: I simply introduced a new attribute:
| [[dateStart::{{{Termin|}}}]] - [[dateEnd::{{{TerminEnde|}}}]]
Since my calendar just lists entries with a date attribute, the parent page was not listed anymore.
This is definitely not a clean solution, but a dirty hack. It might even break your wiki, depending on how you use the date attribute in other places, but for me this was the easiest way to allow my users to add single as well as multi day events via one form, without resulting in separate pages for each day of an event.
If somebody knows a better and/or cleaner way, please let me know.

Keine Kommentare:

Kommentar veröffentlichen