1<?php
2
3namespace Sabre\CalDAV;
4
5use Sabre\DAVACL\PrincipalBackend;
6
7/**
8 * Calendars collection
9 *
10 * This object is responsible for generating a list of calendar-homes for each
11 * user.
12 *
13 * This is the top-most node for the calendars tree. In most servers this class
14 * represents the "/calendars" path.
15 *
16 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
17 * @author Evert Pot (http://evertpot.com/)
18 * @license http://sabre.io/license/ Modified BSD License
19 */
20class CalendarRoot extends \Sabre\DAVACL\AbstractPrincipalCollection {
21
22    /**
23     * CalDAV backend
24     *
25     * @var Sabre\CalDAV\Backend\BackendInterface
26     */
27    protected $caldavBackend;
28
29    /**
30     * Constructor
31     *
32     * This constructor needs both an authentication and a caldav backend.
33     *
34     * By default this class will show a list of calendar collections for
35     * principals in the 'principals' collection. If your main principals are
36     * actually located in a different path, use the $principalPrefix argument
37     * to override this.
38     *
39     * @param PrincipalBackend\BackendInterface $principalBackend
40     * @param Backend\BackendInterface $caldavBackend
41     * @param string $principalPrefix
42     */
43    function __construct(PrincipalBackend\BackendInterface $principalBackend, Backend\BackendInterface $caldavBackend, $principalPrefix = 'principals') {
44
45        parent::__construct($principalBackend, $principalPrefix);
46        $this->caldavBackend = $caldavBackend;
47
48    }
49
50    /**
51     * Returns the nodename
52     *
53     * We're overriding this, because the default will be the 'principalPrefix',
54     * and we want it to be Sabre\CalDAV\Plugin::CALENDAR_ROOT
55     *
56     * @return string
57     */
58    function getName() {
59
60        return Plugin::CALENDAR_ROOT;
61
62    }
63
64    /**
65     * This method returns a node for a principal.
66     *
67     * The passed array contains principal information, and is guaranteed to
68     * at least contain a uri item. Other properties may or may not be
69     * supplied by the authentication backend.
70     *
71     * @param array $principal
72     * @return \Sabre\DAV\INode
73     */
74    function getChildForPrincipal(array $principal) {
75
76        return new CalendarHome($this->caldavBackend, $principal);
77
78    }
79
80}
81