63 lines
1.5 KiB
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 a permission
|
|
public function find(int $id) {
|
|
try {
|
|
return $this->mapper->find($id);
|
|
} catch(Exception $e) {
|
|
$this->handleException($e);
|
|
}
|
|
}
|
|
|
|
//Create a Permission
|
|
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(string $gid){
|
|
try {
|
|
return $this->mapper->remove($gid);
|
|
} catch(Exception $e) {
|
|
$this->handleException($e);
|
|
}
|
|
}
|
|
|
|
|
|
} |