From 10f706c9657058ca72a5cdaefdc0b9a172faf6b8 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 13 Jan 2014 16:44:04 +0200 Subject: [PATCH] stream --- application/Espo/Controllers/Note.php | 8 +++ application/Espo/Controllers/Stream.php | 16 +++++ application/Espo/Core/Acl.php | 5 ++ application/Espo/Core/ControllerManager.php | 3 +- application/Espo/Entities/Attachment.php | 8 +++ application/Espo/Entities/Note.php | 8 +++ .../Resources/layouts/Note/detailSmall.json | 13 ++++ application/Espo/Resources/routes.json | 11 +++ application/Espo/Services/Record.php | 2 +- application/Espo/Services/Stream.php | 72 +++++++++++++++++++ 10 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 application/Espo/Controllers/Note.php create mode 100644 application/Espo/Entities/Attachment.php create mode 100644 application/Espo/Entities/Note.php create mode 100644 application/Espo/Resources/layouts/Note/detailSmall.json create mode 100644 application/Espo/Services/Stream.php diff --git a/application/Espo/Controllers/Note.php b/application/Espo/Controllers/Note.php new file mode 100644 index 0000000000..bf08634fc1 --- /dev/null +++ b/application/Espo/Controllers/Note.php @@ -0,0 +1,8 @@ +get('offset')); + $maxSize = intval($request->get('maxSize')); + + $service = $this->getService('\\Espo\\Services\\Stream'); + + $result = $service->find($scope, $id, array( + 'offset' => $offset, + 'maxSize' => $maxSize + )); + + return array( + 'total' => $result['total'], + 'list' => $result['collection']->toArray() + ); } } diff --git a/application/Espo/Core/Acl.php b/application/Espo/Core/Acl.php index 09437afa4a..f887d20c6d 100644 --- a/application/Espo/Core/Acl.php +++ b/application/Espo/Core/Acl.php @@ -170,6 +170,11 @@ class Acl 'delete' => 'no', ); $this->data['Role'] = false; + $this->data['Note'] = array( + 'read' => 'own', + 'edit' => 'own', + 'delete' => 'own', + ); } private function merge($tables) diff --git a/application/Espo/Core/ControllerManager.php b/application/Espo/Core/ControllerManager.php index da87cb9be6..77272d2933 100644 --- a/application/Espo/Core/ControllerManager.php +++ b/application/Espo/Core/ControllerManager.php @@ -47,7 +47,8 @@ class ControllerManager $controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName); } } - + + if ($data) { $data = json_decode($data, true); } diff --git a/application/Espo/Entities/Attachment.php b/application/Espo/Entities/Attachment.php new file mode 100644 index 0000000000..c13b9de8ad --- /dev/null +++ b/application/Espo/Entities/Attachment.php @@ -0,0 +1,8 @@ + $this->getRepository()->count($selectParams), 'collection' => $collection, - ); + ); } public function findLinkedEntities($id, $link, $params) diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php new file mode 100644 index 0000000000..35e21b61a0 --- /dev/null +++ b/application/Espo/Services/Stream.php @@ -0,0 +1,72 @@ +injections['entityManager']; + } + + protected function getUser() + { + return $this->injections['user']; + } + + protected function getAcl() + { + return $this->injections['acl']; + } + + protected function getMetadata() + { + return $this->injections['metadata']; + } + + public function find($scope, $id, $params) + { + $entity = $this->getEntityManager()->getEntity($scope, $id); + + if (empty($entity)) { + throw new NotFound(); + } + + if (!$this->getAcl($entity, 'read')) { + throw new Forbidden(); + } + + $where = array( + 'parentType' => $scope, + 'parentId' => $id + ); + + $collection = $this->getEntityManager()->getRepository('Note')->find(array( + 'whereClause' => $where, + 'offset' => $params['offset'], + 'limit' => $params['maxSize'], + 'orderBy' => 'createdAt', + 'order' => 'DESC' + )); + + $count = $this->getEntityManager()->getRepository('Note')->count(array( + 'whereClause' => $where, + )); + + return array( + 'total' => $count, + 'collection' => $collection, + ); + } +} +