PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Joomla_1_6_x/com_gcalendar/admin/libraries/GCalendar/Entry.php

http://joomla-gcalendar.googlecode.com/
PHP | 171 lines | 109 code | 16 blank | 46 comment | 29 complexity | be29802f58e151120bcaf7382ba05fbe MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * GCalendar is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * GCalendar is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with GCalendar. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * @author Allon Moritz
  17. * @copyright 2007-2011 Allon Moritz
  18. * @since 2.2.0
  19. */
  20. class GCalendar_Entry extends Zend_Gdata_Calendar_EventEntry{
  21. const SINGLE_WHOLE_DAY = 1;
  22. const SINGLE_PART_DAY = 2;
  23. const MULTIPLE_WHOLE_DAY = 3;
  24. const MULTIPLE_PART_DAY = 4;
  25. private $dayType = null;
  26. private $startDate = null;
  27. private $endDate = null;
  28. private $location = null;
  29. private $gcalId = null;
  30. private $params = array();
  31. public function setParam($key, $value){
  32. $this->params[$key] = $value;
  33. }
  34. public function getParam($key){
  35. return $this->params[$key];
  36. }
  37. public function getGCalId(){
  38. if($this->gcalId == null){
  39. $this->gcalId = substr($this->getId(), strrpos($this->getId(), '/')+1);
  40. }
  41. return $this->gcalId;
  42. }
  43. public function getDayType(){
  44. if($this->dayType == null){
  45. $SECSINDAY = 86400;
  46. $oldTz = null;
  47. $timezone = $this->getTimezone();
  48. if(!empty($timezone) && function_exists('date_default_timezone_get')){
  49. $oldTz = date_default_timezone_get();
  50. date_default_timezone_set($timezone);
  51. }
  52. if (($this->getStartDate()+ $SECSINDAY) <= $this->getEndDate()) {
  53. if (($this->getStartDate()+ $SECSINDAY) == $this->getEndDate() && (date('g:i a',$this->getStartDate())=='12:00 am')) {
  54. $this->dayType = GCalendar_Entry::SINGLE_WHOLE_DAY;
  55. } else {
  56. if ((date('g:i a',$this->getStartDate())=='12:00 am')&&(date('g:i a',$this->getEndDate())=='12:00 am')){
  57. $this->dayType = GCalendar_Entry::MULTIPLE_WHOLE_DAY;
  58. }else{
  59. $this->dayType = GCalendar_Entry::MULTIPLE_PART_DAY;
  60. }
  61. }
  62. }else{
  63. $this->dayType = GCalendar_Entry::SINGLE_PART_DAY;
  64. }
  65. if($oldTz != null){
  66. date_default_timezone_set($oldTz);
  67. }
  68. }
  69. return $this->dayType;
  70. }
  71. public function getStartDate(){
  72. if($this->startDate == null){
  73. $when = $this->getWhen();
  74. if(empty($when)){
  75. return null;
  76. }
  77. if(is_array($when)){
  78. $when = reset($when);
  79. }
  80. $this->startDate = $this->tstamptotime($when->getStartTime());
  81. }
  82. return $this->startDate;
  83. }
  84. public function getEndDate(){
  85. if($this->endDate == null){
  86. $when = $this->getWhen();
  87. if(empty($when)){
  88. return null;
  89. }
  90. if(is_array($when)){
  91. $when = reset($when);
  92. }
  93. $this->endDate = $this->tstamptotime($when->getEndTime());
  94. }
  95. return $this->endDate;
  96. }
  97. public function getLocation(){
  98. if($this->location == null){
  99. $where = $this->getWhere();
  100. if(is_array($where)){
  101. $where = reset($where);
  102. }
  103. $this->location = $where->getValueString();
  104. }
  105. return $this->location;
  106. }
  107. /**
  108. * Returns a unix timestamp of the given iso date.
  109. *
  110. * @param $iso_date
  111. * @return unix timestamp
  112. */
  113. private function tstamptotime($iso_date) {
  114. // converts ISODATE to unix date
  115. // 1984-09-01T14:21:31Z
  116. $feed_timezone = $this->getTimezone();
  117. if(!empty($feed_timezone) && function_exists('date_default_timezone_get')){
  118. $tz = date_default_timezone_get();
  119. date_default_timezone_set($feed_timezone);
  120. }
  121. sscanf($iso_date,"%u-%u-%uT%u:%u:%uZ",$year,$month,$day,$hour,$min,$sec);
  122. $newtstamp = mktime($hour,$min,$sec,$month,$day,$year);
  123. if(!empty($feed_timezone) && function_exists('date_default_timezone_get')){
  124. date_default_timezone_set($tz);
  125. }
  126. return $newtstamp;
  127. }
  128. /**
  129. * Returns an integer less than, equal to, or greater than zero if
  130. * the first argument is considered to be respectively less than,
  131. * equal to, or greater than the second.
  132. * This function can be used to sort an array of GCalendar_Entry
  133. * items with usort.
  134. *
  135. * @see http://www.php.net/usort
  136. * @param $event1
  137. * @param $event2
  138. * @return the comparison integer
  139. */
  140. public function compare(GCalendar_Entry $event1, GCalendar_Entry $event2){
  141. return $event1->getStartDate()-$event2->getStartDate();
  142. }
  143. /**
  144. * Compares the events descnding.
  145. *
  146. * @see GCalendar_Entry::compare()
  147. * @param GCalendar_Entry $event1
  148. * @param GCalendar_Entry $event2
  149. * @return number
  150. */
  151. public function compareDesc(GCalendar_Entry $event1, GCalendar_Entry $event2){
  152. return $event2->getStartDate()-$event1->getStartDate();
  153. }
  154. }
  155. ?>