From 7977e1d4859d48be00bb11250446d9abeff6ac35 Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 15:34:11 -0200 Subject: Update the Calendar Class --- system/libraries/Calendar.php | 54 ++++++++++++++++++++++++++++++++----- user_guide_src/source/changelog.rst | 7 ++++- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 23d8ffb42..a2d9db14b 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -95,6 +95,13 @@ class CI_Calendar { */ public $next_prev_url = ''; + /** + * Show days of other months + * + * @var bool + */ + public $show_other_days = FALSE; + /** * Class constructor * @@ -143,6 +150,15 @@ class CI_Calendar { $this->$key = $val; } } + + // Set the next_prev_url to the controller if required but not defined + if ($this->show_next_prev === TRUE) + { + if (empty($this->next_prev_url)) + { + $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class . '/' . $this->CI->router->method), '/') . '/'; + } + } } // -------------------------------------------------------------------- @@ -261,10 +277,10 @@ class CI_Calendar { for ($i = 0; $i < 7; $i++) { - $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; - if ($day > 0 && $day <= $total_days) { + $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; + if (isset($data[$day])) { // Cells with content @@ -279,14 +295,37 @@ class CI_Calendar { $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content']; $out .= str_replace('{day}', $day, $temp); } + + $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; } else { - // Blank cells - $out .= $this->temp['cal_cell_blank']; + if ($this->show_other_days === TRUE) + { + $out .= $this->temp['cal_cell_start_other']; + + if ($day <= 0) + { + // Day of previous month + $prev_month = $this->adjust_date(((int) $month) - 1, $year); + $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); + $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); + } + else + { + // Day of next month + $out .= str_replace('{day}', $day - $total_days, $this->temp['cal_cell_other']); + } + + $out .= $this->temp['cal_cell_end_other']; + } + else + { + // Blank cells + $out .= $this->temp['cal_cell_start'] . $this->temp['cal_cell_blank'] . $this->temp['cal_cell_end']; + } } - $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; $day++; } @@ -457,13 +496,16 @@ class CI_Calendar { 'cal_row_start' => '', 'cal_cell_start' => '', 'cal_cell_start_today' => '', + 'cal_cell_start_other' => '', 'cal_cell_content' => '{day}', 'cal_cell_content_today' => '{day}', 'cal_cell_no_content' => '{day}', 'cal_cell_no_content_today' => '{day}', 'cal_cell_blank' => ' ', + 'cal_cell_other' => '{day}', 'cal_cell_end' => '', 'cal_cell_end_today' => '', + 'cal_cell_end_other' => '', 'cal_row_end' => '', 'table_close' => '' ); @@ -490,7 +532,7 @@ class CI_Calendar { $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); - 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_day_cell', 'week_row_end', 'cal_row_start', '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') as $val) + 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_day_cell', 'week_row_end', 'cal_row_start', '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) { if (preg_match('/\{'.$val.'\}(.*?)\{\/'.$val.'\}/si', $this->template, $match)) { diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 3fa27ffa8..5da0330e5 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -184,7 +184,7 @@ Release Date: Not Released - Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query. - Added persistent connections support for PHP >= 5.3. - Added support for ``backup()`` in :doc:`Database Utilities `. - - Changed methods ``trans_begin()``, ``trans_commit()`` and ``trans_rollback()`` to use the PHP API instead of sending queries. + - Changed methods ``trans_begin()``, ``trans_commit()`` and ``trans_rollback()`` to use the PHP API instead of sending queries. - Improved support of the PDO driver, including: @@ -278,6 +278,11 @@ Release Date: Not Released - Added **file_ext_tolower** config setting. - Added **mod_mime_fix** option to disable suffixing multiple file extensions with an underscore. + - :doc:`Calendar library ` changes include: + + - Add configuration to generate days of other months instead of blank cells + - Auto set the *next_prev_url* if is empty and the *show_prev_next* is set to TRUE + - :doc:`Cart library ` changes include: - ``insert()`` now auto-increments quantity for an item when inserted twice instead of resetting it, this is the default behaviour of large e-commerce sites. -- cgit v1.2.3-24-g4f1b From a593e3eb218002a630b7d0cf90002ec4a6fd1db3 Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 18:22:12 -0200 Subject: Code Corrections for the Calendar Pull Request --- system/libraries/Calendar.php | 39 +++++++++++++++++-------------------- user_guide_src/source/changelog.rst | 4 ++-- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index a2d9db14b..efaa49a34 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -156,7 +156,7 @@ class CI_Calendar { { if (empty($this->next_prev_url)) { - $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class . '/' . $this->CI->router->method), '/') . '/'; + $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; } } } @@ -298,32 +298,29 @@ class CI_Calendar { $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; } - else + elseif ($this->show_other_days === TRUE) { - if ($this->show_other_days === TRUE) + $out .= $this->temp['cal_cell_start_other']; + + if ($day <= 0) { - $out .= $this->temp['cal_cell_start_other']; - - if ($day <= 0) - { - // Day of previous month - $prev_month = $this->adjust_date(((int) $month) - 1, $year); - $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); - $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); - } - else - { - // Day of next month - $out .= str_replace('{day}', $day - $total_days, $this->temp['cal_cell_other']); - } - - $out .= $this->temp['cal_cell_end_other']; + // Day of previous month + $prev_month = $this->adjust_date(((int) $month) - 1, $year); + $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); + $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); } else { - // Blank cells - $out .= $this->temp['cal_cell_start'] . $this->temp['cal_cell_blank'] . $this->temp['cal_cell_end']; + // Day of next month + $out .= str_replace('{day}', $day - $total_days, $this->temp['cal_cell_other']); } + + $out .= $this->temp['cal_cell_end_other']; + } + else + { + // Blank cells + $out .= $this->temp['cal_cell_start'].$this->temp['cal_cell_blank'].$this->temp['cal_cell_end']; } $day++; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 5da0330e5..ff7c09b48 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -280,8 +280,8 @@ Release Date: Not Released - :doc:`Calendar library ` changes include: - - Add configuration to generate days of other months instead of blank cells - - Auto set the *next_prev_url* if is empty and the *show_prev_next* is set to TRUE + - Added configuration to generate days of other months instead of blank cells. + - Auto set *next_prev_url* if it is empty and *show_prev_next* is set to TRUE. - :doc:`Cart library ` changes include: -- cgit v1.2.3-24-g4f1b From c4f661613eefb6ea15b4109beb61c823d9ec51cc Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 18:57:09 -0200 Subject: Join two if statement into one --- system/libraries/Calendar.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index efaa49a34..e393345df 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -152,12 +152,9 @@ class CI_Calendar { } // Set the next_prev_url to the controller if required but not defined - if ($this->show_next_prev === TRUE) + if ($this->show_next_prev === TRUE && empty($this->next_prev_url)) { - if (empty($this->next_prev_url)) - { - $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; - } + $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; } } -- cgit v1.2.3-24-g4f1b From 0cd7c92ee59b4b03588e45229944d4b83eea3d8e Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 19:38:00 -0200 Subject: Unnecessary rtrim and update docs for Calendar class --- system/libraries/Calendar.php | 2 +- user_guide_src/source/libraries/calendar.rst | 41 +++++++++++++++++----------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index e393345df..de77e3d7f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -154,7 +154,7 @@ class CI_Calendar { // Set the next_prev_url to the controller if required but not defined if ($this->show_next_prev === TRUE && empty($this->next_prev_url)) { - $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; + $this->next_prev_url = $this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method); } } diff --git a/user_guide_src/source/libraries/calendar.rst b/user_guide_src/source/libraries/calendar.rst index 3964db25e..8b2f503b9 100644 --- a/user_guide_src/source/libraries/calendar.rst +++ b/user_guide_src/source/libraries/calendar.rst @@ -86,21 +86,23 @@ The above code would start the calendar on saturday, use the "long" month heading, and the "short" day names. More information regarding preferences below. -====================== =========== =============================================== =================================================================== -Preference Default Options Description -====================== =========== =============================================== =================================================================== -**template** None None A string containing your calendar template. - See the template section below. -**local_time** time() None A Unix timestamp corresponding to the current time. -**start_day** sunday Any week day (sunday, monday, tuesday, etc.) Sets the day of the week the calendar should start on. -**month_type** long long, short Determines what version of the month name to use in the header. - long = January, short = Jan. -**day_type** abr long, short, abr Determines what version of the weekday names to use in - the column headers. long = Sunday, short = Sun, abr = Su. -**show_next_prev** FALSE TRUE/FALSE (boolean) Determines whether to display links allowing you to toggle - to next/previous months. See information on this feature below. -**next_prev_url** None A URL Sets the basepath used in the next/previous calendar links. -====================== =========== =============================================== =================================================================== +====================== ============== =============================================== =================================================================== +Preference Default Options Description +====================== ============== =============================================== =================================================================== +**template** None None A string containing your calendar template. + See the template section below. +**local_time** time() None A Unix timestamp corresponding to the current time. +**start_day** sunday Any week day (sunday, monday, tuesday, etc.) Sets the day of the week the calendar should start on. +**month_type** long long, short Determines what version of the month name to use in the header. + long = January, short = Jan. +**day_type** abr long, short, abr Determines what version of the weekday names to use in + the column headers. long = Sunday, short = Sun, abr = Su. +**show_next_prev** FALSE TRUE/FALSE (boolean) Determines whether to display links allowing you to toggle + to next/previous months. See information on this feature below. +**next_prev_url** Controller URL A URL Sets the basepath used in the next/previous calendar links. +**show_other_days** FALSE TRUE/FALSE (boolean) Determines whether to display days of other months that shares the + first or last week of the calendar month. +====================== ============== =============================================== =================================================================== Showing Next/Previous Month Links @@ -123,7 +125,8 @@ You'll notice a few things about the above example: - You must set the "show_next_prev" to TRUE. - You must supply the URL to the controller containing your calendar in - the "next_prev_url" preference. + the "next_prev_url" preference. The Code Igniter will try to guess + the link for the current controller/method if you don't supply. - You must supply the "year" and "month" to the calendar generating function via the URI segments where they appear (Note: The calendar class automatically adds the year/month to the base URL you @@ -154,6 +157,8 @@ pair of pseudo-variables as shown here:: {cal_row_start}{/cal_row_start} {cal_cell_start}{/cal_cell_start} + {cal_cell_start_today}{/cal_cell_start_today} + {cal_cell_start_other}{/cal_cell_start_other} {cal_cell_content}{day}{/cal_cell_content} {cal_cell_content_today}{/cal_cell_content_today} @@ -163,7 +168,11 @@ pair of pseudo-variables as shown here:: {cal_cell_blank} {/cal_cell_blank} + {cal_cell_other}{day}{cal_cel_other} + {cal_cell_end}{/cal_cell_end} + {cal_cell_end_today}{/cal_cell_end_today} + {cal_cell_end_other}{/cal_cell_end_other} {cal_row_end}{/cal_row_end} {table_close}{/table_close} -- cgit v1.2.3-24-g4f1b From 2e914b7dc6acaf2938fac4c332ff682a033b93d7 Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Thu, 9 Jan 2014 09:20:55 -0200 Subject: Updates for the Calendar Pull Request --- system/libraries/Calendar.php | 2 +- user_guide_src/source/libraries/calendar.rst | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index de77e3d7f..711d23bec 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -302,7 +302,7 @@ class CI_Calendar { if ($day <= 0) { // Day of previous month - $prev_month = $this->adjust_date(((int) $month) - 1, $year); + $prev_month = $this->adjust_date($month - 1, $year); $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); } diff --git a/user_guide_src/source/libraries/calendar.rst b/user_guide_src/source/libraries/calendar.rst index 8b2f503b9..e24ee80b8 100644 --- a/user_guide_src/source/libraries/calendar.rst +++ b/user_guide_src/source/libraries/calendar.rst @@ -86,23 +86,23 @@ The above code would start the calendar on saturday, use the "long" month heading, and the "short" day names. More information regarding preferences below. -====================== ============== =============================================== =================================================================== -Preference Default Options Description -====================== ============== =============================================== =================================================================== -**template** None None A string containing your calendar template. +====================== ================= =============================================== =================================================================== +Preference Default Options Description +====================== ================= =============================================== =================================================================== +**template** None None A string containing your calendar template. See the template section below. -**local_time** time() None A Unix timestamp corresponding to the current time. -**start_day** sunday Any week day (sunday, monday, tuesday, etc.) Sets the day of the week the calendar should start on. -**month_type** long long, short Determines what version of the month name to use in the header. +**local_time** time() None A Unix timestamp corresponding to the current time. +**start_day** sunday Any week day (sunday, monday, tuesday, etc.) Sets the day of the week the calendar should start on. +**month_type** long long, short Determines what version of the month name to use in the header. long = January, short = Jan. -**day_type** abr long, short, abr Determines what version of the weekday names to use in +**day_type** abr long, short, abr Determines what version of the weekday names to use in the column headers. long = Sunday, short = Sun, abr = Su. -**show_next_prev** FALSE TRUE/FALSE (boolean) Determines whether to display links allowing you to toggle +**show_next_prev** FALSE TRUE/FALSE (boolean) Determines whether to display links allowing you to toggle to next/previous months. See information on this feature below. -**next_prev_url** Controller URL A URL Sets the basepath used in the next/previous calendar links. -**show_other_days** FALSE TRUE/FALSE (boolean) Determines whether to display days of other months that shares the +**next_prev_url** controller/method A URL Sets the basepath used in the next/previous calendar links. +**show_other_days** FALSE TRUE/FALSE (boolean) Determines whether to display days of other months that share the first or last week of the calendar month. -====================== ============== =============================================== =================================================================== +====================== ================= =============================================== =================================================================== Showing Next/Previous Month Links @@ -125,8 +125,8 @@ You'll notice a few things about the above example: - You must set the "show_next_prev" to TRUE. - You must supply the URL to the controller containing your calendar in - the "next_prev_url" preference. The Code Igniter will try to guess - the link for the current controller/method if you don't supply. + the "next_prev_url" preference. If you don't, it will be set to the current + *controller/method*. - You must supply the "year" and "month" to the calendar generating function via the URI segments where they appear (Note: The calendar class automatically adds the year/month to the base URL you -- cgit v1.2.3-24-g4f1b