Commit d51e337a authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Les destinataires/observateurs sont filtrés par email et rangés par Nom

parent 6c6a8e9d
Loading
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -336,8 +336,10 @@ class SignatureService
                }
            }

            $currentStep['recipients'] = $recipients;
            $currentStep['observers'] = $observers;
            $currentStep['recipients'] = $this->arrayUniqueEmailSorted($recipients);
            $currentStep['observers'] = $this->arrayUniqueEmailSorted($observers);
//            $currentStep['recipients'] = $recipients;
//            $currentStep['observers'] = $observers;

            if (count($currentStep['recipients']) == 0) {
                $missing_recipients = true;
@@ -352,6 +354,22 @@ class SignatureService
        return $out;
    }

    protected function arrayUniqueEmailSorted( array $array ) : array {
        $result = [];
        $seen = [];
        foreach ($array as $row) {
            if( !in_array( $row['email'], $seen, true ) ) {
                $seen[] = $row['email'];
                $result[] = $row;
            }
        }
        // Trie par lastname
        usort($result, function ($a, $b) {
            return strcmp($a['lastname'], $b['lastname']);
        });
        return $result;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// API
    ///