Commit 3726eb4d authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

[WIP] Notif quand forçage correction attendue

parent 58198630
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
<?php

namespace Application\Entity\Db;

class DataObserv extends \UnicaenDbImport\Entity\Db\ImportObserv
{
    const CODE_RESULTAT_PASSE_A_ADMIS = 'RESULTAT_PASSE_A_ADMIS';
    const CODE_CORRECTION_PASSE_A_FACULTATIVE = 'CORRECTION_PASSE_A_FACULTATIVE';
    const CODE_CORRECTION_PASSE_A_OBLIGATOIRE = 'CORRECTION_PASSE_A_OBLIGATOIRE';

    const CODES = [
        self::CODE_RESULTAT_PASSE_A_ADMIS,
        self::CODE_CORRECTION_PASSE_A_FACULTATIVE,
        self::CODE_CORRECTION_PASSE_A_OBLIGATOIRE,
    ];
}
+106 −0
Original line number Diff line number Diff line
<?php

namespace Application\Entity\Db;

use These\Entity\Db\These;
use DateTime;
use UnicaenDbImport\Entity\Db\AbstractImportObserv;

class ImportObservResult extends \UnicaenDbImport\Entity\Db\ImportObservResult
{
    /**
     * @var DateTime
     */
    protected $dateLimiteNotif;

    /**
     * @var ImportObserv
     */
    protected $importObserv;

    /**
     * @param ImportObserv $importObserv
     */
    public function setImportObserv(AbstractImportObserv $importObserv)
    {
        $this->importObserv = $importObserv;
    }

    /**
     * @return ImportObserv
     */
    public function getImportObserv(): AbstractImportObserv
    {
        return $this->importObserv;
    }

    /**
     * @return string
     */
    public function getResultatToString()
    {
        switch ($this->getImportObserv()->getTableName()) {
            case 'THESE':
                return $this->getResultatToStringForThese();
            default:
                return $this->getResultat();
        }
    }

    /**
     * @return string
     */
    private function getResultatToStringForThese()
    {
        switch ($this->getImportObserv()->getColumnName()) {
            case 'RESULTAT':
                $values = explode('>', $this->getResultat());
                $values[0] = $values[0] <> "" ? These::$resultatsLibellesLongs[$values[0]] : "Aucun";
                $values[1] = $values[1] <> "" ? These::$resultatsLibellesLongs[$values[1]] : "Aucun";
                return "Résultat: $values[0] => $values[1]";
            case 'CORREC_AUTORISEE':
                $values = explode('>', $this->getResultat());
                $values[0] = $values[0] <> "" ? These::$correctionsLibelles[$values[0]] : "Aucune";
                $values[1] = $values[1] <> "" ? These::$correctionsLibelles[$values[1]] : "Aucune";
                return "Correction attendue: $values[0] => $values[1]";
            default:
                return $this->getResultat();
        }
    }

    /**
     * @return DateTime
     */
    public function getDateLimiteNotif(): DateTime
    {
        // Solution provisoire pour avoir un moyen de ne pas notifier si l'observation est trop vieille.
        if ($this->dateLimiteNotif === null) {
            $this->dateLimiteNotif = $this->dateCreation->add(new \DateInterval('P1D')); // 1 jour
        }
        //

        return $this->dateLimiteNotif;
    }

    /**
     * @param DateTime|null $dateLimiteNotif
     * @return self
     */
    public function setDateLimiteNotif(?DateTime $dateLimiteNotif = null): self
    {
        $this->dateLimiteNotif = $dateLimiteNotif;
        return $this;
    }

    /**
     * @return bool
     */
    public function isDateLimiteNotifDepassee(): bool
    {
        if ($this->getDateLimiteNotif() === null) {
            return false;
        }

        return date_create() > $this->getDateLimiteNotif();
    }
}
+11 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Application\Entity\Db\DataObserv" table="data_observ">

        <id name="id" type="integer" column="id"/>

    </entity>
</doctrine-mapping>
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Application\Entity\Db\DataObservResult"
            table="data_observ_result"
            repository-class="Application\Entity\Db\DataObservResultRepository">

        <id name="id" type="integer" column="id"/>

        <many-to-one field="dataObserv" target-entity="Application\Entity\Db\DataObserv">
            <join-columns>
                <join-column name="data_observ_id"/>
            </join-columns>
        </many-to-one>

        <many-to-one field="source" target-entity="Application\Entity\Db\Source">
            <join-columns>
                <join-column name="source_id"/>
            </join-columns>
        </many-to-one>

    </entity>
</doctrine-mapping>
+69 −0
Original line number Diff line number Diff line
<?php

namespace Application\Entity\Db\Repository;

use Application\SourceCodeStringHelperAwareTrait;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Application\Entity\Db\DataObserv;
use Application\Entity\Db\DataObservResult;
use UnicaenApp\Exception\RuntimeException;

class DataObservResultRepository extends DefaultEntityRepository
{
    use SourceCodeStringHelperAwareTrait;

    /**
     * Recherche des résultats d'observation.
     *
     * @return \Application\Entity\Db\DataObservResult[]
     */
    public function fetchDataObservResults(DataObserv $importObserv, array $criteria = []): array
    {
        switch ($importObserv->getCode()) {
            case DataObserv::CODE_RESULTAT_PASSE_A_ADMIS:
            case DataObserv::CODE_CORRECTION_PASSE_A_FACULTATIVE:
                $qb = $this->createDataObservResultsQueryBuilder($importObserv, $criteria);
                $qb->andWhere('ior.dateNotif is null'); // aucune notification ne doit avoir été faite
                break;
            case DataObserv::CODE_CORRECTION_PASSE_A_OBLIGATOIRE:
                $qb = $this->createDataObservResultsQueryBuilder($importObserv, $criteria);
                $qb->andWhere('ior.dateNotif is null OR ior.dateNotif is not null'); // une notif peut avoir été faite ou non
                break;
            default:
                throw new RuntimeException("Cas non prévu!");
        }

        /** @var DataObservResult[] $records */
        $records = $qb->getQuery()->getResult();

        return $records;
    }

    private function createDataObservResultsQueryBuilder(DataObserv $importObserv, array $criteria = []): QueryBuilder
    {
        $qb = $this->createQueryBuilder('ior')
            ->addSelect('io')
            ->join('ior.importObserv', 'io', Join::WITH, 'io = :io')
            ->andWhere('io.enabled = true')
            ->setParameter('io', $importObserv);

        /** @var \Application\Entity\Db\Source|null $source */
        $source = $criteria['source'] ?? null;
        if ($source !== null) {
            $qb
                ->andWhere('ior.source = :source')
                ->setParameter('source', $source->getId());
        }

        /** @var \These\Entity\Db\These|null $these */
        $these = $criteria['these'] ?? null;
        if ($these !== null) {
            $qb
                ->andWhere('ior.sourceCode = :sourceCode')
                ->setParameter('sourceCode', $these->getSourceCode());
        }

        return $qb;
    }
}
 No newline at end of file
Loading