This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
espocrm-base/application/Espo/Services/Stream.php
T
Yuri Kuznetsov 10f706c965 stream
2014-01-13 16:44:04 +02:00

73 lines
1.3 KiB
PHP

<?php
namespace Espo\Services;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\NotFound;
class Stream extends \Espo\Core\Services\Base
{
static public $dependencies = array(
'entityManager',
'user',
'metadata',
'acl'
);
protected function getEntityManager()
{
return $this->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,
);
}
}