@@ -10,16 +10,16 @@ |
||
10 | 10 | class NotificationService |
11 | 11 | { |
12 | 12 | |
13 | - public function __construct( |
|
13 | + public function __construct( |
|
14 | 14 | private EntityManagerInterface $manager, |
15 | 15 | private Security $security, |
16 | 16 | private RequestStack $requestStack, |
17 | 17 | private PusherService $pusher |
18 | - ) { |
|
19 | - } |
|
18 | + ) { |
|
19 | + } |
|
20 | 20 | |
21 | - public function postPersist(Notification $notification) |
|
22 | - { |
|
21 | + public function postPersist(Notification $notification) |
|
22 | + { |
|
23 | 23 | $this->pusher->push(['company' => 1, 'people' => 1], 'my_topic'); |
24 | - } |
|
24 | + } |
|
25 | 25 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | |
65 | 65 | //$this->manager->persist($entity); |
66 | 66 | } else { |
67 | - $json = json_decode($this->request->getContent(), true); |
|
67 | + $json = json_decode($this->request->getContent(), true); |
|
68 | 68 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
69 | 69 | if (!$extra_data) |
70 | 70 | return; |
@@ -35,8 +35,9 @@ discard block |
||
35 | 35 | |
36 | 36 | public function discoveryDevice(&$entity) |
37 | 37 | { |
38 | - if ($entity instanceof Device || $entity instanceof DeviceConfig) |
|
39 | - return; |
|
38 | + if ($entity instanceof Device || $entity instanceof DeviceConfig) { |
|
39 | + return; |
|
40 | + } |
|
40 | 41 | |
41 | 42 | $deviceId = $this->request->headers->get('DEVICE') ?: $this->getUserIp(); |
42 | 43 | if (method_exists($entity, 'setDevice')) { |
@@ -47,14 +48,16 @@ discard block |
||
47 | 48 | |
48 | 49 | public function discoveryUser(&$entity) |
49 | 50 | { |
50 | - if (method_exists($entity, 'setUser')) |
|
51 | - $entity->setUser($this->security->getUser()); |
|
51 | + if (method_exists($entity, 'setUser')) { |
|
52 | + $entity->setUser($this->security->getUser()); |
|
53 | + } |
|
52 | 54 | } |
53 | 55 | |
54 | 56 | public function persist(&$entity) |
55 | 57 | { |
56 | - if (self::$persisted == true) |
|
57 | - return; |
|
58 | + if (self::$persisted == true) { |
|
59 | + return; |
|
60 | + } |
|
58 | 61 | self::$persisted = true; |
59 | 62 | |
60 | 63 | //$this->manager->persist($entity); |
@@ -72,15 +75,17 @@ discard block |
||
72 | 75 | } else { |
73 | 76 | $json = json_decode($this->request->getContent(), true); |
74 | 77 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
75 | - if (!$extra_data) |
|
76 | - return; |
|
78 | + if (!$extra_data) { |
|
79 | + return; |
|
80 | + } |
|
77 | 81 | $entity_id = $extra_data['entity_id']; |
78 | 82 | $entity_name = $extra_data['entity_name']; |
79 | 83 | } |
80 | 84 | |
81 | 85 | |
82 | - if (!$entity_id || !$entity_name) |
|
83 | - return; |
|
86 | + if (!$entity_id || !$entity_name) { |
|
87 | + return; |
|
88 | + } |
|
84 | 89 | |
85 | 90 | foreach ($extra_data['data'] as $key => $data) { |
86 | 91 | $extra_fields = $this->manager->getRepository(ExtraFields::class)->find($key); |
@@ -91,8 +96,9 @@ discard block |
||
91 | 96 | 'extra_fields' => $extra_fields |
92 | 97 | ]); |
93 | 98 | |
94 | - if (!$extraData) |
|
95 | - $extraData = new ExtraData(); |
|
99 | + if (!$extraData) { |
|
100 | + $extraData = new ExtraData(); |
|
101 | + } |
|
96 | 102 | |
97 | 103 | $extraData->setExtraFields($extra_fields); |
98 | 104 | $extraData->setEntityName($entity_name); |
@@ -14,8 +14,8 @@ |
||
14 | 14 | */ |
15 | 15 | class ModuleRepository extends ServiceEntityRepository |
16 | 16 | { |
17 | - public function __construct(ManagerRegistry $registry) |
|
18 | - { |
|
17 | + public function __construct(ManagerRegistry $registry) |
|
18 | + { |
|
19 | 19 | parent::__construct($registry, Module::class); |
20 | - } |
|
20 | + } |
|
21 | 21 | } |
@@ -18,31 +18,31 @@ |
||
18 | 18 | |
19 | 19 | class AddAppConfigAction |
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 | + ) {} |
|
27 | 27 | |
28 | - public function __invoke(Request $request): JsonResponse |
|
29 | - { |
|
28 | + public function __invoke(Request $request): JsonResponse |
|
29 | + { |
|
30 | 30 | try { |
31 | - $json = json_decode($request->getContent(), true); |
|
32 | - $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
33 | - $module = $this->manager->getRepository(Module::class)->find(preg_replace("/[^0-9]/", "", $json['module'])); |
|
34 | - $configValue = json_decode($json['configValue'], true); |
|
35 | - $config = $this->configService->addConfig( |
|
31 | + $json = json_decode($request->getContent(), true); |
|
32 | + $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
33 | + $module = $this->manager->getRepository(Module::class)->find(preg_replace("/[^0-9]/", "", $json['module'])); |
|
34 | + $configValue = json_decode($json['configValue'], true); |
|
35 | + $config = $this->configService->addConfig( |
|
36 | 36 | $people, |
37 | 37 | $json['configKey'], |
38 | 38 | $configValue, |
39 | 39 | $module, |
40 | 40 | $json['visibility'] |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - return new JsonResponse($this->hydratorService->item(Config::class, $config->getId(), "config:read"), Response::HTTP_OK); |
|
43 | + return new JsonResponse($this->hydratorService->item(Config::class, $config->getId(), "config:read"), Response::HTTP_OK); |
|
44 | 44 | } catch (Exception $e) { |
45 | - return new JsonResponse($this->hydratorService->error($e)); |
|
45 | + return new JsonResponse($this->hydratorService->error($e)); |
|
46 | + } |
|
46 | 47 | } |
47 | - } |
|
48 | 48 | } |
@@ -54,8 +54,9 @@ |
||
54 | 54 | if (method_exists($service, $method)) { |
55 | 55 | $newEntity = $service->$method($entity); |
56 | 56 | |
57 | - if ('postPersist' === $method && $newEntity) |
|
58 | - $this->manager->refresh($newEntity); |
|
57 | + if ('postPersist' === $method && $newEntity) { |
|
58 | + $this->manager->refresh($newEntity); |
|
59 | + } |
|
59 | 60 | } |
60 | 61 | } |
61 | 62 | return $entity; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | public function addLine($prefix = '', $suffix = '', $delimiter = ' ') |
21 | 21 | { |
22 | 22 | $initialSpace = str_repeat(" ", $this->initialSpace); |
23 | - $count = $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix); |
|
23 | + $count = $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix); |
|
24 | 24 | if ($count > 0) |
25 | 25 | $delimiter = str_repeat($delimiter, $count); |
26 | 26 | $this->text .= $initialSpace . $prefix . $delimiter . $suffix . "\n"; |
@@ -21,8 +21,9 @@ |
||
21 | 21 | { |
22 | 22 | $initialSpace = str_repeat(" ", $this->initialSpace); |
23 | 23 | $count = $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix); |
24 | - if ($count > 0) |
|
25 | - $delimiter = str_repeat($delimiter, $count); |
|
24 | + if ($count > 0) { |
|
25 | + $delimiter = str_repeat($delimiter, $count); |
|
26 | + } |
|
26 | 27 | $this->text .= $initialSpace . $prefix . $delimiter . $suffix . "\n"; |
27 | 28 | } |
28 | 29 |
@@ -13,22 +13,22 @@ |
||
13 | 13 | |
14 | 14 | class DiscoveryMainConfigsAction |
15 | 15 | { |
16 | - public function __construct( |
|
16 | + public function __construct( |
|
17 | 17 | private EntityManagerInterface $manager, |
18 | 18 | private HydratorService $hydratorService, |
19 | 19 | private ConfigService $configService |
20 | - ) {} |
|
20 | + ) {} |
|
21 | 21 | |
22 | - public function __invoke(Request $request): JsonResponse |
|
23 | - { |
|
22 | + public function __invoke(Request $request): JsonResponse |
|
23 | + { |
|
24 | 24 | try { |
25 | - $json = json_decode($request->getContent(), true); |
|
26 | - $device = $this->manager->getRepository(People::class)->findOneBy(['device' => $request->headers->get('device')]); |
|
27 | - $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
28 | - $configs = $this->configService->discoveryMainConfigs($people, $device); |
|
29 | - return new JsonResponse($this->hydratorService->collectionData($configs, Config::class, 'config:read')); |
|
25 | + $json = json_decode($request->getContent(), true); |
|
26 | + $device = $this->manager->getRepository(People::class)->findOneBy(['device' => $request->headers->get('device')]); |
|
27 | + $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
28 | + $configs = $this->configService->discoveryMainConfigs($people, $device); |
|
29 | + return new JsonResponse($this->hydratorService->collectionData($configs, Config::class, 'config:read')); |
|
30 | 30 | } catch (Exception $e) { |
31 | - return new JsonResponse($this->hydratorService->error($e)); |
|
31 | + return new JsonResponse($this->hydratorService->error($e)); |
|
32 | + } |
|
32 | 33 | } |
33 | - } |
|
34 | 34 | } |
@@ -14,23 +14,23 @@ |
||
14 | 14 | |
15 | 15 | class AddDeviceConfigAction |
16 | 16 | { |
17 | - public function __construct( |
|
17 | + public function __construct( |
|
18 | 18 | private EntityManagerInterface $manager, |
19 | 19 | private HydratorService $hydratorService, |
20 | 20 | private DeviceService $deviceService |
21 | - ) {} |
|
21 | + ) {} |
|
22 | 22 | |
23 | - public function __invoke(Request $request): JsonResponse |
|
24 | - { |
|
23 | + public function __invoke(Request $request): JsonResponse |
|
24 | + { |
|
25 | 25 | try { |
26 | - $json = json_decode($request->getContent(), true); |
|
27 | - $device = $request->headers->get('device'); |
|
28 | - $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
29 | - $configs = json_decode($json['configs'], true); |
|
30 | - $device_config = $this->deviceService->addDeviceConfigs($people, $configs, $device); |
|
31 | - return new JsonResponse($this->hydratorService->item(DeviceConfig::class, $device_config->getId(), 'device_config:read'), Response::HTTP_OK); |
|
26 | + $json = json_decode($request->getContent(), true); |
|
27 | + $device = $request->headers->get('device'); |
|
28 | + $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
29 | + $configs = json_decode($json['configs'], true); |
|
30 | + $device_config = $this->deviceService->addDeviceConfigs($people, $configs, $device); |
|
31 | + return new JsonResponse($this->hydratorService->item(DeviceConfig::class, $device_config->getId(), 'device_config:read'), Response::HTTP_OK); |
|
32 | 32 | } catch (Exception $e) { |
33 | - return new JsonResponse($this->hydratorService->error($e)); |
|
33 | + return new JsonResponse($this->hydratorService->error($e)); |
|
34 | + } |
|
34 | 35 | } |
35 | - } |
|
36 | 36 | } |
@@ -51,9 +51,9 @@ |
||
51 | 51 | { |
52 | 52 | $device = $this->discoveryDevice($deviceId); |
53 | 53 | |
54 | - $device_config = $this->discoveryDeviceConfig($device, $people); |
|
54 | + $device_config = $this->discoveryDeviceConfig($device, $people); |
|
55 | 55 | foreach ($configs as $key => $config) |
56 | - $device_config->addConfig($key, $config); |
|
56 | + $device_config->addConfig($key, $config); |
|
57 | 57 | |
58 | 58 | $this->manager->persist($device_config); |
59 | 59 | $this->manager->flush(); |
@@ -52,8 +52,9 @@ |
||
52 | 52 | $device = $this->discoveryDevice($deviceId); |
53 | 53 | |
54 | 54 | $device_config = $this->discoveryDeviceConfig($device, $people); |
55 | - foreach ($configs as $key => $config) |
|
56 | - $device_config->addConfig($key, $config); |
|
55 | + foreach ($configs as $key => $config) { |
|
56 | + $device_config->addConfig($key, $config); |
|
57 | + } |
|
57 | 58 | |
58 | 59 | $this->manager->persist($device_config); |
59 | 60 | $this->manager->flush(); |