This extension provides tools to add the 'recurring events' feature to your application.
The widget displays a form together with your eventmodel, witch generates one or more recurrence rule (see iCalendar spec It uses the library 'WHEN' from T. Planer to calculate the datetimes from rules and to show a preview the datetimes as list or in a calendar. More included third party tools see Resources below.
This extension is very easy to use and supports languages and jquery ui themes.
Requirements ¶
- Developed with Yii 1.1.10
- needs PHP 5.3 >
How it works ¶
Adds a 'rulescontainer' to your model edit/create form It contains multiple recurring rules/except rules as hidden inputs and a userfriendly description of the rule
Adds a form where the user can generate the rule (Every first sunday, monday in feb ...)
Adds buttons/icons to preview the resulting datetimes as list or in a calendar
Adds a button to add the rule to the rulescontainer
Usage ¶
- Register the RRuleFormAction component in the controller that runs the RRuleForm widget (see the view code below). In the demo this is the SiteController.
class EventController extends Controller {
/**
* Declares class-based actions.
*/
public function actions()
{
return array(
....
'rruleform'=>array(
'class'=>'ext.recur.components.RRuleFormAction',
),
);
}
- Create the rrules model instance in your event models insert/create controller action
Yii::import('ext.recur.models.*');
...
public function actionCreate()
{
$model = new Event(); //your Event, Exhibition, whatever-model
...
//handle your model
...
$rrules = RRules::createFromPOST();
$this->render('create',array('model'=>$model,'rrules'=>$rrules);
}
See demo app: views/site/eventform.php
- Add the RRuleForm widget in the views of the eventmodel (edit/create) It have to be created inside your eventmodel edit/create form-tags, where the rulescontainer should be visible.
<div class="form">
<?php
// show the errors of the rrules model too
echo CHtml::errorSummary(array_merge(array($model),$rrules));
echo CHtml::beginForm();
?>
<div class="row">
<?php
.....
// show your event input fields here
....
//Create the widget inside the events form
//This will create the rulescontainer
$recurWidget = $this->widget('ext.recur.components.RRuleForm',
array(
//'theme' => 'cupertino',
'rrules' => $rrules,
)
);
//display the preview buttons
$recurWidget->renderRulesListPreviewButton();
$recurWidget->renderRulesCalPreviewButton();
echo CHtml::submitButton('Submit'); //the event form
echo CHtml::endForm(); //end of the event form
//render the rrule-form outside the event-form
$recurWidget->renderForm();
See the demo and code for more details or options.
DB storage ¶
This extension doesn't provide AR models for the db, but it should be easy to implement this. You can save the rule-strings directly to the db or generate a 'EventRRules'- AR-model. Use RRules::getRules(); to get the array of string rules for save to db.
See the 'pseudo-code' in SiteController::actionIndex from the demo app.
TIP: If you want to display the datetime of a lot of events it may be useful to save the generated datetimes of the rules too. This will save memory and will increase performance if not for every event/rule the datetimes have to be calculated. You can use RRules->getDateTimes() for that purpose.
And: Take a look at the code...
Customizing ¶
Use the 'rruleform.php' view or 'rrule_summary.php' as template to generate your own rruleform/summary views. You can register the customized views with the widget attributes formView / ruleSummaryView.
Resources and included libraries/extensions ¶
- iCalendar: Recurrence rule
- PHP Date recursion library
- jQuery FullCalendar
- Yii extension echmultiselect
- Yii extension jtimepicker
- Yii extension slidetoggle
Many thanks to the authors.
crit. error
hy. i have this error. anybody have good idea?
Error: Invalid start date DateTime: exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (2012.08.06.) at position 5 (0): Double time specification' in /var/www/clients/client0/web37/web/admin/protected/extensions/recur/vendors/tplaner-When/When.php:115 Stack trace: #0 /var/www/clients/client0/web37/web/admin/protected/extensions/recur/vendors/tplaner-When/When.php(115): DateTime->__construct('2012.08.06.') #1 /var/www/clients/client0/web37/web/admin/protected/extensions/recur/models/RRule.php(108): When->recur('2012.08.06.') #2 /var/www/clients/client0/web37/web/admin/protected/extensions/recur/models/RRule.php(535): RRule::getDateTimesFromRRuleStr('FREQ=DAILY;UNTI...', '2012.08.06.') #3 /var/www/clients/client0/web37/web/admin/protected/extensions/recur/models/RRule.php(485): RRule->getDateTimes(true, true) #4 /var/www/clients/client0/web37/web/admin/protected/extensions/recur/components/RRuleFormAction.php(228): RRule->getFullCalendarEvents() #5 /var/www/clients/client0/web37/web/admin/protected/extensions/recur/components/RRuleFormAction.php(208): RRuleFormAction->renderCalendarView(Object(RRule)) #6 /var/www/clients/client0/web37/web/admin/protected/extensions/recur/components/RRuleFormAction.php(382): RRuleFormAction->renderFullCalendarRulePreview() #7 /var/www/clients/client0/web37/web/framework/web/actions/CAction.php(75): RRuleFormAction->run() #8 /var/www/clients/client0/web37/web/framework/web/CController.php(309): CAction->runWithParams(Array) #9 /var/www/clients/client0/web37/web/framework/web/CController.php(287): CController->runAction(Object(RRuleFormAction)) #10 /var/www/clients/client0/web37/web/framework/web/CController.php(266): CController->runActionWithFilters(Object(RRuleFormAction), Array) #11 /var/www/clients/client0/web37/web/framework/web/CWebApplication.php(283): CController->run('rruleform') #12 /var/www/clients/client0/web37/web/framework/web/CWebApplication.php(142): CWebApplication->runController('site/rruleform') #13 /var/www/clients/client0/web37/web/framework/base/CApplication.php(162): CWebApplication->processRequest() #14 /var/www/clients/client0/web37/web/admin/index.php(13): CApplication->run() #15 {main}
nice extension
great extension. only problem is lack of proper documentation.
But loved it, saved a lot of time.
Thanks joblo.
Source on github?
Is this source available on github (or anywhere else) as a public repository?
Thx for the contribution!
github
recur on github
Re: crit. error
@stageline
Error: Invalid start date DateTime: exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (2012.08.06.) at position 5 (0): Double time specification' in /var/www/clients/client0/web37/web/admin/protected/extensions/recur/vendors/tplaner-When/When.php:115 Stack trace: #0
Your date format should be yyyy-mm-dd or yyyy/mm/dd
Using Recur in a Module?
I can get the demo to work when using it at the site level - like in the demo. However, when attempting to use it with a model in a module, it doesn't seem to work properly. I can get the widgets to appear, but if I click to preview the rules or try to save a rule I can see that I'm getting a 404 from the action in Firebug.
Demo?
Does anyone have a complete working demo utilizing this component in a module, using Active Record?
Thanks a lot for a very nice extension
Hi,
Your extension is impressive and cleverly done. Thanks a lot for sharing it.
I like to point out one issue which I haven't solved yet. It seems that Twitter bootstrap menu with "responsive design" enabled goes haywire on the page which includes the Recur form.
I shall keep you posted when I figure out how to bypass the overlapping JavaScript conflict.
Merry XMAS
Sincerely Babak Bandpey
Hourly recursion
Hi,
https://github.com/tplaner/When/blob/master/When.php is the branch which has the hourly, minutely, secondly recursion capabilities and can be utilised with minor changes.
There is still a piece of road left to make the When class fullblown Recur.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.