Welcome Guest, Not a member yet? Register   Sign In
[Solved] Display multiple rows on calendar Question
#1

(This post was last modified: 12-20-2015, 04:06 AM by wolfgang1983.)

Hi All,

I would like to know how I would be able to do this.

Lets say I have two rows on database table that has the same date example: 2015 - 12 - 25 As shown in attached image.

How could I get my function to return multiple rows if date is the same?

Currently as shown on calendar image on 2015-12-25 I can only display one row.

PHP Code:
public function get_calendar_data($year$month) {
 
       $cell_data = array();

 
       $this->db->where('year'$year);
 
       $this->db->where('month'$month);
 
       $query $this->db->get();

 
       foreach ($query->result() as $result) {
 
           $cell_data[$result->day] =  $result->data;
 
       }

 
       return $cell_data;
 
   


Controller

Note: model functions on controller just for testing once all working properly will move to proper model.


PHP Code:
<?php

class Calendar extends MX_Controller {

 
   public function __construct() {
 
       parent::__construct();
 
       $this->load->model('dashboard/model_calendar');
 
       $this->load->library('calendar');
 
   }

 
   public function index() {

 
       if ($this->uri->segment(3) == FALSE) {
 
           $year date('Y');
 
       } else {
 
           $year $this->uri->segment(3);
 
       }

 
       $data['year'] = $year;

 
       if ($this->uri->segment(4) == FALSE) {
 
           $month date('m');
 
       } else {
 
           $month $this->uri->segment(4);
 
       }

 
       $data['month'] = $month;

 
       
        
        $prefs 
= array(
 
           'start_day' => 'monday',
 
           'show_next_prev' => true,
 
           'day_type' => 'long',
 
           'next_prev_url' => base_url('dashboard/calendar')
 
       );

 
       $prefs['template'] = '
            {table_open}<div class="table-responsive"><table border="0" cellpadding="0" cellspacing="0" class="table table-striped table-bordered calendar">{/table_open}
            
            {heading_row_start}<tr>{/heading_row_start}
            
            {heading_previous_cell}<th><a href="{previous_url}"><i class="fa fa-chevron-left fa-2x "></i></a></th>{/heading_previous_cell}
            {heading_title_cell}<th class="text-center" colspan="{colspan}">{heading}</th>{/heading_title_cell}
            {heading_next_cell}<th class="text-right"><a href="{next_url}"><i class="fa fa-chevron-right fa-2x"></i></a></th>{/heading_next_cell}
            
            {heading_row_end}</tr>{/heading_row_end}
            
            {week_row_start}<tr>{/week_row_start}
            {week_day_cell}<td>{week_day}</td>{/week_day_cell}
            {week_row_end}</tr>{/week_row_end}
            
            {cal_row_start}<tr class="days">{/cal_row_start}
            {cal_cell_start}<td class="day">{/cal_cell_start}
            
            {cal_cell_content}
                <div class="day_number">{day}</div>
                <div class="content" style="margin-top: 10px;">{content}</div>
            {/cal_cell_content}
            {cal_cell_content_today}
                <div class="day_number highlight">{day}</div>
                <div class="content" style="margin-top: 10px;">{content}</div>
            {/cal_cell_content_today}
            
            {cal_cell_no_content}
            <div class="day_number">{day}</div>
            {/cal_cell_no_content}
            {cal_cell_no_content_today}
            <div class="day_number highlight">{day}</div>
            {/cal_cell_no_content_today}
            {cal_cell_blank}&nbsp;{/cal_cell_blank}
            
            {cal_cell_end}</td>{/cal_cell_end}
            {cal_row_end}</tr>{/cal_row_end}
            
            {table_close}</table></div>{/table_close}
        '
;

 
       $this->calendar->initialize($prefs);

 
       $this->delete_calendar_event();

 
       if ($this->input->post('day')) {
 
           
            if 
($this->check_calendar_event($year$month$this->input->post('day'))) {
 
               $this->update_calendar_event($year$month);
 
           } else {
 
               $this->add_calendar_event($year$month);
 
           }

 
       }

 
       $data $this->get_calendar_data($year$month);

 
       $data['calendar'] = $this->calendar->generate($year$month$data);

 
       if ($this->uri->segment(3) == TRUE) {
 
           $data['view_more'] = site_url('report/events/' $year .'/'$month);
 
       } else {
 
           $data['view_more'] = site_url('report/events');
 
       }

 
       $date date('Y-m-d'mktime(000date('m'), date('d') + 3date('Y')));

 
       //echo $date;

 
      // echo '<br/>';

 
       //echo $this->test();

 
       $this->load->view('dashboard/calender_view'$data);
 
   }

 
   public function test() {
 
       $date date('Y-m-d'mktime(000date('m'), date('d') + 3date('Y')));
 
       $this->db->where('date <'$date);
 
       $query $this->db->get('calendar');
 
       return $query->num_rows();
 
   }

 
   public function add_calendar_event($year$month) {
 
       $date $year .'-'$month .'-'$this->input->post('day');

 
       $calendar = array(
 
           'year' => $year,
 
           'month' => $month,
 
           'day' => $this->input->post('day'TRUE),
 
           'date' => $date,
 
           'data' => $this->input->post('event_data')
 
       );

 
       $this->db->insert('calendar'$calendar);
 
   }

 
   public function update_calendar_event($year$month) {
 
       $date $year .'-'$month .'-'$this->input->post('day');

 
       $calendar = array(
 
           'year' => $year,
 
           'month' => $month,
 
           'day' => $this->input->post('day'TRUE),
 
           'data' => $this->input->post('event_data')
 
       );

 
       $this->db->where('date'$date);
 
       $this->db->update('calendar'$calendar);
 
   }

 
   public function delete_calendar_event() {
 
       $this->db->where("date <"date('Y-m-d'));
 
       $this->db->or_where('data''');
 
       $this->db->delete('calendar');
 
   }

 
   public function get_calendar_data($year$month) {
 
       $cell_data = array();

 
       $this->db->where('year'$year);
 
       $this->db->where('month'$month);
 
       $query $this->db->get();

 
       foreach ($query->result() as $result) {
 
           $cell_data[$result->day] =  $result->data;
 
       }

 
       return $cell_data;
 
   }

 
   public function check_calendar_event($year$month$day) {
 
       $date $year .'-'$month .'-'$day;
 
       $this->db->select('year, month, day');
 
       $this->db->from('calendar');
 
       $this->db->where('date'$date);
 
       $results $this->db->count_all_results();

 
       return $results;
 
   }

 
   public function check_calendar_event_date() {

 
   }



Attached Files Thumbnail(s)
       

.php   Calendar.php (Size: 5.86 KB / Downloads: 164)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

(This post was last modified: 12-19-2015, 04:57 AM by Happy Camper. Edit Reason: Fixing typo )

Hello,

The way I did this in the past was to have each cell in the calendar contain an unordered list  with a list item for each event happening on a particular day.

So assuming there were 2 events happening on a particular day the cells data would be like this

PHP Code:
$cell_data ='<ul><li>' .$event1'</li><li>' .$event2'</li></ul>'

Where $cell_data is constructed within a foreach loop

You will need an extra function in your model to return all events happening on a given day which the previously mentioned foreach will loop through.

Hope this helps!
Reply
#3

(12-19-2015, 04:03 AM)Happy Camper Wrote: Hello,

The way I did this in the past was to have each cell in the calendar contain an unordered list  with a list item for each event happening on a particular day.

So assuming there were 2 events happening on a particular day the cells data would be like this

PHP Code:
$cell_data ='<ul><li>' .$event1'</li><li>' .$event2'</li></ul>'

Where $cell_data is constructed within a foreach loop

You will need an extra function in your model to return all events happening on a given day which the previously mentioned foreach will loop through.

Hope this helps!

But what I can not seem to make it work with my get function need example.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

>>> But what I can not seem to make it work with my get function need example.

Try adding this extra line:

Quote:public function get_calendar_data($year, $month) {
$cell_data = array();

$this->db->where('year', $year);
$this->db->where('month', $month);

$this->db->where('calendar_id', TRUE); // EXTRA LINE NEEDS VALIDATING
$query = $this->db->get();

If that doesn't work then echo last_query() and add " WHERE calendar_id > 0"
Reply
#5

(12-19-2015, 08:01 PM)John_Betong Wrote: >>> But what I can not seem to make it work with my get function need example.

Try adding this extra line:

Quote:public function get_calendar_data($year, $month) {
       $cell_data = array();

       $this->db->where('year', $year);
       $this->db->where('month', $month);

       $this->db->where('calendar_id', TRUE); // EXTRA LINE NEEDS VALIDATING
       $query = $this->db->get();

If that doesn't work then echo last_query() and add " WHERE calendar_id > 0"

Been searching the web and found that this code below works fine now

PHP Code:
public function get_events($year$month) {
 
       $calendar = array();

 
       $this->db->where('year'$year);
 
       $this->db->where('month'$month);
 
       $query $this->db->get('calendar');

 
       $results $query->result_array();

 
       foreach ($results as $event) {

 
           if (array_key_exists$event['day'], $calendar ) ) {
 
                   
                $calendar
[$event['day']] = $calendar[$event['day']] .'<br />'anchor(base_url() .'report/events/'$year .'/'$month .'/'$event['calendar_id'], $event['data']);
 
               
            
} else {
 
               
                $calendar
[$event['day']] = anchor(base_url() .'report/events/'$year .'/'$month .'/'$event['calendar_id'], $event['data'])   ;
 
           }
 
       }

 
       return $calendar;
 
   

I have attached image proof.

Attached Files Thumbnail(s)
   
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB