Code Duplication    Length = 173-173 lines in 2 locations

src/OroCRM/Bundle/CallBundle/Provider/CallActivityListProvider.php 1 location

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

src/OroCRM/Bundle/TaskBundle/Provider/TaskActivityListProvider.php 1 location

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