Yii 1.1: efullcalendar

Arshaw's FullCalendar as Yii extension
29 followers

This is so far the best calendar library I've seen in my life :) That's what I call a rapid development.

Installation

Just unpack to extensions directory.

Usage

$this->widget('ext.EFullCalendar.EFullCalendar', array(
    // polish version available, uncomment to use it
    // 'lang'=>'pl',
    // you can create your own translation by copying locale/pl.php
    // and customizing it
 
    // remove to use without theme
    // this is relative path to:
    // themes/<path>
    'themeCssFile'=>'cupertino/theme.css',
 
    // raw html tags
    'htmlOptions'=>array(
        // you can scale it down as well, try 80%
        'style'=>'width:100%'
    ),
    // FullCalendar's options.
    // Documentation available at
    // http://arshaw.com/fullcalendar/docs/
    'options'=>array(
        'header'=>array(
            'left'=>'prev,next',
            'center'=>'title',
            'right'=>'today'
        ),
        'lazyFetching'=>true,
        'events'=>$calendarEventsUrl, // action URL for dynamic events, or
        'events'=>array() // pass array of events directly
 
        // event handling
        // mouseover for example
        'eventMouseover'=>new CJavaScriptExpression("js_function_callback"),
    )
));

Example action

public function actionCalendarEvents()
{
    $items[]=array(
        'title'=>'Meeting',
        'start'=>'2012-11-23',
        'color'=>'#CC0000',
        'allDay'=>true,
        'url'=>'http://anyurl.com'
    );
    $items[]=array(
        'title'=>'Meeting reminder',
        'start'=>'2012-11-19',
        'end'=>'2012-11-22',
 
        // can pass unix timestamp too
        // 'start'=>time()
 
        'color'=>'blue',
    );
 
    echo CJSON::encode($items);
    Yii::app()->end();
}

Result

Result

Homepage

Total 20 comments

#16611 report it
realtebo at 2014/03/10 11:50am
Please use forum, not comment for discussion !!!

If you have some long term discussion opened, please use forum, and NOT comment.

This because every user, like me, which has starred this esxtension will receive an email every time a comment is posted.

Please, stop...

#16610 report it
bandpay at 2014/03/10 11:29am
@AhmedK

Tell me that it's working, so we are all happy :)

#16607 report it
AhmedK at 2014/03/10 07:21am
@bandpay @muhammad RAfiq

hi im getting my json under the calender :) [{"title":"Meeting","start":"2014-03-09","color":"#CC0000","allDay":true,"url":"http:\/\/anyurl.com"},{"title":"Meeting reminder","start":"2014-03-10","end":"2014-03-11","color":"blue"}]

#16606 report it
Muhammad Rafiq at 2014/03/10 06:47am
Re: AhmedK

Greeting,

I spotted 2 problems First, it should be 'events' => Yii::app()->createUrl

Note the 's' in the event

2nd, when you use createUrl, you have to use the class name of the controller, i.e. if my controller is CalendarController, I will use Yii::app()->createUrl('calendar/CalendarEvents')

Note the calendar in createUrl is without the controller word.

I tried your code and dump it into my own program by fixing the 2 issues above and it works for me.

#16605 report it
bandpay at 2014/03/10 06:04am
@AhmedK

My friend, I told you to take it easy :)

'event'=>Yii::app()->createUrl('CalendrierController/CalendarEvents'),

it is 'events' not 'event'

and check in the accessRules if the CalendarEvents should be spelled "calendarEvents"

I have other problems which are as big for me as this one is for you :)

#16604 report it
AhmedK at 2014/03/10 05:00am
@bandpay @muhammad RAfiq

why when i put this 'events'=>$calendarEventsUrl, it says Undefined variable: calendarEventsUrl ???

#16603 report it
AhmedK at 2014/03/10 04:54am
@bandpay @muhammad RAfiq

hi guys !! ive made a calendar model and generated the crud !! ive puted the calendar view in the index of the calendar model !! ive puted the fonction action CalendarEvents in the controller !! but it's not working !!

public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view','CalendarEvents'),
                'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('create','update','admin','delete','CalendarEvents'),
                'users'=>array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions'=>array('admin','delete'),
                'users'=>array('admin'),
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }
public function actionCalendarEvents()
                {
 
                    $items[]=array(
                        'title'=>'Meeting',
                        'start'=>strtotime('2014-03-09'),
                        'color'=>'#CC0000',
                        'allDay'=>true,
                        'url'=>'http://anyurl.com'
                    );
                    $items[]=array(
                        'title'=>'Meeting reminder',
                        'start'=>strtotime('2014-03-10'),
                        'end'=>strtotime('2014-03-11'),
                        'color'=>'blue',
                    );
 
                    echo CJSON::encode($items);
                    Yii::app()->end();
                }
