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