@@ -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; |
@@ -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); |
@@ -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 | } |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | public function getConfig(People $people, $key, $json = false) |
| 27 | 27 | { |
| 28 | 28 | $config = $this->discoveryConfig($people, $key, false); |
| 29 | - $value = $config ? $config->getConfigValue() : null; |
|
| 29 | + $value = $config ? $config->getConfigValue() : null; |
|
| 30 | 30 | return $json ? json_decode($value, true) : $value; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | private function discoveryConfig(People $people, $key, $create = true): ?Config |
| 34 | 34 | { |
| 35 | - $config = $this->manager->getRepository(Config::class)->findOneBy([ |
|
| 35 | + $config = $this->manager->getRepository(Config::class)->findOneBy([ |
|
| 36 | 36 | 'people' => $people, |
| 37 | 37 | 'configKey' => $key |
| 38 | 38 | ]); |
@@ -36,8 +36,9 @@ |
||
| 36 | 36 | 'people' => $people, |
| 37 | 37 | 'configKey' => $key |
| 38 | 38 | ]); |
| 39 | - if ($config) |
|
| 40 | - return $config; |
|
| 39 | + if ($config) { |
|
| 40 | + return $config; |
|
| 41 | + } |
|
| 41 | 42 | if ($create) { |
| 42 | 43 | $config = new Config(); |
| 43 | 44 | $config->setConfigKey($key); |
@@ -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 | |
@@ -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 | } |