blob: e24ee80b82143aac793bcb554090614259f22283 [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
Marcos SF Filho2e914b72014-01-09 09:20:55 -020089====================== ================= =============================================== ===================================================================
90Preference Default Options Description
91====================== ================= =============================================== ===================================================================
92**template** None None A string containing your calendar template.
Marcos SF Filho0cd7c922014-01-08 19:38:00 -020093 See the template section below.
Marcos SF Filho2e914b72014-01-09 09:20:55 -020094**local_time** time() None A Unix timestamp corresponding to the current time.
95**start_day** sunday Any week day (sunday, monday, tuesday, etc.) Sets the day of the week the calendar should start on.
96**month_type** long long, short Determines what version of the month name to use in the header.
Marcos SF Filho0cd7c922014-01-08 19:38:00 -020097 long = January, short = Jan.
Marcos SF Filho2e914b72014-01-09 09:20:55 -020098**day_type** abr long, short, abr Determines what version of the weekday names to use in
Marcos SF Filho0cd7c922014-01-08 19:38:00 -020099 the column headers. long = Sunday, short = Sun, abr = Su.
Marcos SF Filho2e914b72014-01-09 09:20:55 -0200100**show_next_prev** FALSE TRUE/FALSE (boolean) Determines whether to display links allowing you to toggle
Marcos SF Filho0cd7c922014-01-08 19:38:00 -0200101 to next/previous months. See information on this feature below.
Marcos SF Filho2e914b72014-01-09 09:20:55 -0200102**next_prev_url** controller/method A URL Sets the basepath used in the next/previous calendar links.
103**show_other_days** FALSE TRUE/FALSE (boolean) Determines whether to display days of other months that share the
Marcos SF Filho0cd7c922014-01-08 19:38:00 -0200104 first or last week of the calendar month.
Marcos SF Filho2e914b72014-01-09 09:20:55 -0200105====================== ================= =============================================== ===================================================================
Derek Jones8ede1a22011-10-05 13:34:52 -0500106
107
108Showing Next/Previous Month Links
109=================================
110
111To allow your calendar to dynamically increment/decrement via the
112next/previous links requires that you set up your calendar code similar
113to this example::
114
115 $prefs = array (
Derek Jones3ab40a62011-10-05 16:19:27 -0500116 'show_next_prev' => TRUE,
117 'next_prev_url' => 'http://example.com/index.php/calendar/show/'
118 );
Derek Jones8ede1a22011-10-05 13:34:52 -0500119
120 $this->load->library('calendar', $prefs);
121
122 echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));
123
124You'll notice a few things about the above example:
125
126- You must set the "show_next_prev" to TRUE.
127- You must supply the URL to the controller containing your calendar in
Marcos SF Filho2e914b72014-01-09 09:20:55 -0200128 the "next_prev_url" preference. If you don't, it will be set to the current
129 *controller/method*.
Derek Jones8ede1a22011-10-05 13:34:52 -0500130- You must supply the "year" and "month" to the calendar generating
131 function via the URI segments where they appear (Note: The calendar
132 class automatically adds the year/month to the base URL you
133 provide.).
134
135Creating a Calendar Template
136============================
137
138By creating a calendar template you have 100% control over the design of
139your calendar. Each component of your calendar will be placed within a
140pair of pseudo-variables as shown here::
141
142 $prefs['template'] = '
143
Derek Jones3ab40a62011-10-05 16:19:27 -0500144 {table_open}<table border="0" cellpadding="0" cellspacing="0">{/table_open}
Derek Jones8ede1a22011-10-05 13:34:52 -0500145
Derek Jones3ab40a62011-10-05 16:19:27 -0500146 {heading_row_start}<tr>{/heading_row_start}
Derek Jones8ede1a22011-10-05 13:34:52 -0500147
Derek Jones3ab40a62011-10-05 16:19:27 -0500148 {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
149 {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
150 {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
Derek Jones8ede1a22011-10-05 13:34:52 -0500151
Derek Jones3ab40a62011-10-05 16:19:27 -0500152 {heading_row_end}</tr>{/heading_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500153
Derek Jones3ab40a62011-10-05 16:19:27 -0500154 {week_row_start}<tr>{/week_row_start}
155 {week_day_cell}<td>{week_day}</td>{/week_day_cell}
156 {week_row_end}</tr>{/week_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500157
Derek Jones3ab40a62011-10-05 16:19:27 -0500158 {cal_row_start}<tr>{/cal_row_start}
159 {cal_cell_start}<td>{/cal_cell_start}
Marcos SF Filho0cd7c922014-01-08 19:38:00 -0200160 {cal_cell_start_today}<td>{/cal_cell_start_today}
161 {cal_cell_start_other}<td class="other-month">{/cal_cell_start_other}
Derek Jones8ede1a22011-10-05 13:34:52 -0500162
Derek Jones3ab40a62011-10-05 16:19:27 -0500163 {cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
164 {cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
Derek Jones8ede1a22011-10-05 13:34:52 -0500165
Derek Jones3ab40a62011-10-05 16:19:27 -0500166 {cal_cell_no_content}{day}{/cal_cell_no_content}
167 {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}
Derek Jones8ede1a22011-10-05 13:34:52 -0500168
Derek Jones3ab40a62011-10-05 16:19:27 -0500169 {cal_cell_blank}&nbsp;{/cal_cell_blank}
Derek Jones8ede1a22011-10-05 13:34:52 -0500170
Marcos SF Filho0cd7c922014-01-08 19:38:00 -0200171 {cal_cell_other}{day}{cal_cel_other}
172
Derek Jones3ab40a62011-10-05 16:19:27 -0500173 {cal_cell_end}</td>{/cal_cell_end}
Marcos SF Filho0cd7c922014-01-08 19:38:00 -0200174 {cal_cell_end_today}</td>{/cal_cell_end_today}
175 {cal_cell_end_other}</td>{/cal_cell_end_other}
Derek Jones3ab40a62011-10-05 16:19:27 -0500176 {cal_row_end}</tr>{/cal_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500177
Derek Jones3ab40a62011-10-05 16:19:27 -0500178 {table_close}</table>{/table_close}
Derek Jones8ede1a22011-10-05 13:34:52 -0500179 ';
180
181 $this->load->library('calendar', $prefs);
182
183 echo $this->calendar->generate();