app/Services/IndividualListService.php
public function surnameAlpha(bool $marnm, bool $fams, string $locale, string $collation): array
    {
        $n_surn = $this->fieldWithCollation('n_surn', $collation);
        $alphas = [];

        $query = DB::table('name')->where('n_file', '=', $this->tree->id());

        $this->whereFamily($fams, $query);
        $this->whereMarriedName($marnm, $query);

        // Fetch all the letters in our alphabet, whether or not there
        // are any names beginning with that letter. It looks better to
        // show the full alphabet, rather than omitting rare letters such as X.
        foreach ($this->localization_service->alphabet() as $letter) {
            $query2 = clone $query;

            $this->whereInitial($query2, 'n_surn', $letter, $locale, $collation);

            $alphas[$letter] = $query2->count();
        }

        // Now fetch initial letters that are not in our alphabet,
        // including "@" (for "@N.N.") and "" for no surname.
        $query2 = clone $query;
        foreach ($this->localization_service->alphabet() as $n => $letter) {
            $query2->where($n_surn, 'NOT LIKE', $letter . '%');
        }

        $rows = $query2
            ->select([DB::raw('SUBSTR(n_surn, 1, 1) AS initial'), DB::raw('COUNT(*) AS count')])
            ->groupBy('initial')
            ->orderBy(DB::raw("CASE initial WHEN '' THEN 1 ELSE 0 END"))
            ->orderBy(DB::raw("CASE initial WHEN '@' THEN 1 ELSE 0 END"))
            ->orderBy('initial')
            ->pluck('count', 'initial');

        foreach ($rows as $alpha => $count) {
            $alphas[$alpha] = (int) $count;
        }

        $count_no_surname = $query->where('n_surn', '=', '')->count();

        if ($count_no_surname !== 0) {
            // Special code to indicate "no surname"
            $alphas[','] = $count_no_surname;
        }

        return $alphas;
    }
public function surnameAlpha(bool $marnm, bool $fams, string $locale, string $collation): array
    {
        $n_surn = $this->fieldWithCollation('n_surn', $collation);
        $alphas = [];

        $query = DB::table('name')->where('n_file', '=', $this->tree->id());

        $this->whereFamily($fams, $query);
        $this->whereMarriedName($marnm, $query);

        // Fetch all the letters in our alphabet, whether or not there
        // are any names beginning with that letter. It looks better to
        // show the full alphabet, rather than omitting rare letters such as X.
        foreach ($this->localization_service->alphabet() as $letter) {
            $query2 = clone $query;

            $this->whereInitial($query2, 'n_surn', $letter, $locale, $collation);

            $alphas[$letter] = $query2->count();
        }

        // Now fetch initial letters that are not in our alphabet,
        // including "@" (for "@N.N.") and "" for no surname.
        $query2 = clone $query;
        foreach ($this->localization_service->alphabet() as $n => $letter) {
            $query2->where($n_surn, 'NOT LIKE', $letter . '%');
        }

        $rows = $query2
            ->select([DB::raw('SUBSTR(n_surn, 1, 1) AS initial'), DB::raw('COUNT(*) AS count')])
            ->groupBy('initial')
            ->orderBy(DB::raw("CASE initial WHEN '' THEN 1 ELSE 0 END"))
            ->orderBy(DB::raw("CASE initial WHEN '@' THEN 1 ELSE 0 END"))
            ->orderBy('initial')
            ->pluck('count', 'initial');

        foreach ($rows as $alpha => $count) {
            $alphas[$alpha] = (int) $count;
        }

        $count_no_surname = $query->where('n_surn', '=', '')->count();

        if ($count_no_surname !== 0) {
            // Special code to indicate "no surname"
            $alphas[','] = $count_no_surname;
        }

        return $alphas;
    }
public function surnameAlpha ( bool $ marnm , bool $ fams , string $ locale , string $ collation ) : array { $ n_surn = $ this -> fieldWithCollation ( 'n_surn' , $ collation ) ; $ alphas = [ ] ; $ query = DB :: table ( 'name' ) -> where ( 'n_file' , '=' , $ this -> tree -> id ( ) ) ; $ this -> whereFamily ( $ fams , $ query ) ; $ this -> whereMarriedName ( $ marnm , $ query ) ; // Fetch all the letters in our alphabet, whether or not there // are any names beginning with that letter. It looks better to // show the full alphabet, rather than omitting rare letters such as X. foreach ( $ this -> localization_service -> alphabet ( ) as $ letter ) { $ query2 = clone $ query ; $ this -> whereInitial ( $ query2 , 'n_surn' , $ letter , $ locale , $ collation ) ; $ alphas [ $ letter ] = $ query2 -> count ( ) ; } // Now fetch initial letters that are not in our alphabet, // including "@" (for "@N.N.") and "" for no surname. $ query2 = clone $ query ; foreach ( $ this -> localization_service -> alphabet ( ) as $ n => $ letter ) { $ query2 -> where ( $ n_surn , 'NOT LIKE' , $ letter . '%' ) ; } $ rows = $ query2 -> select ( [ DB :: raw ( 'SUBSTR(n_surn, 1, 1) AS initial' ) , DB :: raw ( 'COUNT(*) AS count' ) ] ) -> groupBy ( 'initial' ) -> orderBy ( DB :: raw ( "CASE initial WHEN '' THEN 1 ELSE 0 END" ) ) -> orderBy ( DB :: raw ( "CASE initial WHEN '@' THEN 1 ELSE 0 END" ) ) -> orderBy ( 'initial' ) -> pluck ( 'count' , 'initial' ) ; foreach ( $ rows as $ alpha => $ count ) { $ alphas [ $ alpha ] = ( int ) $ count ; } $ count_no_surname = $ query -> where ( 'n_surn' , '=' , '' ) -> count ( ) ; if ( $ count_no_surname !== 0 ) { // Special code to indicate "no surname" $ alphas [ ',' ] = $ count_no_surname ; } return $ alphas ; }
Get a list of initial surname letters.

@param bool   $marnm if set, include married names
@param bool   $fams  if set, only consider individuals with FAMS records
@param string $locale
@param string $collation

@return int[]
Get a list of initial surname letters .