Commit b9e15580 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Entité FichierThese (ex-Fichier) : abandon des get/setEstAnnexe() et...

Entité FichierThese (ex-Fichier) : abandon des get/setEstAnnexe() et get/setEstExpturge() deprecated.
parent 28a049e0
Loading
Loading
Loading
Loading
+3 −161
Changes for module/Application/src/Application/Entity/Db/FichierThese.php: 3 added lines, 161 removed lines.
Original line number Diff line number Diff line
@@ -81,7 +81,9 @@ class FichierThese implements ResourceInterface
     */
    public function supporteTestValidite()
    {
        return ! $this->getEstAnnexe() && ! $this->getEstExpurge();
        $fichier = $this->getFichier();

        return $fichier->getNature()->estThesePdf() && ! $fichier->getVersion()->estVersionDiffusion();
    }

    /**
@@ -94,27 +96,6 @@ class FichierThese implements ResourceInterface
        return $this->id;
    }

    /**
     * @return boolean
     * @deprecated Exploiter la NatureFichier
     */
    public function getEstAnnexe()
    {
        return $this->estAnnexe;
    }

    /**
     * @param boolean $estAnnexe
     * @return self
     * @deprecated Exploiter la NatureFichier
     */
    public function setEstAnnexe($estAnnexe = true)
    {
        $this->estAnnexe = $estAnnexe;

        return $this;
    }

    /**
     * @return bool
     */
@@ -150,27 +131,6 @@ class FichierThese implements ResourceInterface
        return $this;
    }

    /**
     * @return boolean
     * @deprecated Redondant avec la version du fichier (version de diffusion)
     */
    public function getEstExpurge()
    {
        return $this->estExpurge;
    }

    /**
     * @param boolean $estExpurge
     * @return self
     * @deprecated Redondant avec la version du fichier (version de diffusion)
     */
    public function setEstExpurge($estExpurge = true)
    {
        $this->estExpurge = $estExpurge;

        return $this;
    }

    /**
     * Retourne :
     * - <code>1</code> si le thésard a certifié que le fichier de thèse était conforme ;
@@ -274,121 +234,3 @@ class FichierThese implements ResourceInterface
        return self::RESOURCE_ID;
    }
}




class FichierTheseFiltering
{
    /**
     * @param int|bool $estExpurge
     * @return \Closure
     */
    static public function getFilterByExpurge($estExpurge = true)
    {
        return function(FichierThese $fichier = null) use ($estExpurge) {
            if ($estExpurge === null) {
                return $fichier;
            }
            if ($fichier === null) {
                return null;
            }

            $actual = $fichier->getEstExpurge();
            $expected = (bool) $estExpurge;

            return $actual === $expected ? $fichier : null;
        };
    }

    /**
     * @param int|bool $estAnnexe
     * @return \Closure
     */
    static public function getFilterByAnnexe($estAnnexe = true)
    {
        return function(FichierThese $fichier = null) use ($estAnnexe) {
            if ($estAnnexe === null) {
                return $fichier;
            }
            if ($fichier === null) {
                return null;
            }

            $actual = $fichier->getEstAnnexe();
            $expected = (bool) $estAnnexe;

            return $actual === $expected ? $fichier : null;
        };
    }

    /**
     * @param int|bool|string $estRetraite '0', '1', booléen ou code du retraitement
     * @return \Closure
     */
    static public function getFilterByRetraitement($estRetraite = true)
    {
        return function(FichierThese $fichier = null) use ($estRetraite) {
            if ($estRetraite === null) {
                return $fichier;
            }
            if ($fichier === null) {
                return null;
            }

            $actual = $fichier->getRetraitement();
            $expected = $estRetraite;

            if (is_numeric($expected) || is_bool($expected)) {
                $expected = (bool) $estRetraite;
                $actual = (bool) $actual;
            }

            return $actual === $expected ? $fichier : null;
        };
    }

    /**
     * @param NatureFichier|string $nature
     * @return \Closure
     */
    static public function getFilterByNature($nature = null)
    {
        return function(FichierThese $fichier = null) use ($nature) {
            if ($nature === null) {
                return $fichier;
            }
            if ($fichier === null) {
                return null;
            }

            if ($nature instanceof NatureFichier) {
                $nature = $nature->getCode();
            }

            return $nature === $fichier->getFichier()->getNature()->getCode() ? $fichier : null;
        };
    }

    /**
     * @param VersionFichier|string $version
     * @return \Closure
     */
    static public function getFilterByVersion($version = null)
    {
        return function(FichierThese $fichier = null) use ($version) {
            if ($version === null) {
                return $fichier;
            }
            if ($fichier === null) {
                return null;
            }

            if ($version instanceof VersionFichier) {
                $version = $version->getCode();
            }

            return $version === $fichier->getFichier()->getVersion()->getCode() ? $fichier : null;
        };
    }
}
 No newline at end of file
