Welcome Guest, Not a member yet? Register   Sign In
[3.1.4 modification] modify calendar library, add extra column before calendar
#1

(This post was last modified: 05-26-2017, 12:01 PM by eagle00789.)

i love the calendar library, but i just miss a single feature. i need to add a column before or after the calendar for (for example) the weeknumber or other thing relevant for that week.
Is there any way to modify the calendar library (by copying it to my own library folder and modify it) to allow for an extra column before the first or after the last column with a way to add data into it ofcourse....
Reply
#2

(This post was last modified: 05-20-2017, 03:04 PM by skunkbad.)

I've done a lot of work extending the calendar class. Yes, you will create a MY_calendar.php. You will spend quite a bit of time learning what's going on in the calendar class so that you can make your modifications.

Also, I ended up needing to extend the calendar class in two different ways, and so you should think about the modifications you are making, and remember that there may be a time when you don't want those specific mods to affect the calendar.
Reply
#3

(This post was last modified: 05-21-2017, 06:29 AM by ivantcholakov. Edit Reason: directory clarification )

A library under a different name could be an option to be considered:

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

// application/libraries/Calendar_extra.php

if (!class_exists('CI_Calendar', false)) {
    get_instance()->load->library('calendar');
}

class Calendar_extra extends CI_Calendar {

    public function __construct($config = array()) {

        // If a configuration file is to be used,
        // its name would be calendar_extra.php

        parent::__construct($config);
    }

    // Put your customizations here.
}

Code:
// A Quick Test
        $this->load->library('calendar_extra');
        echo $this->calendar_extra->generate();
Reply
#4

(This post was last modified: 05-22-2017, 12:53 PM by eagle00789. Edit Reason: added screenshot )

if you want a quick and dirty method like me, you can do the following:
the mentiond line numbers represent the original line numbers from the original calendar.php file. that is why the changes are in reverse order, from the bottom up:
Copy the system/libraries/calendar.php file to Application/libraries/MY_calendar.php
Go to line 526 and replace it with the following text:

PHP Code:
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_row_before_cell''week_day_cell''week_row_end''cal_row_start''cal_row_before''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
Go to line 336 and paste the following before the line already there

PHP Code:
           if (array_key_exists('cal_row_before'$this->replacements))
 
           {
 
               $maxday $day-1;
 
               if ($maxday >= 32)
 
               {
 
                   $maxday max(array_keys($data));
 
               }
 
               $out str_replace('{to_day}'$maxday$out);
 
           
Go to line 297 and paste the following before the line already there

PHP Code:
                       if (array_key_exists('cal_row_before'$this->replacements))
 
                       {
 
                           $out str_replace('{from_day}'$day$out);
 
                       
Go to line 284 and paste the following before the line already there
PHP Code:
           if (array_key_exists('cal_row_before'$this->replacements))
 
           {
 
               $out .= $this->replacements['cal_row_before'];
 
           
Go to line 271 and paste the following before the line already there
PHP Code:
        if (array_key_exists('week_row_before_cell'$this->replacements))
        {
 
           $out .= $this->replacements['week_row_before_cell'];
 
       
Replace line 51 with the line below

PHP Code:
class MY_Calendar extends CI_Calendar 
Now just call your extra calendar like below

PHP Code:
       $this->load->library('calendar'$prefs);
 
       $this->load->library('MY_calendar'$prefs); 
and just use the normal functions like you are used to.
Now you can use the following fields in your template (with examples included)

PHP Code:
           {week_row_before_cell}<td>&nbsp;</td>{/week_row_before_cell}
 
           {cal_row_before}<td>{from_day}-{to_day}</td>{/cal_row_before
The field week_row_before is to accommodate the extra column in the week name row
The field cal_row_before is the extra cell before each week row. In this field, you can use the fields from_day and to_day to use the first and last day of that week in your extra cell.
View a demo (partial screenshot) below:
   
Reply




Theme © iAndrew 2016 - Forum software by © MyBB