| [ Index ] |
PHP Cross Reference of Web Application Component Toolkit |
[Summary view] [Print] [Text view]
1 <?php 2 //-------------------------------------------------------------------------------- 3 // Copyright 2003 Procata, Inc. 4 // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html) 5 //-------------------------------------------------------------------------------- 6 /** 7 * @package WACT_COMPONENT 8 * @version $Id: calendar_month.inc.php,v 1.5 2004/11/20 18:09:48 jeffmoore Exp $ 9 */ 10 //-------------------------------------------------------------------------------- 11 /** 12 * Include PEAR::Calendar 13 */ 14 15 //CALENDAR_ROOT 16 17 if ( !defined('CALENDAR_ROOT') ) { 18 define('CALENDAR_ROOT', ConfigManager::getOptionAsPath('config', 'pear', 'library_path') . 'Calendar/'); 19 } 20 if (!@include_once CALENDAR_ROOT . 'Month/Weekdays.php') { 21 RaiseError('runtime', 'LIBRARY_REQUIRED', array( 22 'library' => 'PEAR::Calendar v0.4+', 23 'path' => CALENDAR_ROOT)); 24 } 25 require_once CALENDAR_ROOT . 'Day.php'; 26 require_once CALENDAR_ROOT . 'Decorator/Textual.php'; 27 require_once CALENDAR_ROOT . 'Decorator/Uri.php'; 28 require_once CALENDAR_ROOT . 'Decorator/Wrapper.php'; 29 30 require_once WACT_ROOT . 'template/components/html/html_base.inc.php'; 31 //-------------------------------------------------------------------------------- 32 /** 33 * Runtime calendar API 34 * @todo EXPERIMENTAL 35 * @see http://wact.sourceforge.net/index.php/CalendarMonthComponent 36 * @access public 37 * @package WACT_COMPONENT 38 */ 39 class CalendarMonthComponent extends HtmlBaseComponent { 40 /** 41 * Instance of PEAR::Calendar_Month_Weekdays 42 * @var Calendar_Month_Weekdays 43 * @access private 44 */ 45 var $Calendar; 46 /** 47 * Instance of PEAR::Calendar_Decorator_Textual 48 * @var Calendar_Decorator_Textual 49 * @access private 50 */ 51 var $Textual; 52 /** 53 * Instance of PEAR::Calendar_Decorator_Uri 54 * @var Calendar_Decorator_Uri 55 * @access private 56 */ 57 var $Uri; 58 /** 59 * Instance of PEAR::Calendar_Decorator_Wrapper 60 * @var Calendar_Decorator_Wrapper 61 * @access private 62 */ 63 var $Wrapper; 64 65 var $baseUrl; 66 /** 67 * String for year GET variable 68 * @var string 69 * @access private 70 */ 71 var $yearUri = 'y'; 72 /** 73 * String for month GET variable 74 * @var string 75 * @access private 76 */ 77 var $monthUri = 'm'; 78 /** 79 * String for day GET variable 80 * @var string 81 * @access private 82 */ 83 var $dayUri = 'd'; 84 /** 85 * Array of PEAR::Calendar_Day objects to be used in selection 86 * @var array 87 * @access private 88 */ 89 var $selection = array(); 90 91 function CalendarMonthComponent() { 92 $this->baseUrl = $_SERVER['REQUEST_URI']; 93 $pos = strpos($this->baseUrl, '?'); 94 if (is_integer($pos)) { 95 $this->baseUrl = substr($this->baseUrl, 0, $pos); 96 } 97 } 98 99 /** 100 * Returns the URI string for the previous month 101 * @return string 102 * @access protected 103 */ 104 function prevLink() { 105 return $this->getBaseUri().$this->Uri->prev('month'); 106 } 107 /** 108 * Returns the URI string for the next month 109 * @return string 110 * @access protected 111 */ 112 function nextLink() { 113 return $this->getBaseUri().$this->Uri->next('month'); 114 } 115 116 function dayLink($day) { 117 return $this->getBaseUri().$this->Uri->this('day'); 118 } 119 /** 120 * Returns the year 121 * @param string how to format: 'full', 'two' (digits) or 'hide' 122 * @return string 123 * @access protected 124 */ 125 function yearFormatted($format) { 126 $formats = array('full','two','hide'); 127 if ( !in_array($format,$formats) ) { 128 $format = 'full'; 129 } 130 switch ( $format ) { 131 case 'hide': 132 return ''; 133 break; 134 case 'two': 135 return substr($this->Calendar->thisYear(),2); 136 break; 137 case 'full': 138 case 'default': 139 return $this->Calendar->thisYear(); 140 break; 141 } 142 } 143 /** 144 * Returns the month name formated 145 * @param string how to format: 'long', 'short','two','one' 146 * @return string 147 * @access protected 148 */ 149 function monthName($format) { 150 return $this->Textual->thisMonthName($format); 151 } 152 /** 153 * Returns the headers for the days of the week 154 * @param string how to format: 'long', 'short','two','one' 155 * @return string 156 * @access protected 157 */ 158 function dayHeaders($format) { 159 return $this->Textual->orderedWeekdays($format); 160 } 161 /** 162 * Sets a selection of PEAR::Calendar_Day objects 163 * @param array 164 * @return void 165 * @access public 166 */ 167 function setSelection(& $selection) { 168 $this->selection = & $selection; 169 } 170 /** 171 * @return void 172 * @access protected 173 */ 174 function prepare() { 175 if ( !isset($_GET[$this->yearUri]) ) $_GET[$this->yearUri] = date('Y'); 176 if ( !isset($_GET[$this->monthUri]) ) $_GET[$this->monthUri] = date('n'); 177 178 $this->Calendar = & new Calendar_Month_Weekdays($_GET[$this->yearUri],$_GET[$this->monthUri]); 179 $this->Textual = & new Calendar_Decorator_Textual($this->Calendar); 180 $this->Uri = & new Calendar_Decorator_Uri($this->Calendar); 181 $this->Uri->setFragments($this->yearUri,$this->monthUri); 182 $this->Wrapper = & new Calendar_Decorator_Wrapper($this->Calendar); 183 $selection = array(); 184 $selection[] = new Calendar_Day(date('Y'),date('n'),date('d')); 185 if ( isset($_GET[$this->dayUri]) ) { 186 $selection[] = new Calendar_Day($_GET[$this->yearUri],$_GET[$this->monthUri],$_GET[$this->dayUri]); 187 } 188 if ( count ($this->selection) > 0 ) { 189 foreach ( array_keys($this->selection) as $key ) { 190 $selection[] = & $this->selection[$key]; 191 } 192 } 193 $this->Wrapper->build($selection); 194 } 195 /** 196 * Returns the PEAR::Calendar_Month_Weekdays object wrapped in a 197 * Calendar_Decorator_Wrapper instance 198 * @return Calendar_Decorator_Wrapper 199 * @access protected 200 */ 201 function & getCalendar() { 202 return $this->Wrapper; 203 } 204 205 /** 206 * Return the URI to a specific page in the list. 207 * @return string 208 * @access public 209 */ 210 function getBaseUri() { 211 212 $params = $_GET; 213 if ( isset($params[$this->yearUri]) ) { 214 unset($params[$this->yearUri]); 215 } 216 if ( isset($params[$this->monthUri]) ) { 217 unset($params[$this->monthUri]); 218 } 219 if ( isset($params[$this->dayUri]) ) { 220 unset($params[$this->dayUri]); 221 } 222 223 $sep = ''; 224 $query = ''; 225 foreach ($params as $key => $value) { 226 $query .= $sep . $key . '=' . urlencode($value); 227 $sep = '&'; 228 } 229 if (empty($query)) { 230 return $this->baseUrl.'?'; 231 } else { 232 return $this->baseUrl . '?' . $query . '&'; 233 } 234 235 } 236 } 237 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Nov 28 19:36:09 2004 | Cross-referenced by PHPXref 0.5 |