Moodle

[patch] Multi Calendar support

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.4
  • Fix Version/s: 2.1.5
  • Component/s: Calendar
  • Labels:
    None
  • Environment:
    cross platform
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_21_STABLE

Description

I implemented a patch to add the capability of working with other calendar systems than just Gregorian.
I'll provide the instructions to apply the patch in following post

  1. patch.txt
    10/Mar/10 10:03 AM
    49 kB
    Shamim Rezaie
  2. patch.txt
    25/Feb/09 9:56 PM
    48 kB
    Shamim Rezaie

Issue Links

Activity

Hide
Shamim Rezaie added a comment - - edited

0. This SQL command should be executed first:
ALTER TABLE `mdl_user` ADD COLUMN `calendar_system` VARCHAR(20) DEFAULT NULL AFTER `lang`;

1. The calendar system directory (can be found in the attached archived file) should be copied to the Moodle root directory. In this directory there is a file named calendar_system.class.php. This file contains the definition of calendar_system_base abstract class (interface) and also a factory function named calendar_system_factory which is used to "manufacture" an instance of desired calendar system. New Calendar systems are located in a sub-directory in the mentioned directory. They have to implement the mentioned base class. I implemented and included Gregorian and Persian calendar systems.

2. In /lib/moodlelib.php:
2.1. The functions make_timestamp( ), userdate( ), and usergetdate( ) should be renamed to make_timestamp_old( ), userdate_old( ), and usergetdate_old( ) respectively. New implementations for the above functions are presented.
2.2. All calls to mktime( ) function should be replaced with $CALENDAR_SYSTEM->mktime( )
2.3. In some places the numbers 1971 and 2035 are used as the minimum and maximum year. They should be replaced with $CALENDAR_SYSTEM->get_min_year( ) and $CALENDAR_SYSTEM->get_max_year()
2.4. New implementation are presented for days_in_month( ) and dayofweek( ), dayofweek( ) functions.

3. /lib/setup.php should be slightly changed.
2.1. $CALENDAR_SYSTEM should be defined as a global object somewhere at the beginning of the file.
2.2. /calendar_system/calendar_system.class.php should be included
2.3. the following snippet should be inserted at the and of the file:
if (empty($USER->calendar_system)) { $USER->calendar_system = ''; }
$CALENDAR_SYSTEM = calendar_system_factory::factory($USER->calendar_system);

4. The following line should be added to /config.php (I do confirm that it would be nice to have a global setting in the moodle interface to change the above config through it):
$CFG->calendar_system = 'gregorian';

    • It just specifies the default calendar system. Each user can override it. **

5. In the file /lib/weblib.php, the implementation of print_date_selector( ) should be slightly changed.

6. I stop describing changes more since they can be found in the patch file.

Here is the list of modified files:

  • /admin/roles/assign.php
  • /calendar/event.php
  • /calendar/export.php
  • /calendar/lib.php
  • /calendar/view.php
  • /enrol/authorize/config_form.php
  • /lang/en_utf8/moodle.php
  • /lib/bennu/iCalendar_rfc2445.php
  • /lib/form/dateselector.php
  • /lib/form/datetimeselector.php
  • /lib/accesslib.php
  • /lib/moodlelib.php
  • /lib/setup.php
  • /lib/weblib.php
  • /user/extendenrol.php
  • /user/groupextendenrol.php
  • /user/editlib.php
