Welcome Guest, Not a member yet? Register   Sign In
[solved] Calendaring customization [highlighting the current month]
#1

(This post was last modified: 11-27-2016, 05:37 AM by BabalooAye. Edit Reason: Marking post as solved )

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?
Reply
#2

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 11-26-2016, 09:12 AM by BabalooAye.)

(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?
Reply
#4

Yes, you can also extend the Calendar library with MY_Calendar
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(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
Reply
#6

(This post was last modified: 11-28-2016, 09:07 AM by BabalooAye. Edit Reason: Include image to improve explanation )

(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]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB