Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ################# |
| 2 | Calendaring Class |
| 3 | ################# |
| 4 | |
| 5 | The Calendar class enables you to dynamically create calendars. Your |
| 6 | calendars can be formatted through the use of a calendar template, |
| 7 | allowing 100% control over every aspect of its design. In addition, you |
| 8 | can pass data to your calendar cells. |
| 9 | |
| 10 | Initializing the Class |
| 11 | ====================== |
| 12 | |
| 13 | Like most other classes in CodeIgniter, the Calendar class is |
| 14 | initialized in your controller using the $this->load->library function:: |
| 15 | |
| 16 | $this->load->library('calendar'); |
| 17 | |
| 18 | Once loaded, the Calendar object will be available using:: |
| 19 | |
| 20 | $this->calendar |
| 21 | |
| 22 | Displaying a Calendar |
| 23 | ===================== |
| 24 | |
| 25 | Here is a very simple example showing how you can display a calendar:: |
| 26 | |
| 27 | $this->load->library('calendar'); |
| 28 | echo $this->calendar->generate(); |
| 29 | |
| 30 | The above code will generate a calendar for the current month/year based |
| 31 | on your server time. To show a calendar for a specific month and year |
| 32 | you will pass this information to the calendar generating function:: |
| 33 | |
| 34 | $this->load->library('calendar'); |
| 35 | echo $this->calendar->generate(2006, 6); |
| 36 | |
| 37 | The above code will generate a calendar showing the month of June in |
| 38 | 2006. The first parameter specifies the year, the second parameter |
| 39 | specifies the month. |
| 40 | |
| 41 | Passing Data to your Calendar Cells |
| 42 | =================================== |
| 43 | |
| 44 | To add data to your calendar cells involves creating an associative |
| 45 | array in which the keys correspond to the days you wish to populate and |
| 46 | the array value contains the data. The array is passed to the third |
| 47 | parameter of the calendar generating function. Consider this example:: |
| 48 | |
| 49 | $this->load->library('calendar'); |
| 50 | |
| 51 | $data = array( |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 52 | 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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 57 | |
| 58 | echo $this->calendar->generate(2006, 6, $data); |
| 59 | |
| 60 | Using the above example, day numbers 3, 7, 13, and 26 will become links |
| 61 | pointing 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 | |
| 68 | Setting Display Preferences |
| 69 | =========================== |
| 70 | |
| 71 | There are seven preferences you can set to control various aspects of |
| 72 | the calendar. Preferences are set by passing an array of preferences in |
| 73 | the second parameter of the loading function. Here is an example:: |
| 74 | |
| 75 | $prefs = array ( |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 76 | 'start_day' => 'saturday', |
| 77 | 'month_type' => 'long', |
| 78 | 'day_type' => 'short' |
| 79 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 80 | |
| 81 | $this->load->library('calendar', $prefs); |
| 82 | |
| 83 | echo $this->calendar->generate(); |
| 84 | |
| 85 | The above code would start the calendar on saturday, use the "long" |
| 86 | month heading, and the "short" day names. More information regarding |
| 87 | preferences below. |
| 88 | |
purwandi | 89f6f1a | 2011-10-07 19:58:22 +0700 | [diff] [blame] | 89 | ====================== =========== =============================================== =================================================================== |
| 90 | Preference 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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 104 | |
| 105 | |
| 106 | Showing Next/Previous Month Links |
| 107 | ================================= |
| 108 | |
| 109 | To allow your calendar to dynamically increment/decrement via the |
| 110 | next/previous links requires that you set up your calendar code similar |
| 111 | to this example:: |
| 112 | |
| 113 | $prefs = array ( |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 114 | 'show_next_prev' => TRUE, |
| 115 | 'next_prev_url' => 'http://example.com/index.php/calendar/show/' |
| 116 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 117 | |
| 118 | $this->load->library('calendar', $prefs); |
| 119 | |
| 120 | echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4)); |
| 121 | |
| 122 | You'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 | |
| 132 | Creating a Calendar Template |
| 133 | ============================ |
| 134 | |
| 135 | By creating a calendar template you have 100% control over the design of |
| 136 | your calendar. Each component of your calendar will be placed within a |
| 137 | pair of pseudo-variables as shown here:: |
| 138 | |
| 139 | $prefs['template'] = ' |
| 140 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 141 | {table_open}<table border="0" cellpadding="0" cellspacing="0">{/table_open} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 142 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 143 | {heading_row_start}<tr>{/heading_row_start} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 144 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 145 | {heading_previous_cell}<th><a href="{previous_url}"><<</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}">>></a></th>{/heading_next_cell} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 148 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 149 | {heading_row_end}</tr>{/heading_row_end} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 150 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 151 | {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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 154 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 155 | {cal_row_start}<tr>{/cal_row_start} |
| 156 | {cal_cell_start}<td>{/cal_cell_start} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 157 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 158 | {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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 160 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 161 | {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 Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 163 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 164 | {cal_cell_blank} {/cal_cell_blank} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 165 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 166 | {cal_cell_end}</td>{/cal_cell_end} |
| 167 | {cal_row_end}</tr>{/cal_row_end} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 168 | |
Derek Jones | 3ab40a6 | 2011-10-05 16:19:27 -0500 | [diff] [blame] | 169 | {table_close}</table>{/table_close} |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 170 | '; |
| 171 | |
| 172 | $this->load->library('calendar', $prefs); |
| 173 | |
| 174 | echo $this->calendar->generate(); |