ctucx.git: tinyDAV

[php] Cal-/ CardDAV server with a simple web-GUI based on SabreDAV

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
<?php

class CalendarCollectionManager extends GenericCollectionManager {
	public $dataFolder         = PATH.'/../data/';
	public $collectionsFile    = 'calendars/calendars.json';
	public $collectionsFolder  = 'calendars/';
	public $collectionType     = 'Calendar';
	public $datafield          = 'calendardata';


	public function newCollection ($username, $uri, array $properties) {
		$collection = [ 
				'id'            => $this->getHighestCollectionId($username)+1,
				'principaluri'  => $username,
				'uri'           => $uri,
				'displayname'   => NULL,
				'description'   => NULL,
				'timezone'      => NULL,
				'calendarorder' => NULL,
				'calendarcolor' => NULL,
				'components'    => 'VEVENT,VTODO',
				'synctoken'     => 1,
			];

		$collection = array_merge($collection, $properties);

		return $collection;
	}

	public function newObject ($collectionId, $uri, $data, $extraData = NULL) {
		$object = [
				'id'             => $this->getHighestObjectId($collectionId)+1,
				'uri'            => $uri,
				'componenttype'  => NULL,
				'firstoccurence' => NULL,
				'lastoccurence'  => NULL,
				'uid'            => NULL,
				'etag'           => md5($data),
				'lastmodified'   => time(),
				'size'           => strlen($data),
			];

		if ($extraData !== NULL) {
			$object = array_merge($object, $extraData);
		}

		return $object;
	}

	public function newObjectUpdate ($collectionId, $uri, $data, $extraData = NULL) {
		$update = [
				'etag'          => md5($data),
				'size'          => strlen($data),
				'lastmodified'  => time(),
			];

		if ($extraData !== NULL) {
			$update = array_merge($update, $extraData);
		}

		return $update;
	}

	public function getUriByUID($username, $uid) {
		$collections = $this->getCollections($username);

		foreach ($collections as $collection) {
			$objects = $this->getObjects($collection['id']);

			foreach ($objects as $object) {
				if ($object['uid'] == $uid) return $collection['uri'].'/'.$object['uri'];
			}
		}

		return null;
	}
}