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
|
|
|
|
10
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
13
|
|
|
|
14
|
|
|
use Oro\Bundle\ActivityBundle\Entity\Manager\ActivityTargetApiEntityManager; |
15
|
|
|
use Oro\Bundle\SoapBundle\Controller\Api\Rest\RestGetController; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @RouteResource("activity_target") |
19
|
|
|
* @NamePrefix("oro_api_") |
20
|
|
|
*/ |
21
|
|
|
class ActivityTargetController extends RestGetController |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Get types of entities which can be associated with at least one activity type. |
25
|
|
|
* |
26
|
|
|
* @Get("/activities/targets") |
27
|
|
|
* |
28
|
|
|
* @ApiDoc( |
29
|
|
|
* description="Get types of entities which can be associated with at least one activity type", |
30
|
|
|
* resource=true |
31
|
|
|
* ) |
32
|
|
|
* |
33
|
|
|
* @return Response |
34
|
|
|
*/ |
35
|
|
|
public function getAllTypesAction() |
36
|
|
|
{ |
37
|
|
|
$result = $this->getManager()->getTargetTypes(); |
38
|
|
|
|
39
|
|
|
return $this->buildResponse($result, self::ACTION_LIST, ['result' => $result]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get types of activities which can be added to the specified entity type. |
44
|
|
|
* |
45
|
|
|
* @param string $entity The type of the target entity. |
46
|
|
|
* |
47
|
|
|
* @Get("/activities/targets/{entity}") |
48
|
|
|
* |
49
|
|
|
* @ApiDoc( |
50
|
|
|
* description="Get types of activities which can be added to the specified entity type", |
51
|
|
|
* resource=true |
52
|
|
|
* ) |
53
|
|
|
* |
54
|
|
|
* @return Response |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function getActivityTypesAction($entity) |
57
|
|
|
{ |
58
|
|
|
$manager = $this->getManager(); |
59
|
|
|
$manager->setClass($manager->resolveEntityClass($entity, true)); |
60
|
|
|
|
61
|
|
|
$result = $this->getManager()->getActivityTypes(); |
62
|
|
|
|
63
|
|
|
return $this->buildResponse($result, self::ACTION_LIST, ['result' => $result]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get activities for the specified entity. |
68
|
|
|
* |
69
|
|
|
* @param string $entity The type of the target entity. |
70
|
|
|
* @param mixed $id The id of the target entity. |
71
|
|
|
* |
72
|
|
|
* @Get("/activities/targets/{entity}/{id}") |
73
|
|
|
* |
74
|
|
|
* @QueryParam( |
75
|
|
|
* name="page", |
76
|
|
|
* requirements="\d+", |
77
|
|
|
* nullable=true, |
78
|
|
|
* description="Page number, starting from 1. Defaults to 1." |
79
|
|
|
* ) |
80
|
|
|
* @QueryParam( |
81
|
|
|
* name="limit", |
82
|
|
|
* requirements="\d+", |
83
|
|
|
* nullable=true, |
84
|
|
|
* description="Number of items per page. Defaults to 10." |
85
|
|
|
* ) |
86
|
|
|
* |
87
|
|
|
* @ApiDoc( |
88
|
|
|
* description="Get activities for the specified entity", |
89
|
|
|
* resource=true |
90
|
|
|
* ) |
91
|
|
|
* |
92
|
|
|
* @return Response |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public function getActivitiesAction($entity, $id) |
95
|
|
|
{ |
96
|
|
|
$manager = $this->getManager(); |
97
|
|
|
$manager->setClass($manager->resolveEntityClass($entity, true)); |
98
|
|
|
|
99
|
|
|
$page = (int)$this->getRequest()->get('page', 1); |
100
|
|
|
$limit = (int)$this->getRequest()->get('limit', self::ITEMS_PER_PAGE); |
101
|
|
|
|
102
|
|
|
$criteria = $this->buildFilterCriteria(['id' => ['=', $id]], [], ['id' => 'target.id']); |
103
|
|
|
|
104
|
|
|
return $this->handleGetListRequest($page, $limit, $criteria); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get entity manager |
109
|
|
|
* |
110
|
|
|
* @return ActivityTargetApiEntityManager |
111
|
|
|
*/ |
112
|
|
|
public function getManager() |
113
|
|
|
{ |
114
|
|
|
return $this->container->get('oro_activity.manager.activity_target.api'); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
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: