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/Hooks/Common/Stream.php
T
Yuri Kuznetsov 596e59d667 stream
2014-01-17 17:49:58 +02:00

67 lines
1.3 KiB
PHP

<?php
namespace Espo\Hooks\Common;
use Espo\ORM\Entity;
class Stream extends \Espo\Core\Hooks\Base
{
protected $streamService = null;
protected $dependencies = array(
'entityManager',
'config',
'metadata',
'acl',
'user',
);
protected function init()
{
$this->dependencies[] = 'serviceFactory';
}
protected function getServiceFactory()
{
return $this->getInjection('serviceFactory');
}
protected function checkHasStream(Entity $entity)
{
$entityName = $entity->getEntityName();
return $this->getMetadata()->get("scopes.{$entityName}.stream");
}
public function afterRemove(Entity $entity)
{
if ($this->checkHasStream($entity)) {
$this->getStreamService()->unfollowAllUsersFromEntity($entity);
}
}
public function afterSave(Entity $entity)
{
$entityName = $entity->getEntityName();
if ($this->checkHasStream($entity)) {
if (!$entity->getFetchedValue('id')) {
$this->noteCreate($entity);
}
}
}
protected function getStreamService()
{
if (empty($this->streamService)) {
$this->streamService = $this->getServiceFactory()->createByClassName('\\Espo\\Services\\Stream');
}
return $this->streamService;
}
protected function noteCreate(Entity $entity)
{
$this->getStreamService()->noteCreate($entity);
}
}