Commit 5ad06f89 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Mise à jour majeure d'UnicaenTbl : on s'approche d'une vraie V1!!

Au menu :
 - architecture compatible ZF3
 - possibilité d'actualiser les tableaux de bord depuis l'interface, avec éventuellement des paramètres comme un intervenant, une année, etc. (utile en cas de pb de trigger ou autre)
 - interface de gestion qui présente la liste des tableaux de bord et leurs spécifications
 - possibilité de réactualiser les procédures d'actualisation des tableaux de bord (comme pour les vues et procédures d'UnicaenImport)
parent 6e1a737e
......@@ -2,5 +2,4 @@
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'UnicaenTbl\Module' => __DIR__ . '/Module.php',
// 'UnicaenTbl\Options\ModuleOptions' => __DIR__ . '/src/UnicaenTbl/Options/ModuleOptions.php',
);
......@@ -3,9 +3,54 @@
namespace UnicaenTbl;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenTbl\Controller\AdminController;
use UnicaenTbl\Form\ActualisationForm;
use UnicaenTbl\Options\ModuleOptions;
use UnicaenTbl\Provider\Privilege\Privileges;
use UnicaenTbl\Service\QueryGeneratorService;
use UnicaenTbl\Service\SchemaService;
use UnicaenTbl\Service\TableauBordService;
return [
'router' => [
'routes' => [
'unicaen-tbl' => [
'type' => 'Literal',
'options' => [
'route' => '/unicaen-tbl',
'defaults' => [
'controller' => AdminController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'update-actuproc' => [
'type' => 'Literal',
'options' => [
'route' => '/update-actuproc',
'defaults' => [
'action' => 'update-actuproc',
],
],
'may_terminate' => true,
],
'actualisation' => [
'type' => 'Segment',
'options' => [
'route' => '/actualisation/:tableauBord',
'defaults' => [
'action' => 'actualisation',
],
],
'may_terminate' => true,
],
],
],
],
],
'doctrine' => [
'driver' => [
'unicaen_tbl_driver' => [
......@@ -29,11 +74,46 @@ return [
],
],
'controllers' => [
'factories' => [
AdminController::class => Controller\Factory\AdminControllerFactory::class,
],
],
'service_manager' => [
'factories' => [
'UnicaenTbl\Options\Module' => Options\ModuleOptionsFactory::class,
'UnicaenTbl\Service\Schema' => Service\SchemaServiceFactory::class,
'UnicaenTbl\Service\QueryGenerator' => Service\QueryGeneratorServiceFactory::class,
ModuleOptions::class => Options\Factory\ModuleOptionsFactory::class,
SchemaService::class => Service\Factory\SchemaServiceFactory::class,
QueryGeneratorService::class => Service\Factory\QueryGeneratorServiceFactory::class,
TableauBordService::class => Service\Factory\TableauBordServiceFactory::class,
],
],
'form_elements' => [
'factories' => [
ActualisationForm::class => Form\Factory\ActualisationFormFactory::class,
],
],
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
[
'controller' => AdminController::class,
'action' => ['index'],
'privileges' => [Privileges::UNICAEN_TBL_ADMIN],
],
[
'controller' => AdminController::class,
'action' => ['update-actuproc'],
'privileges' => [Privileges::UNICAEN_TBL_UPDATE_ACTUPROC],
],
[
'controller' => AdminController::class,
'action' => ['actualisation'],
'privileges' => [Privileges::UNICAEN_TBL_ACTUALISATION],
],
],
],
],
......
/*********************************************************************************************
* Privilèges
*********************************************************************************************/
/
insert into CATEGORIE_PRIVILEGE (ID, CODE, LIBELLE, ORDRE) values (
CATEGORIE_PRIVILEGE_ID_SEQ.NEXTVAL,
'unicaen-tbl',
'Tableaux de bord',
999
);
/
insert into PRIVILEGE (ID, CATEGORIE_ID, CODE, LIBELLE, ORDRE) select
PRIVILEGE_ID_SEQ.NEXTVAL,
cat.id,
'admin',
'Gestion des tableaux de bord',
1
from CATEGORIE_PRIVILEGE cat where code = 'unicaen-tbl';
<?php
namespace UnicaenTbl\Controller;
use UnicaenTbl\Form\Traits\ActualisationFormAwareTrait;
use UnicaenTbl\Service\Traits\QueryGeneratorServiceAwareTrait;
use UnicaenTbl\Service\Traits\SchemaServiceAwareTrait;
use UnicaenTbl\Service\Traits\TableauBordServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
/**
*
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
*/
class AdminController extends AbstractActionController
{
use SchemaServiceAwareTrait;
use QueryGeneratorServiceAwareTrait;
use ActualisationFormAwareTrait;
use TableauBordServiceAwareTrait;
public function indexAction()
{
$tbls = $this->getServiceSchema()->getTableauBords();
return compact('tbls');
}
public function updateActuprocAction()
{
try {
$this->getServiceQueryGenerator()->updateProcedures();
$message = 'Mise à jour des packages d\'actualisation terminée.';
} catch (\Exception $e) {
$message = 'Une erreur a été rencontrée.';
throw new \UnicaenApp\Exception\LogicException("mise à jour impossible", null, $e);
}
$title = "Résultat";
return compact('message', 'title');
}
public function actualisationAction()
{
$tableauBord = $this->params()->fromRoute('tableauBord');
if (!$tableauBord) {
throw new \LogicException('Le tableau de bord n\'a pas été spécifié');
}
$form = $this->getFormActualisation();
$form->setAttribute('action', $this->url()->fromRoute('unicaen-tbl/actualisation', ['tableauBord' => $tableauBord]));
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if ($form->isValid()) {
try{
$params = $form->extractArrayParams();
$this->getServiceTableauBord()->calculer($tableauBord, $params);
$this->flashMessenger()->addSuccessMessage('Actualisation réussie');
}catch(\Exception $e){
$this->flashMessenger()->addErrorMessage($e->getMessage());
}
}
}
return compact('form');
}
}
\ No newline at end of file
<?php
namespace UnicaenTbl\Controller\Factory;
use UnicaenTbl\Controller\AdminController;
use UnicaenTbl\Form\ActualisationForm;
use UnicaenTbl\Service\QueryGeneratorService;
use UnicaenTbl\Service\SchemaService;
use UnicaenTbl\Service\TableauBordService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class AdminControllerFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
*
* @return AdminController
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$controller = new AdminController();
$sl = $serviceLocator->getServiceLocator();
$controller->setServiceSchema(
$sl->get(SchemaService::class)
);
$controller->setServiceQueryGenerator(
$sl->get(QueryGeneratorService::class)
);
$controller->setServiceTableauBord(
$sl->get(TableauBordService::class)
);
$controller->setFormActualisation(
$sl->get('FormElementManager')->get(ActualisationForm::class)
);
return $controller;
}
}
?>
\ No newline at end of file
<?php
namespace UnicaenTbl\Entity;
class Column
{
/**
* Nom de la colonne du tableau de bord
*
* @var string
*/
protected $name;
/**
* @var bool
*/
protected $nullable;
/**
* @var bool
*/
protected $key;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return Column
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return bool
*/
public function isNullable()
{
return $this->nullable;
}
/**
* @param bool $nullable
*
* @return Column
*/
public function setNullable($nullable)
{
$this->nullable = $nullable;
return $this;
}
/**
* @return bool
*/
public function isKey()
{
return $this->key;
}
/**
* @param bool $key
*
* @return Column
*/
public function setKey($key)
{
$this->key = $key;
return $this;
}
/**
* The __toString method allows a class to decide how it will react when it is converted to a string.
*
* @return string
* @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
*/
function __toString()
{
return $this->getName();
}
}
\ No newline at end of file
......@@ -2,6 +2,11 @@
namespace UnicaenTbl\Entity;
/**
* Class TableauBord
*
* @package UnicaenTbl\Entity
*/
class TableauBord
{
......@@ -38,16 +43,19 @@ class TableauBord
protected $customCalculProc;
/**
* @var string[]
* @var Column[]
*/
protected $keyColumns = [];
protected $columns = [];
/**
* @var string[]
* @var self[]
*/
protected $columns = [];
protected $depsPost = [];
/**
* @var self[]
*/
protected $depsPre = [];
......@@ -78,8 +86,14 @@ class TableauBord
/**
* @return string
*/
public function getTableName()
public function getTableName($byTblNameIfNull = false)
{
if (!$this->tableName && $byTblNameIfNull) {
$tableName = strtoupper($this->name);
return $tableName;
}
return $this->tableName;
}
......@@ -102,8 +116,14 @@ class TableauBord
/**
* @return string
*/
public function getViewName()
public function getViewName($byTblNameIfNull = false)
{
if (!$this->viewName && $byTblNameIfNull) {
$viewName = strtoupper('V_TBL_' . substr($this->name, 0, 24));
return $viewName;
}
return $this->viewName;
}
......@@ -126,8 +146,14 @@ class TableauBord
/**
* @return string
*/
public function getConstraintName()
public function getConstraintName($byTblNameIfNull = false)
{
if (!$this->constraintName && $byTblNameIfNull) {
$constraintName = strtoupper(substr($this->name, 0, 26) . '__UN');
return $constraintName;
}
return $this->constraintName;
}
......@@ -150,8 +176,14 @@ class TableauBord
/**
* @return string
*/
public function getSequenceName()
public function getSequenceName($byTblNameIfNull = false)
{
if (!$this->sequenceName && $byTblNameIfNull) {
$sequenceName = strtoupper(substr($this->tableName, 0, 23) . '_ID_SEQ');
return $sequenceName;
}
return $this->sequenceName;
}
......@@ -196,23 +228,57 @@ class TableauBord
/**
* @return \string[]
* @return Column[]
*/
public function getKeyColumns()
{
return $this->keyColumns;
$key = [];
foreach ($this->columns as $column) {
if ($column->isKey()) {
$key[$column->getName()] = $column;
}
}
return $key;
}
/**
* @return Column[]
*/
public function getColumns()
{
return $this->columns;
}
/**
* @param Column $column
*
* @return $this
*/
public function addColumn(Column $column)
{
$this->columns[$column->getName()] = $column;
return $this;
}
/**
* @param \string[] $keyColumns
* @param $column
*
* @return TableauBord
* @return $this
*/
public function setKeyColumns($keyColumns)
public function removeColumn($column)
{
$this->keyColumns = $keyColumns;
if ($column instanceof Column) {
$column = $column->getName();
}
unset($this->columns[$column]);
return $this;
}
......@@ -220,25 +286,112 @@ class TableauBord
/**
* @return \string[]
* @return TableauBord[]
*/
public function getColumns()
public function getDepsPost()
{
return $this->columns;
return $this->depsPost;
}
/**
* @param \string[] $columns
* @param TableauBord $tableauBord
*
* @return TableauBord
* @return bool
*/
public function isDepPost(TableauBord $tableauBord)
{
return isset($this->depsPost[$tableauBord->getName()]);
}
/**
* @param TableauBord $tableauBord
*
* @return $this
*/
public function setColumns($columns)
public function addDepPost(TableauBord $tableauBord)
{
$this->columns = $columns;
$this->depsPost[$tableauBord->getName()] = $tableauBord;
if (!$tableauBord->isDepPre($this)){
$tableauBord->addDepPre($this);
}
return $this;
}
/**
* @param TableauBord|string $tableauBord
*
* @return $this
*/
public function removeDepPost($tableauBord)
{
unset($this->depsPost[$tableauBord]);
if ($tableauBord->isDepPre($this)) {
$tableauBord->removeDepPre($this);
}
return $this;
}
/**
* @return TableauBord[]
*/
public function getDepsPre()
{
return $this->depsPre;
}
/**
* @param TableauBord $tableauBord
*
* @return bool
*/
public function isDepPre(TableauBord $tableauBord)
{
return isset($this->depsPre[$tableauBord->getName()]);
}