1: <?php
2: /**
3: * This class provides the Kolab specific resource name requested from
4: * the free/busy system.
5: *
6: * PHP version 5
7: *
8: * @category Kolab
9: * @package Kolab_FreeBusy
10: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
11: * @author Gunnar Wrobel <wrobel@pardus.de>
12: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
13: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
14: */
15:
16: /**
17: * This class provides the Kolab specific resource name requested from
18: * the free/busy system.
19: *
20: * Copyright 2004-2007 Klarälvdalens Datakonsult AB
21: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
22: *
23: * See the enclosed file COPYING for license information (LGPL). If you did not
24: * receive this file, see
25: * http://www.horde.org/licenses/lgpl21.
26: *
27: * @category Kolab
28: * @package Kolab_FreeBusy
29: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
30: * @author Gunnar Wrobel <wrobel@pardus.de>
31: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
32: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
33: */
34: class Horde_Kolab_FreeBusy_Params_Freebusy_Resource_Kolab
35: {
36: /**
37: * The current user.
38: *
39: * @var Horde_Kolab_FreeBusy_Params_User
40: */
41: private $_user;
42:
43: /**
44: * The requested folder.
45: *
46: * @var Horde_Kolab_FreeBusy_Params_Freebusy_Folder
47: */
48: private $_folder;
49:
50: /**
51: * Constructor.
52: *
53: * @param Horde_Kolab_FreeBusy_Params_User $user The current user.
54: * @param Horde_Kolab_FreeBusy_Params_Freebusy_Folder $folder The requested
55: * folder.
56: */
57: public function __construct(
58: Horde_Kolab_FreeBusy_Params_User $user,
59: Horde_Kolab_FreeBusy_Params_Freebusy_Folder $folder
60: ) {
61: $this->_user = $user;
62: $this->_folder = $folder;
63: }
64:
65: /**
66: * Extract the resource name from the request.
67: *
68: * @return string The requested resource.
69: */
70: public function getResourceId()
71: {
72: list($user, $userdom) = $this->_splitMailAddress(
73: $this->_user->getId()
74: );
75: list($owner, $ownerdom) = $this->_splitMailAddress(
76: $this->_folder->getOwner()
77: );
78:
79: //@todo: This should be based on the namespaces.
80: $fldrcomp = array();
81: if ($user == $owner) {
82: $fldrcomp[] = 'INBOX';
83: } else {
84: $fldrcomp[] = 'user';
85: $fldrcomp[] = $owner;
86: }
87:
88: $fld = $this->_folder->getFolder();
89: if (!empty($fld)) {
90: $fldrcomp[] = $fld;
91: }
92:
93: $folder = join('/', $fldrcomp);
94: if ($ownerdom && !$userdom) {
95: $folder .= '@' . $ownerdom;
96: }
97: return $folder;
98: }
99:
100: /**
101: * Split a mail address at the '@' sign.
102: *
103: * @param string $address The address to split.
104: *
105: * @return array The two splitted parts.
106: */
107: private function _splitMailAddress($address)
108: {
109: if (preg_match('/(.*)@(.*)/', $address, $regs)) {
110: return array($regs[1], $regs[2]);
111: } else {
112: return array($address, false);
113: }
114: }
115: }