2017-08-31 16:47:02 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2017-08-31 16:47:02 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-08-31 16:47:02 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Collaboration\Collaborators;
|
|
|
|
|
|
|
|
|
|
use OCP\Collaboration\Collaborators\ISearchResult;
|
2017-09-06 10:09:29 -04:00
|
|
|
use OCP\Collaboration\Collaborators\SearchResultType;
|
2017-08-31 16:47:02 -04:00
|
|
|
|
|
|
|
|
class SearchResult implements ISearchResult {
|
2023-07-03 03:36:55 -04:00
|
|
|
protected array $result = [
|
2017-09-06 10:09:29 -04:00
|
|
|
'exact' => [],
|
2017-08-31 16:47:02 -04:00
|
|
|
];
|
|
|
|
|
|
2023-07-03 03:36:55 -04:00
|
|
|
protected array $exactIdMatches = [];
|
2017-08-31 16:47:02 -04:00
|
|
|
|
2024-03-28 11:13:19 -04:00
|
|
|
public function addResultSet(SearchResultType $type, array $matches, ?array $exactMatches = null): void {
|
2017-09-06 10:09:29 -04:00
|
|
|
$type = $type->getLabel();
|
2017-08-31 16:47:02 -04:00
|
|
|
if (!isset($this->result[$type])) {
|
2017-09-06 10:09:29 -04:00
|
|
|
$this->result[$type] = [];
|
|
|
|
|
$this->result['exact'][$type] = [];
|
2017-08-31 16:47:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->result[$type] = array_merge($this->result[$type], $matches);
|
|
|
|
|
if (is_array($exactMatches)) {
|
|
|
|
|
$this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 03:36:55 -04:00
|
|
|
public function markExactIdMatch(SearchResultType $type): void {
|
2017-09-06 10:09:29 -04:00
|
|
|
$this->exactIdMatches[$type->getLabel()] = 1;
|
2017-08-31 16:47:02 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-03 03:36:55 -04:00
|
|
|
public function hasExactIdMatch(SearchResultType $type): bool {
|
2017-09-06 10:09:29 -04:00
|
|
|
return isset($this->exactIdMatches[$type->getLabel()]);
|
2017-08-31 16:47:02 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-03 03:36:55 -04:00
|
|
|
public function hasResult(SearchResultType $type, $collaboratorId): bool {
|
2017-09-06 10:09:29 -04:00
|
|
|
$type = $type->getLabel();
|
2017-08-31 16:47:02 -04:00
|
|
|
if (!isset($this->result[$type])) {
|
2017-09-06 10:09:29 -04:00
|
|
|
return false;
|
2017-08-31 16:47:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$resultArrays = [$this->result['exact'][$type], $this->result[$type]];
|
|
|
|
|
foreach ($resultArrays as $resultArray) {
|
2017-10-25 04:38:26 -04:00
|
|
|
foreach ($resultArray as $result) {
|
|
|
|
|
if ($result['value']['shareWith'] === $collaboratorId) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-31 16:47:02 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 03:36:55 -04:00
|
|
|
public function asArray(): array {
|
2017-08-31 16:47:02 -04:00
|
|
|
return $this->result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 03:36:55 -04:00
|
|
|
public function unsetResult(SearchResultType $type): void {
|
2017-09-06 10:09:29 -04:00
|
|
|
$type = $type->getLabel();
|
2017-08-31 16:47:02 -04:00
|
|
|
$this->result[$type] = [];
|
2017-09-11 10:46:05 -04:00
|
|
|
if (isset($this->result['exact'][$type])) {
|
2017-08-31 16:47:02 -04:00
|
|
|
$this->result['exact'][$type] = [];
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-13 16:49:42 -04:00
|
|
|
|
|
|
|
|
public function removeCollaboratorResult(SearchResultType $type, string $collaboratorId): bool {
|
|
|
|
|
$type = $type->getLabel();
|
|
|
|
|
if (!isset($this->result[$type])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$actionDone = false;
|
|
|
|
|
$resultArrays = [&$this->result['exact'][$type], &$this->result[$type]];
|
|
|
|
|
foreach ($resultArrays as &$resultArray) {
|
|
|
|
|
foreach ($resultArray as $k => $result) {
|
|
|
|
|
if ($result['value']['shareWith'] === $collaboratorId) {
|
|
|
|
|
unset($resultArray[$k]);
|
|
|
|
|
$actionDone = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $actionDone;
|
|
|
|
|
}
|
2017-08-31 16:47:02 -04:00
|
|
|
}
|