params = $params; $this->httpClient = $httpClient; $this->requestStack = $requestStack; $this->respondService = $respondService; } /** * @return array [description] */ public function list(): array { $result = $this->httpClient->data( 'GET', $this->params->get('domain_template') . '/templates.json', [ 'headers' => [ 'x-auth-token' => "command", ], ] ); if ($result && isset($result['data'])) { return $result['data']; } return []; } /** * @return array [description] */ public function listInfo(): array { $result = $this->httpClient->data( 'GET', $this->params->get('domain_template') . '/templates/info.json', [ 'headers' => [ 'x-auth-token' => "command", ], ] ); if ($result && isset($result['data'])) { return $result['data']; } return []; } /** * @param int $exportId [description] * * @return array [description] */ public function listByExport(int $exportId): array { $result = $this->httpClient->data( 'GET', $this->params->get('domain_template') . '/templates/twigs/export/' . $exportId . '.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); if ($result && isset($result['data'])) { return $result['data']; } return []; } /** * @param int $template_id [description] * * @return array [description] */ public function listPositionMedia(int $template_id): array { $result = $this->httpClient->data( 'GET', $this->params->get('domain_template') . '/medias/template/' . $template_id . '.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); if ($result && isset($result['data'])) { return $result['data']; } return []; } /** * @param int $template_id [description] * * @return array [description] */ public function listOption(int $template_id): array { $result = $this->httpClient->data( 'GET', $this->params->get('domain_template') . '/options/template/' . $template_id . '.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); if ($result && isset($result['data'])) { return $result['data']; } return []; } /** * @param int $id [description] * * @return bool [description] */ public function getTemplateArchive(int $id, string $path): bool { try { $result = $this->httpClient->data( 'POST', $this->params->get('domain_template') . '/template/' . $id . '/archive.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => [ 'path' => $path, ], ] ); if (!$result || !isset($result['type']) || 'success' !== $result['type']) { return false; } return true; } catch (Exception $e) { return false; } } /** * @param int $id [description] * @param array $elementsGabValues [description] * * @return string|Exception [description] */ public function getTemplateGenerationData(int $id, array $elementsGabValues, string $fileType, ?int $folio) { try { $response = $this->httpClient->dataProvider( 'POST', $this->params->get('domain_template') . '/' . $fileType . '/template/' . $id . '.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => [ "values" => $elementsGabValues, "folio" => $folio ], ] ); $result = $this->respondService->checkResponse($response); } catch (Exception $e) { $result = $e; } return $result; } /** * @param int $id [description] * * @return array|Exception [description] */ public function getTemplateFilesGenerationData(int $id) { try { $response = $this->httpClient->dataProvider( 'GET', $this->params->get('domain_template') . '/files/template/' . $id . '.json', [ 'headers' => [ // 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), 'x-auth-token' => "command", ], ] ); $result = $this->respondService->checkResponse($response); } catch (Exception $e) { $result = $e; } return $result; } /** * @param int $id [description] * * @return array|Exception [description] */ public function getHTMLTemplateFilesGenerationData(int $id) { try { $response = $this->httpClient->dataProvider( 'GET', $this->params->get('domain_template') . '/files/template/html/' . $id . '.json', [ 'headers' => [ 'x-auth-token' => "command", ], ] ); $result = $this->respondService->checkResponse($response); } catch (Exception $e) { $result = $e; } return $result; } public function getCommonFiles() { try { $response = $this->httpClient->dataProvider( 'GET', $this->params->get('domain_template') . '/pictos.json', [ 'headers' => [ 'x-auth-token' => "command", ], ] ); $result = $this->respondService->checkResponse($response); } catch (Exception $e) { $result = $e; } return $result; } }