Maha Bouchiba 2 лет назад
Родитель
Сommit
6f35d26b79

+ 153 - 144
composer.json

@@ -1,150 +1,159 @@
 {
-    "type": "project",
-    "license": "proprietary",
-    "repositories": [
-        {
-            "type": "vcs",
-            "url": "ssh://git@gitlab.2iopenservice.com/vincent/foselastica.git"
-        }
-    ],
-    "require": {
-        "php": ">=8.1",
-        "ext-ctype": "*",
-        "ext-iconv": "*",
-        "api-platform/core": "^3.1",
-        "beberlei/doctrineextensions": "^1.3",
-        "blackfire/php-sdk": "^1.23",
-        "composer/package-versions-deprecated": "^1.11",
-        "doctrine/dbal": "^2.6",
-        "doctrine/doctrine-bundle": "^2.1",
-        "doctrine/doctrine-migrations-bundle": "^3.0",
-        "doctrine/orm": "^2.9",
-        "egulias/email-validator": "^3.0",
-        "jbouzekri/phumbor-bundle": "^3.1.0",
-        "knplabs/knp-gaufrette-bundle": "^0.8.0",
-        "knplabs/knp-snappy-bundle": "^1.9",
-        "lcobucci/jwt": "^4.1",
-        "lexik/jwt-authentication-bundle": "^2.8",
-        "lorenzo/pinky": "^1.0",
-        "myclabs/php-enum": "^1.7",
-        "nelmio/cors-bundle": "^2.1",
-        "odolbeau/phone-number-bundle": "^3.1",
-        "phpdocumentor/reflection-docblock": "^5.2",
-        "ramsey/uuid": "^4.2",
-        "ramsey/uuid-doctrine": "^2.0",
-        "symfony/asset": "6.2.*",
-        "symfony/console": "6.2.*",
-        "symfony/doctrine-messenger": "6.2.*",
-        "symfony/dotenv": "6.2.*",
-        "symfony/error-handler": "6.2.*",
-        "symfony/expression-language": "6.2.*",
-        "symfony/flex": "^1.3.1",
-        "symfony/framework-bundle": "6.2.*",
-        "symfony/http-client": "6.2.*",
-        "symfony/intl": "6.2.*",
-        "symfony/lock": "6.2.*",
-        "symfony/mailer": "6.2.*",
-        "symfony/mercure": "^0.6.1",
-        "symfony/mercure-bundle": "^0.3.4",
-        "symfony/messenger": "6.2.*",
-        "symfony/monolog-bundle": "^3.7",
-        "symfony/polyfill-intl-icu": "^1.21",
-        "symfony/polyfill-intl-messageformatter": "^1.24",
-        "symfony/property-access": "6.2.*",
-        "symfony/property-info": "6.2.*",
-        "symfony/security-bundle": "6.2.*",
-        "symfony/serializer": "6.2.*",
-        "symfony/translation": "6.2.*",
-        "symfony/twig-bundle": "6.2.*",
-        "symfony/uid": "6.2.*",
-        "symfony/validator": "6.2.*",
-        "symfony/yaml": "6.2.*",
-        "twig/cssinliner-extra": "^3.4",
-        "twig/extra-bundle": "^3.4",
-        "twig/inky-extra": "^3.4",
-        "vincent/foselastica": "1.3.1",
-        "webonyx/graphql-php": "^14.3",
-        "xantios/mimey": "*"
-    },
-    "require-dev": {
-        "cyclonedx/cyclonedx-php-composer": "^3.4",
-        "dg/bypass-finals": "^1.4",
-        "doctrine/doctrine-fixtures-bundle": "^3.4",
-        "hautelook/alice-bundle": "^2.11",
-        "justinrainbow/json-schema": "^5.2",
-        "phpstan/extension-installer": "^1.2",
-        "phpstan/phpstan": "^1.9",
-        "phpstan/phpstan-doctrine": "^1.3",
-        "phpstan/phpstan-phpunit": "^1.3",
-        "phpstan/phpstan-symfony": "^1.2",
-        "phpunit/phpunit": "^9.6",
-        "rector/rector": "^0.15.13",
-        "symfony/browser-kit": "6.2.*",
-        "symfony/css-selector": "6.2.*",
-        "symfony/debug-bundle": "6.2.*",
-        "symfony/maker-bundle": "^1.21",
-        "symfony/phpunit-bridge": "^6.2",
-        "symfony/stopwatch": "6.2.*",
-        "symfony/web-profiler-bundle": "6.2.*",
-        "timeweb/phpstan-enum": "^3.1",
-        "zenstruck/foundry": "^1.31"
-    },
-    "config": {
-        "optimize-autoloader": true,
-        "preferred-install": {
-            "*": "dist"
-        },
-        "sort-packages": true,
-        "allow-plugins": {
-            "cyclonedx/cyclonedx-php-composer": true,
-            "symfony/flex": true,
-            "phpstan/extension-installer": true
-        }
-    },
-    "autoload": {
-        "psr-4": {
-            "App\\": "src/"
-        }
-    },
-    "autoload-dev": {
-        "psr-4": {
-            "DataFixtures\\": "tests/Fixture",
-            "App\\Tests\\": "tests/"
-        }
+  "type": "project",
+  "license": "proprietary",
+  "repositories": [
+    {
+      "type": "vcs",
+      "url": "ssh://git@gitlab.2iopenservice.com/vincent/foselastica.git"
     },
-    "replace": {
-        "paragonie/random_compat": "2.*",
-        "symfony/polyfill-ctype": "*",
-        "symfony/polyfill-iconv": "*",
-        "symfony/polyfill-php72": "*",
-        "symfony/polyfill-php71": "*",
-        "symfony/polyfill-php70": "*",
-        "symfony/polyfill-php56": "*"
+    {
+      "type": "vcs",
+      "url": "ssh://git@gitlab.2iopenservice.com/opentalent/phpdocx.git"
+    }
+  ],
+  "require": {
+    "php": ">=8.1",
+    "ext-ctype": "*",
+    "ext-iconv": "*",
+    "api-platform/core": "^3.1",
+    "beberlei/doctrineextensions": "^1.3",
+    "blackfire/php-sdk": "^1.23",
+    "composer/package-versions-deprecated": "^1.11",
+    "doctrine/dbal": "^2.6",
+    "doctrine/doctrine-bundle": "^2.1",
+    "doctrine/doctrine-migrations-bundle": "^3.0",
+    "doctrine/orm": "^2.9",
+    "egulias/email-validator": "^3.0",
+    "jbouzekri/phumbor-bundle": "^3.1.0",
+    "knplabs/knp-gaufrette-bundle": "^0.8.0",
+    "knplabs/knp-snappy-bundle": "^1.9",
+    "lcobucci/jwt": "^4.1",
+    "lexik/jwt-authentication-bundle": "^2.8",
+    "lorenzo/pinky": "^1.0",
+    "myclabs/php-enum": "^1.7",
+    "nelmio/cors-bundle": "^2.1",
+    "odolbeau/phone-number-bundle": "^3.1",
+    "phpdocumentor/reflection-docblock": "^5.2",
+    "ramsey/uuid": "^4.2",
+    "ramsey/uuid-doctrine": "^2.0",
+    "symfony/asset": "6.2.*",
+    "symfony/console": "6.2.*",
+    "symfony/doctrine-messenger": "6.2.*",
+    "symfony/dotenv": "6.2.*",
+    "symfony/error-handler": "6.2.*",
+    "symfony/expression-language": "6.2.*",
+    "symfony/flex": "^1.3.1",
+    "symfony/framework-bundle": "6.2.*",
+    "symfony/http-client": "6.2.*",
+    "symfony/intl": "6.2.*",
+    "symfony/lock": "6.2.*",
+    "symfony/mailer": "6.2.*",
+    "symfony/mercure": "^0.6.1",
+    "symfony/mercure-bundle": "^0.3.4",
+    "symfony/messenger": "6.2.*",
+    "symfony/monolog-bundle": "^3.7",
+    "symfony/polyfill-intl-icu": "^1.21",
+    "symfony/polyfill-intl-messageformatter": "^1.24",
+    "symfony/property-access": "6.2.*",
+    "symfony/property-info": "6.2.*",
+    "symfony/security-bundle": "6.2.*",
+    "symfony/serializer": "6.2.*",
+    "symfony/translation": "6.2.*",
+    "symfony/twig-bundle": "6.2.*",
+    "symfony/uid": "6.2.*",
+    "symfony/validator": "6.2.*",
+    "symfony/yaml": "6.2.*",
+    "twig/cssinliner-extra": "^3.4",
+    "twig/extra-bundle": "^3.4",
+    "twig/inky-extra": "^3.4",
+    "vincent/foselastica": "1.3.1",
+    "opentalent/phpdocx": "dev-master",
+    "webonyx/graphql-php": "^14.3",
+    "xantios/mimey": "*"
+  },
+  "require-dev": {
+    "cyclonedx/cyclonedx-php-composer": "^3.4",
+    "dg/bypass-finals": "^1.4",
+    "doctrine/doctrine-fixtures-bundle": "^3.4",
+    "hautelook/alice-bundle": "^2.11",
+    "justinrainbow/json-schema": "^5.2",
+    "phpstan/extension-installer": "^1.2",
+    "phpstan/phpstan": "^1.9",
+    "phpstan/phpstan-doctrine": "^1.3",
+    "phpstan/phpstan-phpunit": "^1.3",
+    "phpstan/phpstan-symfony": "^1.2",
+    "phpunit/phpunit": "^9.6",
+    "rector/rector": "^0.15.13",
+    "symfony/browser-kit": "6.2.*",
+    "symfony/css-selector": "6.2.*",
+    "symfony/debug-bundle": "6.2.*",
+    "symfony/maker-bundle": "^1.21",
+    "symfony/phpunit-bridge": "^6.2",
+    "symfony/stopwatch": "6.2.*",
+    "symfony/web-profiler-bundle": "6.2.*",
+    "timeweb/phpstan-enum": "^3.1",
+    "zenstruck/foundry": "^1.31"
+  },
+  "config": {
+    "optimize-autoloader": true,
+    "preferred-install": {
+      "*": "dist"
     },
-    "scripts": {
-        "auto-scripts": {
-            "cache:clear": "symfony-cmd",
-            "assets:install %PUBLIC_DIR%": "symfony-cmd"
-        },
-        "post-install-cmd": [
-            "@auto-scripts"
-        ],
-        "post-update-cmd": [
-            "@auto-scripts"
-        ]
+    "sort-packages": true,
+    "allow-plugins": {
+      "cyclonedx/cyclonedx-php-composer": true,
+      "symfony/flex": true,
+      "phpstan/extension-installer": true
+    }
+  },
+  "autoload": {
+    "psr-4": {
+      "App\\": "src/"
+    }
+  },
+  "classmap": [
+    "vendor/opentalent/phpdocx/Classes/Phpdocx/Create/CreateDocx.php",
+    "vendor/opentalent/phpdocx/Classes/Phpdocx/Create/CreateDocxFromTemplate.php"
+  ],
+  "autoload-dev": {
+    "psr-4": {
+      "DataFixtures\\": "tests/Fixture",
+      "App\\Tests\\": "tests/"
+    }
+  },
+  "replace": {
+    "paragonie/random_compat": "2.*",
+    "symfony/polyfill-ctype": "*",
+    "symfony/polyfill-iconv": "*",
+    "symfony/polyfill-php72": "*",
+    "symfony/polyfill-php71": "*",
+    "symfony/polyfill-php70": "*",
+    "symfony/polyfill-php56": "*"
+  },
+  "scripts": {
+    "auto-scripts": {
+      "cache:clear": "symfony-cmd",
+      "assets:install %PUBLIC_DIR%": "symfony-cmd"
     },
-    "conflict": {
-        "symfony/symfony": "*"
+    "post-install-cmd": [
+      "@auto-scripts"
+    ],
+    "post-update-cmd": [
+      "@auto-scripts"
+    ]
+  },
+  "conflict": {
+    "symfony/symfony": "*"
+  },
+  "extra": {
+    "symfony": {
+      "allow-contrib": false,
+      "require": "6.2.*"
     },
-    "extra": {
-        "symfony": {
-            "allow-contrib": false,
-            "require": "6.2.*"
-        },
-        "phpstan": {
-            "includes": [
-                "extension.neon"
-            ]
-        }
+    "phpstan": {
+      "includes": [
+        "extension.neon"
+      ]
     }
-}
+  }
+}

+ 23 - 22
src/ApiResources/Export/LicenceCmf/LicenceCmfOrganizationER.php

@@ -1,4 +1,5 @@
 <?php
+
 declare (strict_types=1);
 
 namespace App\ApiResources\Export\LicenceCmf;
@@ -15,38 +16,38 @@ use App\State\Processor\Export\LicenceCmf\ExportRequestProcessor;
 use Symfony\Component\Validator\Constraints as Assert;
 
 /**
- * Requête d'export d'une licence CMF pour l'organization ciblée
- *
- * Appeler avec une requête POST à /export/licence-cmf/organization,
- * avec un body comme :
- *
- *   {"organizationId" : 1}
- */
+* Requête d'export d'une licence CMF pour l'organization ciblée
+*
+* Appeler avec une requête POST à /export/licence-cmf/organization,
+* avec un body comme :
+*
+* {"organizationId" : 1}
+*/
 #[ApiResource(
     operations: [
-        new Post(
-            uriTemplate: '/cmf-licence/organization',
-            security: '(is_granted("ROLE_ADMIN_CORE") or is_granted("ROLE_ADMINISTRATIF_MANAGER_CORE"))'
-        ),
-    ],
+new Post(
+    uriTemplate: '/cmf-licence/organization',
+    security: '(is_granted("ROLE_ADMIN_CORE") or is_granted("ROLE_ADMINISTRATIF_MANAGER_CORE"))'
+),
+],
     routePrefix: '/export',
     processor: ExportRequestProcessor::class
 )]
 class LicenceCmfOrganizationER extends ExportRequest
 {
     /**
-     * Format de sortie attendu (pdf seulement ici)
-     * @var string
-     */
-    #[Assert\EqualTo('pdf')]
-    protected string $format = 'pdf';
+    * Format de sortie attendu (pdf seulement ici)
+    * @var string
+    */
+    // #[Assert\EqualTo('pdf')]
+    protected string $format = 'docx';
 
     /**
-     * Retourne l'année de la licence
-     * (toujours l'année courante, sauf dans le cas des tests où on pourra mocker cette méthode)
-     *
-     * @return int
-     */
+    * Retourne l'année de la licence
+    * (toujours l'année courante, sauf dans le cas des tests où on pourra mocker cette méthode)
+    *
+    * @return int
+    */
     public function getYear(): int
     {
         return (int)date('Y');

+ 1 - 0
src/Enum/Export/ExportFormatEnum.php

@@ -15,4 +15,5 @@ class ExportFormatEnum extends Enum
     private const TXT = 'txt';
     private const XLSX = 'xlsx';
     private const XML = 'xml';
+    private const DOCX = 'docx';
 }

+ 39 - 0
src/Service/Export/Encoder/DocXEncoder

@@ -0,0 +1,39 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Service\Export\Encoder;
+
+use App\Enum\Export\ExportFormatEnum;
+use Phpdocx\Create\CreateDocx;
+
+/**
+ * Encode HTML to docx format
+ */
+class DocXEncoder implements EncoderInterface
+{
+
+  public function support(string $format): bool
+  {
+    return $format === ExportFormatEnum::DOCX()->getValue();
+  }
+
+  /**
+   * Encode the given HTML content into docX, and
+   * return the encoded content
+   *
+   * @param string $html
+   * @param array<mixed> $options
+   * @return string
+   */
+  public function encode(string $html, array $options = []): string
+  {
+    $docx = new CreateDocx();
+    $docx->addText($html);
+    $tempFile = tempnam(sys_get_temp_dir(), 'docx');
+    $docx->createDocx($tempFile);
+    $docxContent = file_get_contents($tempFile);
+    unlink($tempFile);
+    return $docxContent;
+  }
+}