Selectively Removing Event Types

Selectively Removing Event Types

by Mike Churchward -
Number of replies: 5
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi Jon -

Is there an easy way (programatically) to remove event types from the calendar feature? This is kind of like a permanent filter.

My group would like to introduce the calendar, but initially have only global events. So, I don't need the filters, and I don't want users to even know there are other types of events (user, group, course).

Can you steer me to the right place?

mike

Average of ratings: -
In reply to Mike Churchward

Re: Selectively Removing Event Types

by John Papaioannou -
The easiest thing to do is go to lib.php, calendar_session_vars() which is supposed to initialize the session variables. This function is called from just about everywhere before any work is done. The isset() tests are there to prevent it from killing your custom filters.

function calendar_session_vars() {
global $SESSION, $USER;

if(!isset($SESSION->cal_course_referer)) {
$SESSION->cal_course_referer = 0;
}
if(!isset($SESSION->cal_show_global)) {
$SESSION->cal_show_global = true;
}
if(!isset($SESSION->cal_show_groups)) {
$SESSION->cal_show_groups = true;
}
if(!isset($SESSION->cal_show_course)) {
$SESSION->cal_show_course = true;
}
if(!isset($SESSION->cal_show_user)) {
$SESSION->cal_show_user = $USER->id;
}
}

What you want to do is change the last three var assignments and set them to false. Of course, you can also remove the isset() tests to be sure that they will never change from false. The rest of the calendar will think that you have filtered out these kinds of events, so you 're set.

Cheers,
Jon
In reply to John Papaioannou

Re: Selectively Removing Event Types

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

Thanks Jon -

I guess I then need to go into all the display routines to hide the on-screen filter selections, and the event type selectors too?

I'll dig.

mike

In reply to Mike Churchward

Re: Selectively Removing Event Types

by John Papaioannou -
Well, first of all go to calendar_filter_controls() and hack it to return an empty string. That should remove pretty much everything, except maybe for the filters in the detailed month view (I can't recall right now).

Jon
In reply to John Papaioannou

Re: Selectively Removing Event Types

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

Think I found everything...

I commented out the filter table output in 'calendar_filter_controls' in 'lib.php' and in 'calendar_show_month_detailed' in 'view.php', to get rid of the filter controls.

In 'event.php', I forced '$_REQUEST['type']' to always be 'site'. That bypassed the select event screen.

Make sense?

mike

In reply to Mike Churchward

Re: Selectively Removing Event Types

by John Papaioannou -

Yes, that should be just about everything. I 'll make a note to see if it's possible to move the filters from calendar_show_month_detailed() to calendar_filter_controls() so they will all be in one place.

And of course the $_REQUEST['type'] thing is pretty straightforward.

I kinda liked the fact that it was so easy to hack the code and make the changes you wanted. It sort of confirms that I met my design goals, up to a point at least. Not to mention the warm fuzzy feeling inside! blush

Jon