blob: 471fd64f9950c2e46cda90ac140bf5a816bf72fd [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001#################
2Calendaring Class
3#################
4
5The Calendar class enables you to dynamically create calendars. Your
6calendars can be formatted through the use of a calendar template,
7allowing 100% control over every aspect of its design. In addition, you
8can pass data to your calendar cells.
9
10Initializing the Class
11======================
12
13Like most other classes in CodeIgniter, the Calendar class is
14initialized in your controller using the $this->load->library function::
15
16 $this->load->library('calendar');
17
18Once loaded, the Calendar object will be available using::
19
20 $this->calendar
21
22Displaying a Calendar
23=====================
24
25Here is a very simple example showing how you can display a calendar::
26
27 $this->load->library('calendar');
28 echo $this->calendar->generate();
29
30The above code will generate a calendar for the current month/year based
31on your server time. To show a calendar for a specific month and year
32you will pass this information to the calendar generating function::
33
34 $this->load->library('calendar');
35 echo $this->calendar->generate(2006, 6);
36
37The above code will generate a calendar showing the month of June in
382006. The first parameter specifies the year, the second parameter
39specifies the month.
40
41Passing Data to your Calendar Cells
42===================================
43
44To add data to your calendar cells involves creating an associative
45array in which the keys correspond to the days you wish to populate and
46the array value contains the data. The array is passed to the third
47parameter of the calendar generating function. Consider this example::
48
49 $this->load->library('calendar');
50
51 $data = array(
Derek Jones3ab40a62011-10-05 16:19:27 -050052 3 => 'http://example.com/news/article/2006/03/',
53 7 => 'http://example.com/news/article/2006/07/',
54 13 => 'http://example.com/news/article/2006/13/',
55 26 => 'http://example.com/news/article/2006/26/'
56 );
Derek Jones8ede1a22011-10-05 13:34:52 -050057
58 echo $this->calendar->generate(2006, 6, $data);
59
60Using the above example, day numbers 3, 7, 13, and 26 will become links
61pointing to the URLs you've provided.
62
63.. note:: By default it is assumed that your array will contain links.
64 In the section that explains the calendar template below you'll see how
65 you can customize how data passed to your cells is handled so you can
66 pass different types of information.
67
68Setting Display Preferences
69===========================
70
71There are seven preferences you can set to control various aspects of
72the calendar. Preferences are set by passing an array of preferences in
73the second parameter of the loading function. Here is an example::
74
75 $prefs = array (
Derek Jones3ab40a62011-10-05 16:19:27 -050076 'start_day' => 'saturday',
77 'month_type' => 'long',
78 'day_type' => 'short'
79 );
Derek Jones8ede1a22011-10-05 13:34:52 -050080
81 $this->load->library('calendar', $prefs);
82
83 echo $this->calendar->generate();
84
85The above code would start the calendar on saturday, use the "long"
86month heading, and the "short" day names. More information regarding
87preferences below.
88
89+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
90| Preference | Default | Options | Description |
91+=======================+===========+===============================================+===================================================================+
92| **template** | None | None | A string containing your calendar template. |
93| | | | See the template section below. |
94+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
95| **local_time** | time() | None | A Unix timestamp corresponding to the current time. |
96+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
97| **start_day** | sunday | Any week day (sunday, monday, tuesday, etc.) | Sets the day of the week the calendar should start on. |
98+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
99| **month_type** | long | long, short | Determines what version of the month name to use in the header. |
100| | | | long = January, short = Jan. |
101+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
102| **day_type** | abr | long, short, abr | Determines what version of the weekday names to use in |
103| | | | the column headers. |
104| | | | long = Sunday, short = Sun, abr = Su. |
105+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
106| **show_next_prev** | FALSE | TRUE/FALSE (boolean) | Determines whether to display links allowing you to toggle |
107| | | | to next/previous months. See information on this feature below. |
108+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
109| **next_prev_url** | None | A URL | Sets the basepath used in the next/previous calendar links. |
110+-----------------------+-----------+-----------------------------------------------+-------------------------------------------------------------------+
111
112
113Showing Next/Previous Month Links
114=================================
115
116To allow your calendar to dynamically increment/decrement via the
117next/previous links requires that you set up your calendar code similar
118to this example::
119
120 $prefs = array (
Derek Jones3ab40a62011-10-05 16:19:27 -0500121 'show_next_prev' => TRUE,
122 'next_prev_url' => 'http://example.com/index.php/calendar/show/'
123 );
Derek Jones8ede1a22011-10-05 13:34:52 -0500124
125 $this->load->library('calendar', $prefs);
126
127 echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));
128
129You'll notice a few things about the above example:
130
131- You must set the "show_next_prev" to TRUE.
132- You must supply the URL to the controller containing your calendar in
133 the "next_prev_url" preference.
134- You must supply the "year" and "month" to the calendar generating
135 function via the URI segments where they appear (Note: The calendar
136 class automatically adds the year/month to the base URL you
137 provide.).
138
139Creating a Calendar Template
140============================
141
142By creating a calendar template you have 100% control over the design of
143your calendar. Each component of your calendar will be placed within a
144pair of pseudo-variables as shown here::
145
146 $prefs['template'] = '
147
Derek Jones3ab40a62011-10-05 16:19:27 -0500148 {table_open}<table border="0" cellpadding="0" cellspacing="0">{/table_open}
Derek Jones8ede1a22011-10-05 13:34:52 -0500149
Derek Jones3ab40a62011-10-05 16:19:27 -0500150 {heading_row_start}<tr>{/heading_row_start}
Derek Jones8ede1a22011-10-05 13:34:52 -0500151
Derek Jones3ab40a62011-10-05 16:19:27 -0500152 {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
153 {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
154 {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
Derek Jones8ede1a22011-10-05 13:34:52 -0500155
Derek Jones3ab40a62011-10-05 16:19:27 -0500156 {heading_row_end}</tr>{/heading_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500157
Derek Jones3ab40a62011-10-05 16:19:27 -0500158 {week_row_start}<tr>{/week_row_start}
159 {week_day_cell}<td>{week_day}</td>{/week_day_cell}
160 {week_row_end}</tr>{/week_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500161
Derek Jones3ab40a62011-10-05 16:19:27 -0500162 {cal_row_start}<tr>{/cal_row_start}
163 {cal_cell_start}<td>{/cal_cell_start}
Derek Jones8ede1a22011-10-05 13:34:52 -0500164
Derek Jones3ab40a62011-10-05 16:19:27 -0500165 {cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
166 {cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
Derek Jones8ede1a22011-10-05 13:34:52 -0500167
Derek Jones3ab40a62011-10-05 16:19:27 -0500168 {cal_cell_no_content}{day}{/cal_cell_no_content}
169 {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}
Derek Jones8ede1a22011-10-05 13:34:52 -0500170
Derek Jones3ab40a62011-10-05 16:19:27 -0500171 {cal_cell_blank}&nbsp;{/cal_cell_blank}
Derek Jones8ede1a22011-10-05 13:34:52 -0500172
Derek Jones3ab40a62011-10-05 16:19:27 -0500173 {cal_cell_end}</td>{/cal_cell_end}
174 {cal_row_end}</tr>{/cal_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500175
Derek Jones3ab40a62011-10-05 16:19:27 -0500176 {table_close}</table>{/table_close}
Derek Jones8ede1a22011-10-05 13:34:52 -0500177 ';
178
179 $this->load->library('calendar', $prefs);
180
181 echo $this->calendar->generate();