Welcome Guest, Not a member yet? Register   Sign In
Need help with finishing touches for multi-day and multi-same-day events in Calendar please :)
#1

[eluser]Kinsbane[/eluser]
Okay, so, I'm trying to hack n slash the CI Calendar to show both multi-day events, and multiple events on the same day. I've almost got it, but there's a few things bugging me that I just can't seem to figure out.

First and foremost, dates for my events are stored with the starting date as a UNIX timestamp, and then the number of days for the event is specified.
Here's how I'm grabbing and storing the event data:
Code:
$query = $this->db->select('event_id, event_date, event_length, event_title')->from('event')
            ->where("MONTH(FROM_UNIXTIME(event_date))='$month' AND YEAR(FROM_UNIXTIME(event_date))='$year'")->get();
            
        $cal_data = array();
        
        foreach ($query->result_array() as $row) {
            
            
                for($i = 0; $i < $row['event_length']; $i++)
                {
                    
                    $day = 24 * 60 * 60 * $i;
                    $eday = $row['event_date']+$day;
                    
                    $cal_data[date('j', $eday)][$i] = '/events/show/'.$row['event_id'];
                }
                        
        }
        ksort($cal_data);
        return $cal_data;

For the month of April, here's the print_r() of what the $cal_data array looks like:
Code:
Array
(
    [06] => Array
        (
            [0] => /events/show/1294
        )

    [07] => Array
        (
            [1] => /events/show/1294
        )

    [08] => Array
        (
            [0] => /events/show/1265
        )

    [09] => Array
        (
            [1] => /events/show/1265
        )

    [10] => Array
        (
            [2] => /events/show/1265
        )

    [11] => Array
        (
            [3] => /events/show/1265
        )

    [12] => Array
        (
            [0] => /events/show/1293
        )

    [13] => Array
        (
            [1] => /events/show/1293
        )

    [14] => Array
        (
            [0] => /events/show/1235
        )

    [15] => Array
        (
            [1] => /events/show/1235
            [0] => /events/show/1288
        )

    [19] => Array
        (
            [0] => /events/show/1282
        )

    [20] => Array
        (
            [1] => /events/show/1282
        )

    [21] => Array
        (
            [2] => /events/show/1282
        )

    [27] => Array
        (
            [0] => /events/show/1261
        )

    [28] => Array
        (
            [1] => /events/show/1261
        )

    [29] => Array
        (
            [2] => /events/show/1261
        )

)

As you can see, the top-level arrays are all days of the month - the arrays in those keys are the events for that day.

And, finally, here's what I did to change the CI Library to loop through the arrays under each day with events, starting on or about line 220 in /libraries/Calendar.php
Code:
if (isset($data[$day]))
                    {    
                        // Cells with content
                        $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
                        $out .= str_replace('{day}', $day, $temp);
                        
                        foreach($data[$day] as $d)
                        {
                            //echo $d;
                            $out .= str_replace('{content}', '<li>'.$d.'</li>', $temp);
                        }
                    }
                    else
                    {
                        // Cells with no content
                        $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
                        $out .= str_replace('{day}', $day, $temp);
                    }

I must have done something wrong, though, because when I view my source, it looks like this:
Code:
<td class="day">
                <div class="day_num">10</div>
                <div class="content"></div>
            
                <div class="day_num"></div>
                <div class="content"><li>/events/show/1265</li></div>

            </td>
I would rather not have the duplicate div's in there for content and day_num, but I don't know where they're getting generated.

Also, I noticed I was getting outputs of {day} and {content} in the days with events - the only way I could find out to remove those was to use str_replace at the very end of the generate() function to remove it:
Code:
$out .= $this->temp['table_close'];
        $out = str_replace('{day}', '', $out);
        $out = str_replace('{content}', '', $out);
        return $out;

I know I am very close but I have been looking at this for two days and I can't seem follow the path of the data and the templates and I think I just need new eyeballs.

Thanks!
#2

[eluser]Kinsbane[/eluser]
No one's got ideas? I figure if we can get this together it would be a really good addition to the CI core.
#3

[eluser]Kinsbane[/eluser]
Well, now my day-cells in the table look like this:
Code:
<td class="day">
    <div class="day_num">16</div>
    <div class="content event1">/events/show/1266</div>
    <div class="content event2">/events/show/1290</div>
</td>

This is the behavior I want - in the day before this, only event # 1266 is the event for that day. The day after this, is #1290 - but the issue here is making sure that the block for event #1290 stays in-line with where #1290 is for this current day - that is, one level below where #1266 would be if 1266 were also happening on the 17th. Can anyone offer assistance?
#4

[eluser]Kinsbane[/eluser]
Is there a way to find out what position a current element is in an array?

If I run a print_r() on my cal_data array, I have some days where the array for the day looks like this:
Code:
[3] => Array
        (
            [1] => /events/show/1274
            [0] => /events/show/1277
        )

It would be great if I could have the program detect that event #1277 is in the 2nd position of the array (even though its index says 0) and use that to calculate a height position within the day-cell of the table to keep everything in line.
#5

[eluser]Philipp GĂ©rard[/eluser]
Did you get around solving this riddle? I wanted to implement a similar feature-set and thus searched the forums.
#6

[eluser]bcorcoran[/eluser]
Hi,

I realize this is an old thread, but I was having the same issues myself (the fact the calendar only allows one entry per day is ridiculously short-sighted).

I managed to come up with a way to add multiple events to each day. Each event's name is displayed and is a link to whatever link is in your data array.

Copy /libraries/Calendar.php to /application/libraries/ and modify starting at line 219.

Replace
Code:
if (isset($data[$day]))
                    {    
                        // Cells with content
                        $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
                        $out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp));
                    }

With
Code:
if (isset($data[$day]))
                    {    
                        // Cells with content
                        $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];                        
                        $out .= str_replace('{day}', $day, str_replace('{content}', '#', $temp));
                        
                        if(!empty($data[$day])) {
                            $out .= "<ul>";
                            foreach($data[$day] as $k => $v) {
                                $out .= "<li>";
                                
                                $find = array('{content}', '{day}');
                                $replace = array($v, $k);
                                
                                $out .= str_replace($find, $replace, $temp);
                                
                                $out .= "</li>";
                            }
                            $out .= "</ul>";
                        }    
                                        
                    }




Theme © iAndrew 2016 - Forum software by © MyBB