Welcome Guest, Not a member yet? Register   Sign In
Calendar Multiple Events Per Day (Available)
#1

[eluser]Unknown[/eluser]
Because yesterday i've search the forum and i saw many people search for a way to have multiple events per day on the codeigniter calendar. Here is the code that i made in order my calendar to have multiple events per day.

The calendar is based on the nettus tutorial if anyone interested and can be found here: [email=http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-the-calendar-library/]Nettuts Codeignitter Calendar[/email]

Step 1) make sure the nettuts way of calendar work on you.

Step 2) copy the calendar.php from system/libraries to application/libraries

Step 3) make an adjustment in the calendar.php library in line 217 and put the code below (Thanks to member zoltano):


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'];
                                                if (is_array($data[$day]))
                                                  {
                                                    $several_events = '';
                                                    foreach ($data[$day] as $key)
                                                    {
                                                      $several_events .= $key.'<br />';
                                                      
                                                    }
                                                     $out .= str_replace('{day}', $day, str_replace('{content}', $several_events, $temp));
                                                  }

                                                  // One event per day
                                                  else
                                                  {
                                                    $out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $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);
                    }


Step 4) now on the calendar model you must make your output array. The code you must put on the get_calendar_data function of the model is shown below:

Code:
function get_calendar_data($year, $month) {
        $query = $this->db->query("SELECT DISTINCT DATE_FORMAT(date, '%Y-%m-%e') AS date
                                            FROM calendar
                                            WHERE date LIKE '$year-$month%' "); //date format eliminates zeros make
                                                                           //days look 05 to 5
  
                $cal_data = array();
              
                foreach ($query->result() as $row) { //for every date fetch data
                    $a = array();
                    $i = 0;
                    $query2 = $this->db->query("SELECT data
                                                FROM calendar
                                                WHERE date LIKE DATE_FORMAT('$row->date', '%Y-%m-%d') ");
                                                            //date format change back the date format
                                                            //that fetched earlier
                     foreach ($query2->result() as $r) {
                         $a[$i] = $r->data;     //make data array to put to specific date
                         $i++;                        
                     }
                        $cal_data[substr($row->date,8,2)] = $a;
                    
                }

                return $cal_data;
                }
You are done !! :-)
Result on photo here: Multiple Events Codeigniter Calendar
Good luck coding.
#2

[eluser]dekimpeb[/eluser]
and the controller?
#3

[eluser]Unknown[/eluser]
can you explain the last function?
why isn't it displaying the events after loading the calendar,
the event will only show when i click the prev or next on the calendar




Theme © iAndrew 2016 - Forum software by © MyBB