Projet

Général

Profil

Actions

Evolution #1001

fermé

Empêcher les adhérents de rentrer la date actuelle à la place de la ddn

Ajouté par Amaury Froment il y a environ 7 ans. Mis à jour il y a presque 6 ans.

Statut:
Fermé
Priorité:
Normal
Assigné à:
Catégorie:
Core
Version cible:
Début:
21/01/2017
Echéance:
% réalisé:

0%

Temps estimé:

Description

Contexte: https://github.com/trasher/galette/pull/1
J'ai modifié la class Adherent.php pour brider un peu les inscriptions et éviter ainsi que les adhérents puissent taper a date courante à la place de leur date de naissance.
Mon plugin a besoin d'une date de naissance valide pour calculer des tarifs.
J'ai donc fait un contrôle de l'age:
un age dépassant ]200ans..1an[ est invalide.
(idée: On pourrait laisser l'admin choisir le type de filtre ou le choix de l'activer ou non.)
détails du code:

case 'date_crea_adh':
    try {
        $d = \DateTime::createFromFormat(_T("Y-m-d"), $value);

        if ( $d === false ) {
            //try with non localized date
            $d = \DateTime::createFromFormat("Y-m-d", $value);
            if ( $d === false ) {
                throw new \Exception('Incorrect format');
            }
        }
        $this->$prop = $d->format('Y-m-d');
    } catch (\Exception $e) {
        Analog::log(
            'Wrong date format. field: ' . $key .
            ', value: ' . $value . ', expected fmt: ' .
            _T("Y-m-d") . ' | ' . $e->getMessage(),
            Analog::INFO
        );
        $errors[] = str_replace(
            array(
                '%date_format',
                '%field'
            ),
            array(
                _T("Y-m-d"),
                $this->_fields[$key]['label']
            ),
            _T("- Wrong date format (%date_format) for %field!")
        );
    }
    break;
case 'ddn_adh':
    try {
        $d = \DateTime::createFromFormat(_T("Y-m-d"), $value);

        $birthdate= \DateTime::createFromFormat('j/m/Y',$value);
        $today= new \DateTime("now");
        //echo('today:');
        //var_dump($today);
        //echo('birthdate:');
        //var_dump($birthdate);
        //echo('diff:');
        $age=$birthdate->diff($today);
        //var_dump($age->format('%R%Y'));

        $age=$age->format('%Y');
        if($age>200 || $age<1)
            {
            $d=false;
            }

        if ( $d === false ) {
            //try with non localized date
            $d = \DateTime::createFromFormat("Y-m-d", $value);
            if ( $d === false ) {
                throw new \Exception('Incorrect format');
            }
        }
        $this->$prop = $d->format('Y-m-d');
    } catch (\Exception $e) {
        Analog::log(
            'Wrong date format. field: ' . $key .
            ', value: ' . $value . ', expected fmt: ' .
            _T("Y-m-d") . ' | ' . $e->getMessage(),
            Analog::INFO
        );
        $errors[] = str_replace(
            array(
                '%date_format',
                '%field'
            ),
            array(
                _T("Y-m-d"),
                $this->_fields[$key]['label']
            ),
            _T("- Wrong date format (%date_format) for %field!")
        );
    }
    break;

Mis à jour par Johan Cwiklinski il y a environ 6 ans

  • Version cible 0.9 supprimé

Mis à jour par Johan Cwiklinski il y a presque 6 ans

  • Description mis à jour (diff)

Mis à jour par Johan Cwiklinski il y a presque 6 ans

  • Statut changé de Nouveau à In Progress
  • Version cible mis à 0.9.2

Mis à jour par Johan Cwiklinski il y a presque 6 ans

  • Statut changé de In Progress à Résolu
  • % réalisé changé de 0 à 100

Mis à jour par Johan Cwiklinski il y a presque 6 ans

  • Statut changé de Résolu à Fermé
  • % réalisé changé de 100 à 0
Actions

Formats disponibles : Atom PDF