diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-09-06 16:09:29 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-09-26 23:10:23 +0200 |
commit | 4a96e222588104f647f911857e370b3ab692ea22 (patch) | |
tree | c0859c504c83b8e4e6f11a2d1c39974ca338e63b /lib/private/Collaboration | |
parent | 579c1476a3ec5d9b93130c84a5cc1438b9bd03a9 (diff) | |
download | nextcloud-server-4a96e222588104f647f911857e370b3ab692ea22.tar.gz nextcloud-server-4a96e222588104f647f911857e370b3ab692ea22.zip |
don't keep result types hard coded
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private/Collaboration')
8 files changed, 53 insertions, 47 deletions
diff --git a/lib/private/Collaboration/Collaborators/CirclePlugin.php b/lib/private/Collaboration/Collaborators/CirclePlugin.php index 3d476644ecc..951f70e968b 100644 --- a/lib/private/Collaboration/Collaborators/CirclePlugin.php +++ b/lib/private/Collaboration/Collaborators/CirclePlugin.php @@ -27,8 +27,10 @@ namespace OC\Collaboration\Collaborators; use OCA\Circles\Api\Sharees; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; class CirclePlugin implements ISearchPlugin { + public function search($search, $limit, $offset, ISearchResult $searchResult) { $result = ['wide' => [], 'exact' => []]; @@ -41,7 +43,8 @@ class CirclePlugin implements ISearchPlugin { $result['wide'] = $circles['circles']; } - $searchResult->addResultSet('circles', $result['wide'], $result['exact']); + $type = new SearchResultType('circles'); + $searchResult->addResultSet($type, $result['wide'], $result['exact']); } return false; diff --git a/lib/private/Collaboration/Collaborators/GroupPlugin.php b/lib/private/Collaboration/Collaborators/GroupPlugin.php index d156190eed9..0b2b3d71028 100644 --- a/lib/private/Collaboration/Collaborators/GroupPlugin.php +++ b/lib/private/Collaboration/Collaborators/GroupPlugin.php @@ -25,6 +25,7 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; @@ -115,8 +116,9 @@ class GroupPlugin implements ISearchPlugin { $result['wide'] = []; } - $searchResult->addResultSet('groups', $result['wide'], $result['exact']); + $type = new SearchResultType('groups'); + $searchResult->addResultSet($type, $result['wide'], $result['exact']); - return [$result, $hasMoreResults]; + return $hasMoreResults; } } diff --git a/lib/private/Collaboration/Collaborators/LookupPlugin.php b/lib/private/Collaboration/Collaborators/LookupPlugin.php index 567b41ca76f..e3a04fb7dde 100644 --- a/lib/private/Collaboration/Collaborators/LookupPlugin.php +++ b/lib/private/Collaboration/Collaborators/LookupPlugin.php @@ -26,6 +26,7 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\Share; @@ -77,7 +78,9 @@ class LookupPlugin implements ISearchPlugin { } catch (\Exception $e) { } - $searchResult->addResultSet('lookup', $result, []); + $type = new SearchResultType('lookup'); + $searchResult->addResultSet($type, $result, []); + return false; } } diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php index bd4d70e41de..e6bda176566 100644 --- a/lib/private/Collaboration/Collaborators/MailPlugin.php +++ b/lib/private/Collaboration/Collaborators/MailPlugin.php @@ -26,6 +26,7 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Contacts\IManager; use OCP\Federation\ICloudIdManager; use OCP\IConfig; @@ -59,6 +60,8 @@ class MailPlugin implements ISearchPlugin { */ public function search($search, $limit, $offset, ISearchResult $searchResult) { $result = ['wide' => [], 'exact' => []]; + $userType = new SearchResultType('users'); + $emailType = new SearchResultType('emails'); // Search in contacts //@todo Pagination missing @@ -81,7 +84,7 @@ class MailPlugin implements ISearchPlugin { continue; } - if (!$searchResult->hasResult('users', $cloud->getUser())) { + if (!$searchResult->hasResult($userType, $cloud->getUser())) { $singleResult = [[ 'label' => $contact['FN'] . " ($emailAddress)", 'value' => [ @@ -89,8 +92,8 @@ class MailPlugin implements ISearchPlugin { 'shareWith' => $cloud->getUser(), ], ]]; - $searchResult->addResultSet('users', [], $singleResult); - $searchResult->markExactIdMatch('emails'); + $searchResult->addResultSet($userType, [], $singleResult); + $searchResult->markExactIdMatch($emailType); } return false; } @@ -102,7 +105,7 @@ class MailPlugin implements ISearchPlugin { continue; } - if (!$searchResult->hasResult('users', $cloud->getUser())) { + if (!$searchResult->hasResult($userType, $cloud->getUser())) { $singleResult = [[ 'label' => $contact['FN'] . " ($emailAddress)", 'value' => [ @@ -110,8 +113,7 @@ class MailPlugin implements ISearchPlugin { 'shareWith' => $cloud->getUser(), ]], ]; - $searchResult->addResultSet('users', $singleResult, []); - $result = []; + $searchResult->addResultSet($userType, $singleResult, []); } } continue; @@ -119,7 +121,7 @@ class MailPlugin implements ISearchPlugin { if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) { if ($exactEmailMatch) { - $searchResult->markExactIdMatch('emails'); + $searchResult->markExactIdMatch($emailType); } $result['exact'][] = [ 'label' => $contact['FN'] . " ($emailAddress)", @@ -145,7 +147,7 @@ class MailPlugin implements ISearchPlugin { $result['wide'] = []; } - if (!$searchResult->hasExactIdMatch('emails') && filter_var($search, FILTER_VALIDATE_EMAIL)) { + if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) { $result['exact'][] = [ 'label' => $search, 'value' => [ @@ -155,7 +157,7 @@ class MailPlugin implements ISearchPlugin { ]; } - $searchResult->addResultSet('emails', $result['wide'], $result['exact']); + $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); return false; } diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index ff075b8e42d..c97a951be7e 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -26,6 +26,7 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Contacts\IManager; use OCP\Federation\ICloudIdManager; use OCP\IConfig; @@ -51,6 +52,7 @@ class RemotePlugin implements ISearchPlugin { public function search($search, $limit, $offset, ISearchResult $searchResult) { $result = ['wide' => [], 'exact' => []]; + $resultType = new SearchResultType('remotes'); // Search in contacts //@todo Pagination missing @@ -74,7 +76,7 @@ class RemotePlugin implements ISearchPlugin { if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { if (strtolower($cloudId) === $lowerSearch) { - $searchResult->hasExactIdMatch('remotes'); + $searchResult->hasExactIdMatch($resultType); } $result['exact'][] = [ 'label' => $contact['FN'] . " ($cloudId)", @@ -102,7 +104,7 @@ class RemotePlugin implements ISearchPlugin { $result['wide'] = []; } - if (!$searchResult->hasExactIdMatch('remotes') && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { + if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { $result['exact'][] = [ 'label' => $search, 'value' => [ @@ -112,7 +114,7 @@ class RemotePlugin implements ISearchPlugin { ]; } - $searchResult->addResultSet('remotes', $result['wide'], $result['exact']); + $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); return false; } diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index abca13bcfe9..815b9eea3e9 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -26,6 +26,7 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearch; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; use OCP\IContainer; use OCP\Share; @@ -71,10 +72,12 @@ class Search implements ISearch { // if we have a exact match, either for the federated cloud id or for the // email address we only return the exact match. It is highly unlikely // that the exact same email address and federated cloud id exists - if($searchResult->hasExactIdMatch('emails') && !$searchResult->hasExactIdMatch('remotes')) { - $searchResult->unsetResult('remotes'); - } elseif (!$searchResult->hasExactIdMatch('emails') && $searchResult->hasExactIdMatch('remotes')) { - $searchResult->unsetResult('emails'); + $emailType = new SearchResultType('emails'); + $remoteType = new SearchResultType('remotes'); + if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { + $searchResult->unsetResult($remoteType); + } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { + $searchResult->unsetResult($emailType); } return [$searchResult->asArray(), $hasMoreResults]; diff --git a/lib/private/Collaboration/Collaborators/SearchResult.php b/lib/private/Collaboration/Collaborators/SearchResult.php index f3559c9327f..9c9503ea945 100644 --- a/lib/private/Collaboration/Collaborators/SearchResult.php +++ b/lib/private/Collaboration/Collaborators/SearchResult.php @@ -25,30 +25,21 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; class SearchResult implements ISearchResult { protected $result = [ - 'exact' => [ - 'users' => [], - 'groups' => [], - 'remotes' => [], - 'emails' => [], - 'circles' => [], - ], - 'users' => [], - 'groups' => [], - 'remotes' => [], - 'emails' => [], - 'lookup' => [], - 'circles' => [], + 'exact' => [], ]; protected $exactIdMatches = []; - public function addResultSet($type, array $matches, array $exactMatches = null) { + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { + $type = $type->getLabel(); if(!isset($this->result[$type])) { - throw new \InvalidArgumentException('Invalid type provided'); + $this->result[$type] = []; + $this->result['exact'][$type] = []; } $this->result[$type] = array_merge($this->result[$type], $matches); @@ -57,17 +48,18 @@ class SearchResult implements ISearchResult { } } - public function markExactIdMatch($type) { - $this->exactIdMatches[$type] = 1; + public function markExactIdMatch(SearchResultType $type) { + $this->exactIdMatches[$type->getLabel()] = 1; } - public function hasExactIdMatch($type) { - return isset($this->exactIdMatches[$type]); + public function hasExactIdMatch(SearchResultType$type) { + return isset($this->exactIdMatches[$type->getLabel()]); } - public function hasResult($type, $collaboratorId) { + public function hasResult(SearchResultType $type, $collaboratorId) { + $type = $type->getLabel(); if(!isset($this->result[$type])) { - throw new \InvalidArgumentException('Invalid type provided'); + return false; } $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; @@ -84,11 +76,8 @@ class SearchResult implements ISearchResult { return $this->result; } - public function unsetResult($type) { - if(!isset($this->result[$type])) { - throw new \InvalidArgumentException('Invalid type provided'); - } - + public function unsetResult(SearchResultType $type) { + $type = $type->getLabel(); $this->result[$type] = []; if(isset($this->$result['exact'][$type])) { $this->result['exact'][$type] = []; diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php index 815862b8726..6d2709f8bd0 100644 --- a/lib/private/Collaboration/Collaborators/UserPlugin.php +++ b/lib/private/Collaboration/Collaborators/UserPlugin.php @@ -26,6 +26,7 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; use OCP\IConfig; use OCP\IGroupManager; use OCP\IUser; @@ -140,7 +141,8 @@ class UserPlugin implements ISearchPlugin { $result['wide'] = []; } - $searchResult->addResultSet('users', $result['wide'], $result['exact']); + $type = new SearchResultType('users'); + $searchResult->addResultSet($type, $result['wide'], $result['exact']); return $hasMoreResults; } |