+0 −112
Changes for module/Application/src/Application/Filter/FichierFilter.php: 0 added lines, 112 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Filter;

use Application\Entity\Db\FichierThese;
use Application\Entity\Db\FichierTheseFiltering;
use Application\Entity\Db\VersionFichier;
use Doctrine\Common\Collections\Collection;
use Zend\Filter\FilterChain;
use Zend\Filter\FilterInterface;

class FichierFilter implements FilterInterface
{
    /**
     * @return static
     */
    static public function inst()
    {
        return new static();
    }

    /**
     * Filtre la collection de fichiers.
     *
     * @param  Collection $collection
     * @return Collection
     */
    public function filter($collection)
    {
        $chain = new FilterChain();
        if ($this->estAnnexe !== null) {
            $chain->attach(FichierTheseFiltering::getFilterByAnnexe($this->estAnnexe));
        }
        if ($this->estExpurge !== null) {
            $chain->attach(FichierTheseFiltering::getFilterByExpurge($this->estExpurge));
        }
        if ($this->estRetraite !== null) {
            $chain->attach(FichierTheseFiltering::getFilterByRetraitement($this->estRetraite));
        }
        if ($this->version !== null) {
            $chain->attach(FichierTheseFiltering::getFilterByVersion($this->version));
        }

        return $collection->filter(function(FichierThese $f) use ($chain) {
            return (bool) $chain->filter($f);
        });
    }

    /**
     * @var int|bool
     */
    protected $estAnnexe;

    /**
     * @var int|bool
     */
    protected $estExpurge;

    /**
     * @var int|bool|string
     */
    protected $estRetraite;

    /**
     * @var VersionFichier|string
     */
    protected $version;

    /**
     * @param bool|int $estAnnexe
     * @return FichierFilter
     */
    public function annexe($estAnnexe)
    {
        $this->estAnnexe = $estAnnexe;

        return $this;
    }

    /**
     * @param bool|int $estExpurge
     * @return FichierFilter
     */
    public function expurge($estExpurge)
    {
        $this->estExpurge = $estExpurge;

        return $this;
    }

    /**
     * @param bool|int|string $estRetraite
     * @return FichierFilter
     */
    public function retraite($estRetraite)
    {
        $this->estRetraite = $estRetraite;

        return $this;
    }

    /**
     * @param VersionFichier|string $version
     * @return FichierFilter
     */
    public function version($version)
    {
        $this->version = $version;

        return $this;
    }
}
+1 −1
Changes for module/Application/src/Application/Filter/NomFichierFormatter.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ class NomFichierFormatter extends AbstractFilter
                break;
        }

        if ($fichierThese->getEstAnnexe()) {
        if ($fichierThese->getFichier()->getNature()->estFichierNonPdf()) {
            $parts['annexe'] = 'ANNEXE';
        }

+1 −3
Changes for module/Application/src/Application/Service/FichierThese/FichierTheseService.php: 1 added line, 3 removed lines.
Original line number Diff line number Diff line
@@ -164,7 +164,6 @@ class FichierTheseService extends BaseService
            $fichierThese
                ->setFichier($fichier)
                ->setThese($these)
                ->setEstAnnexe($nature->estFichierNonPdf())
                ->setRetraitement($retraitement);

            // à faire en dernier car le formatter exploite des propriétés du FichierThese
@@ -272,8 +271,7 @@ class FichierTheseService extends BaseService
        $fichierTheseRetraite
            ->setFichier($fichier)
            ->setThese($these)
            ->setEstPartiel(true)
            ->setEstAnnexe($fichierThese->getEstAnnexe());
            ->setEstPartiel(true);

        $fichierTheseRetraite->setRetraitement(FichierThese::RETRAITEMENT_AUTO);

+2 −3
Changes for module/Application/tests/ApplicationUnitTest/Test/Asset/EntityAsset.php: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@ use Application\Entity\Db\MetadonneeThese;
use Application\Entity\Db\NatureFichier;
use Application\Entity\Db\RdvBu;
use Application\Entity\Db\Role;
use Application\Entity\Db\Source;
use Application\Entity\Db\These;
use Application\Entity\Db\TypeValidation;
use Application\Entity\Db\Utilisateur;
use Application\Entity\Db\Validation;
use Application\Entity\Db\ValiditeFichier;
use Application\Entity\Db\VersionFichier;
use Application\Entity\Db\Source;

/**
 * Données de tests.
@@ -64,8 +64,7 @@ class EntityAsset
        $e = new FichierThese();
        $e
            ->setFichier($fichier)
            ->setThese($these)
            ->setEstAnnexe($fichier->getNature()->estFichierNonPdf());
            ->setThese($these);

        return $e;
    }