53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
namespace OCA\Agency\Service;
|
|
|
|
use Exception;
|
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
|
|
|
use OCA\Agency\Db\AgencyUser;
|
|
use OCA\Agency\Db\AgencyUserMapper;
|
|
|
|
|
|
class AgencyUserService {
|
|
|
|
private $mapper;
|
|
|
|
public function __construct(AgencyUserMapper $mapper){
|
|
$this->mapper = $mapper;
|
|
}
|
|
|
|
private function handleException ($e) {
|
|
if ($e instanceof DoesNotExistException ||
|
|
$e instanceof MultipleObjectsReturnedException) {
|
|
throw new NotFoundException($e->getMessage());
|
|
} else {
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
//Find an Agency-User
|
|
public function find(int $id) {
|
|
try {
|
|
return $this->mapper->find($id);
|
|
} catch(Exception $e) {
|
|
$this->handleException($e);
|
|
}
|
|
}
|
|
|
|
//Find an Agency-User
|
|
public function getAgencyIdByUserUid(string $useruid) {
|
|
try {
|
|
return $this->mapper->getAgencyIdByUserUid($useruid);
|
|
} catch(Exception $e) {
|
|
$this->handleException($e);
|
|
}
|
|
}
|
|
|
|
//Checks, if a given User is in given Agency. Use for secure reason to make save, that agencydata is only changed by user which belongs to that agency.
|
|
public function checkAgencyIdUserId(string $useruid, int $agencyid){
|
|
# TODO: Hier einmal prüfen, dass der eingeloggte Nutzer auch zur angefragten Agentur passt!
|
|
return false;
|
|
}
|
|
} |