da_agency/lib/Service/GroupPermissionService.php

63 lines
1.5 KiB
PHP

<?php
namespace OCA\Agency\Service;
use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCA\Agency\Db\GroupPermission;
use OCA\Agency\Db\GroupPermissionMapper;
class GroupPermissionService {
private $mapper;
public function __construct(GroupPermissionMapper $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
public function find(int $id) {
try {
return $this->mapper->find($id);
} catch(Exception $e) {
$this->handleException($e);
}
}
//Create an Agency
public function create(string $gid, string $permission = "") {
$grouppermission = new GroupPermission();
$grouppermission->setGid($gid);
return $this->mapper->insert($grouppermission);
}
public function findbygid(string $gid){
try {
return $this->mapper->findbygid($gid);
} catch(Exception $e) {
$this->handleException($e);
}
}
public function remove(int $id){
try {
return $this->mapper->remove($id);
} catch(Exception $e) {
$this->handleException($e);
}
}
}