Commit 1958aaea authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Retrait de et de (classes inutilisées)

parent 84fec862
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ Journal des modifications

4.2.1
-----
- Retrait de `IntervenantEmailFormatter` et de `IntervenantTrouveFormatter` (classes inutilisées)
- Changement du terme Établissement par Site dans l'affichage des rôles des EDs et des URs pour éviter la confusion
- [FIX] retrait d'un début faisant planter la génération de convaocation de soutenance 

+0 −78
Changes for module/Application/src/Application/Filter/IntervenantEmailFormatter.php: 0 added lines, 78 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Filter;

use Application\Entity\Db\Intervenant;
use Laminas\Filter\AbstractFilter;

class IntervenantEmailFormatter extends AbstractFilter
{
    private $intervenantsWithNoEmail = [];

    /**
     * Returns the result of filtering $value
     *
     * @param  mixed $value Un ou plusieurs objets de type Intervenant
     * @throws \RuntimeException If filtering $value is impossible
     * @throws \RuntimeException Rencontre d'un intervenant sans adresse mail
     * @return array email => name
     */
    public function filter($value)
    {
        $this->intervenantsWithNoEmail = [];

        return $this->filterRecursive($value);
    }

    private function filterRecursive($value)
    {
        $emails = [];

        if ($value instanceof Intervenant) {
            $intervenant = $value;
            $email = $intervenant->getEmailPerso(true);
            if (! $email) {
                $this->intervenantsWithNoEmail[$intervenant->getSourceCode()] = $intervenant;
            }

            $emails = [
                $email => $intervenant->getNomComplet()
            ];
        }
        elseif (is_array($value)) {
            foreach ($value as $intervenant) {
                $emails = array_merge($emails, $this->filterRecursive($intervenant));
            }
        }
        else {
            throw new \RuntimeException("Type d'entrée attendue : Intervenant ou Intervenant[].");
        }

        return $emails;
    }

    /**
     * Retourne les intervenants sans adresse mail rencontrés lors du filtrage.
     *
     * @return array Intervenant[]
     */
    public function getIntervenantsWithNoEmail()
    {
        return $this->intervenantsWithNoEmail;
    }

    /**
     * Convenient method.
     *
     * @param mixed $value
     * @return array
     * @throws \RuntimeException If filtering $value is impossible
     * @throws \RuntimeException Rencontre d'un intervenant sans adresse mail
     */
    static public function filtered($value)
    {
        $instance = new static();

        return $instance->filter($value);
    }
}
 No newline at end of file
+0 −100
Changes for module/Application/src/Application/Filter/IntervenantTrouveFormatter.php: 0 added lines, 100 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Filter;

use Laminas\Filter\AbstractFilter;
use Application\Entity\Db\IntervenantInterface;
use stdClass;
use Application\Constants;

/**
 * Formatte un intervenant pour le transmettre à l'élément de formulaire SearchAndSelect.
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 * @see \UnicaenApp\Form\Element\SearchAndSelect
 */
class IntervenantTrouveFormatter extends AbstractFilter
{
    /**
     * @var NomCompletFormatter
     */
    protected $nomCompletFormatter;

    /**
     * Constructeur.
     *
     * @param IntervenantInterface|stdClass|array $intervenant
     */
    public function __construct()
    {
        $this->nomCompletFormatter = new NomCompletFormatter(true, false, true);
    }

    /**
     * Returns the result of filtering $value
     *
     * @param IntervenantInterface|stdClass|array $value
     * @return string
     */
    public function filter($value)
    {
        // normalisation
        if ($value instanceof IntervenantInterface) {
            /* @var $value IntervenantInterface */
            $id        = $value->getSourceCode();
            $label     = $this->nomCompletFormatter->filter($value);
            $civilite  = $value->getCiviliteToString();
            $dateNaiss = $value->getDateNaissance();
            $feminin   = $value->estUneFemme();
            $affectat  = $value->getAffectationsToString();
        }
        else if ($value instanceof \stdClass) {
            foreach (['civilite', 'sourceCode', 'dateNaissance', 'estUneFemme', 'affectation'] as $prop) {
                if (!isset($value->$prop)) {
                    throw new \LogicException("L'objet à formatter doit posséder l'attribut public '$prop'.");
                }
            }
            $id        = $value->sourceCode;
            $label     = $this->nomCompletFormatter->filter($value);
            $civilite  = $value->civilite;
            $dateNaiss = $value->dateNaissance;
            $feminin   = $value->estUneFemme();
            $affectat  = $value->affectation;
        }
        else if (is_array($value)) {
            foreach (['civilite', 'source_code', 'date_naissance', 'est_une_femme', 'affectation'] as $prop) {
                if (!array_key_exists($prop, $value)) {
                    throw new \LogicException("Le tableau à formatter doit posséder la clé '$prop'.");
                }
            }
            $id        = $value['source_code'];
            $label     = $this->nomCompletFormatter->filter($value);
            $civilite  = $value['civilite'];
            $dateNaiss = $value['date_naissance'];
            $feminin   = $value['est_une_femme'];
            $affectat  = $value['affectation'];
        }
        else {
            throw new \LogicException("L'objet à formatter n'est pas d'un type supporté.");
        }

        if (!$dateNaiss instanceof \DateTime) {
            $dateNaiss = new \DateTime($dateNaiss);
        }

        $extra  = sprintf("(%s, né%s le %s, n°%s, %s)",
                $civilite,
                (boolean) $feminin ? 'e' : '',
                $dateNaiss->format(Constants::DATE_FORMAT),
                $id ?: "Inconnu",
                $affectat ?: "Affectation inconnue");

        $result = [
            'id'    => $id,
            'label' => $label,
            'extra' => $extra,
        ];

	return $result;
    }
}
 No newline at end of file