Show
Shamim Rezaie added a comment - - edited 0. This SQL command should be executed first: ALTER TABLE `mdl_user` ADD COLUMN `calendar_system` VARCHAR(20) DEFAULT NULL AFTER `lang`; 1. The calendar system directory (can be found in the attached archived file) should be copied to the Moodle root directory. In this directory there is a file named calendar_system.class.php. This file contains the definition of calendar_system_base abstract class (interface) and also a factory function named calendar_system_factory which is used to "manufacture" an instance of desired calendar system. New Calendar systems are located in a sub-directory in the mentioned directory. They have to implement the mentioned base class. I implemented and included Gregorian and Persian calendar systems. 2. In /lib/moodlelib.php: 2.1. The functions make_timestamp( ), userdate( ), and usergetdate( ) should be renamed to make_timestamp_old( ), userdate_old( ), and usergetdate_old( ) respectively. New implementations for the above functions are presented. 2.2. All calls to mktime( ) function should be replaced with $CALENDAR_SYSTEM->mktime( ) 2.3. In some places the numbers 1971 and 2035 are used as the minimum and maximum year. They should be replaced with $CALENDAR_SYSTEM->get_min_year( ) and $CALENDAR_SYSTEM->get_max_year() 2.4. New implementation are presented for days_in_month( ) and dayofweek( ), dayofweek( ) functions. 3. /lib/setup.php should be slightly changed. 2.1. $CALENDAR_SYSTEM should be defined as a global object somewhere at the beginning of the file. 2.2. /calendar_system/calendar_system.class.php should be included 2.3. the following snippet should be inserted at the and of the file: if (empty($USER->calendar_system)) { $USER->calendar_system = ''; } $CALENDAR_SYSTEM = calendar_system_factory::factory($USER->calendar_system); 4. The following line should be added to /config.php (I do confirm that it would be nice to have a global setting in the moodle interface to change the above config through it): $CFG->calendar_system = 'gregorian';
    • It just specifies the default calendar system. Each user can override it. **
5. In the file /lib/weblib.php, the implementation of print_date_selector( ) should be slightly changed. 6. I stop describing changes more since they can be found in the patch file. Here is the list of modified files:
  • /admin/roles/assign.php
  • /calendar/event.php
  • /calendar/export.php
  • /calendar/lib.php
  • /calendar/view.php
  • /enrol/authorize/config_form.php
  • /lang/en_utf8/moodle.php
  • /lib/bennu/iCalendar_rfc2445.php
  • /lib/form/dateselector.php
  • /lib/form/datetimeselector.php
  • /lib/accesslib.php
  • /lib/moodlelib.php
  • /lib/setup.php
  • /lib/weblib.php
  • /user/extendenrol.php
  • /user/groupextendenrol.php
  • /user/editlib.php
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Shamim,

nice functionality (and patch) ! B-)

IMO is a good idea to move all the calendar/dates thing to one OOP like that, 100%. More with potential changes coming in Moodle 2.0 related with switching from our "custom" timezones support to the "native" one offered by PHP since some time ago. Doing that under one OOP umbrella will enable to do it easier, sure!

In the other side, I think we cannot include that in the middle of one stable release (1.9.x) because changes of functionality like that aren't normally accepted in stable versions.

So, perhaps, the way to handle this could be:

1) Keep it as a patch for Moodle 1.9.x, ppl needing it will be able to do it.
2) Apply it to HEAD (perhaps something will change in the final OOP implementation, but the goal of supporting multiple calendar systems will remain).
3) Add a new set of PHP5-time-zoned calendars as alternative to the "custom-time-zoned" ones
4) Decide if we keep both sets of calendars or we migrate to PHP5 ones or we keep using current ones.

That way we'll end in Moodle 2.0 with multiple-calendars support available and with various problems sorted in the timezones stuff out too. And, at the same time, all the date/time/calendar stuff will be OOP, allowing new calendars to come and so on...

In any case, very interesting stuff, thanks!

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi Shamim, nice functionality (and patch) ! B-) IMO is a good idea to move all the calendar/dates thing to one OOP like that, 100%. More with potential changes coming in Moodle 2.0 related with switching from our "custom" timezones support to the "native" one offered by PHP since some time ago. Doing that under one OOP umbrella will enable to do it easier, sure! In the other side, I think we cannot include that in the middle of one stable release (1.9.x) because changes of functionality like that aren't normally accepted in stable versions. So, perhaps, the way to handle this could be: 1) Keep it as a patch for Moodle 1.9.x, ppl needing it will be able to do it. 2) Apply it to HEAD (perhaps something will change in the final OOP implementation, but the goal of supporting multiple calendar systems will remain). 3) Add a new set of PHP5-time-zoned calendars as alternative to the "custom-time-zoned" ones 4) Decide if we keep both sets of calendars or we migrate to PHP5 ones or we keep using current ones. That way we'll end in Moodle 2.0 with multiple-calendars support available and with various problems sorted in the timezones stuff out too. And, at the same time, all the date/time/calendar stuff will be OOP, allowing new calendars to come and so on... In any case, very interesting stuff, thanks! Ciao
Hide
Shamim Rezaie added a comment - - edited

