transitionRepository = $transitionRepository; $this->profileQuery = $profileQuery; $this->requestStack = $requestStack; $this->userCollect = $userCollect; } public function read(string $key): TransitionView { $transition = $this->transitionRepository->findByKey($key); return new TransitionView( $transition->getName(), new PlaceCreateView( $transition->getStartPlace()->getId(), $transition->getStartPlace()->getName(), $transition->getStartPlace()->getDefault(), $transition->getStartPlace()->getDateEnable(), [] ), new PlaceCreateView( $transition->getEndPlace()->getId(), $transition->getEndPlace()->getName(), $transition->getEndPlace()->getDefault(), $transition->getEndPlace()->getDateEnable(), [] ), $transition->getKey(), json_decode(json_encode($transition->getUsers()), true), $transition->getCommands() ); } public function getCommands(string $key): array { $transition = $this->transitionRepository->findByKey($key); $commands = []; foreach ($transition->getCommands() as $command) { $commands[] = new CommandReadView( $command->getId(), $command->getName(), $command->getCommand() ); } return $commands; } /** * @param int $configuration_id * @param string $module * * @return mixed */ public function getFirstTransition(int $configuration_id, string $module) { $keyTransition = $this->transitionRepository->findFirstTransition($configuration_id, $module); return $keyTransition['keyInternal']; } /* * Récupèration de l'étape de l'élémént dans le workflow */ public function TransitionUserValid(string $place): bool { $grant = false; $token = $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'); $profile = $this->profileQuery->getUserIdFromToken($token); $profileId = $this->userCollect->readUser(); if (count($profileId) > 0) { if ($place && 'Administrateur' !== $profileId['name']) { $transitions = $this->transitionRepository->findByStartPlaceKey($place); if ($transitions) { $indexTran = 0; while ($indexTran < count($transitions)) { $transition = $transitions[$indexTran]; $index = 0; while ($index < count($transition->getUsers()) && !$grant) { if ($transition->getUsers()[$index]->id === $profile) { $grant = true; } ++$index; } ++$indexTran; } } else { $grant = true; } } else { $grant = true; } } return $grant; } public function getLastTransition(int $configuration_id, string $module) { $keyTransition = $this->transitionRepository->findLastTransition($module, $configuration_id); return $this->transitionRepository->findByKey($keyTransition['keyInternal']); } }