• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding multiple variables to calendar days

#12
Ok here is my code so far

MY_calendar (modified as you mentioned):
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class 
MY_Calendar extends CI_Calendar {

 
       public function __construct($config = array())
 {
 
   parent::__construct($config);
 }
 
// --------------------------------------------------------------------

 /**
 * Generate the calendar
 *
 * @param int the year
 * @param int the month
 * @param array the data to be shown in the calendar cells
 * @return string
 */
 
public function generate($year ''$month ''$data = array(), $css = array() ) 
 {
 
$local_time time();

 
// Set and validate the supplied month/year
 
if (empty($year))
 {
 
$year date('Y'$local_time);
 }
 elseif (
strlen($year) === 1)
 {
 
$year '200'.$year;
 }
 elseif (
strlen($year) === 2)
 {
 
$year '20'.$year;
 }

 if (empty(
$month))
 {
 
$month date('m'$local_time);
 }
 elseif (
strlen($month) === 1)
 {
 
$month '0'.$month;
 }

 
$adjusted_date $this->adjust_date($month$year);

 
$month $adjusted_date['month'];
 
$year $adjusted_date['year'];

 
// Determine the total days in the month
 
$total_days $this->get_total_days($month$year);

 
// Set the starting day of the week
 
$start_days = array('sunday' => 0'monday' => 1'tuesday' => 2'wednesday' => 3'thursday' => 4'friday' => 5'saturday' => 6);
 
$start_day = isset($start_days[$this->start_day]) ? $start_days[$this->start_day] : 0;

 
// Set the starting day number
 
$local_date mktime(1200$month1$year);
 
$date getdate($local_date);
 
$day  $start_day $date['wday'];

 while (
$day 1)
 {
 
$day -= 7;
 }

 
// Set the current month/year/day
 // We use this to determine the "today" date
 
$cur_year date('Y'$local_time);
 
$cur_month date('m'$local_time);
 
$cur_day date('j'$local_time);

 
$is_current_month = ($cur_year == $year && $cur_month == $month);

 
// Generate the template data array
 
$this->parse_template();

 
// Begin building the calendar output
 
$out $this->replacements['table_open']."\n\n".$this->replacements['heading_row_start']."\n";

 
// "previous" month link
 
if ($this->show_next_prev === TRUE)
 {
 
// Add a trailing slash to the URL if needed
 
$this->next_prev_url preg_replace('/(.+?)\/*$/''\\1/'$this->next_prev_url);

 
$adjusted_date $this->adjust_date($month 1$year);
 
$out .= str_replace('{previous_url}'$this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->replacements['heading_previous_cell'])."\n";
 }

 
// Heading containing the month/year
 
$colspan = ($this->show_next_prev === TRUE) ? 7;

 
$this->replacements['heading_title_cell'] = str_replace('{colspan}'$colspan,
 
str_replace('{heading}'$this->get_month_name($month).'&nbsp;'.$year$this->replacements['heading_title_cell']));

 
$out .= $this->replacements['heading_title_cell']."\n";

 
// "next" month link
 
if ($this->show_next_prev === TRUE)
 {
 
$adjusted_date $this->adjust_date($month 1$year);
 
$out .= str_replace('{next_url}'$this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->replacements['heading_next_cell']);
 }

 
$out .= "\n".$this->replacements['heading_row_end']."\n\n"
 
// Write the cells containing the days of the week
 
.$this->replacements['week_row_start']."\n";

 
$day_names $this->get_day_names();

 for (
$i 0$i 7$i ++)
 {
 
$out .= str_replace('{week_day}'$day_names[($start_day $i) %7], $this->replacements['week_day_cell']);
 }

 
$out .= "\n".$this->replacements['week_row_end']."\n";

 
// Build the main body of the calendar
 
while ($day <= $total_days)
 {
 
$out .= "\n".$this->replacements['cal_row_start']."\n";

 for (
$i 0$i 7$i++)
 {
 if (
$day && $day <= $total_days)
 {
 
$csstmp = isset($css[$day]) ? 'class="' $css[$day] . '"' NULL;
$cstoday str_replace('{css_class}'$csstmp,$this->replacements['cal_cell_start_today']);
$cs str_replace('{css_class}',$csstmp,$this->replacements['cal_cell_start']);
$out .= ($is_current_month === TRUE && $day == $cur_day) ? $cstoday $cs

 if (isset(
$data[$day]))
 {
 
// Cells with content
 
$temp = ($is_current_month === TRUE && $day == $cur_day) ?
 
$this->replacements['cal_cell_content_today'] : $this->replacements['cal_cell_content'];
 
$out .= str_replace(array('{content}''{day}'), array($data[$day], $day), $temp);
 }
 else
 {
 
// Cells with no content
 
$temp = ($is_current_month === TRUE && $day == $cur_day) ?
 
$this->replacements['cal_cell_no_content_today'] : $this->replacements['cal_cell_no_content'];
 
$out .= str_replace('{day}'$day$temp);
 }

 
$out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->replacements['cal_cell_end_today'] : $this->replacements['cal_cell_end'];
 }
 elseif (
$this->show_other_days === TRUE)
 {
 
$out .= $this->replacements['cal_cell_start_other'];

 if (
$day <= 0)
 {
 
// Day of previous month
 
$prev_month $this->adjust_date($month 1$year);
 
$prev_month_days $this->get_total_days($prev_month['month'], $prev_month['year']);
 
$out .= str_replace('{day}'$prev_month_days $day$this->replacements['cal_cell_other']);
 }
 else
 {
 
// Day of next month
 
$out .= str_replace('{day}'$day $total_days$this->replacements['cal_cell_other']);
 }

 
$out .= $this->replacements['cal_cell_end_other'];
 }
 else
 {
 
// Blank cells
 
$out .= $this->replacements['cal_cell_start'].$this->replacements['cal_cell_blank'].$this->replacements['cal_cell_end'];
 }
 
$day++;
 }

 
$out .= "\n".$this->replacements['cal_row_end']."\n";
 }

 return 
$out .= "\n".$this->replacements['table_close'];
 }

 
// -------------------------------------------------------------------- 
}
?>




Controller:
PHP Code:
public function calendar_builder()
 
         {
 
              $prefs['template'] = '
                  {table_open}<table border="0" cellpadding="0" cellspacing="0" class = "text-center table" id = "table-calendar" style = "font-size:13px; border:0; font-family:Arial,sans-serif; width:90%">{/table_open}

                  {heading_row_start}<tr>{/heading_row_start}

                  {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
                  {heading_title_cell}<th colspan="{colspan}"><strong style = "font-size:">{heading}</strong><hr /></th>{/heading_title_cell}
                  {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}

                  {heading_row_end}</tr>{/heading_row_end}

                  {week_row_start}<tr style = " border:0;">{/week_row_start}
                  {week_day_cell}<td style = "padding:0px; border:none;">{week_day}</td>{/week_day_cell}
                  {week_row_end}</tr>{/week_row_end}

                  {cal_row_start}<tr style = " border:0; ">{/cal_row_start}
                  {cal_cell_start}<td {css_class} style = "padding:0px; border:none; line-height:2.2">{/cal_cell_start}
                  {cal_cell_start_today}<div class = "div-day"><td style = "background-color:#419dcd">{/cal_cell_start_today}
                  {cal_cell_start_other}<div class = "div-day"><td class="other-month">{/cal_cell_start_other}

                  {cal_cell_no_content}<div class = "div-day"><a href="controller/method/{year}/{month}/{day}">{day}</a></div>{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="highlight"><a href="controller/method/{year}/{month}/{day}>">{day}</a></div>{/cal_cell_no_content_today}

                  {cal_cell_no_content}<div class = "div-day">{day}{/cal_cell_no_content}
                  {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}

                  {cal_cell_blank}&nbsp;{/cal_cell_blank}

                  {cal_cell_other}{day}{/cal_cel_other}

                  {cal_cell_end}</td>{/cal_cell_end}
                  {cal_cell_end_today}</td>{/cal_cell_end_today}
                  {cal_cell_end_other}</td>{/cal_cell_end_other}
                  {cal_row_end}</tr>{/cal_row_end}

                  {table_close}</table>{/table_close}'
;
 
              $this->load->library('calendar'$prefs);
 
             


View
PHP Code:
<div class="container">
 
 <div class="row">
 
  <?php
   $year 
date('Y');
 
  $month=0;
 
     
   
while($month<12)
 
  {
 
  $data=array();
 
         $css=array();
 
         $days=0;
 
         $month++;
 
         $css = array(
 
             3 => 'cal-blue',
 
             7 => 'cal-red',
 
             13 => 'cal-green',
 
             26 => 'cal-orange'
 
           );
 
         
          while
($days<32)
 
  {
 
  $days++;
 
             foreach($tasks as $row => $val)
 
               {
 
                 if(strtotime($year."-".$month."-".$days)==strtotime($val['date_added']))
 
                   {
 
                       //$data[$days] = array('days'=>$days,'class'=>'active');
 
                       $data[$days] = $days;
 
                   }
 
               }
 
           
 
         ?>
   <div class="col-md-2">
        <?php echo $this->calendar->generate($year,$month$data$css);?></div>
   <?php
   
if($month==6)
 
  {
 
  ?></div><div class="row"><?php
   
}
 
  ?>

   </div> 
</div>
 
<hr /> 

 
Just not sure where this goes

PHP Code:
'cal_cell_start'    => '<td {css_class}>' 


Thanks Smile
Reply


Messages In This Thread
RE: Adding multiple variables to calendar days - by behnampmdg3 - 08-05-2017, 03:32 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.