pageRepository = $pageRepository; // $this->exportProvider = $exportProvider; // $this->workflowProvider = $workflowProvider; $this->placesRepository = $placesRepository; $this->transitionsRepository = $transitionsRepository; $this->configuration = $configuration; $this->module = $module; $this->workflowDeleteQuery = $workflowDeleteQuery; $this->story = $story; $this->registry = $registry; $this->user = $user; $this->entityManager = $entityManager; $this->versionExportRepository = $versionExportRepository; $this->userCollect = $userCollect; $this->projectTransitionQuery = $projectTransitionQuery; } /** * @return mixed|null */ public function getPlace(int $id, ?int $pageDuplicateId) { $currentPlace = ''; $lastPlace = ''; $blockText = false; $blockMedia = false; $placeId = null; $page = $this->pageRepository->read($id); if ($page) { if (!empty($page->getCdf()->getExport()->getWorkflowProjects())) { // $workflowId = $this->exportProvider->collectWorkflow($page->getCdf()->getExport()->getId()); $workflowId = $page->getCdf()->getExport()->getWorkflowProjects()->getWorkflow(); //if ($this->verifWorkflow($workflowId)) { $keyTransition = $this->transitionsRepository->findLastTransition($workflowId); if (isset($keyTransition['keyInternal'])) { $transition = $this->transitionsRepository->findByKey($keyTransition['keyInternal']); if(!empty($transition)){ $lastPlace = $transition->getEndPlace()->getKey(); $currentPlace = $page->getCurrentPlace(); if($pageDuplicateId){ $pageDupliRepo = $this->entityManager->getRepository(PageDuplicate::class); $pageDuplicate = $pageDupliRepo->findOneBy(["id" => $pageDuplicateId]); if(!empty($pageDuplicate)){ if(!empty($pageDuplicate->getCurrentPlace())){ $currentPlace = $pageDuplicate->getCurrentPlace(); } else { $firstTransitionKey = $this->transitionsRepository->findFirstTransition($workflowId, $this->module->getModule()); if (isset($firstTransitionKey['keyInternal'])) { $firstTransition = $this->transitionsRepository->findByKey($firstTransitionKey['keyInternal']); if(!empty($firstTransition)){ $currentPlace = $firstTransition->getStartPlace()->getKey(); } } } } } if(!empty($currentPlace)){ $place = $this->placesRepository->findByKey($currentPlace); } if(isset($place) && !$place->getConfiguration()->getDeletedAt()){ $blockText = $place->getBlockTexts(); $blockMedia = $place->getBlockPictures(); $placeId = $place->getId(); } } } // } // $workflowPage = isset($workflowId['data']) && isset($workflowId['data']['page']) ? $workflowId['data']['page'] : false; } return ['place_id' => $placeId,'place' => $currentPlace, 'last' => $currentPlace === $lastPlace, "blockText" => $blockText, "blockMedia" => $blockMedia, "workflowPage" => true]; } return null; } public function removePlace(int $place_id): bool { $place = $this->placesRepository->findById($place_id); $pages = $this->pageRepository->findByPlace($place->getKey()); $transitionReject = $this->transitionsRepository->findRejectByPlace($place->getId(), $this->module->getModule()); $statusView = null; if ($transitionReject && count($pages) > 0) { $statusView = new StatusView( 0, $transitionReject->getKey(), 0 ); $this->registry->applyStatus($statusView, $place->getConfiguration()->getId(), $pages); } return true; } /** * @param $configView * * @throws NonUniqueResultException */ public function changePlaceKey($configView, array $places): void { $clear = new ClearService(); if ($configView->id) { $configuration = $this->configuration->findById($configView->id); foreach ($places as $place) { $key = $clear->cleanString($place->nom) . '_' . $configuration->getGenericKey(); $this->pageRepository->resetCurrentPlace($place->id, $key); } } } public function getAllPlace(): array { $places = $this->placesRepository->findAll(); $placesView = []; if (count($places) > 0) { foreach ($places as $place) { $placesView[] = new PlaceView( $place->getName(), $place->getDefault(), $place->getKey() ); } } return $placesView; } public function getStepsInfo(int $pageId): array { $steps = $this->story->lastStepAction($pageId); if (count($steps) > 0) { $lastStep = $steps[0]; $history = []; $users = $this->userCollect->collect(); foreach ($steps as $step) { if (isset($step['date']) && $step['date'] > $lastStep['date']) { $lastStep = $step; } // TODO : Think about the fact that if we have 150 hitorie's steps we're calling the user's info 150 time even if their are many times the same user on different step histories. // $user = isset($step['idUser']) ? $this->user->loadUserInfo($step['idUser']) : null; $user = null; if(isset($step['idUser'])){ $user = array_filter($users, function($user) use ($step){ return $user['id'] === $step['idUser']; }); } $note = isset($step['value']['note']) ? $step['value']['note'] : ''; $valueStep = isset($step['value']['step']) ? $step['value']['step'] : ''; $valueTransition = isset($step['value']['transition']) ? $step['value']['transition'] : ''; $history[$valueStep][$valueTransition][] = new PageLastStepView( isset($step['scenario']) && 'Step_valid' === $step['scenario'] ? true : false, isset($step['scenario']) && 'Step_reject' === $step['scenario'] ? true : false, !empty($user) ? reset($user)['name'] : "", isset($step['date']) ? $step['date'] : '', isset($step['scenario']) ? $step['scenario'] : '', $valueStep, $valueTransition, $note ); } return ['transitions' => $history, 'lastTransition' => $lastStep]; } return []; } public function setStepNameToTransitions(array $config, array $transitions): array { $newTransitions = []; if (!empty($config) && !empty($transitions)) { foreach ($transitions as $keyStep => $dataStep) { foreach ($dataStep as $keyTransition => $transition) { $neededObject = array_filter( $config, function ($step) use (&$keyTransition) { if ($step->key === $keyTransition) { return $step; } } ); $neededObject = array_values($neededObject); if (!empty($neededObject)) { if(!isset($newTransitions[$keyStep])){ $newTransitions[$keyStep] = []; } $newTransitions[$keyStep] = array_merge($newTransitions[$keyStep], $transition); usort($newTransitions[$keyStep], function ($a, $b){ return strtotime(str_replace('/', '-', $a->date))- strtotime(str_replace('/', '-', $b->date)); }); } } } return $newTransitions; } return []; } public function removeWorkflow(int $workflow_id): bool { $view = new CommonIdView($workflow_id); $this->workflowDeleteQuery->remove($view, true); return true; } private function verifWorkflow($dataWorkflow) { $result = false; if (isset($dataWorkflow) && isset($dataWorkflow['type']) && $dataWorkflow['type'] === "success" && isset($dataWorkflow['data']) && isset($dataWorkflow['data']['workflow']) && $dataWorkflow['data']['page']) { $result = true; } return $result; } public function changeCurrentPlaceKey(array $placeKeys) { foreach ($placeKeys as $key) { if($key["key"] !== $key["newKey"]){ $this->pageRepository->changeCurrentPlaceKey($key['key'], $key['newKey']); } } } public function userCanSetValue(int $version, int $userId, int $placeId): bool { $grant = false; $profile = $this->userCollect->readUser(); if($profile['data']['code'] != "ADMIN") { $versionWorkflow = $this->versionExportRepository->getVersionWorkflow($version, $placeId); if(!empty($versionWorkflow) && !empty($versionWorkflow->getUsers())) { $index = 0; $countUser = count($versionWorkflow->getUsers()); while($index < $countUser) { if($versionWorkflow->getUsers()[$index]["id"] == $userId){ $grant = true; } $index ++; } } else { $grant = $this->projectTransitionQuery->TransitionUserValid($placeId); } } else { $grant = true; } return $grant; } }