VAvailability.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Sabre\VObject\Component;
  3. use Sabre\VObject;
  4. /**
  5. * The VAvailability component
  6. *
  7. * This component adds functionality to a component, specific for VAVAILABILITY
  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 VAvailability 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. 'DTSTAMP' => 1,
  34. 'BUSYTYPE' => '?',
  35. 'CLASS' => '?',
  36. 'CREATED' => '?',
  37. 'DESCRIPTION' => '?',
  38. 'DTSTART' => '?',
  39. 'LAST-MODIFIED' => '?',
  40. 'ORGANIZER' => '?',
  41. 'PRIORITY' => '?',
  42. 'SEQUENCE' => '?',
  43. 'SUMMARY' => '?',
  44. 'URL' => '?',
  45. 'DTEND' => '?',
  46. 'DURATION' => '?',
  47. 'CATEGORIES' => '*',
  48. 'COMMENT' => '*',
  49. 'CONTACT' => '*',
  50. );
  51. }
  52. /**
  53. * Validates the node for correctness.
  54. *
  55. * The following options are supported:
  56. * Node::REPAIR - May attempt to automatically repair the problem.
  57. * Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
  58. * Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
  59. *
  60. * This method returns an array with detected problems.
  61. * Every element has the following properties:
  62. *
  63. * * level - problem level.
  64. * * message - A human-readable string describing the issue.
  65. * * node - A reference to the problematic node.
  66. *
  67. * The level means:
  68. * 1 - The issue was repaired (only happens if REPAIR was turned on).
  69. * 2 - A warning.
  70. * 3 - An error.
  71. *
  72. * @param int $options
  73. * @return array
  74. */
  75. function validate($options = 0) {
  76. $result = parent::validate($options);
  77. if (isset($this->DTEND) && isset($this->DURATION)) {
  78. $result[] = array(
  79. 'level' => 3,
  80. 'message' => 'DTEND and DURATION cannot both be present',
  81. 'node' => $this
  82. );
  83. }
  84. return $result;
  85. }
  86. }