app/Statistics/Repository/PlaceRepository.php
public function commonCountriesList(): string
    {
        $countries = $this->statsPlaces();

        if (empty($countries)) {
            return '';
        }

        $top10 = [];
        $i     = 1;

        // Get the country names for each language
        $country_names = [];
        foreach (I18N::activeLocales() as $locale) {
            I18N::init($locale->languageTag());
            $all_countries = $this->country_service->getAllCountries();
            foreach ($all_countries as $country_code => $country_name) {
                $country_names[$country_name] = $country_code;
            }
        }

        I18N::init(WT_LOCALE);

        $all_db_countries = [];
        foreach ($countries as $place) {
            $country = trim($place->country);
            if (array_key_exists($country, $country_names)) {
                if (isset($all_db_countries[$country_names[$country]][$country])) {
                    $all_db_countries[$country_names[$country]][$country] += (int) $place->tot;
                } else {
                    $all_db_countries[$country_names[$country]][$country] = (int) $place->tot;
                }
            }
        }

        // get all the user’s countries names
        $all_countries = $this->country_service->getAllCountries();

        foreach ($all_db_countries as $country_code => $country) {
            foreach ($country as $country_name => $tot) {
                $tmp     = new Place($country_name, $this->tree);

                $top10[] = [
                    'place' => $tmp,
                    'count' => $tot,
                    'name'  => $all_countries[$country_code],
                ];
            }

            if ($i++ === 10) {
                break;
            }
        }

        return view(
            'statistics/other/top10-list',
            [
                'records' => $top10,
            ]
        );
    }
public function commonCountriesList(): string
    {
        $countries = $this->statsPlaces();

        if (empty($countries)) {
            return '';
        }

        $top10 = [];
        $i     = 1;

        // Get the country names for each language
        $country_names = [];
        foreach (I18N::activeLocales() as $locale) {
            I18N::init($locale->languageTag());
            $all_countries = $this->country_service->getAllCountries();
            foreach ($all_countries as $country_code => $country_name) {
                $country_names[$country_name] = $country_code;
            }
        }

        I18N::init(WT_LOCALE);

        $all_db_countries = [];
        foreach ($countries as $place) {
            $country = trim($place->country);
            if (array_key_exists($country, $country_names)) {
                if (isset($all_db_countries[$country_names[$country]][$country])) {
                    $all_db_countries[$country_names[$country]][$country] += (int) $place->tot;
                } else {
                    $all_db_countries[$country_names[$country]][$country] = (int) $place->tot;
                }
            }
        }

        // get all the user’s countries names
        $all_countries = $this->country_service->getAllCountries();

        foreach ($all_db_countries as $country_code => $country) {
            foreach ($country as $country_name => $tot) {
                $tmp     = new Place($country_name, $this->tree);

                $top10[] = [
                    'place' => $tmp,
                    'count' => $tot,
                    'name'  => $all_countries[$country_code],
                ];
            }

            if ($i++ === 10) {
                break;
            }
        }

        return view(
            'statistics/other/top10-list',
            [
                'records' => $top10,
            ]
        );
    }
public function commonCountriesList ( ) : string { $ countries = $ this -> statsPlaces ( ) ; if ( empty ( $ countries ) ) { return '' ; } $ top10 = [ ] ; $ i = 1 ; // Get the country names for each language $ country_names = [ ] ; foreach ( I18N :: activeLocales ( ) as $ locale ) { I18N :: init ( $ locale -> languageTag ( ) ) ; $ all_countries = $ this -> country_service -> getAllCountries ( ) ; foreach ( $ all_countries as $ country_code => $ country_name ) { $ country_names [ $ country_name ] = $ country_code ; } } I18N :: init ( WT_LOCALE ) ; $ all_db_countries = [ ] ; foreach ( $ countries as $ place ) { $ country = trim ( $ place -> country ) ; if ( array_key_exists ( $ country , $ country_names ) ) { if ( isset ( $ all_db_countries [ $ country_names [ $ country ] ] [ $ country ] ) ) { $ all_db_countries [ $ country_names [ $ country ] ] [ $ country ] += ( int ) $ place -> tot ; } else { $ all_db_countries [ $ country_names [ $ country ] ] [ $ country ] = ( int ) $ place -> tot ; } } } // get all the user’s countries names $ all_countries = $ this -> country_service -> getAllCountries ( ) ; foreach ( $ all_db_countries as $ country_code => $ country ) { foreach ( $ country as $ country_name => $ tot ) { $ tmp = new Place ( $ country_name , $ this -> tree ) ; $ top10 [ ] = [ 'place' => $ tmp , 'count' => $ tot , 'name' => $ all_countries [ $ country_code ] , ] ; } if ( $ i ++ === 10 ) { break ; } } return view ( 'statistics/other/top10-list' , [ 'records' => $ top10 , ] ) ; }
A list of common countries.

@return string
A list of common countries .