<?php
$this->widget('ext.EFullCalendar.EFullCalendar', array(
 
    'htmlOptions'=>array(
        // you can scale it down as well, try 80%
        'style'=>'width:100%'
    ),
    // FullCalendar's options.
    // Documentation available at
    // http://arshaw.com/fullcalendar/docs/
    'options'=>array(
        'header'=>array(
            'left'=>'prev,next',
            'center'=>'title',
            'right'=>'today,month,agendaWeek,agendaDay'
        ),
        'lazyFetching'=>true,
        //'events'=>CController::createUrl('CalendrierController/CalendarEvents'),
        //'events'=>$calendarEventsUrl,
        'event'=>Yii::app()->createUrl('CalendrierController/CalendarEvents'),
        // // action URL for dynamic events, or
       // 'events'=>'[{"title":"Meeting","start":"2014-03-09","color":"#CC0000","allDay":true,"url":"http:\/\/anyurl.com"}]',
 
        // pass array of events directly
        // event handling
        // mouseover for example
       // 'eventMouseover'=>new CJavaScriptExpression("js_function_callback"),
    )
));
?>
#16601 report it
bandpay at 2014/03/10 03:44am
@AhmedK :)

Don't panik Just try harder :)

#16600 report it
Muhammad Rafiq at 2014/03/10 02:38am
Re: AhmedK

2 things you should pay attention in your actionCalendarEvents()

  1. Make sure in your controller accessRules you have included the calendarEvents
  2. As I have mentioned in one of the replies, for the calendar data array to work, you need to supply date in PHP format. What I saw in the action below is that you use
'start'=>'2014-03-09',

try to change it to

'start'=>strtotime('2014-03-09'),

The same goes for the second array.

public function actionCalendarEvents()
                {
 
                    $items[]=array(
                        'title'=>'Meeting',
                        'start'=>'2014-03-09',
                        'color'=>'#CC0000',
                        'allDay'=>true,
                        'url'=>'http://anyurl.com'
                    );
                    $items[]=array(
                        'title'=>'Meeting reminder',
                        'start'=>'2014-03-10',
                        'end'=>'2014-03-11',
 
                        // can pass unix timestamp too
                        // 'start'=>time()
 
                        'color'=>'blue',
                    );
 
                    echo CJSON::encode($items);
                    Yii::app()->end();
                }
#16596 report it
AhmedK at 2014/03/09 06:44pm
heeeeeeeeeeellllllpppppppp !!

ive made this but nothing is working !! where must i display the calendar !! ive put it in the index view!!

<?php
$this->widget('ext.EFullCalendar.EFullCalendar', array(
    'lang'=>'fr',
   //'themeCssFile'=>'cupertino/theme.css',
    'htmlOptions'=>array(
        // you can scale it down as well, try 80%
        'style'=>'width:100%'
    ),
    // FullCalendar's options.
    // Documentation available at
    // http://arshaw.com/fullcalendar/docs/
 
    'options'=>array(
        'header'=>array(
            'left'=>'prev,next',
            'center'=>'title',
            'right'=>'today,month,agendaWeek,agendaDay'
        ),
        'lazyFetching'=>true,
        'events'=>CController::createUrl('CalendrierController/CalendarEvents'),
    )
));
?>

in my controller

public function actionCalendarEvents()
                {
 
                    $items[]=array(
                        'title'=>'Meeting',
                        'start'=>'2014-03-09',
                        'color'=>'#CC0000',
                        'allDay'=>true,
                        'url'=>'http://anyurl.com'
                    );
                    $items[]=array(
                        'title'=>'Meeting reminder',
                        'start'=>'2014-03-10',
                        'end'=>'2014-03-11',
 
                        // can pass unix timestamp too
                        // 'start'=>time()
 
                        'color'=>'blue',
                    );
 
                    echo CJSON::encode($items);
                    Yii::app()->end();
                }
#16571 report it
bandpay at 2014/03/06 09:18am
@AhmedK

Yes my firend. You have to populate an $events array with your data.
Create a function in your model that delivers the $events array

This code is for guidance purpose and is not of any other value.

public function fetchEvents(){
$events=[];
foreach($schedules as ........){
$events[] = [
    'id'=>'some_uniquid',
    'data'=>[
        'var1'=>'val1',
        'var2'=>'val2',
        'varn'=>'valn',
    ],
    'title'=>'Some_Title',
    'start'=>'a start date with this format Y-m-d H:i:s',
    'end'=>'an end date with this format Y-m-d H:i:s',
    'allDay'=>$isAllDay?true:false,
    'url'=>Yii::app()->createUrl('controller/action',['someVar'=>'someVal']),
];
}
return $events;
}
 
/*
call it in the controller/action which the AJAX call makes in the fullCalendar events function
 
then the $events must be json_encode()'d
*/
echo json_encode($model->fetchEvents());
exit;

I hope that it helps. :)

#16570 report it
AhmedK at 2014/03/06 06:02am
@bandpay

so i have to generate my crud and then send them to the calendar as json format !! i have ( id, description, patient_name, start_time, end_time, location)!!

#16569 report it
bandpay at 2014/03/06 05:50am
@AhmedK

Hello, If you already have the CRUD for the appointments then your are all set to fetch them and deliver them in JSON encoded format to the AJAX call.

#16567 report it
AhmedK at 2014/03/06 04:47am
@bandpay

im making an application for doctor ive completed the patient side !! now i like to display a calendar with appointment for the patients !! thank you for your help

#16566 report it
bandpay at 2014/03/06 04:37am
@AhmedK

What is it you wish to show on the calendar?

#16565 report it
AhmedK at 2014/03/06 04:31am
question!!

do i have to generate crud for this calendar ?? im new in yii and im relay confused right here !! thx for your help :)

#16552 report it
bandpay at 2014/03/05 09:52am
@AhmedK

Hello This is my example: Use the AJAX call to get your event schedules and deliver them to the callback function

'events'=>'js:function(start, end, callback) {
            $.ajax({
                url: "'.$this->createUrl('fullCalendarEvents',array('id'=>$model->id)).'",
                dataType: "json",
                data: {
                    start_date: Math.round(start.getTime() / 1000),
                    end_date: Math.round(end.getTime() / 1000),
                },
                success: function(shifts)
                {
                    callback(shifts);
                }
            });
        }',
#16548 report it
AhmedK at 2014/03/05 08:17am
question!!

hi !! can someone please tell me how to fill this calendar from the database

#16545 report it
JbalTero at 2014/03/04 10:52pm
@Muhammad Rafiq

Thank you very much! It worked! :)

#16520 report it
Muhammad Rafiq at 2014/03/02 12:49am
RE: @Muhammad Rafiq and @bandpay; [HOW TO] Return Selected Date in specific controller

Hi JbalTero,

If you can get the alert of Success, it means that your ajax was successfully sent through. What you are facing now is more of the ajax programming issue. The complicated part about ajax programming is that you can't see the effect off the ajax process and debugging is also difficult because you do not know what has been sent through and how to see them.

This is what I did.

echo '<div id="div1"></div>'; //this div will be used to display the output for debugging purpose
// Your ecalendar code....
...
...
        'dayClick' => new CJavaScriptExpression(
            "function(start, allDay, jsEvent, view) {
                //some logic here...
 
                $.ajax({
                    url: $quotedUrl,
                    data: { 
                        'selectedDate': start,
                    },  
                    success: function(data){
                        $(\"#div1\").html(data);
                    },
                });
 
                $(this).css('background-color', 'red');
             }"

I replaced the success alert by outputting the result into a div (i.e. div1 which I declared earlier) so you can effectively see the result.

In your controller, simply dump out the $_GET variable and you can see very well if the data are passed into your controller.

public function actionAjaxComplete()
{
   print_r($_GET);
}

If everything is good, you will see something like Array ( [selectedDate] => Tue Mar 04 2014 00:00:00 GMT+0300 (Arab Standard Time) ) printed on top of your calendar after you clicked on a date

If you see that, you can proceed to extract the date from the $_GET variable, i.e. $_GET['selectedDate'] and do the necessary processing for your program. You can continue to do all the processing and echo the result and it will appear in the div. Once everything is alright, you can remove the div and the Success action.

BTW I am not sure if this part of your code is correct because in the dayClick function, I do not see selectedDate, mondayDate, fridayDate are being passed into the function.

'selectedDate': selectedDate,
                        'mondayDate': mondayDate,
                        'fridayDate': fridayDate,

In addition, for a more user friendly variable dumping, I recommend you to use the following code. It will print out more human readable output of your variable, be it object or array. Example of usage, $this->printObject($_GET);

public function printObject($object, $ret=FALSE)
{
        if(!$ret)
            echo '<pre>' . htmlspecialchars(print_r($object,true)) . '</pre>';
        else
            return '<pre>' . htmlspecialchars(print_r($object,true)) . '</pre>';        
}

Leave a comment

Please to leave your comment.

Create extension