Initial commit: Auth Server Base
This commit is contained in:
47
local/modules/conmed.authserver/lib/dictionariestrait.php
Normal file
47
local/modules/conmed.authserver/lib/dictionariestrait.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Conmed\Authserver;
|
||||
|
||||
use Bitrix\Main\Context;
|
||||
use Bitrix\Main\Loader;
|
||||
|
||||
trait DictionariesTrait {
|
||||
public static function dictionariesAction() {
|
||||
header('Content-Type: application/json');
|
||||
$req = Context::getCurrent()->getRequest();
|
||||
|
||||
// Проверка прав клиента
|
||||
if(!self::checkClient($req->getPost("client_id"), $req->getPost("client_secret"))) {
|
||||
die(json_encode(['error'=>'forbidden']));
|
||||
}
|
||||
|
||||
// 1. Страны (Стандартный список Битрикс)
|
||||
$countries = [];
|
||||
$arCountries = GetCountryArray();
|
||||
if (is_array($arCountries['reference_id'])) {
|
||||
foreach ($arCountries['reference_id'] as $k => $id) {
|
||||
$countries[] = [
|
||||
'id' => $id,
|
||||
'name' => $arCountries['reference'][$k]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Города (Из модуля statistic)
|
||||
$cities = [];
|
||||
if (Loader::includeModule('statistic')) {
|
||||
$rs = \CCity::GetList(['CITY_NAME' => 'ASC'], []);
|
||||
while ($el = $rs->Fetch()) {
|
||||
if (!empty($el['CITY_NAME'])) {
|
||||
$cities[] = $el['CITY_NAME'];
|
||||
}
|
||||
}
|
||||
$cities = array_unique($cities);
|
||||
$cities = array_values($cities);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'countries' => $countries,
|
||||
'cities' => $cities
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user