VJournal.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Sabre\VObject\Component;
  3. use DateTimeInterface;
  4. use Sabre\VObject;
  5. /**
  6. * VJournal component.
  7. *
  8. * This component contains some additional functionality specific for VJOURNALs.
  9. *
  10. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. class VJournal extends VObject\Component
  15. {
  16. /**
  17. * Returns true or false depending on if the event falls in the specified
  18. * time-range. This is used for filtering purposes.
  19. *
  20. * The rules used to determine if an event falls within the specified
  21. * time-range is based on the CalDAV specification.
  22. *
  23. * @return bool
  24. */
  25. public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
  26. {
  27. $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null;
  28. if ($dtstart) {
  29. $effectiveEnd = $dtstart;
  30. if (!$this->DTSTART->hasTime()) {
  31. $effectiveEnd = $effectiveEnd->modify('+1 day');
  32. }
  33. return $start <= $effectiveEnd && $end > $dtstart;
  34. }
  35. return false;
  36. }
  37. /**
  38. * A simple list of validation rules.
  39. *
  40. * This is simply a list of properties, and how many times they either
  41. * must or must not appear.
  42. *
  43. * Possible values per property:
  44. * * 0 - Must not appear.
  45. * * 1 - Must appear exactly once.
  46. * * + - Must appear at least once.
  47. * * * - Can appear any number of times.
  48. * * ? - May appear, but not more than once.
  49. *
  50. * @var array
  51. */
  52. public function getValidationRules()
  53. {
  54. return [
  55. 'UID' => 1,
  56. 'DTSTAMP' => 1,
  57. 'CLASS' => '?',
  58. 'CREATED' => '?',
  59. 'DTSTART' => '?',
  60. 'LAST-MODIFIED' => '?',
  61. 'ORGANIZER' => '?',
  62. 'RECURRENCE-ID' => '?',
  63. 'SEQUENCE' => '?',
  64. 'STATUS' => '?',
  65. 'SUMMARY' => '?',
  66. 'URL' => '?',
  67. 'RRULE' => '?',
  68. 'ATTACH' => '*',
  69. 'ATTENDEE' => '*',
  70. 'CATEGORIES' => '*',
  71. 'COMMENT' => '*',
  72. 'CONTACT' => '*',
  73. 'DESCRIPTION' => '*',
  74. 'EXDATE' => '*',
  75. 'RELATED-TO' => '*',
  76. 'RDATE' => '*',
  77. ];
  78. }
  79. /**
  80. * This method should return a list of default property values.
  81. *
  82. * @return array
  83. */
  84. protected function getDefaults()
  85. {
  86. return [
  87. 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(),
  88. 'DTSTAMP' => gmdate('Ymd\\THis\\Z'),
  89. ];
  90. }
  91. }