Skip to content

Commit

Permalink
Cria interface para verificar dados da LICC
Browse files Browse the repository at this point in the history
  • Loading branch information
erleibiazzio committed Apr 17, 2024
1 parent 793e64d commit 63a5c2a
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 0 deletions.
102 changes: 102 additions & 0 deletions plugins/SettingsES/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace SettingsES;

use DateTime;
use MapasCulturais\App;
use MapasCulturais\i;

class Controller extends \MapasCulturais\Controllers\EntityController
{
use \MapasCulturais\Traits\ControllerAPI;

function __construct()
{
}


public function GET_liccSummary()
{
$app = App::i();

$this->requireAuthentication();

if (!$app->user->is('admin')) {
return;
}

$this->render('licc-summary', []);
}


public function POST_generateLiccSummary()
{
$app = App::i();

$this->requireAuthentication();

if (!$app->user->is('admin')) {
return;
}

$em = $app->em;
$conn = $em->getConnection();

$request = $this->data;

$errors = [];
if (!isset($request['registrations']) || empty($request['registrations']) || $request['registrations'] == "") {
$errors[] = "Informe o número de pelomenos uma inscrição";
}

$delimiter = "\n";
if (strpos($request['registrations'], ",") !== false) {
$delimiter = ",";
}

if (strpos($request['registrations'], ";") !== false) {
$delimiter = ";";
}

if (!$delimiter) {
$errors[] = "As inscrições devem estar separadas por virgula, ponto e virgula ou uma em cada linha";
}


if ($errors) {
$this->render('licc-summary-erros', ['errors' => $errors]);
}



if ($numbers = explode($delimiter, $request['registrations'])) {
$results = [];
foreach ($numbers as $number) {
$number = trim($number);
$_number = preg_replace('/[^0-9]/i', '', $number);

if ($revisions = $conn->fetchAll("SELECT * FROM entity_revision er WHERE er.object_type = 'MapasCulturais\Entities\Registration' AND er.object_id = '{$_number}' ORDER BY er.create_timestamp ASC")) {
foreach ($revisions as $revision) {
$results[$number]['revisions'][] = [
'data' => (new DateTime($revision['create_timestamp']))->format("d/m/Y H:i:s"),
'action' => $revision['message'],
];
}
}

if($files = $conn->fetchAll("SELECT * FROM file f WHERE f.object_type = 'MapasCulturais\Entities\Registration' AND f.object_id = '{$_number}' ORDER BY f.create_timestamp ASC")) {
foreach ($files as $file) {
$results[$number]['files'][] = [
'data' => (new DateTime($revision['create_timestamp']))->format("d/m/Y H:i:s"),
'name' => $file['name'],
];
}
}
}

if($results) {
$this->render('licc-summary-result', ['results' => $results, 'request' => $request]);
}
}
}
}
3 changes: 3 additions & 0 deletions plugins/SettingsES/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SettingsES;

use MapasCulturais\App;
use SettingsES\Controller;

class Plugin extends \MapasCulturais\Plugin
{
Expand All @@ -29,6 +30,8 @@ public function _init()

public function register()
{
$app = App::i();
$app->registerController('essettings', Controller::class);
}

/**
Expand Down
31 changes: 31 additions & 0 deletions plugins/SettingsES/views/essettings/licc-summary-erros.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* @var MapasCulturais\App $app
* @var MapasCulturais\Themes\BaseV2\Theme $this
*/

use MapasCulturais\i;

$this->import('
mc-card
');

$url = $app->createUrl("essettings", "liccSummary");
?>

<mc-card>
<div class="field col-12">
<ul>
<?php foreach ($errors as $error) : ?>
<li><?= $error ?></li>
<?php endforeach ?>
</ul>
</div>

<div class="col-3">
<a href="<?= $url ?>" type="submit" class="button button--md publish publish-exit">
<?php i::_e("Voltar") ?>
</a>
</div>
</mc-card>
73 changes: 73 additions & 0 deletions plugins/SettingsES/views/essettings/licc-summary-result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* @var MapasCulturais\App $app
* @var MapasCulturais\Themes\BaseV2\Theme $this
*/

use MapasCulturais\i;

$this->import('
mc-card
');

$url = $app->createUrl("essettings", "liccSummary");
?>

<mc-card>
<form method="POST" action="<?= $url ?>">
<div class="field col-12">
<?php foreach ($results as $registration => $result) : ?>
<h2><?= i::_e("Inscrição {$registration}") ?></h2>
<?php if (isset($request['useRevision'])) : ?>
<h3><?= i::_e("Histórico de alterações") ?></h3>
<table style="border: 1px solid black">
<thead>
<tr>
<td style="border: 1px solid black"><?= i::_e("Inscrição") ?></td>
<td style="border: 1px solid black"><?= i::_e("Data da alteração") ?></td>
<td style="border: 1px solid black"><?= i::_e("Ação executada") ?></td>
</tr>
</thead>
<?php foreach ($result['revisions'] as $key => $revision) : ?>
<tbody>
<tr>
<td style="border: 1px solid black"><?= $registration ?></td>
<td style="border: 1px solid black"><?= $revision['data'] ?></td>
<td style="border: 1px solid black"><?= $revision['action'] ?></td>
</tr>
</tbody>
<?php endforeach ?>
</table>
<?php endif ?>
<h3><?= i::_e("Lista de arquivos") ?></h3>
<table style="border: 1px solid black">
<thead>
<tr>
<td style="border: 1px solid black"><?= i::_e("Inscrição") ?></td>
<td style="border: 1px solid black"><?= i::_e("Data de carregamento do arquivo") ?></td>
<td style="border: 1px solid black"><?= i::_e("Nome do arquivo") ?></td>
</tr>
</thead>
<?php foreach ($result['files'] as $key => $file) : ?>
<tbody>
<tr>
<td style="border: 1px solid black"><?= $registration ?></td>
<td style="border: 1px solid black"><?= $file['data'] ?></td>
<td style="border: 1px solid black"><?= $file['name'] ?></td>
</tr>
</tbody>
<?php endforeach ?>
</table>


<?php endforeach ?>
</div>

<div class="col-3">
<a href="<?=$url?>" class="button button--md publish publish-exit">
<?php i::_e("Voltar") ?>
</a>
</div>
</form>
</mc-card>
34 changes: 34 additions & 0 deletions plugins/SettingsES/views/essettings/licc-summary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* @var MapasCulturais\App $app
* @var MapasCulturais\Themes\BaseV2\Theme $this
*/

use MapasCulturais\i;

$this->import('
mc-card
');

$url = $app->createUrl("essettings", "generateLiccSummary");
?>

<mc-card>
<form method="POST" action="<?=$url?>">
<div class="field col-12">
<label><?php i::_e("Inscrições") ?></label>
<textarea name="registrations" cols="30" rows="10" placeholder="<?php i::_e("Informe o número das inscrições separadas por ponto e virgula, virgula ou uma em cada linha") ?>"></textarea>
</div>

<div class="col-3">
<label>
<input type="checkbox" name="useRevision">
<?php i::_e("Exibir historico de alterações") ?>
</label>
<button type="submit" class="button button--md publish publish-exit">
<?php i::_e("Solicitar dados") ?>
</button>
</div>
</form>
</mc-card>

0 comments on commit 63a5c2a

Please sign in to comment.