diff --git a/Dockerfile b/Dockerfile index bcc9446..d16836f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN a2enmod rewrite RUN apt-get update && apt-get install -y \ libicu-dev \ libzip-dev \ + git \ wget \ && docker-php-ext-install \ pdo_mysql \ diff --git a/skeleton/composer.json b/skeleton/composer.json index b4d1e98..4b7d330 100644 --- a/skeleton/composer.json +++ b/skeleton/composer.json @@ -8,12 +8,16 @@ "ext-ctype": "*", "ext-iconv": "*", "google/apiclient": "^2.18", + "symfony/asset": "7.2.*", "symfony/console": "7.2.*", "symfony/dotenv": "7.2.*", "symfony/flex": "^2", "symfony/framework-bundle": "7.2.*", "symfony/runtime": "7.2.*", - "symfony/yaml": "7.2.*" + "symfony/twig-bundle": "7.2.*", + "symfony/yaml": "7.2.*", + "twig/extra-bundle": "^2.12|^3.0", + "twig/twig": "^2.12|^3.0" }, "config": { "allow-plugins": { diff --git a/skeleton/composer.lock b/skeleton/composer.lock index 11ce493..90477ea 100644 --- a/skeleton/composer.lock +++ b/skeleton/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "aac3672b4910405800635913d4753816", + "content-hash": "9f525314ff224889db7547c2f59add6f", "packages": [ { "name": "firebase/php-jwt", @@ -1304,6 +1304,75 @@ }, "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "symfony/asset", + "version": "v7.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/asset.git", + "reference": "cb926cd59fefa1f9b4900b3695f0f846797ba5c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/asset/zipball/cb926cd59fefa1f9b4900b3695f0f846797ba5c0", + "reference": "cb926cd59fefa1f9b4900b3695f0f846797ba5c0", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "conflict": { + "symfony/http-foundation": "<6.4" + }, + "require-dev": { + "symfony/http-client": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Asset\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/asset/tree/v7.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-25T15:15:23+00:00" + }, { "name": "symfony/cache", "version": "v7.2.3", @@ -3283,6 +3352,278 @@ ], "time": "2024-11-13T13:31:26+00:00" }, + { + "name": "symfony/translation-contracts", + "version": "v3.5.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation-contracts.git", + "reference": "4667ff3bd513750603a09c8dedbea942487fb07c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/4667ff3bd513750603a09c8dedbea942487fb07c", + "reference": "4667ff3bd513750603a09c8dedbea942487fb07c", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, + "branch-alias": { + "dev-main": "3.5-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to translation", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/translation-contracts/tree/v3.5.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-25T14:20:29+00:00" + }, + { + "name": "symfony/twig-bridge", + "version": "v7.2.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/twig-bridge.git", + "reference": "45c00afd4c9accf00a91215067c2858e5a9a3c4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/twig-bridge/zipball/45c00afd4c9accf00a91215067c2858e5a9a3c4e", + "reference": "45c00afd4c9accf00a91215067c2858e5a9a3c4e", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/translation-contracts": "^2.5|^3", + "twig/twig": "^3.12" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/console": "<6.4", + "symfony/form": "<6.4", + "symfony/http-foundation": "<6.4", + "symfony/http-kernel": "<6.4", + "symfony/mime": "<6.4", + "symfony/serializer": "<6.4", + "symfony/translation": "<6.4", + "symfony/workflow": "<6.4" + }, + "require-dev": { + "egulias/email-validator": "^2.1.10|^3|^4", + "league/html-to-markdown": "^5.0", + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", + "symfony/asset": "^6.4|^7.0", + "symfony/asset-mapper": "^6.4|^7.0", + "symfony/console": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/emoji": "^7.1", + "symfony/expression-language": "^6.4|^7.0", + "symfony/finder": "^6.4|^7.0", + "symfony/form": "^6.4|^7.0", + "symfony/html-sanitizer": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/intl": "^6.4|^7.0", + "symfony/mime": "^6.4|^7.0", + "symfony/polyfill-intl-icu": "~1.0", + "symfony/property-info": "^6.4|^7.0", + "symfony/routing": "^6.4|^7.0", + "symfony/security-acl": "^2.8|^3.0", + "symfony/security-core": "^6.4|^7.0", + "symfony/security-csrf": "^6.4|^7.0", + "symfony/security-http": "^6.4|^7.0", + "symfony/serializer": "^6.4.3|^7.0.3", + "symfony/stopwatch": "^6.4|^7.0", + "symfony/translation": "^6.4|^7.0", + "symfony/web-link": "^6.4|^7.0", + "symfony/workflow": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0", + "twig/cssinliner-extra": "^2.12|^3", + "twig/inky-extra": "^2.12|^3", + "twig/markdown-extra": "^2.12|^3" + }, + "type": "symfony-bridge", + "autoload": { + "psr-4": { + "Symfony\\Bridge\\Twig\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides integration for Twig with various Symfony components", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/twig-bridge/tree/v7.2.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-02-14T14:27:24+00:00" + }, + { + "name": "symfony/twig-bundle", + "version": "v7.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/twig-bundle.git", + "reference": "cd2be4563afaef5285bb6e0a06c5445e644a5c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/twig-bundle/zipball/cd2be4563afaef5285bb6e0a06c5445e644a5c01", + "reference": "cd2be4563afaef5285bb6e0a06c5445e644a5c01", + "shasum": "" + }, + "require": { + "composer-runtime-api": ">=2.1", + "php": ">=8.2", + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/twig-bridge": "^6.4|^7.0", + "twig/twig": "^3.12" + }, + "conflict": { + "symfony/framework-bundle": "<6.4", + "symfony/translation": "<6.4" + }, + "require-dev": { + "symfony/asset": "^6.4|^7.0", + "symfony/expression-language": "^6.4|^7.0", + "symfony/finder": "^6.4|^7.0", + "symfony/form": "^6.4|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/routing": "^6.4|^7.0", + "symfony/stopwatch": "^6.4|^7.0", + "symfony/translation": "^6.4|^7.0", + "symfony/web-link": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Symfony\\Bundle\\TwigBundle\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides a tight integration of Twig into the Symfony full-stack framework", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/twig-bundle/tree/v7.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-23T08:11:15+00:00" + }, { "name": "symfony/var-dumper", "version": "v7.2.3", @@ -3513,6 +3854,159 @@ } ], "time": "2025-01-07T12:55:42+00:00" + }, + { + "name": "twig/extra-bundle", + "version": "v3.20.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/twig-extra-bundle.git", + "reference": "9df5e1dbb6a68c0665ae5603f6f2c20815647876" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/twig-extra-bundle/zipball/9df5e1dbb6a68c0665ae5603f6f2c20815647876", + "reference": "9df5e1dbb6a68c0665ae5603f6f2c20815647876", + "shasum": "" + }, + "require": { + "php": ">=8.1.0", + "symfony/framework-bundle": "^5.4|^6.4|^7.0", + "symfony/twig-bundle": "^5.4|^6.4|^7.0", + "twig/twig": "^3.2|^4.0" + }, + "require-dev": { + "league/commonmark": "^1.0|^2.0", + "symfony/phpunit-bridge": "^6.4|^7.0", + "twig/cache-extra": "^3.0", + "twig/cssinliner-extra": "^3.0", + "twig/html-extra": "^3.0", + "twig/inky-extra": "^3.0", + "twig/intl-extra": "^3.0", + "twig/markdown-extra": "^3.0", + "twig/string-extra": "^3.0" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Twig\\Extra\\TwigExtraBundle\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + } + ], + "description": "A Symfony bundle for extra Twig extensions", + "homepage": "https://twig.symfony.com", + "keywords": [ + "bundle", + "extra", + "twig" + ], + "support": { + "source": "https://github.com/twigphp/twig-extra-bundle/tree/v3.20.0" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2025-02-08T09:47:15+00:00" + }, + { + "name": "twig/twig", + "version": "v3.20.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "3468920399451a384bef53cf7996965f7cd40183" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/3468920399451a384bef53cf7996965f7cd40183", + "reference": "3468920399451a384bef53cf7996965f7cd40183", + "shasum": "" + }, + "require": { + "php": ">=8.1.0", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" + }, + "require-dev": { + "phpstan/phpstan": "^2.0", + "psr/container": "^1.0|^2.0", + "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/Resources/core.php", + "src/Resources/debug.php", + "src/Resources/escaper.php", + "src/Resources/string_loader.php" + ], + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ], + "support": { + "issues": "https://github.com/twigphp/Twig/issues", + "source": "https://github.com/twigphp/Twig/tree/v3.20.0" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2025-02-13T08:34:43+00:00" } ], "packages-dev": [], diff --git a/skeleton/config/bundles.php b/skeleton/config/bundles.php index 49d3fb6..4ce0d70 100644 --- a/skeleton/config/bundles.php +++ b/skeleton/config/bundles.php @@ -2,4 +2,6 @@ return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], ]; diff --git a/skeleton/config/packages/twig.yaml b/skeleton/config/packages/twig.yaml new file mode 100644 index 0000000..3f795d9 --- /dev/null +++ b/skeleton/config/packages/twig.yaml @@ -0,0 +1,6 @@ +twig: + file_name_pattern: '*.twig' + +when@test: + twig: + strict_variables: true diff --git a/skeleton/public/images/bombeiro-150.png b/skeleton/public/images/bombeiro-150.png new file mode 100644 index 0000000..1270b9e Binary files /dev/null and b/skeleton/public/images/bombeiro-150.png differ diff --git a/skeleton/public/images/fogo.png b/skeleton/public/images/fogo.png new file mode 100644 index 0000000..68a5155 Binary files /dev/null and b/skeleton/public/images/fogo.png differ diff --git a/skeleton/public/style/home.css b/skeleton/public/style/home.css new file mode 100644 index 0000000..46f0ab7 --- /dev/null +++ b/skeleton/public/style/home.css @@ -0,0 +1,73 @@ +header { + background-color: rgb(210, 10, 46); + padding: 15px 20px; + display: flex; + align-items: center; + border-radius: 8px; +} + +.logo-container { + display: flex; + align-items: center; +} + +.logo-container img { + width: 50px; + height: auto; + margin-right: 10px; + border-radius: 20px; +} + +.logo-container span { + color: white; + font-size: 20px; + font-weight: bold; + font-family: Arial, sans-serif; +} + +form { + max-width: 400px; + margin: 20px auto; + padding: 20px; + background: #f9f9f9; + border-radius: 8px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); +} + +.form-group { + display: flex; + flex-direction: column; + margin-bottom: 15px; +} + +label { + font-size: 16px; + font-weight: bold; + margin-bottom: 5px; +} + +input[type="text"] { + width: 100%; + padding: 8px; + margin-bottom: 8px; + border: 1px solid #ccc; + border-radius: 4px; + font-size: 14px; +} + +.submit-btn { + background-color: green; + color: white; + border: none; + padding: 10px 15px; + font-size: 16px; + cursor: pointer; + border-radius: 4px; + display: block; + width: 100%; + text-align: center; +} + +.submit-btn:hover { + background-color: darkgreen; +} \ No newline at end of file diff --git a/skeleton/src/Controller/.gitignore b/skeleton/src/Controller/.gitignore index e69de29..42cd73d 100644 --- a/skeleton/src/Controller/.gitignore +++ b/skeleton/src/Controller/.gitignore @@ -0,0 +1 @@ +/vendor/ \ No newline at end of file diff --git a/skeleton/src/Controller/sheetController.php b/skeleton/src/Controller/SheetController.php similarity index 79% rename from skeleton/src/Controller/sheetController.php rename to skeleton/src/Controller/SheetController.php index f45a9f4..5ded742 100644 --- a/skeleton/src/Controller/sheetController.php +++ b/skeleton/src/Controller/SheetController.php @@ -7,7 +7,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Annotation\Route; -class sheetController extends AbstractController +class SheetController extends AbstractController { private GoogleSheetsService $googleSheetsService; @@ -23,8 +23,9 @@ public function getSheetsData(string $sheetId): JsonResponse // inserir nome se necessário $sheetName = ''; - $data = $this->googleSheetsService->getSheetData($sheetId, $sheetName); + $result = $this->googleSheetsService->getSheetData($sheetId, $sheetName); + + return $this->json($result); - return $this->json($data); } } \ No newline at end of file diff --git a/skeleton/src/Controller/SyncController.php b/skeleton/src/Controller/SyncController.php new file mode 100644 index 0000000..3af986d --- /dev/null +++ b/skeleton/src/Controller/SyncController.php @@ -0,0 +1,56 @@ +isMethod('POST')) + { + $sheetId = $request->request->get('sheetId'); + $sheetIdB = $request->request->get('sheetIdB'); + + if (!$sheetId || !$sheetIdB) + { + $this->addFlash('error', 'Os IDs das planilhas são obrigatórios!'); + return $this->redirectToRoute('home_page'); + } + + try + { + $credentialsPath = $_ENV['GOOGLE_AUTH_CONFIG']; + + $result = $googleSheetsService->getSheetData($sheetId, "A1:C100"); + + $dadosEstruturados = $writeSheetsService->estruturarDados($result); + + $writeSheetsService->configureClient($credentialsPath, $sheetIdB); + $writeSheetsService->appendData("A13:AH13", $dadosEstruturados); + + $this->addFlash('success', 'Dados sincronizados com sucesso!'); + } + + catch (\Exception $e) + { + $this->addFlash('Erro', 'Erro ao sincronizar planilhas: ' . $e->getMessage()); + } + + return $this->redirectToRoute('home_page'); + } + + return $this->render('home.html.twig'); + } +} diff --git a/skeleton/src/Controller/WriteSheetsController.php b/skeleton/src/Controller/WriteSheetsController.php index 367fbff..ffa81a3 100644 --- a/skeleton/src/Controller/WriteSheetsController.php +++ b/skeleton/src/Controller/WriteSheetsController.php @@ -12,17 +12,19 @@ class WriteSheetsController extends AbstractController #[Route('/write-sheet/{sheetIdB}', name:'write_sheets')] public function escreverPlanilha(WriteSheetsService $writeSheetsService, string $sheetIdB): Response { + $credentialsPath = $_ENV['GOOGLE_AUTH_CONFIG']; $writeSheetsService->configureClient($credentialsPath, $sheetIdB); $dados = [ - ['vlr1', 'vlr2', 'vlr3', 'vlr4'] + ['teste', 'teste', 'teste', 'teste'] ]; - $writeSheetsService->appendData('D14:H14', $dados); + $writeSheetsService->appendData('D13:L13', $dados); return new Response("Dados adicionados à planilha: " . $sheetIdB); } -} \ No newline at end of file +} + diff --git a/skeleton/src/Service/GoogleSheetsService.php b/skeleton/src/Service/GoogleSheetsService.php index 28c34c1..476866c 100644 --- a/skeleton/src/Service/GoogleSheetsService.php +++ b/skeleton/src/Service/GoogleSheetsService.php @@ -6,13 +6,13 @@ class GoogleSheetsService { - public function getSheetData(string $sheetId, string $sheetName): array + public function getSheetData(string $sheetId): array { // link da tabela que iremos extrair os dados. Pegamos seu ID $url = "https://docs.google.com/spreadsheets/d/{$sheetId}/gviz/tq?tqx=out:json"; - // aqui pegamos os dados da tabela através da função file_get_contents. Da url passada - $response = file_get_contents($url); + + $response = file_get_contents($url); // removendo prefixos extras add pelo Google $response = substr($response, 47, -2); @@ -20,13 +20,12 @@ public function getSheetData(string $sheetId, string $sheetName): array // usamos json_decode para transformar o arquivo json obtido, em um array $data = json_decode($response, true); - // exceção para não gerar um erro caso a planilha esteja vazia + if (!isset($data['table']['rows'])) { throw new Exception("A planilha está vazia"); } - - // processa e organiza os dados em forma de tabela + $result = []; foreach ($data['table']['rows'] as $row) { diff --git a/skeleton/src/Service/WriteSheetsService.php b/skeleton/src/Service/WriteSheetsService.php index f118e54..a3c5d80 100644 --- a/skeleton/src/Service/WriteSheetsService.php +++ b/skeleton/src/Service/WriteSheetsService.php @@ -39,5 +39,53 @@ public function appendData(string $range, array $values): void $body, $params ); + + } + + public function estruturarDados(array $result): array + { + $dadosEstruturados = []; + $bombeiros = []; + + foreach ($result as $linha) + { + $nome = $linha[1] ?? ''; + + if (!$nome) { + continue; + } + + // criamos o array caso esse não existir ainda + if (!isset($bombeiros[$nome])) { + $bombeiros[$nome] = array_fill(0, 32, ""); + $bombeiros[$nome][0] = $nome; + } + + // procura os turnos + for ($dia = 1; $dia <= 31; $dia++) { + $indiceTurno = $dia + 1; // começa no 2 por conta da estrutura da tabela final + + if (isset($linha[$indiceTurno]) && !empty($linha[$indiceTurno])) { + $turno = $linha[$indiceTurno]; + + $mapeamentoTurno = match ($turno) { + "Integral" => "I", + "Diurno" => "D", + "Noturno" => "N", + default => "", + }; + + $bombeiros[$nome][$dia] = $mapeamentoTurno; + } + } + } + + // array associativo em lista de array + foreach ($bombeiros as $linha) { + $dadosEstruturados[] = $linha; + } + + return $dadosEstruturados; } + } diff --git a/skeleton/symfony.lock b/skeleton/symfony.lock index c69c500..73ad1f5 100644 --- a/skeleton/symfony.lock +++ b/skeleton/symfony.lock @@ -67,5 +67,21 @@ "config/packages/routing.yaml", "config/routes.yaml" ] + }, + "symfony/twig-bundle": { + "version": "7.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "6.4", + "ref": "cab5fd2a13a45c266d45a7d9337e28dee6272877" + }, + "files": [ + "config/packages/twig.yaml", + "templates/base.html.twig" + ] + }, + "twig/extra-bundle": { + "version": "v3.20.0" } } diff --git a/skeleton/templates/base.html.twig b/skeleton/templates/base.html.twig new file mode 100644 index 0000000..1069c14 --- /dev/null +++ b/skeleton/templates/base.html.twig @@ -0,0 +1,16 @@ + + +
+ +