1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ChannelBundle\Provider; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\QueryBuilder; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper; |
8
|
|
|
|
9
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
10
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Repository\ChannelRepository; |
11
|
|
|
|
12
|
|
|
class ChannelsByEntitiesProvider |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var DoctrineHelper |
16
|
|
|
*/ |
17
|
|
|
protected $doctrineHelper; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ChannelRepository |
21
|
|
|
*/ |
22
|
|
|
protected $channelRepository; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array [{parameters_hash} => {Channel[]}, ...] |
26
|
|
|
*/ |
27
|
|
|
protected $channelsCache = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param DoctrineHelper $doctrineHelper |
31
|
|
|
*/ |
32
|
|
|
public function __construct(DoctrineHelper $doctrineHelper) |
33
|
|
|
{ |
34
|
|
|
$this->doctrineHelper = $doctrineHelper; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $entities |
39
|
|
|
* @param bool $status |
40
|
|
|
* |
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
|
|
public function getChannelsByEntities(array $entities = [], $status = Channel::STATUS_ACTIVE) |
44
|
|
|
{ |
45
|
|
|
sort($entities); |
46
|
|
|
$hash = md5(serialize([$entities, $status])); |
47
|
|
|
if (!isset($this->channelsCache[$hash])) { |
48
|
|
|
$this->channelsCache[$hash] = $this->getChannelRepository()->getChannelsByEntities($entities, $status); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->channelsCache[$hash]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param array $entities |
56
|
|
|
* @param bool $status |
57
|
|
|
* |
58
|
|
|
* @return QueryBuilder |
59
|
|
|
*/ |
60
|
|
|
public function getChannelsByEntitiesQB(array $entities = [], $status = Channel::STATUS_ACTIVE) |
61
|
|
|
{ |
62
|
|
|
return $this->getChannelRepository()->getChannelsByEntitiesQB($entities, $status); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return ChannelRepository |
67
|
|
|
*/ |
68
|
|
|
protected function getChannelRepository() |
69
|
|
|
{ |
70
|
|
|
if (null === $this->channelRepository) { |
71
|
|
|
$this->channelRepository = $this->doctrineHelper |
72
|
|
|
->getEntityRepositoryForClass('OroCRMChannelBundle:Channel'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $this->channelRepository; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|