From 5809b23811e515c38589a23f815a13c1b723c0c0 Mon Sep 17 00:00:00 2001 From: brantje Date: Sun, 2 Oct 2016 17:37:21 +0200 Subject: [PATCH] Decline from notification works! --- controller/sharecontroller.php | 10 ++++++---- lib/Db/ShareRequestMapper.php | 10 ++++++++++ lib/Service/ShareService.php | 8 ++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index a077be8c..d53bf64d 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -182,16 +182,18 @@ class ShareController extends ApiController { } public function deleteShareRequest($share_request_id){ - echo $share_request_id; - + $sr = $this->shareService->getSharingRequestById($share_request_id); + $share_requests = $this->shareService->getShareRequestsByItemId($sr->getItemId()); + foreach ($share_requests as $share_request){ + $this->shareService->deleteShareRequestById($share_request->getId()); + } $manager = \OC::$server->getNotificationManager(); $notification = $manager->createNotification(); $notification->setApp('passman') ->setObject('passman_share_request', $share_request_id) ->setUser($this->userId->getUID()); $manager->markProcessed($notification); - //@TODO load other requests and delete them by item id. - $this->shareService->deleteShareRequestById($share_request_id); + return new JSONResponse(array('result'=>true)); } } \ No newline at end of file diff --git a/lib/Db/ShareRequestMapper.php b/lib/Db/ShareRequestMapper.php index f88f3d13..6a09ffad 100644 --- a/lib/Db/ShareRequestMapper.php +++ b/lib/Db/ShareRequestMapper.php @@ -57,4 +57,14 @@ class ShareRequestMapper extends Mapper { public function deleteShareRequest(ShareRequest $shareRequest){ $this->delete($shareRequest); } + + public function getSharingRequestById($id){ + $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE id = ?"; + return $this->findEntity($q, [$id]); + } + + public function getShareRequestsByItemId($item_id){ + $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_id = ?"; + return $this->findEntities($q, [$item_id]); + } } \ No newline at end of file diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 128b5cd9..df3f5926 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -100,4 +100,12 @@ class ShareService { $this->shareRequest->deleteShareRequest($t); } + + public function getSharingRequestById($id){ + return $this->shareRequest->getSharingRequestById($id); + } + + public function getShareRequestsByItemId($item_id){ + return $this->shareRequest->getShareRequestsByItemId($item_id); + } } \ No newline at end of file