12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- declare(strict_types=1);
- namespace OC\KnownUser;
- class KnownUserService {
-
- protected $mapper;
-
- protected $knownUsers = [];
- public function __construct(KnownUserMapper $mapper) {
- $this->mapper = $mapper;
- }
-
- public function deleteKnownTo(string $knownTo): int {
- return $this->mapper->deleteKnownTo($knownTo);
- }
-
- public function deleteByContactUserId(string $contactUserId): int {
- return $this->mapper->deleteKnownUser($contactUserId);
- }
-
- public function storeIsKnownToUser(string $knownTo, string $contactUserId): void {
- $entity = new KnownUser();
- $entity->setKnownTo($knownTo);
- $entity->setKnownUser($contactUserId);
- $this->mapper->insert($entity);
- }
-
- public function isKnownToUser(string $knownTo, string $contactUserId): bool {
- if ($knownTo === $contactUserId) {
- return true;
- }
- if (!isset($this->knownUsers[$knownTo])) {
- $entities = $this->mapper->getKnownUsers($knownTo);
- $this->knownUsers[$knownTo] = [];
- foreach ($entities as $entity) {
- $this->knownUsers[$knownTo][$entity->getKnownUser()] = true;
- }
- }
- return isset($this->knownUsers[$knownTo][$contactUserId]);
- }
- }
|