Completed
Push — 1.9 ( 5c3e2e...1529fd )
by
unknown
60:20
created

CallActivityListProvider::isCommentsEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\CallBundle\Provider;
4
5
use Oro\Bundle\ActivityBundle\Tools\ActivityAssociationHelper;
6
use Oro\Bundle\ActivityListBundle\Entity\ActivityList;
7
use Oro\Bundle\ActivityListBundle\Model\ActivityListProviderInterface;
8
use Oro\Bundle\ActivityListBundle\Entity\ActivityOwner;
9
use Oro\Bundle\ActivityListBundle\Model\ActivityListDateProviderInterface;
10
use Oro\Bundle\CommentBundle\Model\CommentProviderInterface;
11
use Oro\Bundle\CommentBundle\Tools\CommentAssociationHelper;
12
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
13
use Oro\Bundle\EntityConfigBundle\DependencyInjection\Utils\ServiceLink;
14
15
use OroCRM\Bundle\CallBundle\Entity\Call;
16
17 View Code Duplication
class CallActivityListProvider implements
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
18
    ActivityListProviderInterface,
19
    CommentProviderInterface,
20
    ActivityListDateProviderInterface
21
{
22
    const ACTIVITY_CLASS = 'OroCRM\Bundle\CallBundle\Entity\Call';
23
    const ACL_CLASS = 'OroCRM\Bundle\CallBundle\Entity\Call';
24
25
    /** @var DoctrineHelper */
26
    protected $doctrineHelper;
27
28
    /** @var ServiceLink */
29
    protected $entityOwnerAccessorLink;
30
31
    /** @var ActivityAssociationHelper */
32
    protected $activityAssociationHelper;
33
34
    /** @var CommentAssociationHelper */
35
    protected $commentAssociationHelper;
36
37
    /**
38
     * @param DoctrineHelper            $doctrineHelper
39
     * @param ServiceLink               $entityOwnerAccessorLink
40
     * @param ActivityAssociationHelper $activityAssociationHelper
41
     * @param CommentAssociationHelper  $commentAssociationHelper
42
     */
43
    public function __construct(
44
        DoctrineHelper $doctrineHelper,
45
        ServiceLink $entityOwnerAccessorLink,
46
        ActivityAssociationHelper $activityAssociationHelper,
47
        CommentAssociationHelper $commentAssociationHelper
48
    ) {
49
        $this->doctrineHelper            = $doctrineHelper;
50
        $this->entityOwnerAccessorLink   = $entityOwnerAccessorLink;
51
        $this->activityAssociationHelper = $activityAssociationHelper;
52
        $this->commentAssociationHelper  = $commentAssociationHelper;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function isApplicableTarget($entityClass, $accessible = true)
59
    {
60
        return $this->activityAssociationHelper->isActivityAssociationEnabled(
61
            $entityClass,
62
            self::ACTIVITY_CLASS,
63
            $accessible
64
        );
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getSubject($entity)
71
    {
72
        /** @var $entity Call */
73
        return $entity->getSubject();
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getDescription($entity)
80
    {
81
        /** @var $entity Call */
82
        return $entity->getNotes();
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function getOwner($entity)
89
    {
90
        /** @var $entity Call */
91
        return $entity->getOwner();
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function getCreatedAt($entity)
98
    {
99
        /** @var $entity Call */
100
        return $entity->getCreatedAt();
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function getUpdatedAt($entity)
107
    {
108
        /** @var $entity Call */
109
        return $entity->getUpdatedAt();
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function getData(ActivityList $activityListEntity)
116
    {
117
        return [];
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    public function getOrganization($activityEntity)
124
    {
125
        /** @var $activityEntity Call */
126
        return $activityEntity->getOrganization();
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function getTemplate()
133
    {
134
        return 'OroCRMCallBundle:Call:js/activityItemTemplate.js.twig';
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function getRoutes()
141
    {
142
        return [
143
            'itemView'   => 'orocrm_call_widget_info',
144
            'itemEdit'   => 'orocrm_call_update',
145
            'itemDelete' => 'oro_api_delete_call'
146
        ];
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function getActivityClass()
153
    {
154
        return self::ACTIVITY_CLASS;
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function getAclClass()
161
    {
162
        return self::ACL_CLASS;
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     */
168
    public function getActivityId($entity)
169
    {
170
        return $this->doctrineHelper->getSingleEntityIdentifier($entity);
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     */
176
    public function isApplicable($entity)
177
    {
178
        if (is_object($entity)) {
179
            $entity = $this->doctrineHelper->getEntityClass($entity);
180
        }
181
182
        return $entity == self::ACTIVITY_CLASS;
183
    }
184
185
    /**
186
     * {@inheritdoc}
187
     */
188
    public function getTargetEntities($entity)
189
    {
190
        return $entity->getActivityTargetEntities();
191
    }
192
193
    /**
194
     * {@inheritdoc}
195
     */
196
    public function isCommentsEnabled($entityClass)
197
    {
198
        return $this->commentAssociationHelper->isCommentAssociationEnabled($entityClass);
199
    }
200
201
    /**
202
     * {@inheritdoc}
203
     */
204
    public function getActivityOwners($entity, ActivityList $activityList)
205
    {
206
        $organization = $this->getOrganization($entity);
207
        $owner = $this->entityOwnerAccessorLink->getService()->getOwner($entity);
208
209
        if (!$organization || !$owner) {
210
            return [];
211
        }
212
213
        $activityOwner = new ActivityOwner();
214
        $activityOwner->setActivity($activityList);
215
        $activityOwner->setOrganization($organization);
216
        $activityOwner->setUser($owner);
217
        return [$activityOwner];
218
    }
219
}
220