VEvent.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace Sabre\VObject\Component;
  3. use Sabre\VObject;
  4. use Sabre\VObject\Recur\EventIterator;
  5. /**
  6. * VEvent component
  7. *
  8. * This component contains some additional functionality specific for VEVENT's.
  9. *
  10. * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. class VEvent extends VObject\Component {
  15. /**
  16. * Returns true or false depending on if the event falls in the specified
  17. * time-range. This is used for filtering purposes.
  18. *
  19. * The rules used to determine if an event falls within the specified
  20. * time-range is based on the CalDAV specification.
  21. *
  22. * @param \DateTime $start
  23. * @param \DateTime $end
  24. * @return bool
  25. */
  26. public function isInTimeRange(\DateTime $start, \DateTime $end) {
  27. if ($this->RRULE) {
  28. $it = new EventIterator($this);
  29. $it->fastForward($start);
  30. // We fast-forwarded to a spot where the end-time of the
  31. // recurrence instance exceeded the start of the requested
  32. // time-range.
  33. //
  34. // If the starttime of the recurrence did not exceed the
  35. // end of the time range as well, we have a match.
  36. return ($it->getDTStart() < $end && $it->getDTEnd() > $start);
  37. }
  38. $effectiveStart = $this->DTSTART->getDateTime();
  39. if (isset($this->DTEND)) {
  40. // The DTEND property is considered non inclusive. So for a 3 day
  41. // event in july, dtstart and dtend would have to be July 1st and
  42. // July 4th respectively.
  43. //
  44. // See:
  45. // http://tools.ietf.org/html/rfc5545#page-54
  46. $effectiveEnd = $this->DTEND->getDateTime();
  47. } elseif (isset($this->DURATION)) {
  48. $effectiveEnd = clone $effectiveStart;
  49. $effectiveEnd->add(VObject\DateTimeParser::parseDuration($this->DURATION));
  50. } elseif (!$this->DTSTART->hasTime()) {
  51. $effectiveEnd = clone $effectiveStart;
  52. $effectiveEnd->modify('+1 day');
  53. } else {
  54. $effectiveEnd = clone $effectiveStart;
  55. }
  56. return (
  57. ($start <= $effectiveEnd) && ($end > $effectiveStart)
  58. );
  59. }
  60. /**
  61. * This method should return a list of default property values.
  62. *
  63. * @return array
  64. */
  65. protected function getDefaults() {
  66. return array(
  67. 'UID' => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
  68. 'DTSTAMP' => date('Ymd\\THis\\Z'),
  69. );
  70. }
  71. /**
  72. * A simple list of validation rules.
  73. *
  74. * This is simply a list of properties, and how many times they either
  75. * must or must not appear.
  76. *
  77. * Possible values per property:
  78. * * 0 - Must not appear.
  79. * * 1 - Must appear exactly once.
  80. * * + - Must appear at least once.
  81. * * * - Can appear any number of times.
  82. *
  83. * @var array
  84. */
  85. public function getValidationRules() {
  86. $hasMethod = isset($this->parent->METHOD);
  87. return array(
  88. 'UID' => 1,
  89. 'DTSTAMP' => 1,
  90. 'DTSTART' => $hasMethod?'?':'1',
  91. 'CLASS' => '?',
  92. 'CREATED' => '?',
  93. 'DESCRIPTION' => '?',
  94. 'GEO' => '?',
  95. 'LAST-MODIFICATION' => '?',
  96. 'LOCATION' => '?',
  97. 'ORGANIZER' => '?',
  98. 'PRIORITY' => '?',
  99. 'SEQUENCE' => '?',
  100. 'STATUS' => '?',
  101. 'SUMMARY' => '?',
  102. 'TRANSP' => '?',
  103. 'URL' => '?',
  104. 'RECURRENCE-ID' => '?',
  105. 'RRULE' => '?',
  106. 'DTEND' => '?',
  107. 'DURATION' => '?',
  108. 'ATTACH' => '*',
  109. 'ATTENDEE' => '*',
  110. 'CATEGORIES' => '*',
  111. 'COMMENT' => '*',
  112. 'CONTACT' => '*',
  113. 'EXDATE' => '*',
  114. 'REQUEST-STATUS' => '*',
  115. 'RELATED-TO' => '*',
  116. 'RESOURCES' => '*',
  117. 'RDATE' => '*',
  118. );
  119. }
  120. }