makzumi / laravel-calendar

Flexible Calendar for Laravel 4
58 stars 31 forks source link

Display Multiple events #17

Closed omarsafwany closed 9 years ago

omarsafwany commented 10 years ago

Hello Makzumi,

I have installed your calendar package but I have a problem when event(s) per day as found below. capture-cal

Any idea how can I fix that as I just need the day that has events to appear as link where I can redirect to whatever I want? Also is there any sort of documentation for the rest of function that can be used with this calendar?

Thank you in advance.

rginnow commented 10 years ago

Hi Omar,

I'm not sure this is documentation for this, but I believe what you are looking for was mentioned in Issue #1 as it talks about looping through the events and printing them (with an html link) to echo them to your calendar.

Here's an example of my calendar code (using Laravel 4, in my main Calendar controller):

// This is the function that allows the events for the day to be returned as an array
function array_group_by($value, $items) {
    $groupedArray = array();
    foreach ($items as $key => $values) {
        $item = $values[$value];
        $groupedArray[$item][] = $values;
    }
    return $groupedArray;
}

// Some Psudo-code -- I run some logic of my own per project needs
// As an example, you can write code that checks what type of view you are to print
// like this, if your links need to be different
// PLEASE NOTE SOME OF THESE VARIABLES ARE RELATED TO MY ENVIRONMENT ONLY
$view = Input::get('cv'); // I can't remember if the calendar sets CV or if I do...

$events = Meeting::orderby('date')->get()->toArray(); // Get the events from the database
$events = array_group_by('date', $events); // use the above function 
$new_events = []; // create new array for the events
foreach ($events as $datetime => $session) {
    foreach ($session as $v) {
        [...] // other code....
        if($view=='week' || $view=='day') { // the code that decides what link to show for the related view
            $new_events[$datetime][] = '<a class="event-link" href="/admin/meetings/'.$v['id'].'" >Link type 1</a>';
        } else {
            $new_events[$datetime][] = '<a class="event-link" href="/admin/meetings/'.$v['id'].'">Link type 2</a>';
        }
    }
}

// Calendar Settings - the meat of how it's going to output to my calendar
// Some variables are self-explanatory
$date = Input::get('cdate'); // If the date is already set in $_GET, get it.
$cal = Calendar::make();
$cal->setDate($date);
$cal->setView($view);
$cal->setStartEndHours(7,22); // I want to know the hours between 7am and 10pm
$cal->setEvents($new_events); // Get the array
$cal->setBasePath('/admin/meetings');
$cal->setEventsWrap(array('<div>', '</div>'));
$cal->setTableClass('table table-bordered table-responsive'); //Set the table's class name
$cal->setNextIcon('<i class="glyphicon glyphicon-chevron-right"></i>');
$cal->setPrevIcon('<i class="glyphicon glyphicon-chevron-left"></i>');

Let me know if this is what you were looking for :)

rginnow commented 9 years ago

Recommend closing this. Multiple events is already covered, I believe this is user error.