mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Updated PEAR Calendar class to resolve PHP Strict notices
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,197 +1,232 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Day.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Day.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Day and builds Hours.
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Day.php';
|
||||
* $Day = & new Calendar_Day(2003, 10, 21); // Oct 21st 2003
|
||||
* while ($Hour = & $Day->fetch()) {
|
||||
* echo $Hour->thisHour().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Day extends Calendar
|
||||
{
|
||||
/**
|
||||
* Marks the Day at the beginning of a week
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $first = false;
|
||||
|
||||
/**
|
||||
* Marks the Day at the end of a week
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $last = false;
|
||||
|
||||
|
||||
/**
|
||||
* Used for tabular calendars
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $empty = false;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Day
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 8
|
||||
* @param int day e.g. 15
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Day($y, $m, $d)
|
||||
{
|
||||
Calendar::Calendar($y, $m, $d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Hours of the Day
|
||||
* @param array (optional) Caledar_Hour objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Hour.php';
|
||||
|
||||
$hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day);
|
||||
for ($i=0; $i < $hID; $i++) {
|
||||
$this->children[$i]=
|
||||
new Calendar_Hour($this->year, $this->month, $this->day, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
&& $this->day == $sDate->thisDay())
|
||||
{
|
||||
$key = (int)$sDate->thisHour();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines Day object as first in a week
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirst ($state = true)
|
||||
{
|
||||
$this->first = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines Day object as last in a week
|
||||
* Used only following Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setLast($state = true)
|
||||
{
|
||||
$this->last = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Day object is first in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isFirst() {
|
||||
return $this->first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Day object is last in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isLast()
|
||||
{
|
||||
return $this->last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines Day object as empty
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setEmpty ($state = true)
|
||||
{
|
||||
$this->empty = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isEmpty()
|
||||
{
|
||||
return $this->empty;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Day class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Day.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Day and builds Hours.
|
||||
* <code>
|
||||
* require_once 'Calendar/Day.php';
|
||||
* $Day = new Calendar_Day(2003, 10, 21); // Oct 21st 2003
|
||||
* while ($Hour = & $Day->fetch()) {
|
||||
* echo $Hour->thisHour().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Day extends Calendar
|
||||
{
|
||||
/**
|
||||
* Marks the Day at the beginning of a week
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $first = false;
|
||||
|
||||
/**
|
||||
* Marks the Day at the end of a week
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $last = false;
|
||||
|
||||
|
||||
/**
|
||||
* Used for tabular calendars
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $empty = false;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Day
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 8
|
||||
* @param int $d day e.g. 15
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Day($y, $m, $d)
|
||||
{
|
||||
parent::Calendar($y, $m, $d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Hours of the Day
|
||||
*
|
||||
* @param array $sDates (optional) Caledar_Hour objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Hour.php';
|
||||
|
||||
$hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day);
|
||||
for ($i=0; $i < $hID; $i++) {
|
||||
$this->children[$i] =
|
||||
new Calendar_Hour($this->year, $this->month, $this->day, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
*
|
||||
* @param array $sDates dates to be selected
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
&& $this->day == $sDate->thisDay())
|
||||
{
|
||||
$key = (int)$sDate->thisHour();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines Day object as first in a week
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @param boolean $state set this day as first in week
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirst($state = true)
|
||||
{
|
||||
$this->first = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines Day object as last in a week
|
||||
* Used only following Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @param boolean $state set this day as last in week
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setLast($state = true)
|
||||
{
|
||||
$this->last = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Day object is first in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isFirst()
|
||||
{
|
||||
return $this->first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Day object is last in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isLast()
|
||||
{
|
||||
return $this->last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines Day object as empty
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @param boolean $state set this day as empty
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setEmpty ($state = true)
|
||||
{
|
||||
$this->empty = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this day is empty
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isEmpty()
|
||||
{
|
||||
return $this->empty;
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,169 +1,208 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Textual.php,v 1.3 2004/08/16 13:02:44 hfuecks Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Textual.php,v 1.3 2004/08/16 13:02:44 hfuecks Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Load the Uri utility
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Textual.php';
|
||||
|
||||
/**
|
||||
* Decorator to help with fetching textual representations of months and
|
||||
* days of the week.
|
||||
* <b>Note:</b> for performance you should prefer Calendar_Util_Textual unless you
|
||||
* have a specific need to use a decorator
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Textual extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Textual
|
||||
* @param object subclass of Calendar
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Textual(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of 12 month names (first index = 1)
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function monthNames($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::monthNames($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of 7 week day names (first index = 0)
|
||||
* @param string (optional) format of returned days (one,two,short or long)
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function weekdayNames($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::weekdayNames($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous month of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prevMonthName($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::prevMonthName($this->calendar,$format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the month of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function thisMonthName($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::thisMonthName($this->calendar,$format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next month of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function nextMonthName($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::nextMonthName($this->calendar,$format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous day of week of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prevDayName($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::prevDayName($this->calendar,$format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the day of week of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function thisDayName($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::thisDayName($this->calendar,$format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next day of week of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function nextDayName($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::nextDayName($this->calendar,$format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the days of the week using the order defined in the decorated
|
||||
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
|
||||
* and Calendar_Week. Otherwise the returned array will begin on Sunday
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return array ordered array of week day names
|
||||
* @access public
|
||||
*/
|
||||
function orderedWeekdays($format='long')
|
||||
{
|
||||
return Calendar_Util_Textual::orderedWeekdays($this->calendar,$format);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Decorator_Wrapper class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Textual.php 246907 2007-11-24 11:04:24Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Load the Uri utility
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Textual.php';
|
||||
|
||||
/**
|
||||
* Decorator to help with fetching textual representations of months and
|
||||
* days of the week.
|
||||
* <b>Note:</b> for performance you should prefer Calendar_Util_Textual unless you
|
||||
* have a specific need to use a decorator
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Textual extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Textual
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Textual(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of 12 month names (first index = 1)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function monthNames($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::monthNames($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of 7 week day names (first index = 0)
|
||||
*
|
||||
* @param string $format (optional) format of returned days (one|two|short|long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function weekdayNames($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::weekdayNames($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous month of the decorated calendar object
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prevMonthName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::prevMonthName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the month of the decorated calendar object
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function thisMonthName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::thisMonthName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next month of the decorated calendar object
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function nextMonthName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::nextMonthName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous day of week of the decorated calendar object
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prevDayName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::prevDayName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the day of week of the decorated calendar object
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function thisDayName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::thisDayName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next day of week of the decorated calendar object
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function nextDayName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::nextDayName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the days of the week using the order defined in the decorated
|
||||
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
|
||||
* and Calendar_Week. Otherwise the returned array will begin on Sunday
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return array ordered array of week day names
|
||||
* @access public
|
||||
*/
|
||||
function orderedWeekdays($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::orderedWeekdays($this->calendar, $format);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,151 +1,183 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Uri.php,v 1.3 2004/08/16 09:04:20 hfuecks Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Uri.php,v 1.3 2004/08/16 09:04:20 hfuecks Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Load the Uri utility
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Uri.php';
|
||||
|
||||
/**
|
||||
* Decorator to help with building HTML links for navigating the calendar<br />
|
||||
* <b>Note:</b> for performance you should prefer Calendar_Util_Uri unless you
|
||||
* have a specific need to use a decorator
|
||||
* <code>
|
||||
* $Day = new Calendar_Day(2003, 10, 23);
|
||||
* $Uri = & new Calendar_Decorator_Uri($Day);
|
||||
* $Uri->setFragments('year', 'month', 'day');
|
||||
* echo $Uri->getPrev(); // Displays year=2003&month=10&day=22
|
||||
* </code>
|
||||
* @see Calendar_Util_Uri
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Uri extends Calendar_Decorator
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Calendar_Util_Uri
|
||||
* @access private
|
||||
*/
|
||||
var $Uri;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Uri
|
||||
* @param object subclass of Calendar
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Uri(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URI fragment names
|
||||
* @param string URI fragment for year
|
||||
* @param string (optional) URI fragment for month
|
||||
* @param string (optional) URI fragment for day
|
||||
* @param string (optional) URI fragment for hour
|
||||
* @param string (optional) URI fragment for minute
|
||||
* @param string (optional) URI fragment for second
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null) {
|
||||
$this->Uri = & new Calendar_Util_Uri($y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the separator string between fragments
|
||||
* @param string separator e.g. /
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setSeparator($separator)
|
||||
{
|
||||
$this->Uri->separator = $separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts Uri decorator into "scalar mode" - URI variable names are not
|
||||
* returned
|
||||
* @param boolean (optional)
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setScalar($state=true)
|
||||
{
|
||||
$this->Uri->scalar = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the previous calendar unit
|
||||
* @param string calendar unit to fetch uri for (year,month,week or day etc)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prev($method)
|
||||
{
|
||||
return $this->Uri->prev($this, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the current calendar unit
|
||||
* @param string calendar unit to fetch uri for (year,month,week or day etc)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function this($method)
|
||||
{
|
||||
return $this->Uri->this($this, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the next calendar unit
|
||||
* @param string calendar unit to fetch uri for (year,month,week or day etc)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function next($method)
|
||||
{
|
||||
return $this->Uri->next($this, $method);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Decorator_Uri class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Uri.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Load the Uri utility
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Uri.php';
|
||||
|
||||
/**
|
||||
* Decorator to help with building HTML links for navigating the calendar<br />
|
||||
* <b>Note:</b> for performance you should prefer Calendar_Util_Uri unless you
|
||||
* have a specific need to use a decorator
|
||||
* <code>
|
||||
* $Day = new Calendar_Day(2003, 10, 23);
|
||||
* $Uri = new Calendar_Decorator_Uri($Day);
|
||||
* $Uri->setFragments('year', 'month', 'day');
|
||||
* echo $Uri->getPrev(); // Displays year=2003&month=10&day=22
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @see Calendar_Util_Uri
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Uri extends Calendar_Decorator
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Calendar_Util_Uri
|
||||
* @access private
|
||||
*/
|
||||
var $Uri;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Uri
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Uri(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URI fragment names
|
||||
*
|
||||
* @param string $y URI fragment for year
|
||||
* @param string $m (optional) URI fragment for month
|
||||
* @param string $d (optional) URI fragment for day
|
||||
* @param string $h (optional) URI fragment for hour
|
||||
* @param string $i (optional) URI fragment for minute
|
||||
* @param string $s (optional) URI fragment for second
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFragments($y, $m = null, $d = null, $h = null, $i = null, $s = null)
|
||||
{
|
||||
$this->Uri = new Calendar_Util_Uri($y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the separator string between fragments
|
||||
*
|
||||
* @param string $separator url fragment separator e.g. /
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setSeparator($separator)
|
||||
{
|
||||
$this->Uri->separator = $separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts Uri decorator into "scalar mode" - URI variable names are not returned
|
||||
*
|
||||
* @param boolean $state (optional)
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setScalar($state = true)
|
||||
{
|
||||
$this->Uri->scalar = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the previous calendar unit
|
||||
*
|
||||
* @param string $method calendar unit to fetch uri for (year, month, week or day etc)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prev($method)
|
||||
{
|
||||
return $this->Uri->prev($this, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the current calendar unit
|
||||
*
|
||||
* @param string $method calendar unit to fetch uri for (year,month,week or day etc)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function this($method)
|
||||
{
|
||||
return $this->Uri->this($this, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the next calendar unit
|
||||
*
|
||||
* @param string $method calendar unit to fetch uri for (year,month,week or day etc)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function next($method)
|
||||
{
|
||||
return $this->Uri->next($this, $method);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,148 +1,195 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Weekday.php,v 1.3 2004/08/16 12:25:15 hfuecks Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Weekday.php,v 1.3 2004/08/16 12:25:15 hfuecks Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Load a Calendar_Day
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
/**
|
||||
* Decorator for fetching the day of the week
|
||||
* <code>
|
||||
* $Day = new Calendar_Day(2003, 10, 23);
|
||||
* $Weekday = & new Calendar_Decorator_Weekday($Day);
|
||||
* $Weekday->setFirstDay(0); // Set first day of week to Sunday (default Mon)
|
||||
* echo $Weekday->thisWeekDay(); // Displays 5 - fifth day of week relative to Sun
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Weekday extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* First day of week
|
||||
* @var int (default = 1 for Monday)
|
||||
* @access private
|
||||
*/
|
||||
var $firstDay = 1;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Weekday
|
||||
* @param object subclass of Calendar
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Weekday(& $Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the first day of the week (0 = Sunday, 1 = Monday (default) etc)
|
||||
* @param int first day of week
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFirstDay($firstDay) {
|
||||
$this->firstDay = (int)$firstDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous weekday
|
||||
* @param string (default = 'int') return value format
|
||||
* @return int numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function prevWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->prevDay('timestamp');
|
||||
$Day = new Calendar_Day(2000,1,1);
|
||||
$Day->setTimeStamp($ts);
|
||||
$day = $this->calendar->cE->getDayOfWeek($Day->thisYear(),$Day->thisMonth(),$Day->thisDay());
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current weekday
|
||||
* @param string (default = 'int') return value format
|
||||
* @return int numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function thisWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->thisDay('timestamp');
|
||||
$day = $this->calendar->cE->getDayOfWeek($this->calendar->year,$this->calendar->month,$this->calendar->day);
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next weekday
|
||||
* @param string (default = 'int') return value format
|
||||
* @return int numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function nextWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->nextDay('timestamp');
|
||||
$Day = new Calendar_Day(2000,1,1);
|
||||
$Day->setTimeStamp($ts);
|
||||
$day = $this->calendar->cE->getDayOfWeek($Day->thisYear(),$Day->thisMonth(),$Day->thisDay());
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the day of the week relative to the first day of the week
|
||||
* @param int day of week calendar from Calendar_Engine
|
||||
* @return int day of week adjusted to first day
|
||||
* @access private
|
||||
*/
|
||||
function adjustWeekScale($dayOfWeek) {
|
||||
$dayOfWeek = $dayOfWeek - $this->firstDay;
|
||||
if ( $dayOfWeek >= 0 ) {
|
||||
return $dayOfWeek;
|
||||
} else {
|
||||
return $this->calendar->cE->getDaysInWeek(
|
||||
$this->calendar->year,$this->calendar->month,$this->calendar->day
|
||||
) + $dayOfWeek;
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Decorator_Weekday class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Weekday.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Load a Calendar_Day
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
/**
|
||||
* Decorator for fetching the day of the week
|
||||
* <code>
|
||||
* $Day = new Calendar_Day(2003, 10, 23);
|
||||
* $Weekday = new Calendar_Decorator_Weekday($Day);
|
||||
* $Weekday->setFirstDay(0); // Set first day of week to Sunday (default Mon)
|
||||
* echo $Weekday->thisWeekDay(); // Displays 5 - fifth day of week relative to Sun
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Weekday extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* First day of week
|
||||
* @var int (default = 1 for Monday)
|
||||
* @access private
|
||||
*/
|
||||
var $firstDay = 1;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Weekday
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Weekday(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the first day of the week (0 = Sunday, 1 = Monday (default) etc)
|
||||
*
|
||||
* @param int $firstDay first day of week
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFirstDay($firstDay)
|
||||
{
|
||||
$this->firstDay = (int)$firstDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous weekday
|
||||
*
|
||||
* @param string $format (default = 'int') return value format
|
||||
*
|
||||
* @return int $format numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function prevWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->prevDay('timestamp');
|
||||
$Day = new Calendar_Day(2000, 1, 1);
|
||||
$Day->setTimeStamp($ts);
|
||||
$day = $this->calendar->cE->getDayOfWeek(
|
||||
$Day->thisYear(),
|
||||
$Day->thisMonth(),
|
||||
$Day->thisDay()
|
||||
);
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current weekday
|
||||
*
|
||||
* @param string $format (default = 'int') return value format
|
||||
*
|
||||
* @return int numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function thisWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->thisDay('timestamp');
|
||||
$day = $this->calendar->cE->getDayOfWeek(
|
||||
$this->calendar->year,
|
||||
$this->calendar->month,
|
||||
$this->calendar->day
|
||||
);
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next weekday
|
||||
*
|
||||
* @param string $format (default = 'int') return value format
|
||||
*
|
||||
* @return int numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function nextWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->nextDay('timestamp');
|
||||
$Day = new Calendar_Day(2000, 1, 1);
|
||||
$Day->setTimeStamp($ts);
|
||||
$day = $this->calendar->cE->getDayOfWeek(
|
||||
$Day->thisYear(),
|
||||
$Day->thisMonth(),
|
||||
$Day->thisDay()
|
||||
);
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the day of the week relative to the first day of the week
|
||||
*
|
||||
* @param int $dayOfWeek day of week calendar from Calendar_Engine
|
||||
*
|
||||
* @return int day of week adjusted to first day
|
||||
* @access private
|
||||
*/
|
||||
function adjustWeekScale($dayOfWeek)
|
||||
{
|
||||
$dayOfWeek = $dayOfWeek - $this->firstDay;
|
||||
if ($dayOfWeek >= 0) {
|
||||
return $dayOfWeek;
|
||||
} else {
|
||||
return $this->calendar->cE->getDaysInWeek(
|
||||
$this->calendar->year,
|
||||
$this->calendar->month,
|
||||
$this->calendar->day
|
||||
) + $dayOfWeek;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,90 +1,115 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Wrapper.php,v 1.2 2005/11/03 20:35:03 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Wrapper.php,v 1.2 2005/11/03 20:35:03 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Decorator to help with wrapping built children in another decorator
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Wrapper extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Wrapper
|
||||
* @param object subclass of Calendar
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Wrapper(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps objects returned from fetch in the named Decorator class
|
||||
* @param string name of Decorator class to wrap with
|
||||
* @return object instance of named decorator
|
||||
* @access public
|
||||
*/
|
||||
function & fetch($decorator)
|
||||
{
|
||||
$Calendar = parent::fetch();
|
||||
if ($Calendar) {
|
||||
$ret =& new $decorator($Calendar);
|
||||
} else {
|
||||
$ret = false;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the returned calendar objects from fetchAll in the named decorator
|
||||
* @param string name of Decorator class to wrap with
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function fetchAll($decorator)
|
||||
{
|
||||
$children = parent::fetchAll();
|
||||
foreach ($children as $key => $Calendar) {
|
||||
$children[$key] = & new $decorator($Calendar);
|
||||
}
|
||||
return $children;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Decorator_Wrapper class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Wrapper.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Decorator to help with wrapping built children in another decorator
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Wrapper extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Wrapper
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Wrapper(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps objects returned from fetch in the named Decorator class
|
||||
*
|
||||
* @param string $decorator name of Decorator class to wrap with
|
||||
*
|
||||
* @return object instance of named decorator
|
||||
* @access public
|
||||
*/
|
||||
function & fetch($decorator)
|
||||
{
|
||||
$Calendar = parent::fetch();
|
||||
if ($Calendar) {
|
||||
$ret = new $decorator($Calendar);
|
||||
} else {
|
||||
$ret = false;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the returned calendar objects from fetchAll in the named decorator
|
||||
*
|
||||
* @param string $decorator name of Decorator class to wrap with
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function fetchAll($decorator)
|
||||
{
|
||||
$children = parent::fetchAll();
|
||||
foreach ($children as $key => $Calendar) {
|
||||
$children[$key] = new $decorator($Calendar);
|
||||
}
|
||||
return $children;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,293 +1,377 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Interface.php,v 1.5 2004/08/16 12:29:18 hfuecks Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Interface.php,v 1.5 2004/08/16 12:29:18 hfuecks Exp $
|
||||
*/
|
||||
/**
|
||||
* The methods the classes implementing the Calendar_Engine must implement.
|
||||
* Note this class is not used but simply to help development
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_Interface
|
||||
{
|
||||
/**
|
||||
* Provides a mechansim to make sure parsing of timestamps
|
||||
* into human dates is only performed once per timestamp.
|
||||
* Typically called "internally" by methods like stampToYear.
|
||||
* Return value can vary, depending on the specific implementation
|
||||
* @param int timestamp (depending on implementation)
|
||||
* @return mixed
|
||||
* @access protected
|
||||
*/
|
||||
function stampCollection($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric year given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToYear($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric month given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMonth($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric day given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToDay($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric hour given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToHour($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric minute given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMinute($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric second given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToSecond($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp. Can be worth "caching" generated
|
||||
* timestamps in a static variable, identified by the
|
||||
* params this method accepts, to timestamp will only
|
||||
* be calculated once.
|
||||
* @param int year (e.g. 2003)
|
||||
* @param int month (e.g. 9)
|
||||
* @param int day (e.g. 13)
|
||||
* @param int hour (e.g. 13)
|
||||
* @param int minute (e.g. 34)
|
||||
* @param int second (e.g. 53)
|
||||
* @return int (depends on implementation)
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y,$m,$d,$h,$i,$s)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
* @return int (e.g. 2037)
|
||||
* @access protected
|
||||
*/
|
||||
function getMaxYears()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
* @return int (e.g 1902)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinYears()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
* @param int (optional) year to get months for
|
||||
* @return int (e.g. 12)
|
||||
* @access protected
|
||||
*/
|
||||
function getMonthsInYear($y=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
* @param int year (e.g. 2003)
|
||||
* @param int month (e.g. 9)
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInMonth($y, $m)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
* @param int year (e.g. 2003)
|
||||
* @param int month (e.g. 9)
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayInMonth ($y, $m)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int (e.g. 7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @param int first day of the week (default: 1 - monday)
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInMonth($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int first day of the week (default: 1 - monday)
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeeksInMonth($y, $m)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
function getDayOfWeek($y, $m, $d)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numeric values of the days of the week.
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return array list of numeric values of days in week, beginning 0
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week as an integer. Must be a
|
||||
* member of the array returned from getWeekDays
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int (e.g. 1 for Monday)
|
||||
* @see getWeekDays
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day<br>
|
||||
* @param int (optional) day to get hours for
|
||||
* @return int (e.g. 24)
|
||||
* @access protected
|
||||
*/
|
||||
function getHoursInDay($y=null,$m=null,$d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
* @param int (optional) hour to get minutes for
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getMinutesInHour($y=null,$m=null,$d=null,$h=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
* @param int (optional) minute to get seconds for
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
|
||||
{
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Engine_Interface class (interface)
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Interface.php 269074 2008-11-15 21:21:42Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* The methods the classes implementing the Calendar_Engine must implement.
|
||||
* Note this class is not used but simply to help development
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_Interface
|
||||
{
|
||||
/**
|
||||
* Provides a mechansim to make sure parsing of timestamps
|
||||
* into human dates is only performed once per timestamp.
|
||||
* Typically called "internally" by methods like stampToYear.
|
||||
* Return value can vary, depending on the specific implementation
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return mixed
|
||||
* @access protected
|
||||
*/
|
||||
function stampCollection($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric year given a timestamp
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToYear($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric month given a timestamp
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMonth($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric day given a timestamp
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToDay($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric hour given a timestamp
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToHour($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric minute given a timestamp
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMinute($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric second given a timestamp
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToSecond($stamp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp. Can be worth "caching" generated timestamps in a
|
||||
* static variable, identified by the params this method accepts,
|
||||
* to timestamp will only be calculated once.
|
||||
*
|
||||
* @param int $y year (e.g. 2003)
|
||||
* @param int $m month (e.g. 9)
|
||||
* @param int $d day (e.g. 13)
|
||||
* @param int $h hour (e.g. 13)
|
||||
* @param int $i minute (e.g. 34)
|
||||
* @param int $s second (e.g. 53)
|
||||
*
|
||||
* @return int (depends on implementation)
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y, $m, $d, $h, $i, $s)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (e.g. 2037)
|
||||
* @access protected
|
||||
*/
|
||||
function getMaxYears()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (e.g 1902)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinYears()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
*
|
||||
* @param int $y (optional) year to get months for
|
||||
*
|
||||
* @return int (e.g. 12)
|
||||
* @access protected
|
||||
*/
|
||||
function getMonthsInYear($y=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
*
|
||||
* @param int $y year (e.g. 2003)
|
||||
* @param int $m month (e.g. 9)
|
||||
*
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInMonth($y, $m)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
*
|
||||
* @param int $y year (e.g. 2003)
|
||||
* @param int $m month (e.g. 9)
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayInMonth ($y, $m)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (e.g. 7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $firstDay first day of the week (default: 1 - monday)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInMonth($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeeksInMonth($y, $m)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
function getDayOfWeek($y, $m, $d)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numeric values of the days of the week.
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return array list of numeric values of days in week, beginning 0
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=null, $m=null, $d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week as an integer. Must be a
|
||||
* member of the array returned from getWeekDays
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (e.g. 1 for Monday)
|
||||
* @see getWeekDays
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (e.g. 24)
|
||||
* @access protected
|
||||
*/
|
||||
function getHoursInDay($y=null,$m=null,$d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getMinutesInHour($y=null,$m=null,$d=null,$h=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given day is the current day
|
||||
*
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function isToday($stamp)
|
||||
{
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,407 +1,509 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $
|
||||
*/
|
||||
/**
|
||||
* Load PEAR::Date class
|
||||
*/
|
||||
require_once 'Date.php';
|
||||
|
||||
/**
|
||||
* Performs calendar calculations based on the PEAR::Date class
|
||||
* Timestamps are in the ISO-8601 format (YYYY-MM-DD HH:MM:SS)
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
||||
{
|
||||
/**
|
||||
* Makes sure a given timestamp is only ever parsed once
|
||||
* Uses a static variable to prevent date() being used twice
|
||||
* for a date which is already known
|
||||
* @param mixed Any timestamp format recognized by Pear::Date
|
||||
* @return object Pear::Date object
|
||||
* @access protected
|
||||
*/
|
||||
function stampCollection($stamp)
|
||||
{
|
||||
static $stamps = array();
|
||||
if (!isset($stamps[$stamp])) {
|
||||
$stamps[$stamp] = new Date($stamp);
|
||||
}
|
||||
return $stamps[$stamp];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric year given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToYear($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->year;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric month given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMonth($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->month;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric day given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToDay($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->day;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric hour given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToHour($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->hour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric minute given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMinute($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->minute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric second given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToSecond($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a iso-8601 datetime
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (13)
|
||||
* @param int hour (13)
|
||||
* @param int minute (34)
|
||||
* @param int second (53)
|
||||
* @return string iso-8601 datetime
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0)
|
||||
{
|
||||
$r = array();
|
||||
Calendar_Engine_PearDate::adjustDate($y, $m, $d, $h, $i, $s);
|
||||
$key = $y.$m.$d.$h.$i.$s;
|
||||
if (!isset($r[$key])) {
|
||||
$r[$key] = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
|
||||
$y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
return $r[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the correct date values (useful for math operations on dates)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (13)
|
||||
* @param int hour (13)
|
||||
* @param int minute (34)
|
||||
* @param int second (53)
|
||||
* @access protected
|
||||
*/
|
||||
function adjustDate(&$y, &$m, &$d, &$h, &$i, &$s)
|
||||
{
|
||||
if ($s < 0) {
|
||||
$m -= floor($s / 60);
|
||||
$s = -$s % 60;
|
||||
}
|
||||
if ($s > 60) {
|
||||
$m += floor($s / 60);
|
||||
$s %= 60;
|
||||
}
|
||||
if ($i < 0) {
|
||||
$h -= floor($i / 60);
|
||||
$i = -$i % 60;
|
||||
}
|
||||
if ($i > 60) {
|
||||
$h += floor($i / 60);
|
||||
$i %= 60;
|
||||
}
|
||||
if ($h < 0) {
|
||||
$d -= floor($h / 24);
|
||||
$h = -$h % 24;
|
||||
}
|
||||
if ($h > 24) {
|
||||
$d += floor($h / 24);
|
||||
$h %= 24;
|
||||
}
|
||||
for(; $m < 1; $y--, $m+=12);
|
||||
for(; $m > 12; $y++, $m-=12);
|
||||
|
||||
while ($d < 1) {
|
||||
if ($m > 1) {
|
||||
$m--;
|
||||
} else {
|
||||
$m = 12;
|
||||
$y--;
|
||||
}
|
||||
$d += Date_Calc::daysInMonth($m, $y);
|
||||
}
|
||||
for ($max_days = Date_Calc::daysInMonth($m, $y); $d > $max_days; ) {
|
||||
$d -= $max_days;
|
||||
if ($m < 12) {
|
||||
$m++;
|
||||
} else {
|
||||
$m = 1;
|
||||
$y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
* @return int 9999
|
||||
* @access protected
|
||||
*/
|
||||
function getMaxYears()
|
||||
{
|
||||
return 9999;
|
||||
}
|
||||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
* @return int 0
|
||||
* @access protected
|
||||
*/
|
||||
function getMinYears()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
* @return int (12)
|
||||
* @access protected
|
||||
*/
|
||||
function getMonthsInYear($y=null)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInMonth($y, $m)
|
||||
{
|
||||
return (int)Date_Calc::daysInMonth($m, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @return int from 0 to 7
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayInMonth($y, $m)
|
||||
{
|
||||
return (int)Date_Calc::dayOfWeek(1, $m, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int (7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard!
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @param int first day of the week (default: monday)
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInMonth($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
$weekEnd = ($firstDay == 0) ? $this->getDaysInWeek()-1 : $firstDay-1;
|
||||
$end_of_week = (int)Date_Calc::nextDayOfWeek($weekEnd, 1, $m, $y, '%e', true);
|
||||
$w = 1;
|
||||
while ($d > $end_of_week) {
|
||||
++$w;
|
||||
$end_of_week += $this->getDaysInWeek();
|
||||
}
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int first day of the week (default: monday)
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeeksInMonth($y, $m, $firstDay=1)
|
||||
{
|
||||
$FDOM = Date_Calc::firstOfMonthWeekday($m, $y);
|
||||
if ($FDOM == 0) {
|
||||
$FDOM = $this->getDaysInWeek();
|
||||
}
|
||||
if ($FDOM > $firstDay) {
|
||||
$daysInTheFirstWeek = $this->getDaysInWeek() - $FDOM + $firstDay;
|
||||
$weeks = 1;
|
||||
} else {
|
||||
$daysInTheFirstWeek = $firstDay - $FDOM;
|
||||
$weeks = 0;
|
||||
}
|
||||
$daysInTheFirstWeek %= $this->getDaysInWeek();
|
||||
return (int)(ceil(($this->getDaysInMonth($y, $m) - $daysInTheFirstWeek) /
|
||||
$this->getDaysInWeek()) + $weeks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
function getDayOfWeek($y, $m, $d)
|
||||
{
|
||||
return Date_Calc::dayOfWeek($d, $m, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of integer days of the week beginning 0
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
return array(0, 1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int (default 1 = Monday)
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day
|
||||
* @return int (24)
|
||||
* @access protected
|
||||
*/
|
||||
function getHoursInDay($y=null,$m=null,$d=null)
|
||||
{
|
||||
return 24;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinutesInHour($y=null,$m=null,$d=null,$h=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Engine_PearDate class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: PearDate.php 269076 2008-11-15 21:41:38Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Load PEAR::Date class
|
||||
*/
|
||||
require_once 'Date.php';
|
||||
|
||||
/**
|
||||
* Performs calendar calculations based on the PEAR::Date class
|
||||
* Timestamps are in the ISO-8601 format (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
||||
{
|
||||
/**
|
||||
* Makes sure a given timestamp is only ever parsed once
|
||||
* Uses a static variable to prevent date() being used twice
|
||||
* for a date which is already known
|
||||
*
|
||||
* @param mixed $stamp Any timestamp format recognized by Pear::Date
|
||||
*
|
||||
* @return object Pear::Date object
|
||||
* @access protected
|
||||
*/
|
||||
function stampCollection($stamp)
|
||||
{
|
||||
static $stamps = array();
|
||||
if (!isset($stamps[$stamp])) {
|
||||
$stamps[$stamp] = new Date($stamp);
|
||||
}
|
||||
return $stamps[$stamp];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric year given a iso-8601 datetime
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToYear($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->year;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric month given a iso-8601 datetime
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMonth($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->month;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric day given a iso-8601 datetime
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToDay($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->day;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric hour given a iso-8601 datetime
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToHour($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->hour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric minute given a iso-8601 datetime
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMinute($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->minute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric second given a iso-8601 datetime
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToSecond($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return (int)$date->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a iso-8601 datetime
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (13)
|
||||
* @param int $h hour (13)
|
||||
* @param int $i minute (34)
|
||||
* @param int $s second (53)
|
||||
*
|
||||
* @return string iso-8601 datetime
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0)
|
||||
{
|
||||
$r = array();
|
||||
Calendar_Engine_PearDate::adjustDate($y, $m, $d, $h, $i, $s);
|
||||
$key = $y.$m.$d.$h.$i.$s;
|
||||
if (!isset($r[$key])) {
|
||||
$r[$key] = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
|
||||
$y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
return $r[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the correct date values (useful for math operations on dates)
|
||||
*
|
||||
* @param int &$y year (2003)
|
||||
* @param int &$m month (9)
|
||||
* @param int &$d day (13)
|
||||
* @param int &$h hour (13)
|
||||
* @param int &$i minute (34)
|
||||
* @param int &$s second (53)
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function adjustDate(&$y, &$m, &$d, &$h, &$i, &$s)
|
||||
{
|
||||
if ($s < 0) {
|
||||
$m -= floor($s / 60);
|
||||
$s = -$s % 60;
|
||||
}
|
||||
if ($s > 60) {
|
||||
$m += floor($s / 60);
|
||||
$s %= 60;
|
||||
}
|
||||
if ($i < 0) {
|
||||
$h -= floor($i / 60);
|
||||
$i = -$i % 60;
|
||||
}
|
||||
if ($i > 60) {
|
||||
$h += floor($i / 60);
|
||||
$i %= 60;
|
||||
}
|
||||
if ($h < 0) {
|
||||
$d -= floor($h / 24);
|
||||
$h = -$h % 24;
|
||||
}
|
||||
if ($h > 24) {
|
||||
$d += floor($h / 24);
|
||||
$h %= 24;
|
||||
}
|
||||
for(; $m < 1; $y--, $m+=12);
|
||||
for(; $m > 12; $y++, $m-=12);
|
||||
|
||||
while ($d < 1) {
|
||||
if ($m > 1) {
|
||||
$m--;
|
||||
} else {
|
||||
$m = 12;
|
||||
$y--;
|
||||
}
|
||||
$d += Date_Calc::daysInMonth($m, $y);
|
||||
}
|
||||
for ($max_days = Date_Calc::daysInMonth($m, $y); $d > $max_days; ) {
|
||||
$d -= $max_days;
|
||||
if ($m < 12) {
|
||||
$m++;
|
||||
} else {
|
||||
$m = 1;
|
||||
$y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int 9999
|
||||
* @access protected
|
||||
*/
|
||||
function getMaxYears()
|
||||
{
|
||||
return 9999;
|
||||
}
|
||||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int 0
|
||||
* @access protected
|
||||
*/
|
||||
function getMinYears()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
*
|
||||
* @param int $y year
|
||||
*
|
||||
* @return int (12)
|
||||
* @access protected
|
||||
*/
|
||||
function getMonthsInYear($y=null)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInMonth($y, $m)
|
||||
{
|
||||
return (int)Date_Calc::daysInMonth($m, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int from 0 to 7
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayInMonth($y, $m)
|
||||
{
|
||||
return (int)Date_Calc::dayOfWeek(1, $m, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
//return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard!
|
||||
list($nYear, $nWeek) = Date_Calc::weekOfYear4th($d, $m, $y);
|
||||
return $nWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInMonth($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
$weekEnd = ($firstDay == 0) ? $this->getDaysInWeek()-1 : $firstDay-1;
|
||||
$end_of_week = (int)Date_Calc::nextDayOfWeek($weekEnd, 1, $m, $y, '%e', true);
|
||||
$w = 1;
|
||||
while ($d > $end_of_week) {
|
||||
++$w;
|
||||
$end_of_week += $this->getDaysInWeek();
|
||||
}
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeeksInMonth($y, $m, $firstDay=1)
|
||||
{
|
||||
$FDOM = Date_Calc::firstOfMonthWeekday($m, $y);
|
||||
if ($FDOM == 0) {
|
||||
$FDOM = $this->getDaysInWeek();
|
||||
}
|
||||
if ($FDOM > $firstDay) {
|
||||
$daysInTheFirstWeek = $this->getDaysInWeek() - $FDOM + $firstDay;
|
||||
$weeks = 1;
|
||||
} else {
|
||||
$daysInTheFirstWeek = $firstDay - $FDOM;
|
||||
$weeks = 0;
|
||||
}
|
||||
$daysInTheFirstWeek %= $this->getDaysInWeek();
|
||||
return (int)(ceil(($this->getDaysInMonth($y, $m) - $daysInTheFirstWeek) /
|
||||
$this->getDaysInWeek()) + $weeks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
function getDayOfWeek($y, $m, $d)
|
||||
{
|
||||
return Date_Calc::dayOfWeek($d, $m, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of integer days of the week beginning 0
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=null, $m=null, $d=null)
|
||||
{
|
||||
return array(0, 1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (default 1 = Monday)
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (24)
|
||||
* @access protected
|
||||
*/
|
||||
function getHoursInDay($y=null,$m=null,$d=null)
|
||||
{
|
||||
return 24;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinutesInHour($y=null,$m=null,$d=null,$h=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given day is the current day
|
||||
*
|
||||
* @param mixed $stamp Any timestamp format recognized by Pear::Date
|
||||
*
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function isToday($stamp)
|
||||
{
|
||||
static $today = null;
|
||||
if (is_null($today)) {
|
||||
$today = new Date();
|
||||
}
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return ( $date->day == $today->getDay()
|
||||
&& $date->month == $today->getMonth()
|
||||
&& $date->year == $today->getYear()
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,365 +1,463 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: UnixTS.php,v 1.9 2004/08/20 20:00:55 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: UnixTS.php,v 1.9 2004/08/20 20:00:55 quipo Exp $
|
||||
*/
|
||||
/**
|
||||
* Performs calendar calculations based on the PHP date() function and
|
||||
* Unix timestamps (using PHP's mktime() function).
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
||||
{
|
||||
/**
|
||||
* Makes sure a given timestamp is only ever parsed once
|
||||
* <pre>
|
||||
* array (
|
||||
* [0] => year (e.g 2003),
|
||||
* [1] => month (e.g 9),
|
||||
* [2] => day (e.g 6),
|
||||
* [3] => hour (e.g 14),
|
||||
* [4] => minute (e.g 34),
|
||||
* [5] => second (e.g 45),
|
||||
* [6] => num days in month (e.g. 31),
|
||||
* [7] => week in year (e.g. 50),
|
||||
* [8] => day in week (e.g. 0 for Sunday)
|
||||
* )
|
||||
* </pre>
|
||||
* Uses a static variable to prevent date() being used twice
|
||||
* for a date which is already known
|
||||
* @param int Unix timestamp
|
||||
* @return array
|
||||
* @access protected
|
||||
*/
|
||||
function stampCollection($stamp)
|
||||
{
|
||||
static $stamps = array();
|
||||
if ( !isset($stamps[$stamp]) ) {
|
||||
$date = @date('Y n j H i s t W w',$stamp);
|
||||
$stamps[$stamp] = sscanf($date, "%d %d %d %d %d %d %d %d %d");
|
||||
}
|
||||
return $stamps[$stamp];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric year given a timestamp
|
||||
* @param int Unix timestamp
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToYear($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric month given a timestamp
|
||||
* @param int Unix timestamp
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMonth($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric day given a timestamp
|
||||
* @param int Unix timestamp
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToDay($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric hour given a timestamp
|
||||
* @param int Unix timestamp
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToHour($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric minute given a timestamp
|
||||
* @param int Unix timestamp
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMinute($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[4];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric second given a timestamp
|
||||
* @param int Unix timestamp
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToSecond($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[5];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (13)
|
||||
* @param int hour (13)
|
||||
* @param int minute (34)
|
||||
* @param int second (53)
|
||||
* @return int Unix timestamp
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0)
|
||||
{
|
||||
static $dates = array();
|
||||
if ( !isset($dates[$y][$m][$d][$h][$i][$s]) ) {
|
||||
$dates[$y][$m][$d][$h][$i][$s] = @mktime($h, $i, $s, $m, $d, $y);
|
||||
}
|
||||
return $dates[$y][$m][$d][$h][$i][$s];
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
* @return int (2037)
|
||||
* @access protected
|
||||
*/
|
||||
function getMaxYears()
|
||||
{
|
||||
return 2037;
|
||||
}
|
||||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
* @return int (1970 if it's Windows and 1902 for all other OSs)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinYears()
|
||||
{
|
||||
return $min = strpos(PHP_OS, 'WIN') === false ? 1902 : 1970;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
* @return int (12)
|
||||
* @access protected
|
||||
*/
|
||||
function getMonthsInYear($y=null)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInMonth($y, $m)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[6];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @return int from 0 to 6
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayInMonth($y, $m)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[8];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int (7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,$d);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[7];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @param int first day of the week (default: monday)
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInMonth($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
$weekEnd = ($firstDay == 0) ? $this->getDaysInWeek()-1 : $firstDay-1;
|
||||
$end_of_week = 1;
|
||||
while (@date('w', @mktime(0, 0, 0, $m, $end_of_week, $y)) != $weekEnd) {
|
||||
++$end_of_week; //find first weekend of the month
|
||||
}
|
||||
$w = 1;
|
||||
while ($d > $end_of_week) {
|
||||
++$w;
|
||||
$end_of_week += $this->getDaysInWeek();
|
||||
}
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int first day of the week (default: monday)
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeeksInMonth($y, $m, $firstDay=1)
|
||||
{
|
||||
$FDOM = $this->getFirstDayInMonth($y, $m);
|
||||
if ($FDOM == 0) {
|
||||
$FDOM = $this->getDaysInWeek();
|
||||
}
|
||||
if ($FDOM > $firstDay) {
|
||||
$daysInTheFirstWeek = $this->getDaysInWeek() - $FDOM + $firstDay;
|
||||
$weeks = 1;
|
||||
} else {
|
||||
$daysInTheFirstWeek = $firstDay - $FDOM;
|
||||
$weeks = 0;
|
||||
}
|
||||
$daysInTheFirstWeek %= $this->getDaysInWeek();
|
||||
return (int)(ceil(($this->getDaysInMonth($y, $m) - $daysInTheFirstWeek) /
|
||||
$this->getDaysInWeek()) + $weeks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
function getDayOfWeek($y, $m, $d)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,$d);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[8];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of integer days of the week beginning 0
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return array (0,1,2,3,4,5,6) 1 = Monday
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
return array(0, 1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @return int (default 1 = Monday)
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day
|
||||
* @return int (24)
|
||||
* @access protected
|
||||
*/
|
||||
function getHoursInDay($y=null,$m=null,$d=null)
|
||||
{
|
||||
return 24;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinutesInHour($y=null,$m=null,$d=null,$h=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Engine_UnixTS class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: UnixTS.php 269074 2008-11-15 21:21:42Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Performs calendar calculations based on the PHP date() function and
|
||||
* Unix timestamps (using PHP's mktime() function).
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
||||
{
|
||||
/**
|
||||
* Makes sure a given timestamp is only ever parsed once
|
||||
* <pre>
|
||||
* array (
|
||||
* [0] => year (e.g 2003),
|
||||
* [1] => month (e.g 9),
|
||||
* [2] => day (e.g 6),
|
||||
* [3] => hour (e.g 14),
|
||||
* [4] => minute (e.g 34),
|
||||
* [5] => second (e.g 45),
|
||||
* [6] => num days in month (e.g. 31),
|
||||
* [7] => week in year (e.g. 50),
|
||||
* [8] => day in week (e.g. 0 for Sunday)
|
||||
* )
|
||||
* </pre>
|
||||
* Uses a static variable to prevent date() being used twice
|
||||
* for a date which is already known
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return array
|
||||
* @access protected
|
||||
*/
|
||||
function stampCollection($stamp)
|
||||
{
|
||||
static $stamps = array();
|
||||
if ( !isset($stamps[$stamp]) ) {
|
||||
$date = @date('Y n j H i s t W w', $stamp);
|
||||
$stamps[$stamp] = sscanf($date, "%d %d %d %d %d %d %d %d %d");
|
||||
}
|
||||
return $stamps[$stamp];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric year given a timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToYear($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric month given a timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMonth($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric day given a timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToDay($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric hour given a timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToHour($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric minute given a timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToMinute($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[4];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric second given a timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
function stampToSecond($stamp)
|
||||
{
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return (int)$date[5];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (13)
|
||||
* @param int $h hour (13)
|
||||
* @param int $i minute (34)
|
||||
* @param int $s second (53)
|
||||
*
|
||||
* @return int Unix timestamp
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0)
|
||||
{
|
||||
static $dates = array();
|
||||
if (!isset($dates[$y][$m][$d][$h][$i][$s])) {
|
||||
$dates[$y][$m][$d][$h][$i][$s] = @mktime($h, $i, $s, $m, $d, $y);
|
||||
}
|
||||
return $dates[$y][$m][$d][$h][$i][$s];
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (2037)
|
||||
* @access protected
|
||||
*/
|
||||
function getMaxYears()
|
||||
{
|
||||
return 2037;
|
||||
}
|
||||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (1970 if it's Windows and 1902 for all other OSs)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinYears()
|
||||
{
|
||||
return $min = strpos(PHP_OS, 'WIN') === false ? 1902 : 1970;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
*
|
||||
* @param int $y year
|
||||
*
|
||||
* @return int (12)
|
||||
* @access protected
|
||||
*/
|
||||
function getMonthsInYear($y=null)
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInMonth($y, $m)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[6];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int from 0 to 6
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayInMonth($y, $m)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[8];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, $d);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[7];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInMonth($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
$weekEnd = (0 == $firstDay) ? $this->getDaysInWeek()-1 : $firstDay-1;
|
||||
$end_of_week = 1;
|
||||
while (@date('w', @mktime(0, 0, 0, $m, $end_of_week, $y)) != $weekEnd) {
|
||||
++$end_of_week; //find first weekend of the month
|
||||
}
|
||||
$w = 1;
|
||||
while ($d > $end_of_week) {
|
||||
++$w;
|
||||
$end_of_week += $this->getDaysInWeek();
|
||||
}
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeeksInMonth($y, $m, $firstDay = 1)
|
||||
{
|
||||
$FDOM = $this->getFirstDayInMonth($y, $m);
|
||||
if ($FDOM == 0) {
|
||||
$FDOM = $this->getDaysInWeek();
|
||||
}
|
||||
if ($FDOM > $firstDay) {
|
||||
$daysInTheFirstWeek = $this->getDaysInWeek() - $FDOM + $firstDay;
|
||||
$weeks = 1;
|
||||
} else {
|
||||
$daysInTheFirstWeek = $firstDay - $FDOM;
|
||||
$weeks = 0;
|
||||
}
|
||||
$daysInTheFirstWeek %= $this->getDaysInWeek();
|
||||
return (int)(ceil(($this->getDaysInMonth($y, $m) - $daysInTheFirstWeek) /
|
||||
$this->getDaysInWeek()) + $weeks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
function getDayOfWeek($y, $m, $d)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, $d);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[8];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of integer days of the week beginning 0
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return array (0,1,2,3,4,5,6) 1 = Monday
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=null, $m=null, $d=null)
|
||||
{
|
||||
return array(0, 1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (default 1 = Monday)
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (24)
|
||||
* @access protected
|
||||
*/
|
||||
function getHoursInDay($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 24;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinutesInHour($y=null, $m=null, $d=null, $h=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null, $m=null, $d=null, $h=null, $i=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given day is the current day
|
||||
*
|
||||
* @param mixed $stamp Any timestamp format recognized by Pear::Date
|
||||
*
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function isToday($stamp)
|
||||
{
|
||||
static $today = null;
|
||||
if (is_null($today)) {
|
||||
$today_date = @date('Y n j');
|
||||
$today = sscanf($today_date, '%d %d %d');
|
||||
}
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return ( $date[2] == $today[2]
|
||||
&& $date[1] == $today[1]
|
||||
&& $date[0] == $today[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,145 +1,168 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Contains a factory method to return a Singleton instance of a class
|
||||
* implementing the Calendar_Engine_Interface.<br>
|
||||
* For Month objects, to control type of month returned, use CALENDAR_MONTH_STATE
|
||||
* constact e.g.;
|
||||
* <code>
|
||||
* require_once 'Calendar/Factory.php';
|
||||
* define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
|
||||
* </code>
|
||||
* It defaults to building Calendar_Month objects.<br>
|
||||
* Use the constract CALENDAR_FIRST_DAY_OF_WEEK to control the first day of the week
|
||||
* for Month or Week objects (e.g. 0 = Sunday, 6 = Saturday)
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Factory
|
||||
{
|
||||
/**
|
||||
* Creates a calendar object given the type and units
|
||||
* @param string class of calendar object to create
|
||||
* @param int year
|
||||
* @param int month
|
||||
* @param int day
|
||||
* @param int hour
|
||||
* @param int minute
|
||||
* @param int second
|
||||
* @return object subclass of Calendar
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function create($type, $y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
|
||||
{
|
||||
$firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1;
|
||||
switch ($type) {
|
||||
case 'Day':
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
return new Calendar_Day($y,$m,$d);
|
||||
case 'Month':
|
||||
// Set default state for which month type to build
|
||||
if (!defined('CALENDAR_MONTH_STATE')) {
|
||||
define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
|
||||
}
|
||||
switch (CALENDAR_MONTH_STATE) {
|
||||
case CALENDAR_USE_MONTH_WEEKDAYS:
|
||||
require_once CALENDAR_ROOT.'Month/Weekdays.php';
|
||||
$class = 'Calendar_Month_Weekdays';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH_WEEKS:
|
||||
require_once CALENDAR_ROOT.'Month/Weeks.php';
|
||||
$class = 'Calendar_Month_Weeks';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH:
|
||||
default:
|
||||
require_once CALENDAR_ROOT.'Month.php';
|
||||
$class = 'Calendar_Month';
|
||||
break;
|
||||
}
|
||||
return new $class($y, $m, $firstDay);
|
||||
case 'Week':
|
||||
require_once CALENDAR_ROOT.'Week.php';
|
||||
return new Calendar_Week($y, $m, $d, $firstDay);
|
||||
case 'Hour':
|
||||
require_once CALENDAR_ROOT.'Hour.php';
|
||||
return new Calendar_Hour($y, $m, $d, $h);
|
||||
case 'Minute':
|
||||
require_once CALENDAR_ROOT.'Minute.php';
|
||||
return new Calendar_Minute($y, $m, $d, $h, $i);
|
||||
case 'Second':
|
||||
require_once CALENDAR_ROOT.'Second.php';
|
||||
return new Calendar_Second($y,$m,$d,$h,$i,$s);
|
||||
case 'Year':
|
||||
require_once CALENDAR_ROOT.'Year.php';
|
||||
return new Calendar_Year($y);
|
||||
default:
|
||||
require_once 'PEAR.php';
|
||||
PEAR::raiseError(
|
||||
'Calendar_Factory::create() unrecognised type: '.$type, null, PEAR_ERROR_TRIGGER,
|
||||
E_USER_NOTICE, 'Calendar_Factory::create()');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates an instance of a calendar object, given a type and timestamp
|
||||
* @param string type of object to create
|
||||
* @param mixed timestamp (depending on Calendar engine being used)
|
||||
* @return object subclass of Calendar
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function & createByTimestamp($type, $stamp)
|
||||
{
|
||||
$cE = & Calendar_Engine_Factory::getEngine();
|
||||
$y = $cE->stampToYear($stamp);
|
||||
$m = $cE->stampToMonth($stamp);
|
||||
$d = $cE->stampToDay($stamp);
|
||||
$h = $cE->stampToHour($stamp);
|
||||
$i = $cE->stampToMinute($stamp);
|
||||
$s = $cE->stampToSecond($stamp);
|
||||
$cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s);
|
||||
return $cal;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Factory class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Factory.php 246404 2007-11-18 21:46:43Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Contains a factory method to return a Singleton instance of a class
|
||||
* implementing the Calendar_Engine_Interface.<br>
|
||||
* For Month objects, to control type of month returned, use CALENDAR_MONTH_STATE
|
||||
* constact e.g.;
|
||||
* <code>
|
||||
* require_once 'Calendar/Factory.php';
|
||||
* define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
|
||||
* </code>
|
||||
* It defaults to building Calendar_Month objects.<br>
|
||||
* Use the constract CALENDAR_FIRST_DAY_OF_WEEK to control the first day of the week
|
||||
* for Month or Week objects (e.g. 0 = Sunday, 6 = Saturday)
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Factory
|
||||
{
|
||||
/**
|
||||
* Creates a calendar object given the type and units
|
||||
*
|
||||
* @param string $type class of calendar object to create
|
||||
* @param int $y year
|
||||
* @param int $m month
|
||||
* @param int $d day
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
* @param int $s second
|
||||
*
|
||||
* @return object subclass of Calendar
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
static function create($type, $y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
|
||||
{
|
||||
$firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1;
|
||||
switch ($type) {
|
||||
case 'Day':
|
||||
include_once CALENDAR_ROOT.'Day.php';
|
||||
return new Calendar_Day($y, $m, $d);
|
||||
case 'Month':
|
||||
// Set default state for which month type to build
|
||||
if (!defined('CALENDAR_MONTH_STATE')) {
|
||||
define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
|
||||
}
|
||||
switch (CALENDAR_MONTH_STATE) {
|
||||
case CALENDAR_USE_MONTH_WEEKDAYS:
|
||||
include_once CALENDAR_ROOT.'Month/Weekdays.php';
|
||||
$class = 'Calendar_Month_Weekdays';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH_WEEKS:
|
||||
include_once CALENDAR_ROOT.'Month/Weeks.php';
|
||||
$class = 'Calendar_Month_Weeks';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH:
|
||||
default:
|
||||
include_once CALENDAR_ROOT.'Month.php';
|
||||
$class = 'Calendar_Month';
|
||||
break;
|
||||
}
|
||||
return new $class($y, $m, $firstDay);
|
||||
case 'Week':
|
||||
include_once CALENDAR_ROOT.'Week.php';
|
||||
return new Calendar_Week($y, $m, $d, $firstDay);
|
||||
case 'Hour':
|
||||
include_once CALENDAR_ROOT.'Hour.php';
|
||||
return new Calendar_Hour($y, $m, $d, $h);
|
||||
case 'Minute':
|
||||
include_once CALENDAR_ROOT.'Minute.php';
|
||||
return new Calendar_Minute($y, $m, $d, $h, $i);
|
||||
case 'Second':
|
||||
include_once CALENDAR_ROOT.'Second.php';
|
||||
return new Calendar_Second($y, $m, $d, $h, $i, $s);
|
||||
case 'Year':
|
||||
include_once CALENDAR_ROOT.'Year.php';
|
||||
return new Calendar_Year($y);
|
||||
default:
|
||||
include_once 'PEAR.php';
|
||||
PEAR::raiseError('Calendar_Factory::create() unrecognised type: '.$type,
|
||||
null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Factory::create()');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of a calendar object, given a type and timestamp
|
||||
*
|
||||
* @param string $type type of object to create
|
||||
* @param mixed $stamp timestamp (depending on Calendar engine being used)
|
||||
*
|
||||
* @return object subclass of Calendar
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
static function & createByTimestamp($type, $stamp)
|
||||
{
|
||||
$cE = & Calendar_Engine_Factory::getEngine();
|
||||
$y = $cE->stampToYear($stamp);
|
||||
$m = $cE->stampToMonth($stamp);
|
||||
$d = $cE->stampToDay($stamp);
|
||||
$h = $cE->stampToHour($stamp);
|
||||
$i = $cE->stampToMinute($stamp);
|
||||
$s = $cE->stampToSecond($stamp);
|
||||
$cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s);
|
||||
return $cal;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -1,113 +1,137 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Hour.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Hour.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents an Hour and builds Minutes
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Hour.php';
|
||||
* $Hour = & new Calendar_Hour(2003, 10, 21, 15); // Oct 21st 2003, 3pm
|
||||
* $Hour->build(); // Build Calendar_Minute objects
|
||||
* while ($Minute = & $Hour->fetch()) {
|
||||
* echo $Minute->thisMinute().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Hour extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Hour
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int day e.g. 11
|
||||
* @param int hour e.g. 13
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Hour($y, $m, $d, $h)
|
||||
{
|
||||
Calendar::Calendar($y, $m, $d, $h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Minutes in the Hour
|
||||
* @param array (optional) Calendar_Minute objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Minute.php';
|
||||
$mIH = $this->cE->getMinutesInHour($this->year, $this->month, $this->day,
|
||||
$this->hour);
|
||||
for ($i=0; $i < $mIH; $i++) {
|
||||
$this->children[$i]=
|
||||
new Calendar_Minute($this->year, $this->month, $this->day,
|
||||
$this->hour, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
&& $this->day == $sDate->thisDay()
|
||||
&& $this->hour == $sDate->thisHour())
|
||||
{
|
||||
$key = (int)$sDate->thisMinute();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Hour class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Hour.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents an Hour and builds Minutes
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Hour.php';
|
||||
* $Hour = new Calendar_Hour(2003, 10, 21, 15); // Oct 21st 2003, 3pm
|
||||
* $Hour->build(); // Build Calendar_Minute objects
|
||||
* while ($Minute = & $Hour->fetch()) {
|
||||
* echo $Minute->thisMinute().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Hour extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Hour
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d day e.g. 11
|
||||
* @param int $h hour e.g. 13
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Hour($y, $m, $d, $h)
|
||||
{
|
||||
parent::Calendar($y, $m, $d, $h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Minutes in the Hour
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Minute objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Minute.php';
|
||||
$mIH = $this->cE->getMinutesInHour($this->year, $this->month, $this->day,
|
||||
$this->hour);
|
||||
for ($i=0; $i < $mIH; $i++) {
|
||||
$this->children[$i] =
|
||||
new Calendar_Minute($this->year, $this->month, $this->day,
|
||||
$this->hour, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
*
|
||||
* @param array $sDates Calendar_Minute objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
&& $this->day == $sDate->thisDay()
|
||||
&& $this->hour == $sDate->thisHour())
|
||||
{
|
||||
$key = (int)$sDate->thisMinute();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,114 +1,138 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Minute.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Minute.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Minute and builds Seconds
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Minute.php';
|
||||
* $Minute = & new Calendar_Minute(2003, 10, 21, 15, 31); // Oct 21st 2003, 3:31pm
|
||||
* $Minute->build(); // Build Calendar_Second objects
|
||||
* while ($Second = & $Minute->fetch()) {
|
||||
* echo $Second->thisSecond().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Minute extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Minute
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int day e.g. 11
|
||||
* @param int hour e.g. 13
|
||||
* @param int minute e.g. 31
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Minute($y, $m, $d, $h, $i)
|
||||
{
|
||||
Calendar::Calendar($y, $m, $d, $h, $i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Calendar_Second objects
|
||||
* @param array (optional) Calendar_Second objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Second.php';
|
||||
$sIM = $this->cE->getSecondsInMinute($this->year, $this->month,
|
||||
$this->day, $this->hour, $this->minute);
|
||||
for ($i=0; $i < $sIM; $i++) {
|
||||
$this->children[$i] = new Calendar_Second($this->year, $this->month,
|
||||
$this->day, $this->hour, $this->minute, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
&& $this->day == $sDate->thisDay()
|
||||
&& $this->hour == $sDate->thisHour()
|
||||
&& $this->minute == $sDate->thisMinute())
|
||||
{
|
||||
$key = (int)$sDate->thisSecond();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Minute class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Minute.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Minute and builds Seconds
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Minute.php';
|
||||
* $Minute = new Calendar_Minute(2003, 10, 21, 15, 31); // Oct 21st 2003, 3:31pm
|
||||
* $Minute->build(); // Build Calendar_Second objects
|
||||
* while ($Second = & $Minute->fetch()) {
|
||||
* echo $Second->thisSecond().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Minute extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Minute
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d day e.g. 11
|
||||
* @param int $h hour e.g. 13
|
||||
* @param int $i minute e.g. 31
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Minute($y, $m, $d, $h, $i)
|
||||
{
|
||||
parent::Calendar($y, $m, $d, $h, $i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Calendar_Second objects
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Second objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Second.php';
|
||||
$sIM = $this->cE->getSecondsInMinute($this->year, $this->month,
|
||||
$this->day, $this->hour, $this->minute);
|
||||
for ($i=0; $i < $sIM; $i++) {
|
||||
$this->children[$i] = new Calendar_Second($this->year, $this->month,
|
||||
$this->day, $this->hour, $this->minute, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
*
|
||||
* @param array $sDates Calendar_Second objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
&& $this->day == $sDate->thisDay()
|
||||
&& $this->hour == $sDate->thisHour()
|
||||
&& $this->minute == $sDate->thisMinute())
|
||||
{
|
||||
$key = (int)$sDate->thisSecond();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,114 +1,138 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Month and builds Days
|
||||
* <code>
|
||||
* require_once 'Calendar/Month.php';
|
||||
* $Month = & new Calendar_Month(2003, 10); // Oct 2003
|
||||
* $Month->build(); // Build Calendar_Day objects
|
||||
* while ($Day = & $Month->fetch()) {
|
||||
* echo $Day->thisDay().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Month
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $firstDay first day of the week [optional]
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month($y, $m, $firstDay=null)
|
||||
{
|
||||
Calendar::Calendar($y, $m);
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Day objects for this Month. Creates as many Calendar_Day objects
|
||||
* as there are days in the month
|
||||
* @param array (optional) Calendar_Day objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month);
|
||||
for ($i=1; $i<=$daysInMonth; $i++) {
|
||||
$this->children[$i] = new Calendar_Day($this->year, $this->month, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
) {
|
||||
$key = $sDate->thisDay();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$class = strtolower(get_class($sDate));
|
||||
if ($class == 'calendar_day' || $class == 'calendar_decorator') {
|
||||
$sDate->setFirst($this->children[$key]->isFirst());
|
||||
$sDate->setLast($this->children[$key]->isLast());
|
||||
}
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Month class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Month.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Month and builds Days
|
||||
* <code>
|
||||
* require_once 'Calendar/Month.php';
|
||||
* $Month = new Calendar_Month(2003, 10); // Oct 2003
|
||||
* $Month->build(); // Build Calendar_Day objects
|
||||
* while ($Day = & $Month->fetch()) {
|
||||
* echo $Day->thisDay().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Month
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $firstDay first day of the week [optional]
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month($y, $m, $firstDay=null)
|
||||
{
|
||||
parent::Calendar($y, $m);
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Day objects for this Month. Creates as many Calendar_Day objects
|
||||
* as there are days in the month
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Day.php';
|
||||
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month);
|
||||
for ($i=1; $i<=$daysInMonth; $i++) {
|
||||
$this->children[$i] = new Calendar_Day($this->year, $this->month, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
*
|
||||
* @param array $sDates Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth()
|
||||
) {
|
||||
$key = $sDate->thisDay();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$class = strtolower(get_class($sDate));
|
||||
if ($class == 'calendar_day' || $class == 'calendar_decorator') {
|
||||
$sDate->setFirst($this->children[$key]->isFirst());
|
||||
$sDate->setLast($this->children[$key]->isLast());
|
||||
}
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,189 +1,215 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Load base month
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Month.php';
|
||||
|
||||
/**
|
||||
* Represents a Month and builds Days in tabular form<br>
|
||||
* <code>
|
||||
* require_once 'Calendar/Month/Weekdays.php';
|
||||
* $Month = & new Calendar_Month_Weekdays(2003, 10); // Oct 2003
|
||||
* $Month->build(); // Build Calendar_Day objects
|
||||
* while ($Day = & $Month->fetch()) {
|
||||
* if ($Day->isFirst()) {
|
||||
* echo '<tr>';
|
||||
* }
|
||||
* if ($Day->isEmpty()) {
|
||||
* echo '<td> </td>';
|
||||
* } else {
|
||||
* echo '<td>'.$Day->thisDay().'</td>';
|
||||
* }
|
||||
* if ($Day->isLast()) {
|
||||
* echo '</tr>';
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month_Weekdays extends Calendar_Month
|
||||
{
|
||||
/**
|
||||
* Instance of Calendar_Table_Helper
|
||||
* @var Calendar_Table_Helper
|
||||
* @access private
|
||||
*/
|
||||
var $tableHelper;
|
||||
|
||||
/**
|
||||
* First day of the week
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $firstDay;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Month_Weekdays
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month_Weekdays($y, $m, $firstDay=null)
|
||||
{
|
||||
Calendar_Month::Calendar_Month($y, $m, $firstDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Day objects in tabular form, to allow display of calendar month
|
||||
* with empty cells if the first day of the week does not fall on the first
|
||||
* day of the month.
|
||||
* @see Calendar_Day::isEmpty()
|
||||
* @see Calendar_Day_Base::isFirst()
|
||||
* @see Calendar_Day_Base::isLast()
|
||||
* @param array (optional) Calendar_Day objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
|
||||
Calendar_Month::build($sDates);
|
||||
$this->buildEmptyDaysBefore();
|
||||
$this->shiftDays();
|
||||
$this->buildEmptyDaysAfter();
|
||||
$this->setWeekMarkers();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends empty days before the real days in the month
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function buildEmptyDaysBefore()
|
||||
{
|
||||
$eBefore = $this->tableHelper->getEmptyDaysBefore();
|
||||
for ($i=0; $i < $eBefore; $i++) {
|
||||
$stamp = $this->cE->dateToStamp($this->year, $this->month, -$i);
|
||||
$Day = new Calendar_Day(
|
||||
$this->cE->stampToYear($stamp),
|
||||
$this->cE->stampToMonth($stamp),
|
||||
$this->cE->stampToDay($stamp));
|
||||
$Day->setEmpty();
|
||||
$Day->adjust();
|
||||
array_unshift($this->children, $Day);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts the array of children forward, if necessary
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function shiftDays()
|
||||
{
|
||||
if (isset ($this->children[0])) {
|
||||
array_unshift($this->children, null);
|
||||
unset($this->children[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends empty days after the real days in the month
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function buildEmptyDaysAfter()
|
||||
{
|
||||
$eAfter = $this->tableHelper->getEmptyDaysAfter();
|
||||
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
||||
for ($i = 1; $i <= $sDOM-$eAfter; $i++) {
|
||||
$Day = new Calendar_Day($this->year, $this->month+1, $i);
|
||||
$Day->setEmpty();
|
||||
$Day->adjust();
|
||||
array_push($this->children, $Day);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "markers" for the beginning and of a of week, in the
|
||||
* built Calendar_Day children
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setWeekMarkers()
|
||||
{
|
||||
$dIW = $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
);
|
||||
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
||||
for ($i=1; $i <= $sDOM; $i+= $dIW) {
|
||||
$this->children[$i]->setFirst();
|
||||
$this->children[$i+($dIW-1)]->setLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Month_Weekdays class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Weekdays.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Load base month
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Month.php';
|
||||
|
||||
/**
|
||||
* Represents a Month and builds Days in tabular form<br>
|
||||
* <code>
|
||||
* require_once 'Calendar/Month/Weekdays.php';
|
||||
* $Month = new Calendar_Month_Weekdays(2003, 10); // Oct 2003
|
||||
* $Month->build(); // Build Calendar_Day objects
|
||||
* while ($Day = & $Month->fetch()) {
|
||||
* if ($Day->isFirst()) {
|
||||
* echo '<tr>';
|
||||
* }
|
||||
* if ($Day->isEmpty()) {
|
||||
* echo '<td> </td>';
|
||||
* } else {
|
||||
* echo '<td>'.$Day->thisDay().'</td>';
|
||||
* }
|
||||
* if ($Day->isLast()) {
|
||||
* echo '</tr>';
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month_Weekdays extends Calendar_Month
|
||||
{
|
||||
/**
|
||||
* Instance of Calendar_Table_Helper
|
||||
* @var Calendar_Table_Helper
|
||||
* @access private
|
||||
*/
|
||||
var $tableHelper;
|
||||
|
||||
/**
|
||||
* First day of the week
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $firstDay;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Month_Weekdays
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month_Weekdays($y, $m, $firstDay=null)
|
||||
{
|
||||
parent::Calendar_Month($y, $m, $firstDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Day objects in tabular form, to allow display of calendar month
|
||||
* with empty cells if the first day of the week does not fall on the first
|
||||
* day of the month.
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
* @see Calendar_Day::isEmpty()
|
||||
* @see Calendar_Day_Base::isFirst()
|
||||
* @see Calendar_Day_Base::isLast()
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
$this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
|
||||
Calendar_Month::build($sDates);
|
||||
$this->buildEmptyDaysBefore();
|
||||
$this->shiftDays();
|
||||
$this->buildEmptyDaysAfter();
|
||||
$this->setWeekMarkers();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends empty days before the real days in the month
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function buildEmptyDaysBefore()
|
||||
{
|
||||
$eBefore = $this->tableHelper->getEmptyDaysBefore();
|
||||
for ($i=0; $i < $eBefore; $i++) {
|
||||
$stamp = $this->cE->dateToStamp($this->year, $this->month, -$i);
|
||||
$Day = new Calendar_Day(
|
||||
$this->cE->stampToYear($stamp),
|
||||
$this->cE->stampToMonth($stamp),
|
||||
$this->cE->stampToDay($stamp));
|
||||
$Day->setEmpty();
|
||||
$Day->adjust();
|
||||
array_unshift($this->children, $Day);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts the array of children forward, if necessary
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function shiftDays()
|
||||
{
|
||||
if (isset($this->children[0])) {
|
||||
array_unshift($this->children, null);
|
||||
unset($this->children[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends empty days after the real days in the month
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function buildEmptyDaysAfter()
|
||||
{
|
||||
$eAfter = $this->tableHelper->getEmptyDaysAfter();
|
||||
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
||||
for ($i=1; $i <= $sDOM-$eAfter; $i++) {
|
||||
$Day = new Calendar_Day($this->year, $this->month+1, $i);
|
||||
$Day->setEmpty();
|
||||
$Day->adjust();
|
||||
array_push($this->children, $Day);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "markers" for the beginning and of a of week, in the
|
||||
* built Calendar_Day children
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setWeekMarkers()
|
||||
{
|
||||
$dIW = $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
);
|
||||
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
||||
for ($i=1; $i <= $sDOM; $i+= $dIW) {
|
||||
$this->children[$i]->setFirst();
|
||||
$this->children[$i+($dIW-1)]->setLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,139 +1,166 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Load base month
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Month.php';
|
||||
|
||||
/**
|
||||
* Represents a Month and builds Weeks
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Month'.DIRECTORY_SEPARATOR.'Weeks.php';
|
||||
* $Month = & new Calendar_Month_Weeks(2003, 10); // Oct 2003
|
||||
* $Month->build(); // Build Calendar_Day objects
|
||||
* while ($Week = & $Month->fetch()) {
|
||||
* echo $Week->thisWeek().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month_Weeks extends Calendar_Month
|
||||
{
|
||||
/**
|
||||
* Instance of Calendar_Table_Helper
|
||||
* @var Calendar_Table_Helper
|
||||
* @access private
|
||||
*/
|
||||
var $tableHelper;
|
||||
|
||||
/**
|
||||
* First day of the week
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $firstDay;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Month_Weeks
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month_Weeks($y, $m, $firstDay=null)
|
||||
{
|
||||
Calendar_Month::Calendar_Month($y, $m, $firstDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Calendar_Week objects for the Month. Note that Calendar_Week
|
||||
* builds Calendar_Day object in tabular form (with Calendar_Day->empty)
|
||||
* @param array (optional) Calendar_Week objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
|
||||
require_once CALENDAR_ROOT.'Week.php';
|
||||
$numWeeks = $this->tableHelper->getNumWeeks();
|
||||
for ($i=1, $d=1; $i<=$numWeeks; $i++,
|
||||
$d+=$this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()) ) {
|
||||
$this->children[$i] = new Calendar_Week(
|
||||
$this->year, $this->month, $d, $this->tableHelper->getFirstDay());
|
||||
}
|
||||
//used to set empty days
|
||||
$this->children[1]->setFirst(true);
|
||||
$this->children[$numWeeks]->setLast(true);
|
||||
|
||||
// Handle selected weeks here
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth())
|
||||
{
|
||||
$key = $sDate->thisWeek('n_in_month');
|
||||
if (isset($this->children[$key])) {
|
||||
$this->children[$key]->setSelected();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Month_Weeks class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Weeks.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Load base month
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Month.php';
|
||||
|
||||
/**
|
||||
* Represents a Month and builds Weeks
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Month'.DIRECTORY_SEPARATOR.'Weeks.php';
|
||||
* $Month = new Calendar_Month_Weeks(2003, 10); // Oct 2003
|
||||
* $Month->build(); // Build Calendar_Day objects
|
||||
* while ($Week = & $Month->fetch()) {
|
||||
* echo $Week->thisWeek().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month_Weeks extends Calendar_Month
|
||||
{
|
||||
/**
|
||||
* Instance of Calendar_Table_Helper
|
||||
* @var Calendar_Table_Helper
|
||||
* @access private
|
||||
*/
|
||||
var $tableHelper;
|
||||
|
||||
/**
|
||||
* First day of the week
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $firstDay;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Month_Weeks
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month_Weeks($y, $m, $firstDay=null)
|
||||
{
|
||||
parent::Calendar_Month($y, $m, $firstDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Calendar_Week objects for the Month. Note that Calendar_Week
|
||||
* builds Calendar_Day object in tabular form (with Calendar_Day->empty)
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Week objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
$this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
|
||||
include_once CALENDAR_ROOT.'Week.php';
|
||||
$numWeeks = $this->tableHelper->getNumWeeks();
|
||||
for ($i=1, $d=1; $i<=$numWeeks; $i++,
|
||||
$d+=$this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
)
|
||||
) {
|
||||
$this->children[$i] = new Calendar_Week(
|
||||
$this->year, $this->month, $d, $this->tableHelper->getFirstDay());
|
||||
}
|
||||
//used to set empty days
|
||||
$this->children[1]->setFirst(true);
|
||||
$this->children[$numWeeks]->setLast(true);
|
||||
|
||||
// Handle selected weeks here
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
*
|
||||
* @param array $sDates Calendar_Week objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()
|
||||
&& $this->month == $sDate->thisMonth())
|
||||
{
|
||||
$key = $sDate->thisWeek('n_in_month');
|
||||
if (isset($this->children[$key])) {
|
||||
$this->children[$key]->setSelected();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,98 +1,122 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Second.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Second.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Second<br />
|
||||
* <b>Note:</b> Seconds do not build other objects
|
||||
* so related methods are overridden to return NULL
|
||||
* @package Calendar
|
||||
*/
|
||||
class Calendar_Second extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Second
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int day e.g. 11
|
||||
* @param int hour e.g. 13
|
||||
* @param int minute e.g. 31
|
||||
* @param int second e.g. 45
|
||||
*/
|
||||
function Calendar_Second($y, $m, $d, $h, $i, $s)
|
||||
{
|
||||
Calendar::Calendar($y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite build
|
||||
* @return NULL
|
||||
*/
|
||||
function build()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite fetch
|
||||
* @return NULL
|
||||
*/
|
||||
function fetch()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite fetchAll
|
||||
* @return NULL
|
||||
*/
|
||||
function fetchAll()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite size
|
||||
* @return NULL
|
||||
*/
|
||||
function size()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Second class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Second.php 300728 2010-06-24 11:43:56Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Second<br />
|
||||
* <b>Note:</b> Seconds do not build other objects
|
||||
* so related methods are overridden to return NULL
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Second extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Second
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d day e.g. 11
|
||||
* @param int $h hour e.g. 13
|
||||
* @param int $i minute e.g. 31
|
||||
* @param int $s second e.g. 45
|
||||
*/
|
||||
function Calendar_Second($y, $m, $d, $h, $i, $s)
|
||||
{
|
||||
parent::Calendar($y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite build
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function build()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite fetch
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function fetch()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite fetchAll
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function fetchAll()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite size
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function size()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,280 +1,316 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Helper.php,v 1.5 2005/10/22 09:51:53 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Helper.php,v 1.5 2005/10/22 09:51:53 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used by Calendar_Month_Weekdays, Calendar_Month_Weeks and Calendar_Week to
|
||||
* help with building the calendar in tabular form
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Table_Helper
|
||||
{
|
||||
/**
|
||||
* Instance of the Calendar object being helped.
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $calendar;
|
||||
|
||||
/**
|
||||
* Instance of the Calendar_Engine
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $cE;
|
||||
|
||||
/**
|
||||
* First day of the week
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $firstDay;
|
||||
|
||||
/**
|
||||
* The seven days of the week named
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $weekDays;
|
||||
|
||||
/**
|
||||
* Days of the week ordered with $firstDay at the beginning
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $daysOfWeek = array();
|
||||
|
||||
/**
|
||||
* Days of the month built from days of the week
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $daysOfMonth = array();
|
||||
|
||||
/**
|
||||
* Number of weeks in month
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $numWeeks = null;
|
||||
|
||||
/**
|
||||
* Number of emtpy days before real days begin in month
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $emptyBefore = 0;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Table_Helper
|
||||
* @param object Calendar_Month_Weekdays, Calendar_Month_Weeks, Calendar_Week
|
||||
* @param int (optional) first day of the week e.g. 1 for Monday
|
||||
* @access protected
|
||||
*/
|
||||
function Calendar_Table_Helper(& $calendar, $firstDay=null)
|
||||
{
|
||||
$this->calendar = & $calendar;
|
||||
$this->cE = & $calendar->getEngine();
|
||||
if (is_null($firstDay)) {
|
||||
$firstDay = $this->cE->getFirstDayOfWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
);
|
||||
}
|
||||
$this->firstDay = $firstDay;
|
||||
$this->setFirstDay();
|
||||
$this->setDaysOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs $this->daysOfWeek based on $this->firstDay
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirstDay()
|
||||
{
|
||||
$weekDays = $this->cE->getWeekDays(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
);
|
||||
$endDays = array();
|
||||
$tmpDays = array();
|
||||
$begin = false;
|
||||
foreach ($weekDays as $day) {
|
||||
if ($begin) {
|
||||
$endDays[] = $day;
|
||||
} else if ($day === $this->firstDay) {
|
||||
$begin = true;
|
||||
$endDays[] = $day;
|
||||
} else {
|
||||
$tmpDays[] = $day;
|
||||
}
|
||||
}
|
||||
$this->daysOfWeek = array_merge($endDays, $tmpDays);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs $this->daysOfMonth
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setDaysOfMonth()
|
||||
{
|
||||
$this->daysOfMonth = $this->daysOfWeek;
|
||||
$daysInMonth = $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
$firstDayInMonth = $this->cE->getFirstDayInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
$this->emptyBefore=0;
|
||||
foreach ($this->daysOfMonth as $dayOfWeek) {
|
||||
if ($firstDayInMonth == $dayOfWeek) {
|
||||
break;
|
||||
}
|
||||
$this->emptyBefore++;
|
||||
}
|
||||
$this->numWeeks = ceil(
|
||||
($daysInMonth + $this->emptyBefore)
|
||||
/
|
||||
$this->cE->getDaysInWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
)
|
||||
);
|
||||
for ($i=1; $i < $this->numWeeks; $i++) {
|
||||
$this->daysOfMonth =
|
||||
array_merge($this->daysOfMonth, $this->daysOfWeek);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first day of the month
|
||||
* @see Calendar_Engine_Interface::getFirstDayOfWeek()
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDay()
|
||||
{
|
||||
return $this->firstDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the order array of days in a week
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysOfWeek()
|
||||
{
|
||||
return $this->daysOfWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of tabular weeks in a month
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getNumWeeks()
|
||||
{
|
||||
return $this->numWeeks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of real days + empty days
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getNumTableDaysInMonth()
|
||||
{
|
||||
return count($this->daysOfMonth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of empty days before the real days begin
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getEmptyDaysBefore()
|
||||
{
|
||||
return $this->emptyBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last real day in the month
|
||||
* @todo Potential performance optimization with static
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getEmptyDaysAfter()
|
||||
{
|
||||
// Causes bug when displaying more than one month
|
||||
// static $index;
|
||||
// if (!isset($index)) {
|
||||
$index = $this->getEmptyDaysBefore() + $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
// }
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last real day in the month, relative to the
|
||||
* beginning of the tabular week it is part of
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getEmptyDaysAfterOffset()
|
||||
{
|
||||
$eAfter = $this->getEmptyDaysAfter();
|
||||
return $eAfter - (
|
||||
$this->cE->getDaysInWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
) * ($this->numWeeks-1) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp of the first day of the current week
|
||||
*/
|
||||
function getWeekStart($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
$dow = $this->cE->getDayOfWeek($y, $m, $d);
|
||||
if ($dow > $firstDay) {
|
||||
$d -= ($dow - $firstDay);
|
||||
}
|
||||
if ($dow < $firstDay) {
|
||||
$d -= (
|
||||
$this->cE->getDaysInWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
) - $firstDay + $dow);
|
||||
}
|
||||
return $this->cE->dateToStamp($y, $m, $d);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Decorator_Wrapper class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Helper.php 246317 2007-11-16 20:05:32Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used by Calendar_Month_Weekdays, Calendar_Month_Weeks and Calendar_Week to
|
||||
* help with building the calendar in tabular form
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Table_Helper
|
||||
{
|
||||
/**
|
||||
* Instance of the Calendar object being helped.
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $calendar;
|
||||
|
||||
/**
|
||||
* Instance of the Calendar_Engine
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $cE;
|
||||
|
||||
/**
|
||||
* First day of the week
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $firstDay;
|
||||
|
||||
/**
|
||||
* The seven days of the week named
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $weekDays;
|
||||
|
||||
/**
|
||||
* Days of the week ordered with $firstDay at the beginning
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $daysOfWeek = array();
|
||||
|
||||
/**
|
||||
* Days of the month built from days of the week
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $daysOfMonth = array();
|
||||
|
||||
/**
|
||||
* Number of weeks in month
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $numWeeks = null;
|
||||
|
||||
/**
|
||||
* Number of emtpy days before real days begin in month
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $emptyBefore = 0;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Table_Helper
|
||||
*
|
||||
* @param object &$calendar Calendar_Month_Weekdays, Calendar_Month_Weeks, Calendar_Week
|
||||
* @param int $firstDay (optional) first day of the week e.g. 1 for Monday
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function Calendar_Table_Helper(& $calendar, $firstDay=null)
|
||||
{
|
||||
$this->calendar = & $calendar;
|
||||
$this->cE = & $calendar->getEngine();
|
||||
if (is_null($firstDay)) {
|
||||
$firstDay = $this->cE->getFirstDayOfWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
);
|
||||
}
|
||||
$this->firstDay = $firstDay;
|
||||
$this->setFirstDay();
|
||||
$this->setDaysOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs $this->daysOfWeek based on $this->firstDay
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirstDay()
|
||||
{
|
||||
$weekDays = $this->cE->getWeekDays(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
);
|
||||
$endDays = array();
|
||||
$tmpDays = array();
|
||||
$begin = false;
|
||||
foreach ($weekDays as $day) {
|
||||
if ($begin) {
|
||||
$endDays[] = $day;
|
||||
} else if ($day === $this->firstDay) {
|
||||
$begin = true;
|
||||
$endDays[] = $day;
|
||||
} else {
|
||||
$tmpDays[] = $day;
|
||||
}
|
||||
}
|
||||
$this->daysOfWeek = array_merge($endDays, $tmpDays);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs $this->daysOfMonth
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setDaysOfMonth()
|
||||
{
|
||||
$this->daysOfMonth = $this->daysOfWeek;
|
||||
$daysInMonth = $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
$firstDayInMonth = $this->cE->getFirstDayInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
$this->emptyBefore=0;
|
||||
foreach ($this->daysOfMonth as $dayOfWeek) {
|
||||
if ($firstDayInMonth == $dayOfWeek) {
|
||||
break;
|
||||
}
|
||||
$this->emptyBefore++;
|
||||
}
|
||||
$this->numWeeks = ceil(
|
||||
($daysInMonth + $this->emptyBefore)
|
||||
/
|
||||
$this->cE->getDaysInWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
)
|
||||
);
|
||||
for ($i=1; $i < $this->numWeeks; $i++) {
|
||||
$this->daysOfMonth =
|
||||
array_merge($this->daysOfMonth, $this->daysOfWeek);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first day of the month
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
* @see Calendar_Engine_Interface::getFirstDayOfWeek()
|
||||
*/
|
||||
function getFirstDay()
|
||||
{
|
||||
return $this->firstDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the order array of days in a week
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysOfWeek()
|
||||
{
|
||||
return $this->daysOfWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of tabular weeks in a month
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getNumWeeks()
|
||||
{
|
||||
return $this->numWeeks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of real days + empty days
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getNumTableDaysInMonth()
|
||||
{
|
||||
return count($this->daysOfMonth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of empty days before the real days begin
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getEmptyDaysBefore()
|
||||
{
|
||||
return $this->emptyBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last real day in the month
|
||||
*
|
||||
* @todo Potential performance optimization with static
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getEmptyDaysAfter()
|
||||
{
|
||||
// Causes bug when displaying more than one month
|
||||
//static $index;
|
||||
//if (!isset($index)) {
|
||||
$index = $this->getEmptyDaysBefore() + $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
//}
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last real day in the month, relative to the
|
||||
* beginning of the tabular week it is part of
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getEmptyDaysAfterOffset()
|
||||
{
|
||||
$eAfter = $this->getEmptyDaysAfter();
|
||||
return $eAfter - (
|
||||
$this->cE->getDaysInWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
) * ($this->numWeeks-1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp of the first day of the current week
|
||||
*
|
||||
* @param int $y year
|
||||
* @param int $m month
|
||||
* @param int $d day
|
||||
* @param int $firstDay first day of the week (default 1 = Monday)
|
||||
*
|
||||
* @return int timestamp
|
||||
*/
|
||||
function getWeekStart($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
$dow = $this->cE->getDayOfWeek($y, $m, $d);
|
||||
if ($dow > $firstDay) {
|
||||
$d -= ($dow - $firstDay);
|
||||
}
|
||||
if ($dow < $firstDay) {
|
||||
$d -= (
|
||||
$this->cE->getDaysInWeek(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
) - $firstDay + $dow);
|
||||
}
|
||||
return $this->cE->dateToStamp($y, $m, $d);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,239 +1,304 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Static utlities to help with fetching textual representations of months and
|
||||
* days of the week.
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Util_Textual
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of 12 month names (first index = 1)
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function monthNames($format='long')
|
||||
{
|
||||
$formats = array('one'=>'%b', 'two'=>'%b', 'short'=>'%b', 'long'=>'%B');
|
||||
if (!array_key_exists($format,$formats)) {
|
||||
$format = 'long';
|
||||
}
|
||||
$months = array();
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$stamp = mktime(0, 0, 0, $i, 1, 2003);
|
||||
$month = strftime($formats[$format], $stamp);
|
||||
switch($format) {
|
||||
case 'one':
|
||||
$month = substr($month, 0, 1);
|
||||
break;
|
||||
case 'two':
|
||||
$month = substr($month, 0, 2);
|
||||
break;
|
||||
}
|
||||
$months[$i] = $month;
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of 7 week day names (first index = 0)
|
||||
* @param string (optional) format of returned days (one,two,short or long)
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function weekdayNames($format='long')
|
||||
{
|
||||
$formats = array('one'=>'%a', 'two'=>'%a', 'short'=>'%a', 'long'=>'%A');
|
||||
if (!array_key_exists($format,$formats)) {
|
||||
$format = 'long';
|
||||
}
|
||||
$days = array();
|
||||
for ($i=0; $i<=6; $i++) {
|
||||
$stamp = mktime(0, 0, 0, 11, $i+2, 2003);
|
||||
$day = strftime($formats[$format], $stamp);
|
||||
switch($format) {
|
||||
case 'one':
|
||||
$day = substr($day, 0, 1);
|
||||
break;
|
||||
case 'two':
|
||||
$day = substr($day, 0, 2);
|
||||
break;
|
||||
}
|
||||
$days[$i] = $day;
|
||||
}
|
||||
return $days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous month of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function prevMonthName($Calendar, $format='long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->prevMonth()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the month of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function thisMonthName($Calendar, $format='long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->thisMonth()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next month of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function nextMonthName($Calendar, $format='long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->nextMonth()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous day of week of the decorated calendar object
|
||||
* <b>Note:</b> Requires PEAR::Date
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function prevDayName($Calendar, $format='long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
$stamp = $Calendar->prevDay('timestamp');
|
||||
$cE = $Calendar->getEngine();
|
||||
require_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
|
||||
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
|
||||
return $days[$day];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the day of week of the decorated calendar object
|
||||
* <b>Note:</b> Requires PEAR::Date
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function thisDayName($Calendar, $format='long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
require_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear());
|
||||
return $days[$day];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next day of week of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function nextDayName($Calendar, $format='long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
$stamp = $Calendar->nextDay('timestamp');
|
||||
$cE = $Calendar->getEngine();
|
||||
require_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
|
||||
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
|
||||
return $days[$day];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the days of the week using the order defined in the decorated
|
||||
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
|
||||
* and Calendar_Week. Otherwise the returned array will begin on Sunday
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
* @return array ordered array of week day names
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function orderedWeekdays($Calendar, $format='long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
|
||||
// Not so good - need methods to access this information perhaps...
|
||||
if (isset($Calendar->tableHelper)) {
|
||||
$ordereddays = $Calendar->tableHelper->daysOfWeek;
|
||||
} else {
|
||||
$ordereddays = array(0, 1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
$ordereddays = array_flip($ordereddays);
|
||||
$i = 0;
|
||||
$returndays = array();
|
||||
foreach ($ordereddays as $key => $value) {
|
||||
$returndays[$i] = $days[$key];
|
||||
$i++;
|
||||
}
|
||||
return $returndays;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Util_Textual class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Textual.php 247250 2007-11-28 19:42:01Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Textual.php 247250 2007-11-28 19:42:01Z quipo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar decorator base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Decorator.php';
|
||||
|
||||
/**
|
||||
* Static utlities to help with fetching textual representations of months and
|
||||
* days of the week.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Util_Textual
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of 12 month names (first index = 1)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function monthNames($format = 'long')
|
||||
{
|
||||
$formats = array(
|
||||
'one' => '%b',
|
||||
'two' => '%b',
|
||||
'short' => '%b',
|
||||
'long' => '%B',
|
||||
);
|
||||
if (!array_key_exists($format, $formats)) {
|
||||
$format = 'long';
|
||||
}
|
||||
$months = array();
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$stamp = mktime(0, 0, 0, $i, 1, 2003);
|
||||
$month = strftime($formats[$format], $stamp);
|
||||
switch($format) {
|
||||
case 'one':
|
||||
$month = substr($month, 0, 1);
|
||||
break;
|
||||
case 'two':
|
||||
$month = substr($month, 0, 2);
|
||||
break;
|
||||
}
|
||||
$months[$i] = $month;
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of 7 week day names (first index = 0)
|
||||
*
|
||||
* @param string $format (optional) format of returned days (one,two,short or long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function weekdayNames($format = 'long')
|
||||
{
|
||||
$formats = array(
|
||||
'one' => '%a',
|
||||
'two' => '%a',
|
||||
'short' => '%a',
|
||||
'long' => '%A',
|
||||
);
|
||||
if (!array_key_exists($format, $formats)) {
|
||||
$format = 'long';
|
||||
}
|
||||
$days = array();
|
||||
for ($i=0; $i<=6; $i++) {
|
||||
$stamp = mktime(0, 0, 0, 11, $i+2, 2003);
|
||||
$day = strftime($formats[$format], $stamp);
|
||||
switch($format) {
|
||||
case 'one':
|
||||
$day = substr($day, 0, 1);
|
||||
break;
|
||||
case 'two':
|
||||
$day = substr($day, 0, 2);
|
||||
break;
|
||||
}
|
||||
$days[$i] = $day;
|
||||
}
|
||||
return $days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous month of the decorated calendar object
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function prevMonthName($Calendar, $format = 'long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->prevMonth()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the month of the decorated calendar object
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function thisMonthName($Calendar, $format = 'long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->thisMonth()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next month of the decorated calendar object
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function nextMonthName($Calendar, $format = 'long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->nextMonth()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous day of week of the decorated calendar object
|
||||
* <b>Note:</b> Requires PEAR::Date
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function prevDayName($Calendar, $format = 'long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
$stamp = $Calendar->prevDay('timestamp');
|
||||
$cE = $Calendar->getEngine();
|
||||
include_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
|
||||
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
|
||||
return $days[$day];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the day of week of the decorated calendar object
|
||||
* <b>Note:</b> Requires PEAR::Date
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function thisDayName($Calendar, $format='long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
include_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear());
|
||||
return $days[$day];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next day of week of the decorated calendar object
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function nextDayName($Calendar, $format='long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
$stamp = $Calendar->nextDay('timestamp');
|
||||
$cE = $Calendar->getEngine();
|
||||
include_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
|
||||
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
|
||||
return $days[$day];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the days of the week using the order defined in the decorated
|
||||
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
|
||||
* and Calendar_Week. Otherwise the returned array will begin on Sunday
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return array ordered array of week day names
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function orderedWeekdays($Calendar, $format = 'long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
|
||||
if (isset($Calendar->tableHelper)) {
|
||||
$ordereddays = $Calendar->tableHelper->getDaysOfWeek();
|
||||
} else {
|
||||
//default: start from Sunday
|
||||
$firstDay = 0;
|
||||
//check if defined / set
|
||||
if (defined('CALENDAR_FIRST_DAY_OF_WEEK')) {
|
||||
$firstDay = CALENDAR_FIRST_DAY_OF_WEEK;
|
||||
} elseif(isset($Calendar->firstDay)) {
|
||||
$firstDay = $Calendar->firstDay;
|
||||
}
|
||||
$ordereddays = array();
|
||||
for ($i = $firstDay; $i < 7; $i++) {
|
||||
$ordereddays[] = $i;
|
||||
}
|
||||
for ($i = 0; $i < $firstDay; $i++) {
|
||||
$ordereddays[] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
$ordereddays = array_flip($ordereddays);
|
||||
$i = 0;
|
||||
$returndays = array();
|
||||
foreach ($ordereddays as $key => $value) {
|
||||
$returndays[$i] = $days[$key];
|
||||
$i++;
|
||||
}
|
||||
return $returndays;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,169 +1,204 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Uri.php,v 1.1 2004/08/16 09:03:55 hfuecks Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Uri.php,v 1.1 2004/08/16 09:03:55 hfuecks Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility to help building HTML links for navigating the calendar<br />
|
||||
* <code>
|
||||
* $Day = new Calendar_Day(2003, 10, 23);
|
||||
* $Uri = & new Calendar_Util_Uri('year', 'month', 'day');
|
||||
* echo $Uri->prev($Day,'month'); // Displays year=2003&month=10
|
||||
* echo $Uri->prev($Day,'day'); // Displays year=2003&month=10&day=22
|
||||
* $Uri->seperator = '/';
|
||||
* $Uri->scalar = true;
|
||||
* echo $Uri->prev($Day,'month'); // Displays 2003/10
|
||||
* echo $Uri->prev($Day,'day'); // Displays 2003/10/22
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Util_Uri
|
||||
{
|
||||
/**
|
||||
* Uri fragments for year, month, day etc.
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $uris = array();
|
||||
|
||||
/**
|
||||
* String to separate fragments with.
|
||||
* Set to just & for HTML.
|
||||
* For a scalar URL you might use / as the seperator
|
||||
* @var string (default XHTML &)
|
||||
* @access public
|
||||
*/
|
||||
var $separator = '&';
|
||||
|
||||
/**
|
||||
* To output a "scalar" string - variable names omitted.
|
||||
* Used for urls like index.php/2004/8/12
|
||||
* @var boolean (default false)
|
||||
* @access public
|
||||
*/
|
||||
var $scalar = false;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Uri
|
||||
* The term "fragment" means <i>name</i> of a calendar GET variables in the URL
|
||||
* @param string URI fragment for year
|
||||
* @param string (optional) URI fragment for month
|
||||
* @param string (optional) URI fragment for day
|
||||
* @param string (optional) URI fragment for hour
|
||||
* @param string (optional) URI fragment for minute
|
||||
* @param string (optional) URI fragment for second
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Util_Uri($y, $m=null, $d=null, $h=null, $i=null, $s=null)
|
||||
{
|
||||
$this->setFragments($y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URI fragment names
|
||||
* @param string URI fragment for year
|
||||
* @param string (optional) URI fragment for month
|
||||
* @param string (optional) URI fragment for day
|
||||
* @param string (optional) URI fragment for hour
|
||||
* @param string (optional) URI fragment for minute
|
||||
* @param string (optional) URI fragment for second
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null) {
|
||||
if (!is_null($y)) $this->uris['Year'] = $y;
|
||||
if (!is_null($m)) $this->uris['Month'] = $m;
|
||||
if (!is_null($d)) $this->uris['Day'] = $d;
|
||||
if (!is_null($h)) $this->uris['Hour'] = $h;
|
||||
if (!is_null($i)) $this->uris['Minute'] = $i;
|
||||
if (!is_null($s)) $this->uris['Second'] = $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the previous calendar unit
|
||||
* @param object subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string calendar unit ( must be year, month, week, day, hour, minute or second)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prev($Calendar, $unit)
|
||||
{
|
||||
$method = 'prev'.$unit;
|
||||
$stamp = $Calendar->{$method}('timestamp');
|
||||
return $this->buildUriString($Calendar, $method, $stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the current calendar unit
|
||||
* @param object subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string calendar unit ( must be year, month, week, day, hour, minute or second)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function this($Calendar, $unit)
|
||||
{
|
||||
$method = 'this'.$unit;
|
||||
$stamp = $Calendar->{$method}('timestamp');
|
||||
return $this->buildUriString($Calendar, $method, $stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the next calendar unit
|
||||
* @param object subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string calendar unit ( must be year, month, week, day, hour, minute or second)
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function next($Calendar, $unit)
|
||||
{
|
||||
$method = 'next'.$unit;
|
||||
$stamp = $Calendar->{$method}('timestamp');
|
||||
return $this->buildUriString($Calendar, $method, $stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the URI string
|
||||
* @param string method substring
|
||||
* @param int timestamp
|
||||
* @return string build uri string
|
||||
* @access private
|
||||
*/
|
||||
function buildUriString($Calendar, $method, $stamp)
|
||||
{
|
||||
$uriString = '';
|
||||
$cE = & $Calendar->getEngine();
|
||||
$separator = '';
|
||||
foreach ($this->uris as $unit => $uri) {
|
||||
$call = 'stampTo'.$unit;
|
||||
$uriString .= $separator;
|
||||
if (!$this->scalar) $uriString .= $uri.'=';
|
||||
$uriString .= $cE->{$call}($stamp);
|
||||
$separator = $this->separator;
|
||||
}
|
||||
return $uriString;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Util_Uri class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Uri.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility to help building HTML links for navigating the calendar<br />
|
||||
* <code>
|
||||
* $Day = new Calendar_Day(2003, 10, 23);
|
||||
* $Uri = new Calendar_Util_Uri('year', 'month', 'day');
|
||||
* echo $Uri->prev($Day,'month'); // Displays year=2003&month=10
|
||||
* echo $Uri->prev($Day,'day'); // Displays year=2003&month=10&day=22
|
||||
* $Uri->seperator = '/';
|
||||
* $Uri->scalar = true;
|
||||
* echo $Uri->prev($Day,'month'); // Displays 2003/10
|
||||
* echo $Uri->prev($Day,'day'); // Displays 2003/10/22
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Util_Uri
|
||||
{
|
||||
/**
|
||||
* Uri fragments for year, month, day etc.
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $uris = array();
|
||||
|
||||
/**
|
||||
* String to separate fragments with.
|
||||
* Set to just & for HTML.
|
||||
* For a scalar URL you might use / as the seperator
|
||||
* @var string (default XHTML &)
|
||||
* @access public
|
||||
*/
|
||||
var $separator = '&';
|
||||
|
||||
/**
|
||||
* To output a "scalar" string - variable names omitted.
|
||||
* Used for urls like index.php/2004/8/12
|
||||
* @var boolean (default false)
|
||||
* @access public
|
||||
*/
|
||||
var $scalar = false;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Uri
|
||||
* The term "fragment" means <i>name</i> of a calendar GET variables in the URL
|
||||
*
|
||||
* @param string $y URI fragment for year
|
||||
* @param string $m (optional) URI fragment for month
|
||||
* @param string $d (optional) URI fragment for day
|
||||
* @param string $h (optional) URI fragment for hour
|
||||
* @param string $i (optional) URI fragment for minute
|
||||
* @param string $s (optional) URI fragment for second
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Util_Uri($y, $m=null, $d=null, $h=null, $i=null, $s=null)
|
||||
{
|
||||
$this->setFragments($y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URI fragment names
|
||||
*
|
||||
* @param string $y URI fragment for year
|
||||
* @param string $m (optional) URI fragment for month
|
||||
* @param string $d (optional) URI fragment for day
|
||||
* @param string $h (optional) URI fragment for hour
|
||||
* @param string $i (optional) URI fragment for minute
|
||||
* @param string $s (optional) URI fragment for second
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null)
|
||||
{
|
||||
if (!is_null($y)) $this->uris['Year'] = $y;
|
||||
if (!is_null($m)) $this->uris['Month'] = $m;
|
||||
if (!is_null($d)) $this->uris['Day'] = $d;
|
||||
if (!is_null($h)) $this->uris['Hour'] = $h;
|
||||
if (!is_null($i)) $this->uris['Minute'] = $i;
|
||||
if (!is_null($s)) $this->uris['Second'] = $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the previous calendar unit
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prev($Calendar, $unit)
|
||||
{
|
||||
$method = 'prev'.$unit;
|
||||
$stamp = $Calendar->{$method}('timestamp');
|
||||
return $this->buildUriString($Calendar, $method, $stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the current calendar unit
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function this($Calendar, $unit)
|
||||
{
|
||||
$method = 'this'.$unit;
|
||||
$stamp = $Calendar->{$method}('timestamp');
|
||||
return $this->buildUriString($Calendar, $method, $stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the next calendar unit
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function next($Calendar, $unit)
|
||||
{
|
||||
$method = 'next'.$unit;
|
||||
$stamp = $Calendar->{$method}('timestamp');
|
||||
return $this->buildUriString($Calendar, $method, $stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the URI string
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $method method substring
|
||||
* @param int $stamp timestamp
|
||||
*
|
||||
* @return string build uri string
|
||||
* @access private
|
||||
*/
|
||||
function buildUriString($Calendar, $method, $stamp)
|
||||
{
|
||||
$uriString = '';
|
||||
$cE = & $Calendar->getEngine();
|
||||
$separator = '';
|
||||
foreach ($this->uris as $unit => $uri) {
|
||||
$call = 'stampTo'.$unit;
|
||||
$uriString .= $separator;
|
||||
if (!$this->scalar) {
|
||||
$uriString .= $uri.'=';
|
||||
}
|
||||
$uriString .= $cE->{$call}($stamp);
|
||||
$separator = $this->separator;
|
||||
}
|
||||
return $uriString;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,335 +1,377 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validation Error Messages
|
||||
*/
|
||||
if (!defined('CALENDAR_VALUE_TOOSMALL')) {
|
||||
define('CALENDAR_VALUE_TOOSMALL', 'Too small: min = ');
|
||||
}
|
||||
if (!defined('CALENDAR_VALUE_TOOLARGE')) {
|
||||
define('CALENDAR_VALUE_TOOLARGE', 'Too large: max = ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to validate any given Calendar date object. Instances of this class
|
||||
* can be obtained from any data object using the getValidator method
|
||||
* @see Calendar::getValidator()
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Validator
|
||||
{
|
||||
/**
|
||||
* Instance of the Calendar date object to validate
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $calendar;
|
||||
|
||||
/**
|
||||
* Instance of the Calendar_Engine
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $cE;
|
||||
|
||||
/**
|
||||
* Array of errors for validation failures
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $errors = array();
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Validator
|
||||
* @param object subclass of Calendar
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Validator(& $calendar)
|
||||
{
|
||||
$this->calendar = & $calendar;
|
||||
$this->cE = & $calendar->getEngine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls all the other isValidXXX() methods in the validator
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValid()
|
||||
{
|
||||
$checks = array('isValidYear', 'isValidMonth', 'isValidDay',
|
||||
'isValidHour', 'isValidMinute', 'isValidSecond');
|
||||
$valid = true;
|
||||
foreach ($checks as $check) {
|
||||
if (!$this->{$check}()) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid year
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidYear()
|
||||
{
|
||||
$y = $this->calendar->thisYear();
|
||||
$min = $this->cE->getMinYears();
|
||||
if ($min > $y) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Year', $y, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = $this->cE->getMaxYears();
|
||||
if ($y > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Year', $y, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid month
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidMonth()
|
||||
{
|
||||
$m = $this->calendar->thisMonth();
|
||||
$min = 1;
|
||||
if ($min > $m) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Month', $m, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = $this->cE->getMonthsInYear($this->calendar->thisYear());
|
||||
if ($m > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Month', $m, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid day
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidDay()
|
||||
{
|
||||
$d = $this->calendar->thisDay();
|
||||
$min = 1;
|
||||
if ($min > $d) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Day', $d, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
if ($d > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Day', $d, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid hour
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidHour()
|
||||
{
|
||||
$h = $this->calendar->thisHour();
|
||||
$min = 0;
|
||||
if ($min > $h) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Hour', $h, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = ($this->cE->getHoursInDay($this->calendar->thisDay())-1);
|
||||
if ($h > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Hour', $h, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid minute
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidMinute()
|
||||
{
|
||||
$i = $this->calendar->thisMinute();
|
||||
$min = 0;
|
||||
if ($min > $i) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Minute', $i, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = ($this->cE->getMinutesInHour($this->calendar->thisHour())-1);
|
||||
if ($i > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Minute', $i, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid second
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidSecond()
|
||||
{
|
||||
$s = $this->calendar->thisSecond();
|
||||
$min = 0;
|
||||
if ($min > $s) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Second', $s, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = ($this->cE->getSecondsInMinute($this->calendar->thisMinute())-1);
|
||||
if ($s > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Second', $s, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over any validation errors
|
||||
* @return mixed either Calendar_Validation_Error or false
|
||||
* @access public
|
||||
*/
|
||||
function fetch()
|
||||
{
|
||||
$error = each ($this->errors);
|
||||
if ($error) {
|
||||
return $error['value'];
|
||||
} else {
|
||||
reset($this->errors);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For Validation Error messages
|
||||
* @see Calendar::fetch()
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Validation_Error
|
||||
{
|
||||
/**
|
||||
* Date unit (e.g. month,hour,second) which failed test
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $unit;
|
||||
|
||||
/**
|
||||
* Value of unit which failed test
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* Validation error message
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $message;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Validation_Error
|
||||
* @param string Date unit (e.g. month,hour,second)
|
||||
* @param int Value of unit which failed test
|
||||
* @param string Validation error message
|
||||
* @access protected
|
||||
*/
|
||||
function Calendar_Validation_Error($unit,$value,$message)
|
||||
{
|
||||
$this->unit = $unit;
|
||||
$this->value = $value;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Date unit
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getUnit()
|
||||
{
|
||||
return $this->unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the unit
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validation error message
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string containing the unit, value and error message
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toString ()
|
||||
{
|
||||
return $this->unit.' = '.$this->value.' ['.$this->message.']';
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Validator class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Validator.php 247251 2007-11-28 19:42:33Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validation Error Messages
|
||||
*/
|
||||
if (!defined('CALENDAR_VALUE_TOOSMALL')) {
|
||||
define('CALENDAR_VALUE_TOOSMALL', 'Too small: min = ');
|
||||
}
|
||||
if (!defined('CALENDAR_VALUE_TOOLARGE')) {
|
||||
define('CALENDAR_VALUE_TOOLARGE', 'Too large: max = ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to validate any given Calendar date object. Instances of this class
|
||||
* can be obtained from any data object using the getValidator method
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @see Calendar::getValidator()
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Validator
|
||||
{
|
||||
/**
|
||||
* Instance of the Calendar date object to validate
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $calendar;
|
||||
|
||||
/**
|
||||
* Instance of the Calendar_Engine
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $cE;
|
||||
|
||||
/**
|
||||
* Array of errors for validation failures
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $errors = array();
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Validator
|
||||
*
|
||||
* @param object &$calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Validator(&$calendar)
|
||||
{
|
||||
$this->calendar = & $calendar;
|
||||
$this->cE = & $calendar->getEngine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls all the other isValidXXX() methods in the validator
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValid()
|
||||
{
|
||||
$checks = array('isValidYear', 'isValidMonth', 'isValidDay',
|
||||
'isValidHour', 'isValidMinute', 'isValidSecond');
|
||||
$valid = true;
|
||||
foreach ($checks as $check) {
|
||||
if (!$this->{$check}()) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid year
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidYear()
|
||||
{
|
||||
$y = $this->calendar->thisYear();
|
||||
$min = $this->cE->getMinYears();
|
||||
if ($min > $y) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Year', $y, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = $this->cE->getMaxYears();
|
||||
if ($y > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Year', $y, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid month
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidMonth()
|
||||
{
|
||||
$m = $this->calendar->thisMonth();
|
||||
$min = 1;
|
||||
if ($min > $m) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Month', $m, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = $this->cE->getMonthsInYear($this->calendar->thisYear());
|
||||
if ($m > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Month', $m, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid day
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidDay()
|
||||
{
|
||||
$d = $this->calendar->thisDay();
|
||||
$min = 1;
|
||||
if ($min > $d) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Day', $d, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth()
|
||||
);
|
||||
if ($d > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Day', $d, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid hour
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidHour()
|
||||
{
|
||||
$h = $this->calendar->thisHour();
|
||||
$min = 0;
|
||||
if ($min > $h) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Hour', $h, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = ($this->cE->getHoursInDay($this->calendar->thisDay())-1);
|
||||
if ($h > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Hour', $h, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid minute
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidMinute()
|
||||
{
|
||||
$i = $this->calendar->thisMinute();
|
||||
$min = 0;
|
||||
if ($min > $i) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Minute', $i, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = ($this->cE->getMinutesInHour($this->calendar->thisHour())-1);
|
||||
if ($i > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Minute', $i, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this is a valid second
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidSecond()
|
||||
{
|
||||
$s = $this->calendar->thisSecond();
|
||||
$min = 0;
|
||||
if ($min > $s) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Second', $s, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
$max = ($this->cE->getSecondsInMinute($this->calendar->thisMinute())-1);
|
||||
if ($s > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Second', $s, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over any validation errors
|
||||
*
|
||||
* @return mixed either Calendar_Validation_Error or false
|
||||
* @access public
|
||||
*/
|
||||
function fetch()
|
||||
{
|
||||
$error = each($this->errors);
|
||||
if ($error) {
|
||||
return $error['value'];
|
||||
} else {
|
||||
reset($this->errors);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For Validation Error messages
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @see Calendar::fetch()
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Validation_Error
|
||||
{
|
||||
/**
|
||||
* Date unit (e.g. month,hour,second) which failed test
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $unit;
|
||||
|
||||
/**
|
||||
* Value of unit which failed test
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* Validation error message
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $message;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Validation_Error
|
||||
*
|
||||
* @param string $unit Date unit (e.g. month,hour,second)
|
||||
* @param int $value Value of unit which failed test
|
||||
* @param string $message Validation error message
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function Calendar_Validation_Error($unit, $value, $message)
|
||||
{
|
||||
$this->unit = $unit;
|
||||
$this->value = $value;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Date unit
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getUnit()
|
||||
{
|
||||
return $this->unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the unit
|
||||
*
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validation error message
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string containing the unit, value and error message
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toString ()
|
||||
{
|
||||
return $this->unit.' = '.$this->value.' ['.$this->message.']';
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,394 +1,470 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Week and builds Days in tabular format<br>
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Week.php';
|
||||
* $Week = & new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week
|
||||
* echo '<tr>';
|
||||
* while ($Day = & $Week->fetch()) {
|
||||
* if ($Day->isEmpty()) {
|
||||
* echo '<td> </td>';
|
||||
* } else {
|
||||
* echo '<td>'.$Day->thisDay().'</td>';
|
||||
* }
|
||||
* }
|
||||
* echo '</tr>';
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Week extends Calendar
|
||||
{
|
||||
/**
|
||||
* Instance of Calendar_Table_Helper
|
||||
* @var Calendar_Table_Helper
|
||||
* @access private
|
||||
*/
|
||||
var $tableHelper;
|
||||
|
||||
/**
|
||||
* Stores the timestamp of the first day of this week
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
var $thisWeek;
|
||||
|
||||
/**
|
||||
* Stores the timestamp of first day of previous week
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
var $prevWeek;
|
||||
|
||||
/**
|
||||
* Stores the timestamp of first day of next week
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
var $nextWeek;
|
||||
|
||||
/**
|
||||
* Used by build() to set empty days
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $firstWeek = false;
|
||||
|
||||
/**
|
||||
* Used by build() to set empty days
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $lastWeek = false;
|
||||
|
||||
/**
|
||||
* First day of the week (0=sunday, 1=monday...)
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $firstDay = 1;
|
||||
|
||||
/**
|
||||
* Constructs Week
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int a day of the desired week
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Week($y, $m, $d, $firstDay=null)
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
Calendar::Calendar($y, $m, $d);
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
|
||||
$this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay);
|
||||
$this->prevWeek = $this->tableHelper->getWeekStart($y, $m, $d - $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay);
|
||||
$this->nextWeek = $this->tableHelper->getWeekStart($y, $m, $d + $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
|
||||
* passed to the constructor
|
||||
* @param int|string Unix or ISO-8601 timestamp
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setTimestamp($ts)
|
||||
{
|
||||
parent::setTimestamp($ts);
|
||||
$this->thisWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year, $this->month, $this->day, $this->firstDay
|
||||
);
|
||||
$this->prevWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year, $this->month, $this->day - $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay
|
||||
);
|
||||
$this->nextWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year, $this->month, $this->day + $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Calendar_Day objects for this Week
|
||||
* @param array (optional) Calendar_Day objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
$year = $this->cE->stampToYear($this->thisWeek);
|
||||
$month = $this->cE->stampToMonth($this->thisWeek);
|
||||
$day = $this->cE->stampToDay($this->thisWeek);
|
||||
$end = $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
);
|
||||
|
||||
for ($i=1; $i <= $end; $i++) {
|
||||
$stamp = $this->cE->dateToStamp($year, $month, $day++);
|
||||
$this->children[$i] = new Calendar_Day(
|
||||
$this->cE->stampToYear($stamp),
|
||||
$this->cE->stampToMonth($stamp),
|
||||
$this->cE->stampToDay($stamp));
|
||||
}
|
||||
|
||||
//set empty days (@see Calendar_Month_Weeks::build())
|
||||
if ($this->firstWeek) {
|
||||
$eBefore = $this->tableHelper->getEmptyDaysBefore();
|
||||
for ($i=1; $i <= $eBefore; $i++) {
|
||||
$this->children[$i]->setEmpty();
|
||||
}
|
||||
}
|
||||
if ($this->lastWeek) {
|
||||
$eAfter = $this->tableHelper->getEmptyDaysAfterOffset();
|
||||
for ($i = $eAfter+1; $i <= $end; $i++) {
|
||||
$this->children[$i]->setEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirst($state=true)
|
||||
{
|
||||
$this->firstWeek = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setLast($state=true)
|
||||
{
|
||||
$this->lastWeek = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
foreach ($this->children as $key => $child) {
|
||||
if ($child->thisDay() == $sDate->thisDay() &&
|
||||
$child->thisMonth() == $sDate->thisMonth() &&
|
||||
$child->thisYear() == $sDate->thisYear()
|
||||
) {
|
||||
$this->children[$key] = $sDate;
|
||||
$this->children[$key]->setSelected();
|
||||
}
|
||||
}
|
||||
}
|
||||
reset($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the previous week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function prevWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1;
|
||||
break;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->prevWeek),
|
||||
$this->cE->stampToMonth($this->prevWeek),
|
||||
$this->cE->stampToDay($this->prevWeek));
|
||||
break;
|
||||
case 'array':
|
||||
return $this->toArray($this->prevWeek);
|
||||
break;
|
||||
case 'object':
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->prevWeek);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->prevWeek;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the current week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function thisWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
if ($this->firstWeek) {
|
||||
return 1;
|
||||
}
|
||||
if ($this->lastWeek) {
|
||||
return $this->cE->getWeeksInMonth(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->firstDay);
|
||||
}
|
||||
return $this->cE->getWeekNInMonth(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay(),
|
||||
$this->firstDay);
|
||||
break;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->thisWeek),
|
||||
$this->cE->stampToMonth($this->thisWeek),
|
||||
$this->cE->stampToDay($this->thisWeek));
|
||||
break;
|
||||
case 'array':
|
||||
return $this->toArray($this->thisWeek);
|
||||
break;
|
||||
case 'object':
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->thisWeek);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->thisWeek;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the following week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function nextWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1;
|
||||
break;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->nextWeek),
|
||||
$this->cE->stampToMonth($this->nextWeek),
|
||||
$this->cE->stampToDay($this->nextWeek));
|
||||
break;
|
||||
case 'array':
|
||||
return $this->toArray($this->nextWeek);
|
||||
break;
|
||||
case 'object':
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->nextWeek;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance of Calendar_Table_Helper.
|
||||
* Called from Calendar_Validator::isValidWeek
|
||||
* @return Calendar_Table_Helper
|
||||
* @access protected
|
||||
*/
|
||||
function & getHelper()
|
||||
{
|
||||
return $this->tableHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure theres a value for $this->day
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function findFirstDay()
|
||||
{
|
||||
if (!count($this->children) > 0) {
|
||||
$this->build();
|
||||
foreach ($this->children as $Day) {
|
||||
if (!$Day->isEmpty()) {
|
||||
$this->day = $Day->thisDay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Week class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Week.php 300729 2010-06-24 12:05:53Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Week and builds Days in tabular format<br>
|
||||
* <code>
|
||||
* require_once 'Calendar/Week.php';
|
||||
* $Week = new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week
|
||||
* echo '<tr>';
|
||||
* while ($Day = & $Week->fetch()) {
|
||||
* if ($Day->isEmpty()) {
|
||||
* echo '<td> </td>';
|
||||
* } else {
|
||||
* echo '<td>'.$Day->thisDay().'</td>';
|
||||
* }
|
||||
* }
|
||||
* echo '</tr>';
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
class Calendar_Week extends Calendar
|
||||
{
|
||||
/**
|
||||
* Instance of Calendar_Table_Helper
|
||||
* @var Calendar_Table_Helper
|
||||
* @access private
|
||||
*/
|
||||
var $tableHelper;
|
||||
|
||||
/**
|
||||
* Stores the timestamp of the first day of this week
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
var $thisWeek;
|
||||
|
||||
/**
|
||||
* Stores the timestamp of first day of previous week
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
var $prevWeek;
|
||||
|
||||
/**
|
||||
* Stores the timestamp of first day of next week
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
var $nextWeek;
|
||||
|
||||
/**
|
||||
* Used by build() to set empty days
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $firstWeek = false;
|
||||
|
||||
/**
|
||||
* Used by build() to set empty days
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $lastWeek = false;
|
||||
|
||||
/**
|
||||
* First day of the week (0=sunday, 1=monday...)
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $firstDay = 1;
|
||||
|
||||
/**
|
||||
* Constructs Week
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d a day of the desired week
|
||||
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Week($y, $m, $d, $firstDay = null)
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
parent::Calendar($y, $m, $d);
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
$this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
|
||||
$this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay);
|
||||
$this->prevWeek = $this->tableHelper->getWeekStart(
|
||||
$y,
|
||||
$m,
|
||||
$d - $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
$this->nextWeek = $this->tableHelper->getWeekStart(
|
||||
$y,
|
||||
$m,
|
||||
$d + $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
|
||||
* passed to the constructor
|
||||
*
|
||||
* @param int|string $ts Unix or ISO-8601 timestamp
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setTimestamp($ts)
|
||||
{
|
||||
parent::setTimestamp($ts);
|
||||
$this->thisWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year, $this->month, $this->day, $this->firstDay
|
||||
);
|
||||
$this->prevWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year,
|
||||
$this->month,
|
||||
$this->day - $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
$this->nextWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year,
|
||||
$this->month,
|
||||
$this->day + $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Calendar_Day objects for this Week
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Day.php';
|
||||
$year = $this->cE->stampToYear($this->thisWeek);
|
||||
$month = $this->cE->stampToMonth($this->thisWeek);
|
||||
$day = $this->cE->stampToDay($this->thisWeek);
|
||||
$end = $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
);
|
||||
|
||||
for ($i=1; $i <= $end; $i++) {
|
||||
$stamp = $this->cE->dateToStamp($year, $month, $day++);
|
||||
$this->children[$i] = new Calendar_Day(
|
||||
$this->cE->stampToYear($stamp),
|
||||
$this->cE->stampToMonth($stamp),
|
||||
$this->cE->stampToDay($stamp)
|
||||
);
|
||||
}
|
||||
|
||||
//set empty days (@see Calendar_Month_Weeks::build())
|
||||
if ($this->firstWeek) {
|
||||
$eBefore = $this->tableHelper->getEmptyDaysBefore();
|
||||
for ($i=1; $i <= $eBefore; $i++) {
|
||||
$this->children[$i]->setEmpty();
|
||||
}
|
||||
}
|
||||
if ($this->lastWeek) {
|
||||
$eAfter = $this->tableHelper->getEmptyDaysAfterOffset();
|
||||
for ($i = $eAfter+1; $i <= $end; $i++) {
|
||||
$this->children[$i]->setEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set as first week of the month
|
||||
*
|
||||
* @param boolean $state whether it's first or not
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirst($state = true)
|
||||
{
|
||||
$this->firstWeek = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set as last week of the month
|
||||
*
|
||||
* @param boolean $state whether it's lasst or not
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setLast($state = true)
|
||||
{
|
||||
$this->lastWeek = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
*
|
||||
* @param array $sDates Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
foreach ($this->children as $key => $child) {
|
||||
if ($child->thisDay() == $sDate->thisDay() &&
|
||||
$child->thisMonth() == $sDate->thisMonth() &&
|
||||
$child->thisYear() == $sDate->thisYear()
|
||||
) {
|
||||
$this->children[$key] = $sDate;
|
||||
$this->children[$key]->setSelected();
|
||||
}
|
||||
}
|
||||
}
|
||||
reset($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for this year
|
||||
*
|
||||
* When a on the first/last week of the year, the year of the week is
|
||||
* calculated according to ISO-8601
|
||||
*
|
||||
* @param string $format return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @return int e.g. 2003 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function thisYear($format = 'int')
|
||||
{
|
||||
if (null !== $this->thisWeek) {
|
||||
$tmp_cal = new Calendar();
|
||||
$tmp_cal->setTimestamp($this->thisWeek);
|
||||
$first_dow = $tmp_cal->thisDay('array');
|
||||
$days_in_week = $tmp_cal->cE->getDaysInWeek($tmp_cal->year, $tmp_cal->month, $tmp_cal->day);
|
||||
$tmp_cal->day += $days_in_week;
|
||||
$last_dow = $tmp_cal->thisDay('array');
|
||||
|
||||
if ($first_dow['year'] == $last_dow['year']) {
|
||||
return $first_dow['year'];
|
||||
}
|
||||
|
||||
if ($last_dow['day'] > floor($days_in_week / 2)) {
|
||||
return $last_dow['year'];
|
||||
}
|
||||
return $first_dow['year'];
|
||||
}
|
||||
return parent::thisYear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the previous week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function prevWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->prevWeek),
|
||||
$this->cE->stampToMonth($this->prevWeek),
|
||||
$this->cE->stampToDay($this->prevWeek));
|
||||
case 'array':
|
||||
return $this->toArray($this->prevWeek);
|
||||
case 'object':
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->prevWeek);
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->prevWeek;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the current week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function thisWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
if ($this->firstWeek) {
|
||||
return 1;
|
||||
}
|
||||
if ($this->lastWeek) {
|
||||
return $this->cE->getWeeksInMonth(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->firstDay);
|
||||
}
|
||||
return $this->cE->getWeekNInMonth(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay(),
|
||||
$this->firstDay);
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->thisWeek),
|
||||
$this->cE->stampToMonth($this->thisWeek),
|
||||
$this->cE->stampToDay($this->thisWeek));
|
||||
case 'array':
|
||||
return $this->toArray($this->thisWeek);
|
||||
case 'object':
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->thisWeek);
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->thisWeek;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the following week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function nextWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->nextWeek),
|
||||
$this->cE->stampToMonth($this->nextWeek),
|
||||
$this->cE->stampToDay($this->nextWeek));
|
||||
case 'array':
|
||||
return $this->toArray($this->nextWeek);
|
||||
case 'object':
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->nextWeek;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance of Calendar_Table_Helper.
|
||||
* Called from Calendar_Validator::isValidWeek
|
||||
*
|
||||
* @return Calendar_Table_Helper
|
||||
* @access protected
|
||||
*/
|
||||
function & getHelper()
|
||||
{
|
||||
return $this->tableHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure theres a value for $this->day
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function findFirstDay()
|
||||
{
|
||||
if (!count($this->children) > 0) {
|
||||
$this->build();
|
||||
foreach ($this->children as $Day) {
|
||||
if (!$Day->isEmpty()) {
|
||||
$this->day = $Day->thisDay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,113 +1,140 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo Exp $
|
||||
//
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Year and builds Months<br>
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Year.php';
|
||||
* $Year = & new Calendar_Year(2003, 10, 21); // 21st Oct 2003
|
||||
* $Year->build(); // Build Calendar_Month objects
|
||||
* while ($Month = & $Year->fetch()) {
|
||||
* echo $Month->thisMonth().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Year extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Year
|
||||
* @param int year e.g. 2003
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Year($y)
|
||||
{
|
||||
Calendar::Calendar($y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Months of the Year.<br>
|
||||
* <b>Note:</b> by defining the constant CALENDAR_MONTH_STATE you can
|
||||
* control what class of Calendar_Month is built e.g.;
|
||||
* <code>
|
||||
* require_once 'Calendar/Calendar_Year.php';
|
||||
* define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
|
||||
* </code>
|
||||
* It defaults to building Calendar_Month objects.
|
||||
* @param array (optional) array of Calendar_Month objects representing selected dates
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array(), $firstDay = null)
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
|
||||
for ($i=1; $i <= $monthsInYear; $i++) {
|
||||
$this->children[$i] = Calendar_Factory::create('Month', $this->year, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates) {
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()) {
|
||||
$key = $sDate->thisMonth();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Minute class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Year.php 300728 2010-06-24 11:43:56Z quipo $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allows Calendar include path to be redefined
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('CALENDAR_ROOT')) {
|
||||
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Calendar base class
|
||||
*/
|
||||
require_once CALENDAR_ROOT.'Calendar.php';
|
||||
|
||||
/**
|
||||
* Represents a Year and builds Months<br>
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Year.php';
|
||||
* $Year = & new Calendar_Year(2003, 10, 21); // 21st Oct 2003
|
||||
* $Year->build(); // Build Calendar_Month objects
|
||||
* while ($Month = & $Year->fetch()) {
|
||||
* echo $Month->thisMonth().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Year extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Year
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Year($y)
|
||||
{
|
||||
parent::Calendar($y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Months of the Year.<br>
|
||||
* <b>Note:</b> by defining the constant CALENDAR_MONTH_STATE you can
|
||||
* control what class of Calendar_Month is built e.g.;
|
||||
* <code>
|
||||
* require_once 'Calendar/Calendar_Year.php';
|
||||
* define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
|
||||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
|
||||
* </code>
|
||||
* It defaults to building Calendar_Month objects.
|
||||
*
|
||||
* @param array $sDates (optional) array of Calendar_Month objects
|
||||
* representing selected dates
|
||||
* @param int $firstDay (optional) first day of week
|
||||
* (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array(), $firstDay = null)
|
||||
{
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
|
||||
for ($i=1; $i <= $monthsInYear; $i++) {
|
||||
$this->children[$i] = Calendar_Factory::create('Month', $this->year, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
$this->setSelection($sDates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
*
|
||||
* @param array $sDates array of Calendar_Month objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()) {
|
||||
$key = $sDate->thisMonth();
|
||||
if (isset($this->children[$key])) {
|
||||
$sDate->setSelected();
|
||||
$this->children[$key] = $sDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user