PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/iCalendar_v2/class.iCalEvent.inc.php

http://flaimo-php.googlecode.com/
PHP | 404 lines | 120 code | 31 blank | 253 comment | 18 complexity | 9125a9ad7ed244463397ce70102d2e76 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. //+----------------------------------------------------------------------+
  4. //| WAMP (XP-SP2/2.2/5.2/5.1.0) |
  5. //+----------------------------------------------------------------------+
  6. //| Copyright(c) 2001-2008 Michael Wimmer |
  7. //+----------------------------------------------------------------------+
  8. //| Licence: GNU General Public License v3 |
  9. //+----------------------------------------------------------------------+
  10. //| Authors: Michael Wimmer <flaimo@gmail.com> |
  11. //+----------------------------------------------------------------------+
  12. //
  13. // $Id$
  14. /**
  15. * @package iCalendar Everything to generate simple iCal files
  16. */
  17. /**
  18. * We need the base class
  19. */
  20. include_once 'class.iCalBase.inc.php';
  21. /**
  22. * Container for a single event
  23. *
  24. * Tested with WAMP (XP-SP2/2.2/5.2/5.1.0)
  25. * Last Change: 2008-04-07
  26. *
  27. * @access public
  28. * @author Michael Wimmer <flaimo@gmail.com>
  29. * @copyright Copyright Š 2002-2008, Michael Wimmer
  30. * @license GNU General Public License v3
  31. * @link http://code.google.com/p/flaimo-php/
  32. * @package iCalendar
  33. * @version 2.002
  34. */
  35. class iCalEvent extends iCalBase {
  36. /*-------------------*/
  37. /* V A R I A B L E S */
  38. /*-------------------*/
  39. /**
  40. * Timestamp of the start date
  41. *
  42. * @var int
  43. */
  44. private $startdate_ts;
  45. /**
  46. * Timestamp of the end date
  47. *
  48. * @var int
  49. */
  50. private $enddate_ts;
  51. /**
  52. * OPAQUE (1) or TRANSPARENT (1)
  53. *
  54. * @var int
  55. */
  56. private $transp = 0;
  57. /**
  58. * start date in iCal format
  59. *
  60. * @var string
  61. */
  62. private $startdate;
  63. /**
  64. * end date in iCal format
  65. *
  66. * @var string
  67. */
  68. private $enddate;
  69. /**
  70. * Automaticaly created: md5 value of the start date + end date
  71. *
  72. * @var string
  73. */
  74. private $uid;
  75. /**
  76. * '' = never, integer < 4 numbers = number of times, integer >= 4 = timestamp
  77. *
  78. * @var mixed
  79. */
  80. private $rec_end;
  81. /**
  82. * If alarm is set, holds alarm object
  83. *
  84. * @var object
  85. */
  86. private $alarm;
  87. /*-----------------------*/
  88. /* C O N S T R U C T O R */
  89. /*-----------------------*/
  90. /**#@+
  91. * @return void
  92. */
  93. /**
  94. * Constructor
  95. *
  96. * Only job is to set all the variablesnames
  97. *
  98. * @param array $organizer The organizer - use array('Name', 'name@domain.com')
  99. * @param int $start Start time for the event (timestamp; if you want an allday event the startdate has to start at 00:00:00)
  100. * @param int $end Start time for the event (timestamp or write 'allday' for an allday event)
  101. * @param string $location Location
  102. * @param int $transp Transparancy (0 = OPAQUE | 1 = TRANSPARENT)
  103. * @param array $categories Array with Strings (example: array('Freetime','Party'))
  104. * @param string $description Description
  105. * @param string $summary Title for the event
  106. * @param int $class (0 = PRIVATE | 1 = PUBLIC | 2 = CONFIDENTIAL)
  107. * @param array $attendees key = attendee name, value = e-mail, second value = role of the attendee [0 = CHAIR | 1 = REQ | 2 = OPT | 3 =NON] (example: array('Michi' => 'flaimo@gmx.net,1'); )
  108. * @param int $prio riority = 0&#x2013;9
  109. * @param int $frequency frequency: 0 = once, secoundly &#x2013; yearly = 1&#x2013;7
  110. * @param mixed $rec_end recurrency end: ('' = forever | integer = number of times | timestring = explicit date)
  111. * @param int $interval Interval for frequency (every 2,3,4 weeks&#x2026;)
  112. * @param string $days Array with the number of the days the event accures (example: array(0,1,5) = Sunday, Monday, Friday
  113. * @param string $weekstart Startday of the Week ( 0 = Sunday - 6 = Saturday)
  114. * @param string $exept_dates exeption dates: Array with timestamps of dates that should not be includes in the recurring event
  115. * @param array $alarm Array with all the alarm information, "''" for no alarm
  116. * @param int $status Status of the event (0 = TENTATIVE, 1 = CONFIRMED, 2 = CANCELLED)
  117. * @param string $url optional URL for that event
  118. * @param string $language Language of the strings used in the event (iso code)
  119. * @param string $uid Optional UID for the event
  120. * @uses iCalBase::setLanguage()
  121. * @uses iCalBase::setOrganizer()
  122. * @uses setStartDate()
  123. * @uses setEndDate()
  124. * @uses iCalBase::setLocation()
  125. * @uses setTransp()
  126. * @uses iCalBase::setSequence()
  127. * @uses iCalBase::setCategories()
  128. * @uses iCalBase::setDescription()
  129. * @uses iCalBase::setSummary()
  130. * @uses iCalBase::setPriority()
  131. * @uses iCalBase::setClass()
  132. * @uses setUID()
  133. * @uses iCalBase::setAttendees()
  134. * @uses iCalBase::setFrequency()
  135. * @uses setRecEnd()
  136. * @uses iCalBase::setInterval()
  137. * @uses iCalBase::setDays()
  138. * @uses iCalBase::setWeekStart()
  139. * @uses iCalBase::setExeptDates()
  140. * @uses iCalBase::setStatus()
  141. * @uses setAlarm()
  142. * @uses iCalBase::setURL()
  143. * @uses setUID()
  144. */
  145. function __construct($organizer, $start, $end, $location, $transp, $categories,
  146. $description, $summary, $class, $attendees, $prio, $frequency,
  147. $rec_end, $interval, $days, $weekstart, $exept_dates,
  148. $alarm, $status, $url, $language, $uid) {
  149. parent::__construct();
  150. parent::setLanguage($language);
  151. parent::setOrganizer($organizer);
  152. $this->setStartDate($start);
  153. $this->setEndDate($end);
  154. parent::setLocation($location);
  155. $this->setTransp($transp);
  156. parent::setSequence(0);
  157. parent::setCategories($categories);
  158. parent::setDescription($description);
  159. parent::setSummary($summary);
  160. parent::setPriority($prio);
  161. parent::setClass($class);
  162. parent::setAttendees($attendees);
  163. parent::setFrequency($frequency);
  164. $this->setRecEnd($rec_end);
  165. parent::setInterval($interval);
  166. parent::setDays($days);
  167. parent::setWeekStart($weekstart);
  168. parent::setExeptDates($exept_dates);
  169. parent::setStatus($status);
  170. $this->setAlarm($alarm);
  171. parent::setURL($url);
  172. $this->setUID($uid);
  173. } // end constructor
  174. /*-------------------*/
  175. /* F U N C T I O N S */
  176. /*-------------------*/
  177. /**
  178. * Sets the end for a recurring event (0 = never ending,
  179. * integer < 4 numbers = number of times, integer >= 4 enddate)
  180. *
  181. * @param int $freq
  182. * @see getRecEnd()
  183. * @uses iCalEvent::$rec_end
  184. * @since 1.010 - 2002-10-26
  185. */
  186. private function setRecEnd($freq = '') {
  187. if (strlen(trim($freq)) < 1) {
  188. $this->rec_end = 0;
  189. } elseif (is_int($freq) && strlen(trim($freq)) < 4) {
  190. $this->rec_end = $freq;
  191. } else {
  192. $this->rec_end = (string) parent::formatDate($freq);
  193. } // end if
  194. } // end function
  195. /**
  196. * Set $startdate_ts variable
  197. *
  198. * @param int $timestamp
  199. * @see getStartDateTS()
  200. * @uses iCalEvent::$startdate_ts
  201. */
  202. private function setStartDateTS($timestamp = 0) {
  203. if (is_int($timestamp) && $timestamp > 0) {
  204. $this->startdate_ts = (int) $timestamp;
  205. } else {
  206. $this->startdate_ts = (int) ((isset($this->enddate_ts) && is_numeric($this->enddate_ts) && $this->enddate_ts > 0) ? ($this->enddate_ts - 3600) : time());
  207. } // end if
  208. } // end function
  209. /**
  210. * Set $enddate_ts variable
  211. *
  212. * @param int $timestamp
  213. * @see getEndDateTS()
  214. * @uses iCalEvent::$enddate_ts
  215. */
  216. private function setEndDateTS($timestamp = 0) {
  217. if (is_int($timestamp) && $timestamp > 0) {
  218. $this->enddate_ts = (int) $timestamp;
  219. } else {
  220. $this->enddate_ts = (int) ((isset($this->startdate_ts) && is_numeric($this->startdate_ts) && $this->startdate_ts > 0) ? ($this->startdate_ts + 3600) : (time() + 3600));
  221. } // end if
  222. } // end function
  223. /**
  224. * Set $startdate variable
  225. *
  226. * @param int $timestamp
  227. * @see getStartDate()
  228. * @uses setStartDateTS()
  229. * @uses iCalEvent::$startdate
  230. * @uses iCalEvent::$startdate_ts
  231. */
  232. private function setStartDate($timestamp = 0) {
  233. $this->setStartDateTS($timestamp);
  234. $this->startdate = (string) parent::formatDate($this->startdate_ts);
  235. } // end function
  236. /**
  237. * Set $enddate variable
  238. *
  239. * @param (mixed) $timestamp or 'allday'
  240. * @see getEndDate()
  241. * @uses iCalEvent::$enddate
  242. * @uses iCalEvent::$enddate_ts
  243. * @uses setEndDateTS()
  244. */
  245. private function setEndDate($timestamp = 0) {
  246. if (is_int($timestamp)) {
  247. $this->setEndDateTS($timestamp);
  248. $this->enddate = (string) parent::formatDate($this->enddate_ts);
  249. } else {
  250. $this->enddate = (string) '';
  251. } // end if
  252. } // end function
  253. /**
  254. * Set $transp variable
  255. *
  256. * @param int $int 0|1
  257. * @see getTransp()
  258. * @uses iCalEvent::$transp
  259. */
  260. private function setTransp($int = 0) {
  261. $this->transp = (int) $int;
  262. } // end function
  263. /**
  264. * Set $uid variable
  265. *
  266. * @param int $uid
  267. * @see getUID()
  268. * @uses iCalEvent::$uid
  269. * @uses iCalEvent::$startdate
  270. * @uses iCalEvent::$enddate
  271. */
  272. private function setUID($uid = 0) {
  273. if (strlen(trim($uid)) > 0) {
  274. $this->uid = (string) $uid;
  275. } else {
  276. $rawid = (string) $this->startdate . 'plus' . $this->enddate;
  277. $this->uid = (string) md5($rawid);
  278. }
  279. } // end function
  280. /**
  281. * Set $alarm object
  282. *
  283. * @param array $alarm
  284. * @see getAttendees()
  285. * @uses iCalEvent::$alarm
  286. * @uses iCalAlarm
  287. * @since 1.001 - 2002-10-10
  288. */
  289. private function setAlarm($alarm = '') {
  290. if (is_array($alarm)) {
  291. $this->alarm = (object) new iCalAlarm($alarm[0], $alarm[1],
  292. $alarm[2], $alarm[3], $alarm[4],
  293. $alarm[5], $alarm[6], parent::getLanguage());
  294. } // end if
  295. } // end function
  296. /**#@-*/
  297. /**
  298. * Get $rec_end variable
  299. *
  300. * @return mixed $rec_end
  301. * @see setRecEnd()
  302. * @since 1.010 - 2002-10-26
  303. */
  304. public function getRecEnd() {
  305. return $this->rec_end;
  306. } // end function
  307. /**
  308. * Get $startdate_ts variable
  309. *
  310. * @return int $startdate_ts
  311. * @see setStartDateTS()
  312. */
  313. public function getStartDateTS() {
  314. return (int) $this->startdate_ts;
  315. } // end function
  316. /**
  317. * Get $enddate_ts variable
  318. *
  319. * @return int $enddate_ts
  320. * @see setEndDateTS()
  321. */
  322. public function getEndDateTS() {
  323. return (int) $this->enddate_ts;
  324. } // end function
  325. /**
  326. * Get $startdate variable
  327. *
  328. * @return int $startdate
  329. * @see setStartDate()
  330. */
  331. public function getStartDate() {
  332. return (string) $this->startdate;
  333. } // end function
  334. /**
  335. * Get $enddate variable
  336. *
  337. * @return string $enddate
  338. * @see setEndDate()
  339. */
  340. public function getEndDate() {
  341. return (string) $this->enddate;
  342. } // end function
  343. /**
  344. * Get $transp variable
  345. *
  346. * @return int $transp
  347. * @see setTransp()
  348. */
  349. public function getTransp() {
  350. $transps = (array) array('OPAQUE','TRANSPARENT');
  351. return (string) ((array_key_exists($this->transp, $transps)) ? $transps[$this->transp] : $transps[0]);
  352. } // end function
  353. /**
  354. * Get $uid variable
  355. *
  356. * @return string $uid
  357. * @see setUID()
  358. */
  359. public function getUID() {
  360. return (string) $this->uid;
  361. } // end function
  362. /**
  363. * Get $alarm object
  364. *
  365. * @return string $alarm
  366. * @see setAlarm()
  367. * @since 1.001 - 2002-10-10
  368. */
  369. public function getAlarm() {
  370. return ((is_object($this->alarm)) ? $this->alarm : FALSE);
  371. } // end function
  372. } // end class iCalEvent
  373. ?>