exportsRepository = $exportsRepository; $this->elementTypeRepository = $elementTypeRepository; $this->elementCollect = $elementCollect; $this->elementTypeCollect = $elementTypeCollect; $this->pageQuery = $pageQuery; $this->configRepository = $configRepository; } /** * @param int $projectId [description] * * @return array [description] */ public function list(int $projectId): array { $exports = $this->exportsRepository->list($projectId); $view = []; if (!empty($exports)) { $types = $this->elementTypeRepository->list($projectId); $elements = []; $elementTypes = []; if(!empty($types)){ $elemntTypeIds = array_map(function ($type){ return $type->getElementTypePIM(); }, $types); $elementsPimId = array_map(function ($type){ return $type->getElementsPIM(); }, $types); $elementsId = []; foreach($elementsPimId as $element){ $elementsId = array_merge($elementsId, $element); } $elements = $this->elementCollect->readMultiple($elementsId); $elementTypes = $this->elementTypeCollect->readMultiple($elemntTypeIds); } foreach ($exports as $export) { $view[] = $this->viewExport($export, $types, $elements, $elementTypes); } } return $view; } /** * @param int $exportId [description] * * @return ExportsView|null [description] */ public function read(int $exportId): ?ExportsView { $export = $this->exportsRepository->findById($exportId); $view = null; if (isset($export)) { $types = $this->elementTypeRepository->getByExportId($export->getId()); if (isset($types) && !empty($types)) { $elemntTypeIds = array_map(function ($type){ return $type->getElementTypePIM(); }, $types); $elementsPimId = array_map(function ($type){ return $type->getElementsPIM(); }, $types); $elementsId = []; foreach($elementsPimId as $element){ $elementsId = array_merge($elementsId, $element); } $elements = $this->elementCollect->readMultiple($elementsId); $elementTypes = $this->elementTypeCollect->readMultiple($elemntTypeIds); $view = $this->viewExport($export, $types, $element, $elementTypes); } } return $view; } /** * @param Exports $export [description] * @param array $types [description] * * @return [type] [description] */ private function viewExport(Exports $export, array $types, array $elements, array $elementTypes) { $typesView = []; $exportTemplates = []; $nbElementTypes = count($elementTypes); $elementsPIM = []; if(!empty($types)){ foreach($elements as $element){ $elementsPIM[$element['element_type_id']][] = [ 'id' => $element['id'], 'name' => $element['name'], ]; } } $elementTypesSave = []; if(!$export->getTemplates()->isEmpty()){ foreach($export->getTemplates() as $typeTemplate){ if(!empty($typeTemplate->getElementType()->getElementTypePIM())){ $type = $typeTemplate->getElementType(); $templates = []; $defaultTemplate = null; if (!$export->getTemplates()->isEmpty()) { $templates = $typeTemplate->getTemplates(); $defaultId = $typeTemplate->getDefaultTemplate(); if ($defaultId) { $valueFilter = array_values(array_filter($templates, function ($temp) use ($defaultId) { return $temp['id'] === $defaultId; })); if (!empty($valueFilter)) { $defaultTemplate = $valueFilter[0]; } } } $elementTypeFound = false; $indexElementType = 0; while($indexElementType < $nbElementTypes && !$elementTypeFound){ if($elementTypes[$indexElementType]['id'] == $type->getElementTypePIM()){ $elementTypeFound = true; $elementView = []; if(!empty($elementsPIM) && $elementsPIM[$type->getElementTypePIM()] && !empty($typeTemplate->getElementsPIM())){ foreach($typeTemplate->getElementsPIM() as $elemTemplate){ $search = array_filter($elementsPIM[$type->getElementTypePIM()], function ($elem) use ($elemTemplate) { return $elem["id"] == $elemTemplate; }); if(!empty($search)){ $elementView[] = reset($search); } } $typeTemplate->getElementsPIM(); } $typesView[$type->getId()] = new ElementTypeView( $elementTypes[$indexElementType]['id'], $elementTypes[$indexElementType]['name'], $elementView, $defaultTemplate, $templates ); $elementTypesSave[] = $elementTypes[$indexElementType]['id']; } $indexElementType ++; } } else { $exportTemplates = $typeTemplate->getTemplates(); } } $newTypes = array_filter($types, function($type) use ($elementTypesSave){ return !in_array($type->getElementTypePIM(), $elementTypesSave); }); if(!empty($newTypes)){ foreach ($newTypes as $type) { if($type->getDeletedAt() == null){ $elementType = array_filter($elementTypes, function($elemType) use ($type){ return $elemType['id'] == $type->getElementTypePIM(); }); if(!empty($elementType)){ $typesView[$type->getId()] = new ElementTypeView( $type->getElementTypePIM(), reset($elementType)['name'], [], null, null ); } } } } } else { if(!empty($types)){ foreach ($types as $type) { if($type->getDeletedAt() == null){ $elementType = array_filter($elementTypes, function($elemType) use ($type){ return $elemType['id'] == $type->getElementTypePIM(); }); if(!empty($elementType)){ $typesView[$type->getId()] = new ElementTypeView( $type->getElementTypePIM(), reset($elementType)['name'], [], null, null ); } } } } } $return = new ExportsView( $export->getId(), $export->getName(), $export->getDescription(), $export->getExportType() ? ['id' => $export->getExportType(), 'name' => $this->exportsRepository::EXPORT_TYPE[$export->getExportType()]] : null, $export->getCanal(), array_values($typesView), $export->getWorkflowProjects() && $export->getWorkflowProjects()->getWorkflow() ? $export->getWorkflowProjects()->getWorkflow() : null, $export->getWorkflowProjects() ? $export->getWorkflowProjects()->getPage() : false, $exportTemplates ); return $return; } /** * {@inheritDoc} */ public function dashboardExport(int $projectId, array $groups): array { $exports = $this->exportsRepository->list($projectId); $array_exports = []; foreach ($exports as $export) { $nbPage = $this->pageQuery->readNbPageExport($export->getId()); $color = null; $name = null; if ($export->getWorkflowProjects()) { $config_id = $export->getWorkflowProjects()->getWorkflow(); $name = ''; if ($config_id) { $workflowData = $this->configRepository->findById($config_id); $name = $workflowData->getName(); } if ($export->getWorkflowProjects()->getPage()) { $color = $this->pageQuery->getLessAdvancedPage($export->getId()); } } if (!empty($color)) { $color = reset($color)['color']; } else { $color = '#4EB8AA'; } $export_description = ''; if ($export->getDescription()) { $export_description = $export->getDescription(); } $nb_page = 0; $nb_page_max = 0; if (isset($nbPage['nb_page'])) { $nb_page = $nbPage['nb_page']; } if (isset($nbPage['max'])) { $nb_page_max = $nbPage['max']; } $nbProduct = $this->exportsRepository->nbProduct($export->getId()); if (!$nbProduct) { $nbProduct = 0; } $versions = []; foreach ($export->getVersions() as $version) { if ($version->getDeletedAt() === null) { //if(!empty($groups)){ // $filter = array_filter($version->getGroups()->toArray(), static function ($group) use ($groups) { // return in_array($group->getGroup(), $groups); // }); //}else{ //$filter = true; //} //if (!empty($filter)) { $nbPages = 0; foreach ($version->getPageDuplicates() as $dupli) { $nbPages += intval($dupli->getPage()->getOption()->getNbPages()); } $versions[] = [ 'id' => $version->getId(), 'name' => $version->getName(), 'ownerGroup' => $version->getGroups()->isEmpty() ? null : $version->getGroups()->first()->getGroup(), 'idUser' => $version->getIdUser(), 'nbPages' => $nbPages ]; //} } } $array_exports[] = new ExportsDashboardView( $export->getId(), $export->getName(), $export->getExportType() ? $this->exportsRepository::EXPORT_TYPE[$export->getExportType()] : null, $export_description, $nbProduct, $nb_page, $nb_page_max, $name, $color, $versions ); } return $array_exports; } /** * @param int $id * * @return bool */ public function delete(int $id): bool { $export = $this->exportsRepository->findById($id); if ($export) { $result = $this->exportsRepository->delete($export); } return $result; } /** * @return array [description] */ public function listExportType(): array { $exportTypes = $this->exportsRepository->listExportType(); $view = []; foreach ($exportTypes as $id => $value) { switch ($value) { case 'API': break; case 'CDF': $view[] = new ExportsTypeListView( $id, ['en' => 'Brochure', 'fr' => 'Brochure'], $value, ['name' => ['en' => 'Print', 'fr' => 'Impression'], 'id' => 1] ); break; case 'BOOKLET': $view[] = new ExportsTypeListView( $id, ['en' => 'Booklet', 'fr' => 'Booklet'], $value, ['name' => ['en' => 'Print', 'fr' => 'Impression'], 'id' => 1] ); break; case 'Marketing': $view[] = new ExportsTypeListView( $id, ['en' => 'Affiche', 'fr' => 'Poster'], $value, ['name' => ['en' => 'Print', 'fr' => 'Impression'], 'id' => 1] ); $view[] = new ExportsTypeListView( $id, ['en' => 'Flyer', 'fr' => 'Prospectus'], $value, ['name' => ['en' => 'Print', 'fr' => 'Impression'], 'id' => 1] ); $view[] = new ExportsTypeListView( $id, ['en' => 'Stickers', 'fr' => 'Badges'], $value, ['name' => ['en' => 'Print', 'fr' => 'Impression'], 'id' => 1] ); $view[] = new ExportsTypeListView( $id, ['en' => 'Mailing', 'fr' => 'Envoi postal'], $value, ['name' => ['en' => 'Print', 'fr' => 'Impression'], 'id' => 1] ); break; case 'HTML': $view[] = new ExportsTypeListView( $id, ['en' => 'Landing Page', 'fr' => 'Page de landing'], $value, ['name' => ['en' => 'Web', 'fr' => 'Web'], 'id' => 2] ); $view[] = new ExportsTypeListView( $id, ['en' => 'Emailing', 'fr' => 'Emailing'], $value, ['name' => ['en' => 'Web', 'fr' => 'Web'], 'id' => 2] ); $view[] = new ExportsTypeListView( $id, ['en' => 'Banner', 'fr' => 'Bannière'], $value, ['name' => ['en' => 'Web', 'fr' => 'Web'], 'id' => 2] ); $view[] = new ExportsTypeListView( $id, ['en' => 'Web page', 'fr' => 'Page web'], $value, ['name' => ['en' => 'Web', 'fr' => 'Web'], 'id' => 2] ); break; case 'SOCIAL': $view[] = new ExportsTypeListView( $id, ['en' => 'Social network', 'fr' => 'Réseaux sociaux'], $value, ['name' => ['en' => 'Web', 'fr' => 'Web'], 'id' => 2] ); break; case 'CSV': $view[] = new ExportsTypeListView( $id, ['en' => 'CSV', 'fr' => 'CSV'], $value, ['name' => ['en' => 'Feed', 'fr' => 'Flux'], 'id' => 3] ); break; case 'XML': $view[] = new ExportsTypeListView( $id, ['en' => 'XML', 'fr' => 'XML'], $value, ['name' => ['en' => 'Feed', 'fr' => 'Flux'], 'id' => 3] ); break; case 'JSON': $view[] = new ExportsTypeListView( $id, ['en' => 'JSON', 'fr' => 'JSON'], $value, ['name' => ['en' => 'Feed', 'fr' => 'Flux'], 'id' => 3] ); break; } } return $view; } /** * @param int $id [description] * * @return ExportsTypeView|null [description] */ public function getExportType(int $id): ?ExportsTypeView { $export = $this->exportsRepository->findById($id); $view = null; if (isset($export)) { $view = new ExportsTypeView( $export->getId(), $export->getName(), $export->getDescription(), $export->getExportType() ? $this->exportsRepository::EXPORT_TYPE[$export->getExportType()] : '', [] ); } return $view; } /** * @param ExportSetWorkflowView $view [description] * * @return bool [description] */ public function setWorkflow(ExportSetWorkflowView $view): bool { $result = $this->exportsRepository->setWorkflow($view->export_id, $view->workflow_id); if ($result) { $this->pageQuery->updateWorkflow($view->export_id, $view->workflow_id); } return $result; } /** * @param CommonIdView $view [description] * * @return Exports|null [description] */ public function readEntity(CommonIdView $view): ?Exports { return $this->exportsRepository->findById($view->id); } }