improved version is attached.
there is no need to modify config.php anymore.
if you are applying the patch on an installed moodle, just execute this sql command:

  • ALTER TABLE `mdl_user` ADD COLUMN `calendar_system` VARCHAR(20) DEFAULT NULL AFTER `lang`;
    but if you are installing moodle from patched code, the is no need to execute the above sql command
Show
Shamim Rezaie added a comment - - edited improved version is attached. there is no need to modify config.php anymore. if you are applying the patch on an installed moodle, just execute this sql command:
  • ALTER TABLE `mdl_user` ADD COLUMN `calendar_system` VARCHAR(20) DEFAULT NULL AFTER `lang`; but if you are installing moodle from patched code, the is no need to execute the above sql command
Hide
Iman Zamani added a comment -

Hi

Can you explain more about use this patch?

Show
Iman Zamani added a comment - Hi Can you explain more about use this patch?
Hide
Iman Zamani added a comment -

Hi

Can you explain more about use this patch in new version (2.0)?

Best Regards

Show
Iman Zamani added a comment - Hi Can you explain more about use this patch in new version (2.0)? Best Regards
Hide
Shamim Rezaie added a comment -

Iman,
Please post your question in the related thread in the Persian Community Forum at http://moodle.org/course/view.php?id=1008

Show
Shamim Rezaie added a comment - Iman, Please post your question in the related thread in the Persian Community Forum at http://moodle.org/course/view.php?id=1008
Hide
Iman Zamani added a comment -

Hello

I send it there but I don't receive any answer

Show
Iman Zamani added a comment - Hello I send it there but I don't receive any answer
Hide
Shamim Rezaie added a comment -

That's the way a forum work.
You ask something and someone may answer. However in this case you already can find good stuff in the existing discussions.

Show
Shamim Rezaie added a comment - That's the way a forum work. You ask something and someone may answer. However in this case you already can find good stuff in the existing discussions.
Hide
Iman Zamani added a comment -

It is so necessary for me and I have a project that I should do it with this system.
If it is possible for you please send me your yahoo id or other id that I can chat with you
Best Regards

Show
Iman Zamani added a comment - It is so necessary for me and I have a project that I should do it with this system. If it is possible for you please send me your yahoo id or other id that I can chat with you Best Regards
Hide
Shamim Rezaie added a comment -

Sorry but this is not a kind of a request to be asked in Moodle Tracker.

Show
Shamim Rezaie added a comment - Sorry but this is not a kind of a request to be asked in Moodle Tracker.
Hide
Iman Zamani added a comment -

I see
But do you think this is good for us that this CMS don't have this module until now?!
If you really need to help please provide an popular module that all of Iranian peoples can use it easily and don't wander them!

Show
Iman Zamani added a comment - I see But do you think this is good for us that this CMS don't have this module until now?! If you really need to help please provide an popular module that all of Iranian peoples can use it easily and don't wander them!
Hide
Shamim Rezaie added a comment -

I'm sorry if you feel wandered.
We're all in the same boat. you also can contribute and help others to not wander.

Show
Shamim Rezaie added a comment - I'm sorry if you feel wandered. We're all in the same boat. you also can contribute and help others to not wander.
Hide
Iman Zamani added a comment -

I see this module on http://foodle.org.But you don't need to public it's module ?!

Show
Iman Zamani added a comment - I see this module on http://foodle.org.But you don't need to public it's module ?!
Hide
Shamim Rezaie added a comment -

foodle uses the same code that has been shared here with a few minor customisations.
PLEASE continue the discussion in a moodle forum. Tracker is not a forum.

Show
Shamim Rezaie added a comment - foodle uses the same code that has been shared here with a few minor customisations. PLEASE continue the discussion in a moodle forum. Tracker is not a forum.
Hide
Iman Zamani added a comment -

Sorry

Show
Iman Zamani added a comment - Sorry
Hide
Iman Zamani added a comment -

Hi
Can you attach the patch file for improved version(Vrsion 2.x)?

Show
Iman Zamani added a comment - Hi Can you attach the patch file for improved version(Vrsion 2.x)?

People

Vote (93)
Watch (27)

Dates

  • Created:
    Updated: