Mike November

Phonetic alphabet for my initials, k?

Viewing entries posted in February 2011

Adding scheduling to data objects with the Queued Jobs module

Posted by Marcus Nyeholt on 22 February 2011 | 0 Comments

Tags:

I've added a new piece of code to the Queued Jobs module that allows you to quickly add scheduling to any data object.

It's very straight forward to add

  • Install the queuedjobs module and configure the appropriate cronjob
  • Add the ScheduledExecutionExtension to your data object that can have scheduled execution - Object::add_extension('MyDataObject', 'ScheduledExecutionExtension');
  • In your MyDataObject class, define the method onScheduledExecution(). This is called at the appropriate scheduled time.
  • Run dev/build and go into your SilverStripe backend. Any object of type MyDataObject should now have a "Schedule" tab, which allows you to enter a schedule for having onScheduledExecution() called. Set the "First Execution" date some time in the past if you want it to be immediately executed, or for a time in the future.

0 comments | Read the full post

Why your dates in SilverStripe pages never show up as expected

Posted by Marcus Nyeholt on 7 February 2011 | 0 Comments

In SilverStripe, users can select their locale, along with specifying a default date and time format to use. This should also be replicated throughout the site, but if you're forgetful like me, sometimes it won't display as expected. The secret? Making sure you set the user's preference for the request!

In Page_Controller::init() simply add


        $member = Member::currentUser();
        if(!empty($member->Locale)) i18n::set_locale($member->Locale);
        if(!empty($member->DateFormat)) i18n::set_date_format($member->DateFormat);
        if(!empty($member->TimeFormat)) i18n::set_time_format($member->TimeFormat);

0 comments | Read the full post