blob: 3964db25eb1ec7d6ee11e769746cff82d7798854 [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
purwandi89f6f1a2011-10-07 19:58:22 +070089====================== =========== =============================================== ===================================================================
90Preference Default Options Description
91====================== =========== =============================================== ===================================================================
92**template** None None A string containing your calendar template.
93 See the template section below.
94**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.
97 long = January, short = Jan.
98**day_type** abr long, short, abr Determines what version of the weekday names to use in
99 the column headers. long = Sunday, short = Sun, abr = Su.
100**show_next_prev** FALSE TRUE/FALSE (boolean) Determines whether to display links allowing you to toggle
101 to next/previous months. See information on this feature below.
102**next_prev_url** None A URL Sets the basepath used in the next/previous calendar links.
103====================== =========== =============================================== ===================================================================
Derek Jones8ede1a22011-10-05 13:34:52 -0500104
105
106Showing Next/Previous Month Links
107=================================
108
109To allow your calendar to dynamically increment/decrement via the
110next/previous links requires that you set up your calendar code similar
111to this example::
112
113 $prefs = array (
Derek Jones3ab40a62011-10-05 16:19:27 -0500114 'show_next_prev' => TRUE,
115 'next_prev_url' => 'http://example.com/index.php/calendar/show/'
116 );
Derek Jones8ede1a22011-10-05 13:34:52 -0500117
118 $this->load->library('calendar', $prefs);
119
120 echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));
121
122You'll notice a few things about the above example:
123
124- You must set the "show_next_prev" to TRUE.
125- You must supply the URL to the controller containing your calendar in
126 the "next_prev_url" preference.
127- You must supply the "year" and "month" to the calendar generating
128 function via the URI segments where they appear (Note: The calendar
129 class automatically adds the year/month to the base URL you
130 provide.).
131
132Creating a Calendar Template
133============================
134
135By creating a calendar template you have 100% control over the design of
136your calendar. Each component of your calendar will be placed within a
137pair of pseudo-variables as shown here::
138
139 $prefs['template'] = '
140
Derek Jones3ab40a62011-10-05 16:19:27 -0500141 {table_open}<table border="0" cellpadding="0" cellspacing="0">{/table_open}
Derek Jones8ede1a22011-10-05 13:34:52 -0500142
Derek Jones3ab40a62011-10-05 16:19:27 -0500143 {heading_row_start}<tr>{/heading_row_start}
Derek Jones8ede1a22011-10-05 13:34:52 -0500144
Derek Jones3ab40a62011-10-05 16:19:27 -0500145 {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
146 {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
147 {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
Derek Jones8ede1a22011-10-05 13:34:52 -0500148
Derek Jones3ab40a62011-10-05 16:19:27 -0500149 {heading_row_end}</tr>{/heading_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500150
Derek Jones3ab40a62011-10-05 16:19:27 -0500151 {week_row_start}<tr>{/week_row_start}
152 {week_day_cell}<td>{week_day}</td>{/week_day_cell}
153 {week_row_end}</tr>{/week_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500154
Derek Jones3ab40a62011-10-05 16:19:27 -0500155 {cal_row_start}<tr>{/cal_row_start}
156 {cal_cell_start}<td>{/cal_cell_start}
Derek Jones8ede1a22011-10-05 13:34:52 -0500157
Derek Jones3ab40a62011-10-05 16:19:27 -0500158 {cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
159 {cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
Derek Jones8ede1a22011-10-05 13:34:52 -0500160
Derek Jones3ab40a62011-10-05 16:19:27 -0500161 {cal_cell_no_content}{day}{/cal_cell_no_content}
162 {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}
Derek Jones8ede1a22011-10-05 13:34:52 -0500163
Derek Jones3ab40a62011-10-05 16:19:27 -0500164 {cal_cell_blank}&nbsp;{/cal_cell_blank}
Derek Jones8ede1a22011-10-05 13:34:52 -0500165
Derek Jones3ab40a62011-10-05 16:19:27 -0500166 {cal_cell_end}</td>{/cal_cell_end}
167 {cal_row_end}</tr>{/cal_row_end}
Derek Jones8ede1a22011-10-05 13:34:52 -0500168
Derek Jones3ab40a62011-10-05 16:19:27 -0500169 {table_close}</table>{/table_close}
Derek Jones8ede1a22011-10-05 13:34:52 -0500170 ';
171
172 $this->load->library('calendar', $prefs);
173
174 echo $this->calendar->generate();