Punic\Territory::getChildTerritoryCodes PHP Метод

getChildTerritoryCodes() публичный статический Метод

Retrieve the child territories of a parent territory.
public static getChildTerritoryCodes ( string $parentTerritoryCode, boolean $expandSubGroups = false ) : array
$parentTerritoryCode string
$expandSubGroups boolean Set to true to expand the sub-groups, false to retrieve them.
Результат array Return the list of territory codes that are children of $parentTerritoryCode (if $parentTerritoryCode is invalid you'll get an empty list)
    public static function getChildTerritoryCodes($parentTerritoryCode, $expandSubGroups = false)
    {
        $result = array();
        if (is_string($parentTerritoryCode) && preg_match('/^[a-z0-9]{2,3}$/i', $parentTerritoryCode)) {
            $parentTerritoryCode = strtoupper($parentTerritoryCode);
            $data = Data::getGeneric('territoryContainment');
            if (isset($data[$parentTerritoryCode])) {
                $children = $data[$parentTerritoryCode]['contains'];
                if ($expandSubGroups) {
                    foreach ($children as $child) {
                        $grandChildren = static::getChildTerritoryCodes($child, true);
                        if (empty($grandChildren)) {
                            $result[] = $child;
                        } else {
                            $result = array_merge($result, $grandChildren);
                        }
                    }
                } else {
                    $result = $children;
                }
            }
        }
        return $result;
    }