@@ -43,14 +43,16 @@ discard block |
||
43 | 43 | |
44 | 44 | public function discoveryUser(&$entity) |
45 | 45 | { |
46 | - if (method_exists($entity, 'setUser')) |
|
47 | - $entity->setUser($this->security->getUser()); |
|
46 | + if (method_exists($entity, 'setUser')) { |
|
47 | + $entity->setUser($this->security->getUser()); |
|
48 | + } |
|
48 | 49 | } |
49 | 50 | |
50 | 51 | public function persist(&$entity) |
51 | 52 | { |
52 | - if (self::$persisted == true) |
|
53 | - return; |
|
53 | + if (self::$persisted == true) { |
|
54 | + return; |
|
55 | + } |
|
54 | 56 | self::$persisted = true; |
55 | 57 | |
56 | 58 | //$this->manager->persist($entity); |
@@ -68,15 +70,17 @@ discard block |
||
68 | 70 | } else { |
69 | 71 | $json = json_decode($this->request->getContent(), true); |
70 | 72 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
71 | - if (!$extra_data) |
|
72 | - return; |
|
73 | + if (!$extra_data) { |
|
74 | + return; |
|
75 | + } |
|
73 | 76 | $entity_id = $extra_data['entity_id']; |
74 | 77 | $entity_name = $extra_data['entity_name']; |
75 | 78 | } |
76 | 79 | |
77 | 80 | |
78 | - if (!$entity_id || !$entity_name) |
|
79 | - return; |
|
81 | + if (!$entity_id || !$entity_name) { |
|
82 | + return; |
|
83 | + } |
|
80 | 84 | |
81 | 85 | foreach ($extra_data['data'] as $key => $data) { |
82 | 86 | $extra_fields = $this->manager->getRepository(ExtraFields::class)->find($key); |
@@ -87,8 +91,9 @@ discard block |
||
87 | 91 | 'extra_fields' => $extra_fields |
88 | 92 | ]); |
89 | 93 | |
90 | - if (!$extraData) |
|
91 | - $extraData = new ExtraData(); |
|
94 | + if (!$extraData) { |
|
95 | + $extraData = new ExtraData(); |
|
96 | + } |
|
92 | 97 | |
93 | 98 | $extraData->setExtraFields($extra_fields); |
94 | 99 | $extraData->setEntityName($entity_name); |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | $device = $this->manager->getRepository(Device::class)->findOneBy([ |
20 | 20 | 'device' => $deviceId |
21 | 21 | ]); |
22 | - if (! $device) { |
|
22 | + if (!$device) { |
|
23 | 23 | $device = new Device(); |
24 | 24 | $device->setDevice($deviceId); |
25 | 25 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | 'device' => $device, |
33 | 33 | 'people' => $people |
34 | 34 | ]); |
35 | - if (! $device_config) { |
|
35 | + if (!$device_config) { |
|
36 | 36 | $device_config = new DeviceConfig(); |
37 | 37 | $device_config->setDevice($device); |
38 | 38 | $device_config->setPeople($people); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | public function addDeviceConfigs(People $people, array $configs, $deviceId) |
45 | 45 | { |
46 | 46 | $device = $this->discoveryDevice($deviceId); |
47 | - $device_config = $this->discoveryDeviceConfig($device, $people); |
|
47 | + $device_config = $this->discoveryDeviceConfig($device, $people); |
|
48 | 48 | foreach ($configs as $key => $config) |
49 | - $device_config->addConfigs($key, $config); |
|
49 | + $device_config->addConfigs($key, $config); |
|
50 | 50 | |
51 | 51 | $this->manager->persist($device_config); |
52 | 52 | $this->manager->flush(); |
@@ -45,8 +45,9 @@ |
||
45 | 45 | { |
46 | 46 | $device = $this->discoveryDevice($deviceId); |
47 | 47 | $device_config = $this->discoveryDeviceConfig($device, $people); |
48 | - foreach ($configs as $key => $config) |
|
49 | - $device_config->addConfigs($key, $config); |
|
48 | + foreach ($configs as $key => $config) { |
|
49 | + $device_config->addConfigs($key, $config); |
|
50 | + } |
|
50 | 51 | |
51 | 52 | $this->manager->persist($device_config); |
52 | 53 | $this->manager->flush(); |
@@ -18,24 +18,24 @@ |
||
18 | 18 | |
19 | 19 | class AddDeviceConfigAction |
20 | 20 | { |
21 | - public function __construct( |
|
21 | + public function __construct( |
|
22 | 22 | private Security $security, |
23 | 23 | private EntityManagerInterface $manager, |
24 | 24 | private ConfigService $configService, |
25 | 25 | private HydratorService $hydratorService, |
26 | 26 | private DeviceService $deviceService |
27 | - ) {} |
|
27 | + ) {} |
|
28 | 28 | |
29 | - public function __invoke(Request $request): JsonResponse |
|
30 | - { |
|
29 | + public function __invoke(Request $request): JsonResponse |
|
30 | + { |
|
31 | 31 | try { |
32 | - $json = json_decode($request->getContent(), true); |
|
33 | - $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
34 | - $configs = json_decode($json['configs'], true); |
|
35 | - $device = $this->deviceService->addDeviceConfigs($people, $configs, $json['device']); |
|
36 | - return new JsonResponse($this->hydratorService->item(Device::class, $device->getId(), "device:read"), Response::HTTP_OK); |
|
32 | + $json = json_decode($request->getContent(), true); |
|
33 | + $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
34 | + $configs = json_decode($json['configs'], true); |
|
35 | + $device = $this->deviceService->addDeviceConfigs($people, $configs, $json['device']); |
|
36 | + return new JsonResponse($this->hydratorService->item(Device::class, $device->getId(), "device:read"), Response::HTTP_OK); |
|
37 | 37 | } catch (Exception $e) { |
38 | - return new JsonResponse($this->hydratorService->error($e)); |
|
38 | + return new JsonResponse($this->hydratorService->error($e)); |
|
39 | + } |
|
39 | 40 | } |
40 | - } |
|
41 | 41 | } |