CodeIgniter Forums

Full Version: [solved] Calendaring customization [highlighting the current month]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I made a method that writes a view with a calendar table which shows all months of a year using the calendaring class. It works as well, and returns this:

[Image: Screen_Shot_2016_11_25_at_23_37_11_fullpage.png]
But I didn't found a way to highlight only the current month using a template in the calendaring class. I tried to modify the default template but it doesn't work because when I change the class of '{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}', it modifies all the month's labels like this:

[Image: Screen_Shot_2016_11_25_at_23_46_17_fullpage.png]
I'm using the default methods from the basic class tutorial. Any suggestion?
Create a method to check the month and then a method to highlight the current month, you may want to create a MY_ class for this.
(11-26-2016, 06:00 AM)InsiteFX Wrote: [ -> ]Create a method to check the month and then a method to highlight the current month, you may want to create a MY_ class for this.

You mean a function that returns the table array template depending on the month and year that was set? Something like a helper function?
Yes, you can also extend the Calendar library with MY_Calendar
(11-26-2016, 11:35 AM)InsiteFX Wrote: [ -> ]Yes, you can also extend the Calendar library with MY_Calendar

Well, I guess that extending is the right way because the template array is passed on CI_Calendar loading. Thanks, I'll try here. Wink
(11-26-2016, 11:35 AM)InsiteFX Wrote: [ -> ]Yes, you can also extend the Calendar library with MY_Calendar

I extended the CI_Calendar and made the generate() method pass his $month variable to the parse_template($cur_month) method, then, he uses $cur_month to apply an exception and assign the class="info" to heading_row_start:

PHP Code:
        if (is_string($this->template)) {
            $today = array('cal_cell_start_today','cal_cell_content_today','cal_cell_no_content_today','cal_cell_end_today');            
            
foreach (array('table_open''table_close''heading_row_start''heading_previous_cell''heading_title_cell''heading_next_cell''heading_row_end''week_row_start''week_day_cell''week_row_end''cal_row_start''cal_cell_start''cal_cell_content''cal_cell_no_content''cal_cell_blank''cal_cell_end''cal_row_end''cal_cell_start_today''cal_cell_content_today''cal_cell_no_content_today''cal_cell_end_today''cal_cell_start_other''cal_cell_other''cal_cell_end_other') as $val) {
                if (preg_match('/\{' $val '\}(.*?)\{\/' $val '\}/si'$this->template$match)) {
                    if($val == 'heading_row_start'){
                        if( $cur_month == date('m')){
                            $this->replacements[$val] = '<tr class="info">';
                        }
                    }
                    else{
                        $this->replacements[$val] = $match[1];
                    }
                }
                elseif (in_array($val$todayTRUE)) {
                    $this->replacements[$val] = $this->replacements[substr($val0, -6)];
                }
            }
        

Result:

[Image: Screen_Shot_2016_11_26_at_15_30_10_fullpage.png]