Commit 993dbbbd authored by iruiz's avatar iruiz
Browse files

Ajout des états pour type de dossier #1246

parent 5865f0a6
......@@ -23,6 +23,7 @@
- Ajout d'un connecteur global generateur SEDA afin de ne positionner l'URL de l'outil qu'une seule fois #1320
- Ajout du `ServiceLevel` (Niveau de service demandé) dans les bordereaux de transfert du générateur SEDA #1344
- Colonne qui récapitule le nombre de mails sécurisés envoyés, lus et répondus sur la liste des flux "Mail sécurisés" et "Mail sécurisés avec réponse" #1345
- Ajout des états pour type de dossier #1246
# [3.1.5] - 2021-08-04
......
......@@ -6,6 +6,7 @@ use Pastell\Service\TypeDossier\TypeDossierExportService;
use Pastell\Service\TypeDossier\TypeDossierImportService;
use Pastell\Service\TypeDossier\TypeDossierUtilService;
use Pastell\Service\TypeDossier\TypeDossierManager;
use Pastell\Service\TypeDossier\TypeDossierActionService;
class TypeDossierControler extends PastellControler
{
......@@ -72,6 +73,14 @@ class TypeDossierControler extends PastellControler
return $this->getObjectInstancier()->getInstance(TypeDossierEtapeManager::class);
}
/**
* @return TypeDossierActionService
*/
private function getTypeDossierActionService()
{
return $this->getObjectInstancier()->getInstance(TypeDossierActionService::class);
}
/**
* @throws NotFoundException
*/
......@@ -142,14 +151,14 @@ class TypeDossierControler extends PastellControler
}
$typeDossierProperties->id_type_dossier = $target_type_dossier_id;
try {
$id_t = $typeDossierEditionService->edit($id_t, $typeDossierProperties);
$id_t = $typeDossierEditionService->edit($id_t, $typeDossierProperties, $this->getId_u());
} catch (Exception $e) {
$this->setLastError($e->getMessage());
$this->redirect("/TypeDossier/list");
}
if ($is_new) {
$typeDossierEditionService->editLibelleInfo($id_t, $target_type_dossier_id, TypeDossierUtilService::TYPE_DOSSIER_CLASSEMENT_DEFAULT, "", "onglet1");
$typeDossierEditionService->editLibelleInfo($id_t, $target_type_dossier_id, TypeDossierUtilService::TYPE_DOSSIER_CLASSEMENT_DEFAULT, "", "onglet1", $this->getId_u());
$this->setLastMessage("Le type de dossier personnalisé $target_type_dossier_id a été créé");
} else {
$this->setLastMessage("Modification de l'identifiant du type de dossier personnalisé $target_type_dossier_id");
......@@ -210,6 +219,7 @@ class TypeDossierControler extends PastellControler
{
$this->commonEdition();
$this->{'csrfToken'} = $this->getObjectInstancier()->getInstance(CSRFToken::class);
$this->{'typeDossierAction'} = $this->getTypeDossierActionService()->getById($this->{'id_t'});
$this->{'template_milieu'} = "TypeDossierDetail";
$this->renderDefault();
}
......@@ -236,7 +246,7 @@ class TypeDossierControler extends PastellControler
$description = $this->getPostOrGetInfo()->get('description');
$nom_onglet = $this->getPostOrGetInfo()->get('nom_onglet');
try {
$this->getTypeDossierEditionService()->editLibelleInfo($this->{'id_t'}, $nom, $type, $description, $nom_onglet);
$this->getTypeDossierEditionService()->editLibelleInfo($this->{'id_t'}, $nom, $type, $description, $nom_onglet, $this->getId_u());
} catch (Exception $e) {
$this->setLastError($e->getMessage());
$this->redirect("/TypeDossier/editionLibelle?id_t={$this->{'id_t'}}");
......@@ -266,7 +276,7 @@ class TypeDossierControler extends PastellControler
$id_type_dossier = $this->{'type_de_dossier_info'}['id_type_dossier'];
$this->verifyNoDocumentIsUsingTypeDossier($id_type_dossier, '/TypeDossier/detail?id_t=' . $this->{'id_t'});
try {
$this->getTypeDossierService()->editionElement($this->{'id_t'}, $this->getPostOrGetInfo());
$this->getTypeDossierService()->editionElement($this->{'id_t'}, $this->getPostOrGetInfo(), $this->getId_u());
} catch (Exception $e) {
$this->setLastError($e->getMessage());
$this->redirect("/TypeDossier/detail?id_t={$this->{'id_t'}}");
......@@ -287,7 +297,7 @@ class TypeDossierControler extends PastellControler
$this->verifyNoDocumentIsUsingTypeDossier($id_type_dossier, '/TypeDossier/detail?id_t=' . $this->{'id_t'});
$element_id = $this->getPostOrGetInfo()->get('element_id');
try {
$this->getTypeDossierService()->deleteElement($this->{'id_t'}, $element_id);
$this->getTypeDossierService()->deleteElement($this->{'id_t'}, $element_id, $this->getId_u());
} catch (Exception $e) {
$this->setLastMessage($e->getMessage());
$this->redirect("/TypeDossier/detail?id_t={$this->{'id_t'}}");
......@@ -325,7 +335,7 @@ class TypeDossierControler extends PastellControler
$id_type_dossier = $this->{'type_de_dossier_info'}['id_type_dossier'];
$this->verifyNoDocumentIsUsingTypeDossier($id_type_dossier, '/TypeDossier/detail?id_t=' . $this->{'id_t'});
try {
$this->getTypeDossierService()->editionEtape($this->{'id_t'}, $this->getPostOrGetInfo());
$this->getTypeDossierService()->editionEtape($this->{'id_t'}, $this->getPostOrGetInfo(), $this->getId_u());
} catch (Exception $e) {
$this->setLastMessage($e->getMessage());
$this->redirect("/TypeDossier/detail?id_t={$this->{'id_t'}}");
......@@ -345,7 +355,7 @@ class TypeDossierControler extends PastellControler
$this->verifyNoDocumentIsUsingTypeDossier($id_type_dossier, '/TypeDossier/detail?id_t=' . $this->{'id_t'});
$num_etape = $this->getPostOrGetInfo()->getInt('num_etape');
try {
$this->getTypeDossierService()->deleteEtape($this->{'id_t'}, $num_etape);
$this->getTypeDossierService()->deleteEtape($this->{'id_t'}, $num_etape, $this->getId_u());
} catch (Exception $e) {
$this->setLastMessage($e->getMessage());
$this->redirect("/TypeDossier/detail?id_t={$this->{'id_t'}}");
......@@ -361,7 +371,7 @@ class TypeDossierControler extends PastellControler
{
$this->commonEdition();
$tr = $this->getPostInfo()->get("tr");
$this->getTypeDossierService()->sortElement($this->{'id_t'}, $tr);
$this->getTypeDossierService()->sortElement($this->{'id_t'}, $tr, $this->getId_u());
print_r($tr);
echo "OK";
}
......@@ -375,7 +385,7 @@ class TypeDossierControler extends PastellControler
$id_type_dossier = $this->{'type_de_dossier_info'}['id_type_dossier'];
$this->verifyNoDocumentIsUsingTypeDossier($id_type_dossier);
$tr = $this->getPostInfo()->get("tr");
$this->getTypeDossierService()->sortEtape($this->{'id_t'}, $tr);
$this->getTypeDossierService()->sortEtape($this->{'id_t'}, $tr, $this->getId_u());
print_r($tr);
echo "OK";
}
......@@ -402,7 +412,7 @@ class TypeDossierControler extends PastellControler
$this->verifyNoDocumentIsUsingTypeDossier($id_type_dossier, '/TypeDossier/detail?id_t=' . $this->{'id_t'});
$num_etape = 0;
try {
$num_etape = $this->getTypeDossierService()->newEtape($this->{'id_t'}, $this->getPostOrGetInfo());
$num_etape = $this->getTypeDossierService()->newEtape($this->{'id_t'}, $this->getPostOrGetInfo(), $this->getId_u());
} catch (Exception $e) {
$this->setLastMessage($e->getMessage());
$this->redirect("/TypeDossier/detail?id_t={$this->{'id_t'}}");
......@@ -453,7 +463,7 @@ class TypeDossierControler extends PastellControler
$result = [];
try {
$result = $typeDossierImportService->import($file_content);
$result = $typeDossierImportService->import($file_content, $this->getId_u());
} catch (TypeDossierException $e) {
$this->setLastError($e->getMessage());
$this->redirect("/TypeDossier/import");
......
This diff is collapsed.
......@@ -308,9 +308,9 @@ CREATE TABLE `type_dossier_action` (
`id_u` int(11) NOT NULL,
`id_t` int(11) NOT NULL,
`action` varchar(64) NOT NULL,
`message` mediumtext NOT NULL,
`date` datetime NOT NULL,
`empreinte_sha256` varchar(128) NOT NULL,
`export_json` json NOT NULL,
PRIMARY KEY (`id_a`),
KEY `id_t` (`id_t`)
) ENGINE=MyISAM ;
......
<?php
class TypeDossierActionSQL extends SQL
{
public const DEFAULT_LIMIT = 20;
public function add(int $id_u, int $id_t, string $action, string $empreinte_sha256, string $export_json): int
{
$now = date(Date::DATE_ISO);
$sql = "INSERT INTO type_dossier_action(id_u, id_t, action, date, empreinte_sha256, export_json) VALUES (?,?,?,?,?,?)";
$this->query($sql, $id_u, $id_t, $action, $now, $empreinte_sha256, $export_json);
return $this->lastInsertId();
}
public function getById(int $id_t, int $offset = 0, int $limit = self::DEFAULT_LIMIT): array
{
$sql = "SELECT type_dossier_action.id_u AS id_u, " .
" type_dossier_action.action AS action, " .
" type_dossier_action.date AS date, " .
" type_dossier_action.empreinte_sha256 AS empreinte_sha256, " .
" type_dossier_action.export_json AS export_json, " .
" utilisateur.nom AS nom, " .
" utilisateur.prenom AS prenom" .
" FROM type_dossier_action " .
" LEFT JOIN utilisateur ON type_dossier_action.id_u = utilisateur.id_u " .
" WHERE id_t= ? " .
" ORDER BY date DESC,id_a DESC";
$sql .= " LIMIT $offset,$limit";
return $this->query($sql, $id_t);
}
}
......@@ -48,6 +48,9 @@ class TypeDossierSQL extends SQL
{
$sql = "DELETE FROM type_dossier WHERE id_t=?";
$this->query($sql, $id_t);
$sql = "DELETE FROM type_dossier_action WHERE id_t=?";
$this->query($sql, $id_t);
}
public function getByIdTypeDossier($id_type_dossier)
......
<?php
class TypeDossiersActionSQL extends SQL
{
public function add(int $id_u, int $id_t, string $action, string $message, string $empreinte_sha256): int
{
$now = date(Date::DATE_ISO);
$sql = "INSERT INTO type_dossier_action(id_u, id_t, action, message, date, empreinte_sha256) VALUES (?,?,?,?,?,?)";
$this->query($sql, $id_u, $id_t, $action, $message, $now, $empreinte_sha256);
return $this->lastInsertId();
}
public function delete(int $id_t): void
{
$sql = "DELETE FROM type_dossier_action WHERE id_t=?";
$this->query($sql, $id_t);
}
}
......@@ -76,7 +76,7 @@ class TypeDossierService
* @throw TypeDossierException
* @throws Exception
*/
public function editionElement($id_t, Recuperateur $recuperateur)
public function editionElement($id_t, Recuperateur $recuperateur, $id_u = 0)
{
$typeDossierData = $this->typeDossierManager->getTypeDossierProperties($id_t);
......@@ -114,7 +114,7 @@ class TypeDossierService
$recuperateur
);
$this->typeDossierEditionService->edit($id_t, $typeDossierData);
$this->typeDossierEditionService->edit($id_t, $typeDossierData, $id_u);
}
/**
......@@ -122,14 +122,14 @@ class TypeDossierService
* @param $element_id
* @throws Exception
*/
public function deleteElement($id_t, $element_id)
public function deleteElement($id_t, $element_id, $id_u = 0)
{
$typeDossierData = $this->typeDossierManager->getTypeDossierProperties($id_t);
$element_index = $this->getFormulaireElementIndex($typeDossierData, $element_id);
unset($typeDossierData->formulaireElement[$element_index]);
$this->typeDossierEditionService->edit($id_t, $typeDossierData);
$this->typeDossierEditionService->edit($id_t, $typeDossierData, $id_u);
}
/**
......@@ -137,7 +137,7 @@ class TypeDossierService
* @param $tr
* @throws Exception
*/
public function sortElement($id_t, array $tr)
public function sortElement($id_t, array $tr, $id_u = 0)
{
$typeDossierData = $this->typeDossierManager->getTypeDossierProperties($id_t);
$new_form = [];
......@@ -149,7 +149,7 @@ class TypeDossierService
throw new TypeDossierException("Impossible de retrier le tableau");
}
$typeDossierData->formulaireElement = $new_form;
$this->typeDossierEditionService->edit($id_t, $typeDossierData);
$this->typeDossierEditionService->edit($id_t, $typeDossierData, $id_u);
}
public function getFieldWithType($id_t, $type)
......@@ -182,7 +182,7 @@ class TypeDossierService
* @return int
* @throws Exception
*/
public function newEtape($id_t, Recuperateur $recuperateur): int
public function newEtape($id_t, Recuperateur $recuperateur, $id_u = 0): int
{
$typeDossierData = $this->typeDossierManager->getTypeDossierProperties($id_t);
$typeDossierEtape = $this->getTypeDossierEtapeFromRecuperateur(
......@@ -195,7 +195,7 @@ class TypeDossierService
$typeDossierEtape->num_etape = $num_etape ?: 0;
$typeDossierEtape->defaultChecked = (bool)$recuperateur->get('default_checked', false);
$this->typeDossierEditionService->edit($id_t, $typeDossierData);
$this->typeDossierEditionService->edit($id_t, $typeDossierData, $id_u);
return $num_etape;
}
......@@ -204,7 +204,7 @@ class TypeDossierService
* @param Recuperateur $recuperateur
* @throws Exception
*/
public function editionEtape($id_t, Recuperateur $recuperateur)
public function editionEtape($id_t, Recuperateur $recuperateur, $id_u = 0)
{
$num_etape = $recuperateur->get('num_etape') ?: 0;
......@@ -216,7 +216,7 @@ class TypeDossierService
$typeDossierEtape->label = $recuperateur->get('label', null);
$typeDossierEtape->defaultChecked = (bool)$recuperateur->get('default_checked', false);
$typeDossierEtape->num_etape = $num_etape ?: 0;
$this->typeDossierEditionService->edit($id_t, $typeDossierData);
$this->typeDossierEditionService->edit($id_t, $typeDossierData, $id_u);
}
private function getTypeDossierEtapeFromRecuperateur(Recuperateur $recuperateur, $type): TypeDossierEtapeProperties
......@@ -239,7 +239,7 @@ class TypeDossierService
* @param $num_etape
* @throws Exception
*/
public function deleteEtape($id_t, $num_etape)
public function deleteEtape($id_t, $num_etape, $id_u = 0)
{
$typeDossierData = $this->typeDossierManager->getTypeDossierProperties($id_t);
array_splice($typeDossierData->etape, $num_etape, 1);
......@@ -247,7 +247,7 @@ class TypeDossierService
$typeDossierData->etape[$i]->num_etape = $i;
}
$this->typeDossierEditionService->edit($id_t, $typeDossierData);
$this->typeDossierEditionService->edit($id_t, $typeDossierData, $id_u);
}
/**
......@@ -255,7 +255,7 @@ class TypeDossierService
* @param $tr
* @throws Exception
*/
public function sortEtape($id_t, $tr)
public function sortEtape($id_t, $tr, $id_u = 0)
{
$typeDossierData = $this->typeDossierManager->getTypeDossierProperties($id_t);
$new_cheminement = [];
......@@ -269,7 +269,7 @@ class TypeDossierService
foreach ($typeDossierData->etape as $i => $etape) {
$typeDossierData->etape[$i]->num_etape = $i;
}
$this->typeDossierEditionService->edit($id_t, $typeDossierData);
$this->typeDossierEditionService->edit($id_t, $typeDossierData, $id_u);
}
private function getEtapeList($typeDossier, $cheminement_list)
......@@ -327,12 +327,12 @@ class TypeDossierService
/**
* @throws Exception
*/
public function rebuildAll()
public function rebuildAll($id_u = 0)
{
$all_type_dossier = $this->typeDossierSQL->getAll();
foreach ($all_type_dossier as $type_dossier_info) {
$typeDossierData = $this->typeDossierManager->getTypeDossierProperties($type_dossier_info['id_t']);
$this->typeDossierEditionService->edit($type_dossier_info['id_t'], $typeDossierData);
$this->typeDossierEditionService->edit($type_dossier_info['id_t'], $typeDossierData, $id_u);
$this->pastellLogger->info(
"Le fichier YAML du flux personnalisé {$typeDossierData->id_type_dossier} a été reconstruit"
);
......
<?php
namespace Pastell\Service\TypeDossier;
use TypeDossierActionSQL;
use Pastell\Service\TypeDossier\TypeDossierExportService;
use Pastell\Service\TypeDossier\TypeDossierManager;
class TypeDossierActionService
{
public const ACTION_MODIFFIE = 'Modifié';
public const ACTION_AJOUTE = 'Ajouté';
/**
* @var TypeDossierActionSQL
*/
private $typeDossierActionSQL;
/**
* @var TypeDossierExportService
*/
private $typeDossierExportService;
/**
* @var TypeDossierManager
*/
private $typeDossierManager;
public function __construct(
TypeDossierActionSQL $typeDossierActionSQL,
TypeDossierExportService $typeDossierExportService,
TypeDossierManager $typeDossierManager
) {
$this->typeDossierActionSQL = $typeDossierActionSQL;
$this->typeDossierExportService = $typeDossierExportService;
$this->typeDossierManager = $typeDossierManager;
}
public function add(int $id_u, int $id_t, string $action): int
{
return $this->typeDossierActionSQL->add(
$id_u,
$id_t,
$action,
$this->typeDossierManager->getHash($id_t),
$this->typeDossierExportService->export($id_t)
);
}
public function getById(int $id_t): array
{
return $this->typeDossierActionSQL->getById($id_t);
}
}
......@@ -10,8 +10,7 @@ use TypeDossierSQL;
use TypeDossierPersonnaliseDirectoryManager;
use TypeDossierProperties;
use FluxDefinitionFiles;
use EntiteSQL;
use Journal;
use Pastell\Service\TypeDossier\TypeDossierActionService;
class TypeDossierEditionService
{
......@@ -39,80 +38,65 @@ class TypeDossierEditionService
*/
private $typeDossierEtapeManager;
/**
* @var TypeDossierExportService
*/
private $typeDossierExportService;
/**
* @var TypeDossierManager
*/
private $typeDossierManager;
/**
* @var Journal
* @var TypeDossierActionService
*/
private $journal;
private $typeDossierActionService;
public function __construct(
TypeDossierSQL $typeDossierSQL,
TypeDossierPersonnaliseDirectoryManager $typeDossierPersonnaliseDirectoryManager,
TypeDossierEtapeManager $typeDossierEtapeManager,
TypeDossierExportService $typeDossierExportService,
Journal $journal,
TypeDossierManager $typeDossierManager,
FluxDefinitionFiles $fluxDefinitionFiles
FluxDefinitionFiles $fluxDefinitionFiles,
TypeDossierActionService $typeDossierActionService
) {
$this->typeDossierSQL = $typeDossierSQL;
$this->typeDossierPersonnaliseDirectoryManager = $typeDossierPersonnaliseDirectoryManager;
$this->typeDossierEtapeManager = $typeDossierEtapeManager;
$this->typeDossierExportService = $typeDossierExportService;
$this->journal = $journal;
$this->typeDossierManager = $typeDossierManager;
$this->fluxDefinitionFiles = $fluxDefinitionFiles;
$this->typeDossierActionService = $typeDossierActionService;
}
/**
* @param int $id_u
* @param TypeDossierProperties $typeDossierProperties
* @return int
* @throws TypeDossierException
* @throws Exception
*/
public function create(TypeDossierProperties $typeDossierProperties): int
public function create(TypeDossierProperties $typeDossierProperties, int $id_u = 0): int
{
$this->checkTypeDossierId($typeDossierProperties->id_type_dossier);
$this->checkNomOnglet($typeDossierProperties->nom_onglet);
return $this->edit(0, $typeDossierProperties);
return $this->edit(0, $typeDossierProperties, $id_u);
}
/**
* @param int $id_u
* @param int $id_t
* @param TypeDossierProperties $typeDossierProperties
* @return int
* @throws Exception
*/
public function edit(int $id_t, TypeDossierProperties $typeDossierProperties): int
public function edit(int $id_t, TypeDossierProperties $typeDossierProperties, int $id_u): int
{
if (! $id_t) {
$journal_action = Journal::ACTION_AJOUTE;
$message_action = 'Ajout';
$action = TypeDossierActionService::ACTION_AJOUTE;
} else {
$journal_action = Journal::ACTION_MODIFFIE;
$message_action = 'Modification';
$action = TypeDossierActionService::ACTION_MODIFFIE;
}
$typeDossierProperties = $this->fixSameStepsType($typeDossierProperties);
$id_t = $this->typeDossierSQL->edit($id_t, $typeDossierProperties);
$this->typeDossierPersonnaliseDirectoryManager->save($id_t, $typeDossierProperties);
$export = $this->typeDossierExportService->export($id_t);
$this->journal->add(
Journal::TYPE_DOSSIER_EDITION,
EntiteSQL::ID_E_ENTITE_RACINE,
Journal::NO_ID_D,
$journal_action,
$message_action . " du type de dossier id_t=$id_t. JSON contenant l'export de la definition du type de dossier : " . $export
);
$this->typeDossierActionService->add($id_u, $id_t, $action);
return $id_t;
}
......@@ -135,7 +119,7 @@ class TypeDossierEditionService
* @throws TypeDossierException
* @throws Exception
*/
public function editLibelleInfo($id_t, $nom, $type, $description, $nom_onglet)
public function editLibelleInfo($id_t, $nom, $type, $description, $nom_onglet, $id_u = 0)
{
$this->checkNomOnglet($nom_onglet);
$typeDossierProporties = $this->typeDossierManager->getTypeDossierProperties($id_t);
......@@ -143,7 +127,7 @@ class TypeDossierEditionService
$typeDossierProporties->type = $type;
$typeDossierProporties->description = $description;
$typeDossierProporties->nom_onglet = $nom_onglet;
$this->edit($id_t, $typeDossierProporties);
$this->edit($id_t, $typeDossierProporties, $id_u);
}
/**
......
......@@ -43,21 +43,23 @@ class TypeDossierImportService
}
/**
* @param int $id_u
* @param string $filepath
* @return array
* @throws TypeDossierException
*/
public function importFromFilePath(string $filepath): array
public function importFromFilePath(string $filepath, int $id_u = 0): array
{
return $this->import(file_get_contents($filepath));
return $this->import(file_get_contents($filepath), $id_u);
}
/**
* @param int $id_u
* @param $file_content
* @return array
* @throws TypeDossierException
*/
public function import(string $file_content): array
public function import(string $file_content, int $id_u = 0): array
{
$json_content = $this->checkFileContent($file_content);
$typeDossierProperties = $this->typeDossierManager->getTypeDossierFromArray($json_content[TypeDossierUtilService::RAW_DATA]);
......@@ -74,7 +76,7 @@ class TypeDossierImportService
$typeDossierProperties->id_type_dossier = $id_type_dossier;
try {
$id_t = $this->typeDossierEditionService->create($typeDossierProperties);
$id_t = $this->typeDossierEditionService->create($typeDossierProperties, $id_u);
} catch (Exception $e) {
throw new TypeDossierException("Impossible de créer le type de dossier : " . $e->getMessage());
}
......
......@@ -7,6 +7,7 @@
* @var int $id_t
* @var CSRFToken $csrfToken
* @var array $all_etape_type
* @var array $typeDossierAction
*/
?>
<a class='btn btn-link' href='<?php $this->url("TypeDossier/list")?>'>
......@@ -153,6 +154,39 @@
</div>
<div class="box" >
<a class="collapse-link" data-toggle="collapse" href="#collapseExample">
<h2> <i class="fa fa-plus-square"></i>&nbsp;États du type de dossier</h2>
</a>
<div class="collapse" id="collapseExample">
<table class="table table-striped">
<tr>
<th>État</th>
<th>Date</th>
<th>Utilisateur</th>
<th>Empreinte sha256</th>
<th>Export Json</th>
</tr>
<?php foreach ($typeDossierAction as $action) : ?>
<tr>
<td><?php echo $action['action'] ?></td>
<td><?php echo time_iso_to_fr($action['date'])?></td>
<td>
<?php if ($action['id_u'] == 0) : ?>
Action automatique