public function getPackageVersionLocales($packageHandle, $packageVersion, $minimumLevel = null)
    {
        $this->start();
        try {
            $this->getUserControl()->checkRateLimit();
            $accessibleLocales = $this->getUserControl()->checkLocaleAccess(__FUNCTION__);
            $package = $this->app->make(PackageRepository::class)->findOneBy(['handle' => $packageHandle]);
            if ($package === null) {
                throw new UserMessageException(t('Unable to find the specified package'), Response::HTTP_NOT_FOUND);
            }
            $isBestMatch = null;
            $version = $this->getPackageVersion($package, $packageVersion, $isBestMatch);
            if ($version === null) {
                throw new UserMessageException(t('Unable to find the specified package version'), Response::HTTP_NOT_FOUND);
            }
            $minimumLevel = (int) $minimumLevel;
            $stats = $this->app->make(StatsRepository::class)->get($version, $accessibleLocales);
            $utc = new DateTimeZone('UTC');
            $resultData = $this->localesToArray(
                $accessibleLocales,
                function (LocaleEntity $locale, array $item) use ($stats, $minimumLevel, $utc) {
                    $result = null;
                    foreach ($stats as $stat) {
                        if ($stat->getLocale() === $locale) {
                            if ($stat->getPercentage() >= $minimumLevel) {
                                $item['total'] = $stat->getTotal();
                                $item['translated'] = $stat->getTranslated();
                                $item['progress'] = $stat->getPercentage(true);
                                $dt = $stat->getLastUpdated();
                                if ($dt === null) {
                                    $item['updated'] = null;
                                } else {
                                    $dt = clone $dt;
                                    $dt->setTimezone($utc);
                                    $item['updated'] = $dt->format('c');
                                }
                                $result = $item;
                            }
                            break;
                        }
                    }

                    return $result;
                }
            );
            if ($isBestMatch) {
                $resultData = [
                    'versionHandle' => $version->getVersion(),
                    'versionName' => $version->getDisplayVersion(),
                    'locales' => $resultData,
                ];
            }

            $result = $this->buildJsonResponse($resultData);
        } catch (Exception $x) {
            $result = $this->buildErrorResponse($x);
        } catch (Throwable $x) {
            $result = $this->buildErrorResponse($x);
        }

        return $this->finish($result);
    }
public function getPackageVersionLocales($packageHandle, $packageVersion, $minimumLevel = null)
    {
        $this->start();
        try {
            $this->getUserControl()->checkRateLimit();
            $accessibleLocales = $this->getUserControl()->checkLocaleAccess(__FUNCTION__);
            $package = $this->app->make(PackageRepository::class)->findOneBy(['handle' => $packageHandle]);
            if ($package === null) {
                throw new UserMessageException(t('Unable to find the specified package'), Response::HTTP_NOT_FOUND);
            }
            $isBestMatch = null;
            $version = $this->getPackageVersion($package, $packageVersion, $isBestMatch);
            if ($version === null) {
                throw new UserMessageException(t('Unable to find the specified package version'), Response::HTTP_NOT_FOUND);
            }
            $minimumLevel = (int) $minimumLevel;
            $stats = $this->app->make(StatsRepository::class)->get($version, $accessibleLocales);
            $utc = new DateTimeZone('UTC');
            $resultData = $this->localesToArray(
                $accessibleLocales,
                function (LocaleEntity $locale, array $item) use ($stats, $minimumLevel, $utc) {
                    $result = null;
                    foreach ($stats as $stat) {
                        if ($stat->getLocale() === $locale) {
                            if ($stat->getPercentage() >= $minimumLevel) {
                                $item['total'] = $stat->getTotal();
                                $item['translated'] = $stat->getTranslated();
                                $item['progress'] = $stat->getPercentage(true);
                                $dt = $stat->getLastUpdated();
                                if ($dt === null) {
                                    $item['updated'] = null;
                                } else {
                                    $dt = clone $dt;
                                    $dt->setTimezone($utc);
                                    $item['updated'] = $dt->format('c');
                                }
                                $result = $item;
                            }
                            break;
                        }
                    }

                    return $result;
                }
            );
            if ($isBestMatch) {
                $resultData = [
                    'versionHandle' => $version->getVersion(),
                    'versionName' => $version->getDisplayVersion(),
                    'locales' => $resultData,
                ];
            }

            $result = $this->buildJsonResponse($resultData);
        } catch (Exception $x) {
            $result = $this->buildErrorResponse($x);
        } catch (Throwable $x) {
            $result = $this->buildErrorResponse($x);
        }

        return $this->finish($result);
    }
public function getPackageVersionLocales ( $ packageHandle , $ packageVersion , $ minimumLevel = null ) { $ this -> start ( ) ; try { $ this -> getUserControl ( ) -> checkRateLimit ( ) ; $ accessibleLocales = $ this -> getUserControl ( ) -> checkLocaleAccess ( __FUNCTION__ ) ; $ package = $ this -> app -> make ( PackageRepository :: class ) -> findOneBy ( [ 'handle' => $ packageHandle ] ) ; if ( $ package === null ) { throw new UserMessageException ( t ( 'Unable to find the specified package' ) , Response :: HTTP_NOT_FOUND ) ; } $ isBestMatch = null ; $ version = $ this -> getPackageVersion ( $ package , $ packageVersion , $ isBestMatch ) ; if ( $ version === null ) { throw new UserMessageException ( t ( 'Unable to find the specified package version' ) , Response :: HTTP_NOT_FOUND ) ; } $ minimumLevel = ( int ) $ minimumLevel ; $ stats = $ this -> app -> make ( StatsRepository :: class ) -> get ( $ version , $ accessibleLocales ) ; $ utc = new DateTimeZone ( 'UTC' ) ; $ resultData = $ this -> localesToArray ( $ accessibleLocales , function ( LocaleEntity $ locale , array $ item ) use ( $ stats , $ minimumLevel , $ utc ) { $ result = null ; foreach ( $ stats as $ stat ) { if ( $ stat -> getLocale ( ) === $ locale ) { if ( $ stat -> getPercentage ( ) >= $ minimumLevel ) { $ item [ 'total' ] = $ stat -> getTotal ( ) ; $ item [ 'translated' ] = $ stat -> getTranslated ( ) ; $ item [ 'progress' ] = $ stat -> getPercentage ( true ) ; $ dt = $ stat -> getLastUpdated ( ) ; if ( $ dt === null ) { $ item [ 'updated' ] = null ; } else { $ dt = clone $ dt ; $ dt -> setTimezone ( $ utc ) ; $ item [ 'updated' ] = $ dt -> format ( 'c' ) ; } $ result = $ item ; } break ; } } return $ result ; } ) ; if ( $ isBestMatch ) { $ resultData = [ 'versionHandle' => $ version -> getVersion ( ) , 'versionName' => $ version -> getDisplayVersion ( ) , 'locales' => $ resultData , ] ; } $ result = $ this -> buildJsonResponse ( $ resultData ) ; } catch ( Exception $ x ) { $ result = $ this -> buildErrorResponse ( $ x ) ; } catch ( Throwable $ x ) { $ result = $ this -> buildErrorResponse ( $ x ) ; } return $ this -> finish ( $ result ) ; }
Get some stats about the translations of a package version.


@param string $packageHandle
@param string $packageVersion
@param null|int $minimumLevel

@return Response

@example http://www.example.com/api/package/concrete5/8.2/locales/80/
@example http://www.example.com/api/package/concrete5/best-match-version/locales/80/?v=8.2rc1
Get some stats about the translations of a package version .