1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\CampaignBundle\Dashboard; |
4
|
|
|
|
5
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\DashboardBundle\Filter\DateFilterProcessor; |
8
|
|
|
use Oro\Bundle\SecurityBundle\ORM\Walker\AclHelper; |
9
|
|
|
use OroCRM\Bundle\CampaignBundle\Entity\Repository\CampaignRepository; |
10
|
|
|
|
11
|
|
|
class CampaignDataProvider |
12
|
|
|
{ |
13
|
|
|
const CAMPAIGN_LEAD_COUNT = 5; |
14
|
|
|
const CAMPAIGN_OPPORTUNITY_COUNT = 5; |
15
|
|
|
const CAMPAIGN_CLOSE_REVENUE_COUNT = 5; |
16
|
|
|
|
17
|
|
|
/** @var RegistryInterface */ |
18
|
|
|
protected $registry; |
19
|
|
|
|
20
|
|
|
/** @var AclHelper */ |
21
|
|
|
protected $aclHelper; |
22
|
|
|
|
23
|
|
|
/** @var DateFilterProcessor */ |
24
|
|
|
protected $dateFilterProcessor; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param RegistryInterface $doctrine |
28
|
|
|
* @param AclHelper $aclHelper |
29
|
|
|
* @param DateFilterProcessor $processor |
30
|
|
|
*/ |
31
|
|
|
public function __construct( |
32
|
|
|
RegistryInterface $doctrine, |
33
|
|
|
AclHelper $aclHelper, |
34
|
|
|
DateFilterProcessor $processor |
35
|
|
|
) { |
36
|
|
|
$this->registry = $doctrine; |
37
|
|
|
$this->aclHelper = $aclHelper; |
38
|
|
|
$this->dateFilterProcessor = $processor; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param array $dateRange |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function getCampaignLeadsData(array $dateRange) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$qb = $this->getCampaignRepository()->getCampaignsLeadsQB('lead'); |
49
|
|
|
$qb->setMaxResults(self::CAMPAIGN_LEAD_COUNT); |
50
|
|
|
$this->dateFilterProcessor->process($qb, $dateRange, 'lead.createdAt'); |
51
|
|
|
|
52
|
|
|
return $this->aclHelper->apply($qb)->getArrayResult(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param array $dateRange |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function getCampaignOpportunitiesData(array $dateRange) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$qb = $this->getCampaignRepository()->getCampaignsOpportunitiesQB('opportunities'); |
63
|
|
|
$qb->setMaxResults(self::CAMPAIGN_OPPORTUNITY_COUNT); |
64
|
|
|
$this->dateFilterProcessor->process($qb, $dateRange, 'opportunities.createdAt'); |
65
|
|
|
|
66
|
|
|
return $this->aclHelper->apply($qb)->getArrayResult(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param array $dateRange |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function getCampaignsByCloseRevenueData(array $dateRange) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$qb = $this->getCampaignRepository()->getCampaignsByCloseRevenueQB('opportunities'); |
77
|
|
|
$qb->setMaxResults(self::CAMPAIGN_CLOSE_REVENUE_COUNT); |
78
|
|
|
$this->dateFilterProcessor->process($qb, $dateRange, 'opportunities.createdAt'); |
79
|
|
|
|
80
|
|
|
return $this->aclHelper->apply($qb)->getArrayResult(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return CampaignRepository |
85
|
|
|
*/ |
86
|
|
|
protected function getCampaignRepository() |
87
|
|
|
{ |
88
|
|
|
return $this->registry->getRepository('OroCRMCampaignBundle:Campaign'); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.