Available.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Sabre\VObject\Component;
  3. use Sabre\VObject;
  4. /**
  5. * The Available sub-component
  6. *
  7. * This component adds functionality to a component, specific for AVAILABLE
  8. * components.
  9. *
  10. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  11. * @author Ivan Enderlin
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. class Available extends VObject\Component {
  15. /**
  16. * A simple list of validation rules.
  17. *
  18. * This is simply a list of properties, and how many times they either
  19. * must or must not appear.
  20. *
  21. * Possible values per property:
  22. * * 0 - Must not appear.
  23. * * 1 - Must appear exactly once.
  24. * * + - Must appear at least once.
  25. * * * - Can appear any number of times.
  26. * * ? - May appear, but not more than once.
  27. *
  28. * @var array
  29. */
  30. function getValidationRules() {
  31. return array(
  32. 'UID' => 1,
  33. 'DTSTART' => 1,
  34. 'DTSTAMP' => 1,
  35. 'DTEND' => '?',
  36. 'DURATION' => '?',
  37. 'CREATED' => '?',
  38. 'DESCRIPTION' => '?',
  39. 'LAST-MODIFIED' => '?',
  40. 'RECURRENCE-ID' => '?',
  41. 'RRULE' => '?',
  42. 'SUMMARY' => '?',
  43. 'CATEGORIES' => '*',
  44. 'COMMENT' => '*',
  45. 'CONTACT' => '*',
  46. 'EXDATE' => '*',
  47. 'RDATE' => '*',
  48. 'AVAILABLE' => '*',
  49. );
  50. }
  51. /**
  52. * Validates the node for correctness.
  53. *
  54. * The following options are supported:
  55. * Node::REPAIR - May attempt to automatically repair the problem.
  56. * Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
  57. * Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
  58. *
  59. * This method returns an array with detected problems.
  60. * Every element has the following properties:
  61. *
  62. * * level - problem level.
  63. * * message - A human-readable string describing the issue.
  64. * * node - A reference to the problematic node.
  65. *
  66. * The level means:
  67. * 1 - The issue was repaired (only happens if REPAIR was turned on).
  68. * 2 - A warning.
  69. * 3 - An error.
  70. *
  71. * @param int $options
  72. * @return array
  73. */
  74. function validate($options = 0) {
  75. $result = parent::validate($options);
  76. if (isset($this->DTEND) && isset($this->DURATION)) {
  77. $result[] = array(
  78. 'level' => 3,
  79. 'message' => 'DTEND and DURATION cannot both be present',
  80. 'node' => $this
  81. );
  82. }
  83. if (isset($this->DURATION) && !isset($this->DTSTART)) {
  84. $result[] = array(
  85. 'level' => 3,
  86. 'message' => 'DURATION must be declared with a DTSTART.',
  87. 'node' => $this
  88. );
  89. }
  90. return $result;
  91. }
  92. }