@@ -33,47 +33,47 @@ |
||
33 | 33 | */ |
34 | 34 | class TagMapper extends Mapper { |
35 | 35 | |
36 | - /** |
|
37 | - * Constructor. |
|
38 | - * |
|
39 | - * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | - */ |
|
41 | - public function __construct(IDBConnection $db) { |
|
42 | - parent::__construct($db, 'vcategory', 'OC\Tagging\Tag'); |
|
43 | - } |
|
36 | + /** |
|
37 | + * Constructor. |
|
38 | + * |
|
39 | + * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | + */ |
|
41 | + public function __construct(IDBConnection $db) { |
|
42 | + parent::__construct($db, 'vcategory', 'OC\Tagging\Tag'); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Load tags from the database. |
|
47 | - * |
|
48 | - * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | - * @param string $type The type of item for which we are loading tags. |
|
50 | - * @return array An array of Tag objects. |
|
51 | - */ |
|
52 | - public function loadTags($owners, $type) { |
|
53 | - if(!is_array($owners)) { |
|
54 | - $owners = array($owners); |
|
55 | - } |
|
45 | + /** |
|
46 | + * Load tags from the database. |
|
47 | + * |
|
48 | + * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | + * @param string $type The type of item for which we are loading tags. |
|
50 | + * @return array An array of Tag objects. |
|
51 | + */ |
|
52 | + public function loadTags($owners, $type) { |
|
53 | + if(!is_array($owners)) { |
|
54 | + $owners = array($owners); |
|
55 | + } |
|
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | - return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | - } |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | + . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | + return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Check if a given Tag object already exists in the database. |
|
64 | - * |
|
65 | - * @param Tag $tag The tag to look for in the database. |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function tagExists($tag) { |
|
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | - . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | - try { |
|
72 | - $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | - } catch (DoesNotExistException $e) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - return true; |
|
77 | - } |
|
62 | + /** |
|
63 | + * Check if a given Tag object already exists in the database. |
|
64 | + * |
|
65 | + * @param Tag $tag The tag to look for in the database. |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function tagExists($tag) { |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | + . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | + try { |
|
72 | + $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | + } catch (DoesNotExistException $e) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + return true; |
|
77 | + } |
|
78 | 78 | } |
79 | 79 |
@@ -37,54 +37,54 @@ |
||
37 | 37 | */ |
38 | 38 | class Tag extends Entity { |
39 | 39 | |
40 | - protected $owner; |
|
41 | - protected $type; |
|
42 | - protected $name; |
|
40 | + protected $owner; |
|
41 | + protected $type; |
|
42 | + protected $name; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor. |
|
46 | - * |
|
47 | - * @param string $owner The tag's owner |
|
48 | - * @param string $type The type of item this tag is used for |
|
49 | - * @param string $name The tag's name |
|
50 | - */ |
|
51 | - public function __construct($owner = null, $type = null, $name = null) { |
|
52 | - $this->setOwner($owner); |
|
53 | - $this->setType($type); |
|
54 | - $this->setName($name); |
|
55 | - } |
|
44 | + /** |
|
45 | + * Constructor. |
|
46 | + * |
|
47 | + * @param string $owner The tag's owner |
|
48 | + * @param string $type The type of item this tag is used for |
|
49 | + * @param string $name The tag's name |
|
50 | + */ |
|
51 | + public function __construct($owner = null, $type = null, $name = null) { |
|
52 | + $this->setOwner($owner); |
|
53 | + $this->setType($type); |
|
54 | + $this->setName($name); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Transform a database columnname to a property |
|
59 | - * |
|
60 | - * @param string $columnName the name of the column |
|
61 | - * @return string the property name |
|
62 | - * @todo migrate existing database columns to the correct names |
|
63 | - * to be able to drop this direct mapping |
|
64 | - */ |
|
65 | - public function columnToProperty($columnName){ |
|
66 | - if ($columnName === 'category') { |
|
67 | - return 'name'; |
|
68 | - } elseif ($columnName === 'uid') { |
|
69 | - return 'owner'; |
|
70 | - } else { |
|
71 | - return parent::columnToProperty($columnName); |
|
72 | - } |
|
73 | - } |
|
57 | + /** |
|
58 | + * Transform a database columnname to a property |
|
59 | + * |
|
60 | + * @param string $columnName the name of the column |
|
61 | + * @return string the property name |
|
62 | + * @todo migrate existing database columns to the correct names |
|
63 | + * to be able to drop this direct mapping |
|
64 | + */ |
|
65 | + public function columnToProperty($columnName){ |
|
66 | + if ($columnName === 'category') { |
|
67 | + return 'name'; |
|
68 | + } elseif ($columnName === 'uid') { |
|
69 | + return 'owner'; |
|
70 | + } else { |
|
71 | + return parent::columnToProperty($columnName); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Transform a property to a database column name |
|
77 | - * |
|
78 | - * @param string $property the name of the property |
|
79 | - * @return string the column name |
|
80 | - */ |
|
81 | - public function propertyToColumn($property){ |
|
82 | - if ($property === 'name') { |
|
83 | - return 'category'; |
|
84 | - } elseif ($property === 'owner') { |
|
85 | - return 'uid'; |
|
86 | - } else { |
|
87 | - return parent::propertyToColumn($property); |
|
88 | - } |
|
89 | - } |
|
75 | + /** |
|
76 | + * Transform a property to a database column name |
|
77 | + * |
|
78 | + * @param string $property the name of the property |
|
79 | + * @return string the column name |
|
80 | + */ |
|
81 | + public function propertyToColumn($property){ |
|
82 | + if ($property === 'name') { |
|
83 | + return 'category'; |
|
84 | + } elseif ($property === 'owner') { |
|
85 | + return 'uid'; |
|
86 | + } else { |
|
87 | + return parent::propertyToColumn($property); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
@@ -28,38 +28,38 @@ |
||
28 | 28 | use OCP\ILogger; |
29 | 29 | |
30 | 30 | class CachingRouter extends Router { |
31 | - /** |
|
32 | - * @var \OCP\ICache |
|
33 | - */ |
|
34 | - protected $cache; |
|
31 | + /** |
|
32 | + * @var \OCP\ICache |
|
33 | + */ |
|
34 | + protected $cache; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param \OCP\ICache $cache |
|
38 | - * @param ILogger $logger |
|
39 | - */ |
|
40 | - public function __construct($cache, ILogger $logger) { |
|
41 | - $this->cache = $cache; |
|
42 | - parent::__construct($logger); |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param \OCP\ICache $cache |
|
38 | + * @param ILogger $logger |
|
39 | + */ |
|
40 | + public function __construct($cache, ILogger $logger) { |
|
41 | + $this->cache = $cache; |
|
42 | + parent::__construct($logger); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Generate url based on $name and $parameters |
|
47 | - * |
|
48 | - * @param string $name Name of the route to use. |
|
49 | - * @param array $parameters Parameters for the route |
|
50 | - * @param bool $absolute |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function generate($name, $parameters = array(), $absolute = false) { |
|
54 | - asort($parameters); |
|
55 | - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
56 | - $cachedKey = $this->cache->get($key); |
|
57 | - if ($cachedKey) { |
|
58 | - return $cachedKey; |
|
59 | - } else { |
|
60 | - $url = parent::generate($name, $parameters, $absolute); |
|
61 | - $this->cache->set($key, $url, 3600); |
|
62 | - return $url; |
|
63 | - } |
|
64 | - } |
|
45 | + /** |
|
46 | + * Generate url based on $name and $parameters |
|
47 | + * |
|
48 | + * @param string $name Name of the route to use. |
|
49 | + * @param array $parameters Parameters for the route |
|
50 | + * @param bool $absolute |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function generate($name, $parameters = array(), $absolute = false) { |
|
54 | + asort($parameters); |
|
55 | + $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
56 | + $cachedKey = $this->cache->get($key); |
|
57 | + if ($cachedKey) { |
|
58 | + return $cachedKey; |
|
59 | + } else { |
|
60 | + $url = parent::generate($name, $parameters, $absolute); |
|
61 | + $this->cache->set($key, $url, 3600); |
|
62 | + return $url; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | } |
@@ -40,53 +40,53 @@ |
||
40 | 40 | |
41 | 41 | class TagManager implements \OCP\ITagManager { |
42 | 42 | |
43 | - /** |
|
44 | - * User session |
|
45 | - * |
|
46 | - * @var \OCP\IUserSession |
|
47 | - */ |
|
48 | - private $userSession; |
|
43 | + /** |
|
44 | + * User session |
|
45 | + * |
|
46 | + * @var \OCP\IUserSession |
|
47 | + */ |
|
48 | + private $userSession; |
|
49 | 49 | |
50 | - /** |
|
51 | - * TagMapper |
|
52 | - * |
|
53 | - * @var TagMapper |
|
54 | - */ |
|
55 | - private $mapper; |
|
50 | + /** |
|
51 | + * TagMapper |
|
52 | + * |
|
53 | + * @var TagMapper |
|
54 | + */ |
|
55 | + private $mapper; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Constructor. |
|
59 | - * |
|
60 | - * @param TagMapper $mapper Instance of the TagMapper abstraction layer. |
|
61 | - * @param \OCP\IUserSession $userSession the user session |
|
62 | - */ |
|
63 | - public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) { |
|
64 | - $this->mapper = $mapper; |
|
65 | - $this->userSession = $userSession; |
|
57 | + /** |
|
58 | + * Constructor. |
|
59 | + * |
|
60 | + * @param TagMapper $mapper Instance of the TagMapper abstraction layer. |
|
61 | + * @param \OCP\IUserSession $userSession the user session |
|
62 | + */ |
|
63 | + public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) { |
|
64 | + $this->mapper = $mapper; |
|
65 | + $this->userSession = $userSession; |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Create a new \OCP\ITags instance and load tags from db. |
|
71 | - * |
|
72 | - * @see \OCP\ITags |
|
73 | - * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
74 | - * @param array $defaultTags An array of default tags to be used if none are stored. |
|
75 | - * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
76 | - * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
77 | - * logged in user |
|
78 | - * @return \OCP\ITags |
|
79 | - */ |
|
80 | - public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { |
|
81 | - if (is_null($userId)) { |
|
82 | - $user = $this->userSession->getUser(); |
|
83 | - if ($user === null) { |
|
84 | - // nothing we can do without a user |
|
85 | - return null; |
|
86 | - } |
|
87 | - $userId = $this->userSession->getUser()->getUId(); |
|
88 | - } |
|
89 | - return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); |
|
90 | - } |
|
69 | + /** |
|
70 | + * Create a new \OCP\ITags instance and load tags from db. |
|
71 | + * |
|
72 | + * @see \OCP\ITags |
|
73 | + * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
74 | + * @param array $defaultTags An array of default tags to be used if none are stored. |
|
75 | + * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
76 | + * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
77 | + * logged in user |
|
78 | + * @return \OCP\ITags |
|
79 | + */ |
|
80 | + public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { |
|
81 | + if (is_null($userId)) { |
|
82 | + $user = $this->userSession->getUser(); |
|
83 | + if ($user === null) { |
|
84 | + // nothing we can do without a user |
|
85 | + return null; |
|
86 | + } |
|
87 | + $userId = $this->userSession->getUser()->getUId(); |
|
88 | + } |
|
89 | + return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); |
|
90 | + } |
|
91 | 91 | |
92 | 92 | } |
@@ -27,164 +27,164 @@ |
||
27 | 27 | |
28 | 28 | namespace OC { |
29 | 29 | |
30 | - class ContactsManager implements \OCP\Contacts\IManager { |
|
31 | - |
|
32 | - /** |
|
33 | - * This function is used to search and find contacts within the users address books. |
|
34 | - * In case $pattern is empty all contacts will be returned. |
|
35 | - * |
|
36 | - * @param string $pattern which should match within the $searchProperties |
|
37 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
38 | - * @param array $options - for future use. One should always have options! |
|
39 | - * @return array an array of contacts which are arrays of key-value-pairs |
|
40 | - */ |
|
41 | - public function search($pattern, $searchProperties = array(), $options = array()) { |
|
42 | - $this->loadAddressBooks(); |
|
43 | - $result = array(); |
|
44 | - foreach($this->addressBooks as $addressBook) { |
|
45 | - $r = $addressBook->search($pattern, $searchProperties, $options); |
|
46 | - $contacts = array(); |
|
47 | - foreach($r as $c){ |
|
48 | - $c['addressbook-key'] = $addressBook->getKey(); |
|
49 | - $contacts[] = $c; |
|
50 | - } |
|
51 | - $result = array_merge($result, $contacts); |
|
52 | - } |
|
53 | - |
|
54 | - return $result; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * This function can be used to delete the contact identified by the given id |
|
59 | - * |
|
60 | - * @param object $id the unique identifier to a contact |
|
61 | - * @param string $addressBookKey identifier of the address book in which the contact shall be deleted |
|
62 | - * @return bool successful or not |
|
63 | - */ |
|
64 | - public function delete($id, $addressBookKey) { |
|
65 | - $addressBook = $this->getAddressBook($addressBookKey); |
|
66 | - if (!$addressBook) { |
|
67 | - return null; |
|
68 | - } |
|
69 | - |
|
70 | - if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
71 | - return $addressBook->delete($id); |
|
72 | - } |
|
73 | - |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * This function is used to create a new contact if 'id' is not given or not present. |
|
79 | - * Otherwise the contact will be updated by replacing the entire data set. |
|
80 | - * |
|
81 | - * @param array $properties this array if key-value-pairs defines a contact |
|
82 | - * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated |
|
83 | - * @return array representing the contact just created or updated |
|
84 | - */ |
|
85 | - public function createOrUpdate($properties, $addressBookKey) { |
|
86 | - $addressBook = $this->getAddressBook($addressBookKey); |
|
87 | - if (!$addressBook) { |
|
88 | - return null; |
|
89 | - } |
|
90 | - |
|
91 | - if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
92 | - return $addressBook->createOrUpdate($properties); |
|
93 | - } |
|
94 | - |
|
95 | - return null; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Check if contacts are available (e.g. contacts app enabled) |
|
100 | - * |
|
101 | - * @return bool true if enabled, false if not |
|
102 | - */ |
|
103 | - public function isEnabled() { |
|
104 | - return !empty($this->addressBooks) || !empty($this->addressBookLoaders); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param \OCP\IAddressBook $addressBook |
|
109 | - */ |
|
110 | - public function registerAddressBook(\OCP\IAddressBook $addressBook) { |
|
111 | - $this->addressBooks[$addressBook->getKey()] = $addressBook; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param \OCP\IAddressBook $addressBook |
|
116 | - */ |
|
117 | - public function unregisterAddressBook(\OCP\IAddressBook $addressBook) { |
|
118 | - unset($this->addressBooks[$addressBook->getKey()]); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - public function getAddressBooks() { |
|
125 | - $this->loadAddressBooks(); |
|
126 | - $result = array(); |
|
127 | - foreach($this->addressBooks as $addressBook) { |
|
128 | - $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
129 | - } |
|
130 | - |
|
131 | - return $result; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * removes all registered address book instances |
|
136 | - */ |
|
137 | - public function clear() { |
|
138 | - $this->addressBooks = array(); |
|
139 | - $this->addressBookLoaders = array(); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @var \OCP\IAddressBook[] which holds all registered address books |
|
144 | - */ |
|
145 | - private $addressBooks = array(); |
|
146 | - |
|
147 | - /** |
|
148 | - * @var \Closure[] to call to load/register address books |
|
149 | - */ |
|
150 | - private $addressBookLoaders = array(); |
|
151 | - |
|
152 | - /** |
|
153 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
154 | - * address books are actually requested |
|
155 | - * |
|
156 | - * @param \Closure $callable |
|
157 | - */ |
|
158 | - public function register(\Closure $callable) |
|
159 | - { |
|
160 | - $this->addressBookLoaders[] = $callable; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Get (and load when needed) the address book for $key |
|
165 | - * |
|
166 | - * @param string $addressBookKey |
|
167 | - * @return \OCP\IAddressBook |
|
168 | - */ |
|
169 | - protected function getAddressBook($addressBookKey) |
|
170 | - { |
|
171 | - $this->loadAddressBooks(); |
|
172 | - if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
173 | - return null; |
|
174 | - } |
|
175 | - |
|
176 | - return $this->addressBooks[$addressBookKey]; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Load all address books registered with 'register' |
|
181 | - */ |
|
182 | - protected function loadAddressBooks() |
|
183 | - { |
|
184 | - foreach($this->addressBookLoaders as $callable) { |
|
185 | - $callable($this); |
|
186 | - } |
|
187 | - $this->addressBookLoaders = array(); |
|
188 | - } |
|
189 | - } |
|
30 | + class ContactsManager implements \OCP\Contacts\IManager { |
|
31 | + |
|
32 | + /** |
|
33 | + * This function is used to search and find contacts within the users address books. |
|
34 | + * In case $pattern is empty all contacts will be returned. |
|
35 | + * |
|
36 | + * @param string $pattern which should match within the $searchProperties |
|
37 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
38 | + * @param array $options - for future use. One should always have options! |
|
39 | + * @return array an array of contacts which are arrays of key-value-pairs |
|
40 | + */ |
|
41 | + public function search($pattern, $searchProperties = array(), $options = array()) { |
|
42 | + $this->loadAddressBooks(); |
|
43 | + $result = array(); |
|
44 | + foreach($this->addressBooks as $addressBook) { |
|
45 | + $r = $addressBook->search($pattern, $searchProperties, $options); |
|
46 | + $contacts = array(); |
|
47 | + foreach($r as $c){ |
|
48 | + $c['addressbook-key'] = $addressBook->getKey(); |
|
49 | + $contacts[] = $c; |
|
50 | + } |
|
51 | + $result = array_merge($result, $contacts); |
|
52 | + } |
|
53 | + |
|
54 | + return $result; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * This function can be used to delete the contact identified by the given id |
|
59 | + * |
|
60 | + * @param object $id the unique identifier to a contact |
|
61 | + * @param string $addressBookKey identifier of the address book in which the contact shall be deleted |
|
62 | + * @return bool successful or not |
|
63 | + */ |
|
64 | + public function delete($id, $addressBookKey) { |
|
65 | + $addressBook = $this->getAddressBook($addressBookKey); |
|
66 | + if (!$addressBook) { |
|
67 | + return null; |
|
68 | + } |
|
69 | + |
|
70 | + if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
71 | + return $addressBook->delete($id); |
|
72 | + } |
|
73 | + |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * This function is used to create a new contact if 'id' is not given or not present. |
|
79 | + * Otherwise the contact will be updated by replacing the entire data set. |
|
80 | + * |
|
81 | + * @param array $properties this array if key-value-pairs defines a contact |
|
82 | + * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated |
|
83 | + * @return array representing the contact just created or updated |
|
84 | + */ |
|
85 | + public function createOrUpdate($properties, $addressBookKey) { |
|
86 | + $addressBook = $this->getAddressBook($addressBookKey); |
|
87 | + if (!$addressBook) { |
|
88 | + return null; |
|
89 | + } |
|
90 | + |
|
91 | + if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
92 | + return $addressBook->createOrUpdate($properties); |
|
93 | + } |
|
94 | + |
|
95 | + return null; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Check if contacts are available (e.g. contacts app enabled) |
|
100 | + * |
|
101 | + * @return bool true if enabled, false if not |
|
102 | + */ |
|
103 | + public function isEnabled() { |
|
104 | + return !empty($this->addressBooks) || !empty($this->addressBookLoaders); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param \OCP\IAddressBook $addressBook |
|
109 | + */ |
|
110 | + public function registerAddressBook(\OCP\IAddressBook $addressBook) { |
|
111 | + $this->addressBooks[$addressBook->getKey()] = $addressBook; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param \OCP\IAddressBook $addressBook |
|
116 | + */ |
|
117 | + public function unregisterAddressBook(\OCP\IAddressBook $addressBook) { |
|
118 | + unset($this->addressBooks[$addressBook->getKey()]); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + public function getAddressBooks() { |
|
125 | + $this->loadAddressBooks(); |
|
126 | + $result = array(); |
|
127 | + foreach($this->addressBooks as $addressBook) { |
|
128 | + $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
129 | + } |
|
130 | + |
|
131 | + return $result; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * removes all registered address book instances |
|
136 | + */ |
|
137 | + public function clear() { |
|
138 | + $this->addressBooks = array(); |
|
139 | + $this->addressBookLoaders = array(); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @var \OCP\IAddressBook[] which holds all registered address books |
|
144 | + */ |
|
145 | + private $addressBooks = array(); |
|
146 | + |
|
147 | + /** |
|
148 | + * @var \Closure[] to call to load/register address books |
|
149 | + */ |
|
150 | + private $addressBookLoaders = array(); |
|
151 | + |
|
152 | + /** |
|
153 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
154 | + * address books are actually requested |
|
155 | + * |
|
156 | + * @param \Closure $callable |
|
157 | + */ |
|
158 | + public function register(\Closure $callable) |
|
159 | + { |
|
160 | + $this->addressBookLoaders[] = $callable; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Get (and load when needed) the address book for $key |
|
165 | + * |
|
166 | + * @param string $addressBookKey |
|
167 | + * @return \OCP\IAddressBook |
|
168 | + */ |
|
169 | + protected function getAddressBook($addressBookKey) |
|
170 | + { |
|
171 | + $this->loadAddressBooks(); |
|
172 | + if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
173 | + return null; |
|
174 | + } |
|
175 | + |
|
176 | + return $this->addressBooks[$addressBookKey]; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Load all address books registered with 'register' |
|
181 | + */ |
|
182 | + protected function loadAddressBooks() |
|
183 | + { |
|
184 | + foreach($this->addressBookLoaders as $callable) { |
|
185 | + $callable($this); |
|
186 | + } |
|
187 | + $this->addressBookLoaders = array(); |
|
188 | + } |
|
189 | + } |
|
190 | 190 | } |
@@ -25,14 +25,14 @@ |
||
25 | 25 | namespace OC; |
26 | 26 | |
27 | 27 | class NaturalSort_DefaultCollator { |
28 | - public function compare($a, $b) { |
|
29 | - $result = strcasecmp($a, $b); |
|
30 | - if ($result === 0) { |
|
31 | - if ($a === $b) { |
|
32 | - return 0; |
|
33 | - } |
|
34 | - return ($a > $b) ? -1 : 1; |
|
35 | - } |
|
36 | - return ($result < 0) ? -1 : 1; |
|
37 | - } |
|
28 | + public function compare($a, $b) { |
|
29 | + $result = strcasecmp($a, $b); |
|
30 | + if ($result === 0) { |
|
31 | + if ($a === $b) { |
|
32 | + return 0; |
|
33 | + } |
|
34 | + return ($a > $b) ? -1 : 1; |
|
35 | + } |
|
36 | + return ($result < 0) ? -1 : 1; |
|
37 | + } |
|
38 | 38 | } |
@@ -25,12 +25,12 @@ |
||
25 | 25 | use OC\BackgroundJob\QueuedJob; |
26 | 26 | |
27 | 27 | class CallableJob extends QueuedJob { |
28 | - protected function run($serializedCallable) { |
|
29 | - $callable = unserialize($serializedCallable); |
|
30 | - if (is_callable($callable)) { |
|
31 | - $callable(); |
|
32 | - } else { |
|
33 | - throw new \InvalidArgumentException('Invalid serialized callable'); |
|
34 | - } |
|
35 | - } |
|
28 | + protected function run($serializedCallable) { |
|
29 | + $callable = unserialize($serializedCallable); |
|
30 | + if (is_callable($callable)) { |
|
31 | + $callable(); |
|
32 | + } else { |
|
33 | + throw new \InvalidArgumentException('Invalid serialized callable'); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | } |
@@ -26,13 +26,13 @@ |
||
26 | 26 | use SuperClosure\Serializer; |
27 | 27 | |
28 | 28 | class ClosureJob extends QueuedJob { |
29 | - protected function run($serializedCallable) { |
|
30 | - $serializer = new Serializer(); |
|
31 | - $callable = $serializer->unserialize($serializedCallable); |
|
32 | - if (is_callable($callable)) { |
|
33 | - $callable(); |
|
34 | - } else { |
|
35 | - throw new \InvalidArgumentException('Invalid serialized callable'); |
|
36 | - } |
|
37 | - } |
|
29 | + protected function run($serializedCallable) { |
|
30 | + $serializer = new Serializer(); |
|
31 | + $callable = $serializer->unserialize($serializedCallable); |
|
32 | + if (is_callable($callable)) { |
|
33 | + $callable(); |
|
34 | + } else { |
|
35 | + throw new \InvalidArgumentException('Invalid serialized callable'); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | } |
@@ -25,12 +25,12 @@ |
||
25 | 25 | use OCP\IUser; |
26 | 26 | |
27 | 27 | trait FileAccess { |
28 | - protected function setupFS(IUser $user){ |
|
29 | - \OC_Util::setupFS($user->getUID()); |
|
30 | - } |
|
28 | + protected function setupFS(IUser $user){ |
|
29 | + \OC_Util::setupFS($user->getUID()); |
|
30 | + } |
|
31 | 31 | |
32 | - protected function getUserFolder(IUser $user) { |
|
33 | - $this->setupFS($user); |
|
34 | - return \OC::$server->getUserFolder($user->getUID()); |
|
35 | - } |
|
32 | + protected function getUserFolder(IUser $user) { |
|
33 | + $this->setupFS($user); |
|
34 | + return \OC::$server->getUserFolder($user->getUID()); |
|
35 | + } |
|
36 | 36 | } |