1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\ActivityBundle\Controller\Api\Rest; |
4
|
|
|
|
5
|
|
|
use FOS\RestBundle\Controller\Annotations\NamePrefix; |
6
|
|
|
use FOS\RestBundle\Controller\Annotations\RouteResource; |
7
|
|
|
use FOS\RestBundle\Controller\Annotations\QueryParam; |
8
|
|
|
use FOS\RestBundle\Controller\Annotations\Get; |
9
|
|
|
use FOS\RestBundle\Controller\Annotations\Delete; |
10
|
|
|
use FOS\RestBundle\Controller\Annotations\Post; |
11
|
|
|
|
12
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
|
16
|
|
|
use Oro\Bundle\ActivityBundle\Entity\Manager\ActivityEntityApiEntityManager; |
17
|
|
|
use Oro\Bundle\SoapBundle\Controller\Api\Rest\RestController; |
18
|
|
|
use Oro\Bundle\SoapBundle\Model\RelationIdentifier; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @RouteResource("activity_relation") |
22
|
|
|
* @NamePrefix("oro_api_") |
23
|
|
|
*/ |
24
|
|
|
class ActivityEntityController extends RestController |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Get entities associated with the specified activity. |
28
|
|
|
* |
29
|
|
|
* @param string $activity The type of the activity entity. |
30
|
|
|
* @param int $id The id of the activity entity. |
31
|
|
|
* |
32
|
|
|
* @Get("/activities/{activity}/{id}/relations") |
33
|
|
|
* |
34
|
|
|
* @QueryParam( |
35
|
|
|
* name="page", |
36
|
|
|
* requirements="\d+", |
37
|
|
|
* nullable=true, |
38
|
|
|
* description="Page number, starting from 1. Defaults to 1." |
39
|
|
|
* ) |
40
|
|
|
* @QueryParam( |
41
|
|
|
* name="limit", |
42
|
|
|
* requirements="\d+", |
43
|
|
|
* nullable=true, |
44
|
|
|
* description="Number of items per page. Defaults to 10." |
45
|
|
|
* ) |
46
|
|
|
* |
47
|
|
|
* @ApiDoc( |
48
|
|
|
* description="Get entities associated with the specified activity", |
49
|
|
|
* resource=true |
50
|
|
|
* ) |
51
|
|
|
* |
52
|
|
|
* @return Response |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
public function cgetAction($activity, $id) |
55
|
|
|
{ |
56
|
|
|
$manager = $this->getManager(); |
57
|
|
|
$manager->setClass($manager->resolveEntityClass($activity, true)); |
58
|
|
|
|
59
|
|
|
$page = (int)$this->getRequest()->get('page', 1); |
60
|
|
|
$limit = (int)$this->getRequest()->get('limit', self::ITEMS_PER_PAGE); |
61
|
|
|
|
62
|
|
|
$criteria = $this->buildFilterCriteria(['id' => ['=', $id]]); |
63
|
|
|
|
64
|
|
|
return $this->handleGetListRequest($page, $limit, $criteria); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Adds an association between an activity and a target entity. |
69
|
|
|
* |
70
|
|
|
* @param string $activity The type of the activity entity. |
71
|
|
|
* @param int $id The id of the activity entity. |
72
|
|
|
* |
73
|
|
|
* @Post("/activities/{activity}/{id}/relations") |
74
|
|
|
* |
75
|
|
|
* @ApiDoc( |
76
|
|
|
* description="Adds an association between an activity and a target entity", |
77
|
|
|
* resource=true |
78
|
|
|
* ) |
79
|
|
|
* |
80
|
|
|
* @return Response |
81
|
|
|
*/ |
82
|
|
|
public function postAction($activity, $id) |
83
|
|
|
{ |
84
|
|
|
$manager = $this->getManager(); |
85
|
|
|
$manager->setClass($manager->resolveEntityClass($activity, true)); |
86
|
|
|
|
87
|
|
|
return $this->handleUpdateRequest($id); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Deletes an association between an activity and a target entity. |
92
|
|
|
* |
93
|
|
|
* @param string $activity The type of the activity entity. |
94
|
|
|
* @param int $id The id of the activity entity. |
95
|
|
|
* @param string $entity The type of the target entity. |
96
|
|
|
* @param mixed $entityId The id of the target entity. |
97
|
|
|
* |
98
|
|
|
* @Delete("/activities/{activity}/{id}/{entity}/{entityId}") |
99
|
|
|
* |
100
|
|
|
* @ApiDoc( |
101
|
|
|
* description="Deletes an association between an activity and a target entity", |
102
|
|
|
* resource=true |
103
|
|
|
* ) |
104
|
|
|
* |
105
|
|
|
* @return Response |
106
|
|
|
*/ |
107
|
|
|
public function deleteAction($activity, $id, $entity, $entityId) |
108
|
|
|
{ |
109
|
|
|
$manager = $this->getManager(); |
110
|
|
|
$activityClass = $manager->resolveEntityClass($activity, true); |
111
|
|
|
$manager->setClass($activityClass); |
112
|
|
|
|
113
|
|
|
$id = new RelationIdentifier( |
114
|
|
|
$activityClass, |
115
|
|
|
$id, |
116
|
|
|
$manager->resolveEntityClass($entity, true), |
117
|
|
|
$entityId |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
return $this->handleDeleteRequest($id); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get entity manager |
125
|
|
|
* |
126
|
|
|
* @return ActivityEntityApiEntityManager |
127
|
|
|
*/ |
128
|
|
|
public function getManager() |
129
|
|
|
{ |
130
|
|
|
return $this->container->get('oro_activity.manager.activity_entity.api'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* {@inheritdoc} |
135
|
|
|
*/ |
136
|
|
|
public function getFormHandler() |
137
|
|
|
{ |
138
|
|
|
return $this->get('oro_activity.form.handler.activity_entity.api'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* {@inheritdoc} |
143
|
|
|
*/ |
144
|
|
|
protected function getDeleteHandler() |
145
|
|
|
{ |
146
|
|
|
return $this->get('oro_activity.handler.delete.activity_entity'); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: