• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[3.1.4 modification] modify calendar library, add extra column before calendar

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....

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.

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

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

// application/libraries/Calendar_extra.php

if (!class_exists('CI_Calendar', false)) {

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


    // Put your customizations here.

// A Quick Test
        echo $this->calendar_extra->generate();

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:
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:
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:

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

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