Commit 97a83a14 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Quasi finalisation de l'optimisation du calcul des TBLs

parent 026c1c2e
Loading
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -51,6 +51,23 @@ return [
        ],
    ],

    'console' => [
        'router' => [
            'routes' => [
                'unicaen-tbl' => [
                    'options' => [
                        'type'     => 'catchall',
                        'route'    => 'UnicaenTbl build-procedures',
                        'defaults' => [
                            'controller' => AdminController::class,
                            'action'     => 'build-procedures',
                        ],
                    ],
                ],
            ],
        ],
    ],
    
    'doctrine' => [
        'driver' => [
            'unicaen_tbl_driver' => [
@@ -105,7 +122,7 @@ return [
                ],
                [
                    'controller' => AdminController::class,
                    'action'     => ['update-actuproc'],
                    'action'     => ['build-procedures'],
                    'privileges' => [Privileges::UNICAEN_TBL_UPDATE_ACTUPROC],
                ],
                [
+11 −9
Original line number Diff line number Diff line
@@ -32,18 +32,15 @@ class AdminController extends AbstractActionController



    public function updateActuprocAction()
    public function buildProceduresAction()
    {
        echo 'Construction des procédures de mise à jour des tableaux de bord...'."\n";
        try {
            $this->getServiceQueryGenerator()->updateProcedures();
            $message = 'Mise à jour des packages d\'actualisation terminée.';
            echo 'Procédures finalisées'."\n";
        } catch (\Exception $e) {
            $message = 'Une erreur a été rencontrée.';
            throw new \UnicaenApp\Exception\LogicException("mise à jour impossible", null, $e);
            echo 'Une erreur a été rencontrée : '.$e->getMessage().'.'."\n";
        }
        $title = "Résultat";

        return compact('message', 'title');
    }


@@ -57,14 +54,19 @@ class AdminController extends AbstractActionController
        }

        $form = $this->getFormActualisation();
        $options = $this->getServiceSchema()->getTableauBords()[$tableauBord]->getColumns();
        $options = array_keys($options);
        $options = array_combine($options,$options);
        $form->get('param')->setValueOptions($options);
        $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);
                    $param = $form->get('param')->getValue();
                    $value = $form->get('value')->getValue();
                    $this->getServiceTableauBord()->calculer($tableauBord, $param, $value);
                    $this->flashMessenger()->addSuccessMessage('Actualisation réussie');
                }catch(\Exception $e){
                    $this->flashMessenger()->addErrorMessage($e->getMessage());
+29 −0
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@ class Column
     */
    protected $key;

    /**
     * @var bool
     */
    protected $inView = true;



    /**
@@ -96,6 +101,30 @@ class Column



    /**
     * @return bool
     */
    public function isInView(): bool
    {
        return $this->inView;
    }



    /**
     * @param bool $inView
     *
     * @return Column
     */
    public function setInView(bool $inView): Column
    {
        $this->inView = $inView;

        return $this;
    }



    /**
     * The __toString method allows a class to decide how it will react when it is converted to a string.
     *
+17 −42
Original line number Diff line number Diff line
@@ -17,17 +17,22 @@ class ActualisationForm extends Form implements InputFilterProviderInterface

    public function init()
    {
        for ($i = 1; $i <= 5; $i++) {
        $this->add([
                'name' => 'c' . $i,
                'type' => 'Text',
            'name'    => 'param',
            'type'    => 'Select',
            'options' => [
                'label'        => 'Nom du champ éventuel',
                'empty_option' => "- Tout sans filtre -",
            ],
        ]);

        $this->add([
                'name' => 'v' . $i,
            'name'    => 'value',
            'type'    => 'Text',
            'options' => [
                'label' => 'Valeur',
            ],
        ]);
        }

        $this->add([
            'name'       => 'submit',
@@ -41,28 +46,6 @@ class ActualisationForm extends Form implements InputFilterProviderInterface



    /**
     * @param  $object
     *
     * @return array
     */
    public function extractArrayParams()
    {
        $data = [];

        for ($i = 1; $i <= 5; $i++) {
            $c = $this->get('c' . $i)->getValue();
            $v = $this->get('v' . $i)->getValue();
            if (!empty($c)) {
                $data[$c] = $v;
            }
        }

        return $data;
    }



    /**
     * Should return an array specification compatible with
     * {@link Zend\InputFilter\Factory::createInputFilter()}.
@@ -72,16 +55,8 @@ class ActualisationForm extends Form implements InputFilterProviderInterface
    public function getInputFilterSpecification()
    {
        return [
            'c1' => ['required' => false],
            'v1' => ['required' => false],
            'c2' => ['required' => false],
            'v2' => ['required' => false],
            'c3' => ['required' => false],
            'v3' => ['required' => false],
            'c4' => ['required' => false],
            'v4' => ['required' => false],
            'c5' => ['required' => false],
            'v5' => ['required' => false],
            'param' => ['required' => false],
            'value' => ['required' => false],
        ];
    }

+28 −18
Original line number Diff line number Diff line
@@ -259,14 +259,27 @@ class QueryGeneratorService extends AbstractService
            $colLen   = strlen($column);
            $colAjust = str_pad('', $maxColLen - $colLen);

            if ($column->isInView()) {
                if ($column->isNullable()) {
                    $testDiff[] = "COALESCE(t.$column,0)$colAjust = COALESCE(v.$column,0)\n";
                } else {
                    $testDiff[] = "t.$column$colAjust             = v.$column\n";
                }
            }
            if ($column == 'ID') {
                $cols[] = 'ID';
            } else {
                $cols[] = "v.$column";
            }
        }
        $testDiff = trim(implode("        AND ", $testDiff));
        foreach ($cols as $c => $col) {
            if ('ID' == $col) {
                $cols[$c] = "CASE WHEN 
            $testDiff
      THEN -1 ELSE t.ID END ID";
            }
        }
        $cols = trim(implode(",\n      ", $cols));

        $view = $this->getViewDefinition($view);
@@ -292,9 +305,6 @@ class QueryGeneratorService extends AbstractService
    
    OPEN c FOR '
    SELECT
      CASE WHEN 
            $testDiff
      THEN -1 ELSE t.ID END ID,
      $cols
    FROM
      (' || QUERY_APPLY_PARAM(viewQuery,param,value) || ') v
@@ -311,7 +321,7 @@ class QueryGeneratorService extends AbstractService
            $testNull
      THEN
        DELETE FROM $table WHERE id = d.id;
      ELSIF d.id != -1 THEN
      ELSIF d.id <> -1 THEN
        UPDATE $table SET row = d WHERE id = d.id;
      END IF;
    END LOOP;
Loading