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!


Messages In This Thread
Need help with finishing touches for multi-day and multi-same-day events in Calendar please :) - by El Forum - 03-29-2010, 07:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB