make Calendars shareable via CalDAV
[tine20] / tine20 / Tinebase / WebDav / Root.php
1 <?php
2
3 use Sabre\DAV;
4 use Sabre\DAVACL;
5 use Sabre\CardDAV;
6 use Sabre\CalDAV;
7
8 /**
9  * Tine 2.0
10  *
11  * @package     Tinebase
12  * @subpackage  WebDAV
13  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
14  * @author      Lars Kneschke <l.kneschke@metaways.de>
15  * @copyright   Copyright (c) 2011-2013 Metaways Infosystems GmbH (http://www.metaways.de)
16  */
17
18 /**
19  * root of tree for the WebDAV frontend
20  *
21  * This class handles the root of the WebDAV tree
22  *
23  * @package     Tinebase
24  * @subpackage  WebDAV
25  * 
26  * @todo this should look for webdav frontend in installed apps
27  */
28 class Tinebase_WebDav_Root extends DAV\SimpleCollection
29 {
30     public function __construct()
31     {
32         $caldavCalendarChildren = array();
33         $caldavTasksChildren    = array();
34         $carddavChildren        = array();
35         $webdavChildren         = array();
36         $ownCloudChildren       = array();
37         
38         if(Tinebase_Core::getUser()->hasRight('Calendar', Tinebase_Acl_Rights::RUN)) {
39             $caldavCalendarChildren[] = new Calendar_Frontend_CalDAV();
40         }
41        
42         if(Tinebase_Core::getUser()->hasRight('Tasks', Tinebase_Acl_Rights::RUN)) {
43             $caldavTasksChildren[]    = new Tasks_Frontend_CalDAV();
44         }
45
46         if(Tinebase_Core::getUser()->hasRight('Addressbook', Tinebase_Acl_Rights::RUN)) {
47             $carddavChildren[] = new Addressbook_Frontend_CardDAV();
48         }
49         
50         if(Tinebase_Core::getUser()->hasRight('Filemanager', Tinebase_Acl_Rights::RUN)) {
51             $ownCloudChildren[] = new Filemanager_Frontend_WebDAV('webdav');
52         }
53         
54         foreach (array('Addressbook', 'Calendar', 'Felamimail', 'Filemanager', 'Tasks') as $application) {
55             $applicationClass = $application . '_Frontend_WebDAV';
56             if (Tinebase_Core::getUser()->hasRight($application, Tinebase_Acl_Rights::RUN) && class_exists($applicationClass)) {
57                 $webdavChildren[] = new $applicationClass($application);
58             }
59         }
60         
61         parent::__construct('root', array(
62             new DAV\SimpleCollection(CardDAV\Plugin::ADDRESSBOOK_ROOT, $carddavChildren),
63             new DAV\SimpleCollection(CalDAV\Plugin::CALENDAR_ROOT,     $caldavCalendarChildren),
64             new DAV\SimpleCollection('tasks',                          $caldavTasksChildren),
65             new DAV\SimpleCollection('webdav',                         $webdavChildren),
66             new DAV\SimpleCollection('principals', array(
67                 new DAVACL\PrincipalCollection(new Tinebase_WebDav_PrincipalBackend(), Tinebase_WebDav_PrincipalBackend::PREFIX_USERS),
68                 new DAVACL\PrincipalCollection(new Tinebase_WebDav_PrincipalBackend(), Tinebase_WebDav_PrincipalBackend::PREFIX_GROUPS)
69             )),
70             // main entry point for ownCloud 
71             new DAV\SimpleCollection('remote.php',                     $ownCloudChildren)
72         ));
73     }
74 }