api.districts.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. /**
  3. * Coverage map districts absctraction
  4. */
  5. class Districts {
  6. /**
  7. * Contains available districts as id=>name
  8. *
  9. * @var array
  10. */
  11. protected $allDistricts = array();
  12. /**
  13. * Contains array of available districts data as id=>data
  14. *
  15. * @var array
  16. */
  17. protected $allDistrictData = array();
  18. /**
  19. * Contains available cities as id=>data
  20. *
  21. * @var array
  22. */
  23. protected $allCities = array();
  24. /**
  25. * Contains available streets as id=>data
  26. *
  27. * @var array
  28. */
  29. protected $allStreets = array();
  30. /**
  31. * Contains available builds as id=>data
  32. *
  33. * @var array
  34. */
  35. protected $allBuilds = array();
  36. /**
  37. * Contains available apts as id=>data
  38. *
  39. * @var array
  40. */
  41. protected $allApts = array();
  42. /**
  43. * Contains available address data as login=>aptid
  44. *
  45. * @var array
  46. */
  47. protected $allAddress = array();
  48. /**
  49. * Contains available users data as login=>data
  50. *
  51. * @var array
  52. */
  53. protected $allUserData = array();
  54. /**
  55. * Flag that signalizes, how accurate we need to detect user ativity.
  56. * Based only on Cash>=Credit or use Freezing and AO states too, like exhorse.
  57. *
  58. * @var bool
  59. */
  60. protected $accurateActivityDetection = true;
  61. /**
  62. * System message helper object placeholder
  63. *
  64. * @var object
  65. */
  66. protected $messages = '';
  67. /**
  68. * System caching object placeholder
  69. *
  70. * @var object
  71. */
  72. protected $cache = '';
  73. /**
  74. * Contains previously cached login=>districts data
  75. *
  76. * @var array
  77. */
  78. protected $cachedData = array();
  79. /**
  80. * Default caching timeout in seconds
  81. */
  82. const CACHE_TIME = 3600;
  83. /**
  84. * Base module URL
  85. */
  86. const URL_ME = '?module=districts';
  87. /**
  88. * User profile link
  89. */
  90. const URL_PROFILE = '?module=userprofile&username=';
  91. /**
  92. * Creates new districts instance
  93. *
  94. * @return void
  95. */
  96. public function __construct($fullLoaders = false) {
  97. $this->initMessages();
  98. $this->initCache();
  99. $this->loadDistricts();
  100. if ($fullLoaders) {
  101. $this->loadDistrictData();
  102. $this->loadCityData();
  103. $this->loadStreetData();
  104. $this->loadBuildData();
  105. $this->loadAptData();
  106. $this->loadAddressData();
  107. $this->loadUserData();
  108. }
  109. }
  110. /**
  111. * Inits system messages helper object instance
  112. *
  113. * @return void
  114. */
  115. protected function initMessages() {
  116. $this->messages = new UbillingMessageHelper();
  117. }
  118. /**
  119. * Initalizes system caching object for further usage
  120. *
  121. * @return void
  122. */
  123. protected function initCache() {
  124. $this->cache = new UbillingCache();
  125. $this->cachedData = $this->cache->get('DISTRICTS', self::CACHE_TIME);
  126. }
  127. /**
  128. * Loads existing districts from database
  129. *
  130. * @return void
  131. */
  132. protected function loadDistricts() {
  133. $query = "SELECT * from `districtnames`";
  134. $all = simple_queryall($query);
  135. if (!empty($all)) {
  136. foreach ($all as $io => $each) {
  137. $this->allDistricts[$each['id']] = $each['name'];
  138. }
  139. }
  140. }
  141. /**
  142. * Loads existing districts data from database
  143. *
  144. * @return void
  145. */
  146. protected function loadDistrictData() {
  147. $query = "SELECT * from `districtdata`";
  148. $all = simple_queryall($query);
  149. if (!empty($all)) {
  150. foreach ($all as $io => $each) {
  151. $this->allDistrictData[$each['id']] = $each;
  152. }
  153. }
  154. }
  155. /**
  156. * Loads available cities from database
  157. *
  158. * @return void
  159. */
  160. protected function loadCityData() {
  161. $tmpArr = zb_AddressGetCityAllData();
  162. if (!empty($tmpArr)) {
  163. foreach ($tmpArr as $io => $each) {
  164. $this->allCities[$each['id']] = $each;
  165. }
  166. }
  167. }
  168. /**
  169. * Loads available streets from database
  170. *
  171. * @return void
  172. */
  173. protected function loadStreetData() {
  174. $tmpArr = zb_AddressGetStreetAllData();
  175. if (!empty($tmpArr)) {
  176. foreach ($tmpArr as $io => $each) {
  177. $this->allStreets[$each['id']] = $each;
  178. }
  179. }
  180. }
  181. /**
  182. * Loads available builds data from database
  183. *
  184. * @return void
  185. */
  186. protected function loadBuildData() {
  187. $tmpArr = zb_AddressGetBuildAllData();
  188. if (!empty($tmpArr)) {
  189. foreach ($tmpArr as $io => $each) {
  190. $this->allBuilds[$each['id']] = $each;
  191. }
  192. }
  193. }
  194. /**
  195. * Loads available apt data from database
  196. *
  197. * @return void
  198. */
  199. protected function loadAptData() {
  200. $tmpArr = zb_AddressGetAptAllData();
  201. if (!empty($tmpArr)) {
  202. foreach ($tmpArr as $io => $each) {
  203. $this->allApts[$each['id']] = $each;
  204. }
  205. }
  206. }
  207. /**
  208. * Loads available address apt=>login data from database
  209. *
  210. * @return void
  211. */
  212. protected function loadAddressData() {
  213. $tmpArr = zb_AddressGetAddressAllData();
  214. if (!empty($tmpArr)) {
  215. foreach ($tmpArr as $io => $each) {
  216. $this->allAddress[$each['login']] = $each['aptid'];
  217. }
  218. }
  219. }
  220. /**
  221. * Loads existing users data
  222. *
  223. * @return void
  224. */
  225. protected function loadUserData() {
  226. $this->allUserData = zb_UserGetAllDataCache();
  227. }
  228. /**
  229. * Renders district creation form
  230. *
  231. * @return string
  232. */
  233. public function renderDistrictsCreateForm() {
  234. $result = '';
  235. $inputs = wf_TextInput('newdistrictname', __('Name'), '', false, 15);
  236. $inputs.= wf_Submit(__('Create'));
  237. $result.=wf_Form('', 'POST', $inputs, 'glamour');
  238. return ($result);
  239. }
  240. /**
  241. * Renders district edit form
  242. *
  243. * @return string
  244. */
  245. public function renderDistrictsEditForm($districtId) {
  246. $districtId = vf($districtId, 3);
  247. $result = '';
  248. if (isset($this->allDistricts[$districtId])) {
  249. $inputs = wf_TextInput('editdistrictname', __('Name'), $this->allDistricts[$districtId], false, 15);
  250. $inputs.= wf_HiddenInput('editdistrictid', $districtId);
  251. $inputs.= wf_Submit(__('Save'));
  252. $result.=wf_Form('', 'POST', $inputs, 'glamour');
  253. }
  254. return ($result);
  255. }
  256. /**
  257. * Creates new district in database
  258. *
  259. * @param string $name
  260. *
  261. * @return void
  262. */
  263. public function createDistrict($name) {
  264. $nameF = mysql_real_escape_string($name);
  265. $query = "INSERT INTO `districtnames` (`id`,`name`) VALUES "
  266. . "(NULL,'" . $nameF . "');";
  267. nr_query($query);
  268. $newId = simple_get_lastid('districtnames');
  269. log_register('DISTRICT CREATE [' . $newId . '] `' . $name . '`');
  270. }
  271. /**
  272. * Deletes some district from database
  273. *
  274. * @param int $districtId
  275. *
  276. * @return void
  277. */
  278. public function deleteDistrict($districtId) {
  279. $districtId = vf($districtId, 3);
  280. if (isset($this->allDistricts[$districtId])) {
  281. $districtName = $this->allDistricts[$districtId];
  282. $query = "DELETE FROM `districtnames` WHERE `id`='" . $districtId . "';";
  283. nr_query($query);
  284. $query = "DELETE FROM `districtdata` WHERE `districtid`='" . $districtId . "';";
  285. nr_query($query);
  286. log_register('DISTRICT DELETE [' . $districtId . '] `' . $districtName . '`');
  287. }
  288. }
  289. /**
  290. * Changes district name in database
  291. *
  292. * @param int $districtId
  293. * @param string $districtName
  294. *
  295. * @return void
  296. */
  297. public function saveDistrictName($districtId, $districtName) {
  298. if (isset($this->allDistricts[$districtId])) {
  299. simple_update_field('districtnames', 'name', $districtName, "WHERE `id`='" . $districtId . "'");
  300. log_register('DISTRICT EDIT [' . $districtId . '] `' . $districtName . '`');
  301. }
  302. }
  303. /**
  304. * Renders available districts list with some controls
  305. *
  306. * @return string
  307. */
  308. public function renderDistrictsList() {
  309. $result = '';
  310. if (!empty($this->allDistricts)) {
  311. $cells = wf_TableCell(__('ID'));
  312. $cells.= wf_TableCell(__('Name'));
  313. $cells.= wf_TableCell(__('Actions'));
  314. $rows = wf_TableRow($cells, 'row1');
  315. foreach ($this->allDistricts as $io => $each) {
  316. $cells = wf_TableCell($io);
  317. $districtViewLink = wf_link(self::URL_ME . '&viewusers=' . $io, $each);
  318. $cells.= wf_TableCell($districtViewLink);
  319. $actLinks = wf_JSAlert(self::URL_ME . '&deletedistrict=' . $io, web_delete_icon(), $this->messages->getDeleteAlert()) . ' ';
  320. $actLinks.= wf_modalAuto(web_edit_icon(), __('Edit'), $this->renderDistrictsEditForm($io)) . ' ';
  321. $actLinks.= wf_Link(self::URL_ME . '&editdistrict=' . $io, web_icon_extended(__('Settings')));
  322. $cells.= wf_TableCell($actLinks);
  323. $rows.= wf_TableRow($cells, 'row5');
  324. }
  325. $result.=wf_TableBody($rows, '100%', 0, 'sortable');
  326. } else {
  327. $result.=$this->messages->getStyledMessage(__('Nothing to show'), 'info');
  328. }
  329. return ($result);
  330. }
  331. /**
  332. * Returns list of checkbox controls for some previously selected street
  333. *
  334. * @param int $streetId
  335. *
  336. * @return string
  337. */
  338. protected function getBuildForm($streetId) {
  339. $streetId = vf($streetId, 3);
  340. $result = '';
  341. if (!empty($this->allBuilds)) {
  342. foreach ($this->allBuilds as $io => $each) {
  343. if ($each['streetid'] == $streetId) {
  344. $result.=wf_CheckInput('_addbuilds[' . $each['id'] . ']', $each['buildnum'], true, false);
  345. }
  346. }
  347. }
  348. return ($result);
  349. }
  350. /**
  351. * Renders new district data creation form
  352. *
  353. * @param int $districtId
  354. *
  355. * @return string
  356. */
  357. public function renderDistrictDataCreateForm($districtId) {
  358. $districtId = vf($districtId, 3);
  359. $result = '';
  360. $inputs = '';
  361. if (!wf_CheckPost(array('citysel'))) {
  362. $inputs.= web_CitySelectorAc() . wf_tag('br');
  363. } else {
  364. $inputs.= wf_img('skins/icon_ok.gif') . $this->allCities[$_POST['citysel']]['cityname'] . wf_tag('br');
  365. $inputs.= wf_HiddenInput('citysel', $_POST['citysel']);
  366. if (!wf_CheckPost(array('streetsel'))) {
  367. $inputs.=web_StreetSelectorAc($_POST['citysel']) . wf_tag('br');
  368. } else {
  369. $inputs.= wf_img('skins/icon_ok.gif') . ' ' . @$this->allStreets[$_POST['streetsel']]['streetname'] . wf_tag('br');
  370. $inputs.= wf_HiddenInput('streetsel', $_POST['streetsel']);
  371. $inputs.=$this->getBuildForm($_POST['streetsel']);
  372. }
  373. $inputs.=wf_tag('hr');
  374. $inputs.=wf_CheckInput('allchoicesdone', __('I`m ready'), true, false);
  375. $inputs.=wf_Submit(__('Save'));
  376. }
  377. $result.=wf_Form(self::URL_ME . '&editdistrict=' . $districtId, 'POST', $inputs, 'glamour');
  378. return ($result);
  379. }
  380. /**
  381. * Catches new district data creation request
  382. *
  383. * @return void
  384. */
  385. public function catchDistrictDataCreate() {
  386. if (wf_CheckGet(array('editdistrict'))) {
  387. $districtId = vf($_GET['editdistrict'], 3);
  388. if (wf_CheckPost(array('citysel'))) {
  389. $cityId = vf($_POST['citysel'], 3);
  390. $streetId = (wf_CheckPost(array('streetsel'))) ? vf($_POST['streetsel'], 3) : '';
  391. $buildsArr = (wf_CheckPost(array('_addbuilds'))) ? $_POST['_addbuilds'] : array();
  392. //only city
  393. if ((empty($streetId)) AND ( empty($buildsArr)) AND ( !empty($cityId))) {
  394. $query = "INSERT INTO `districtdata` (`id`,`districtid`,`cityid`,`streetid`,`buildid`) VALUES "
  395. . "(NULL,'" . $districtId . "','" . $cityId . "',NULL,NULL);";
  396. nr_query($query);
  397. log_register('DISTRICT DATACREATE [' . $districtId . '] CITY [' . $cityId . ']');
  398. }
  399. //city with street
  400. if ((!empty($streetId)) AND ( empty($buildsArr)) AND ( !empty($cityId))) {
  401. $query = "INSERT INTO `districtdata` (`id`,`districtid`,`cityid`,`streetid`,`buildid`) VALUES "
  402. . "(NULL,'" . $districtId . "','" . $cityId . "','" . $streetId . "',NULL);";
  403. nr_query($query);
  404. log_register('DISTRICT DATACREATE [' . $districtId . '] CITY [' . $cityId . '] STREET [' . $streetId . ']');
  405. }
  406. //city->street->build
  407. if ((!empty($streetId)) AND ( !empty($buildsArr)) AND ( !empty($cityId))) {
  408. $buildCount = 0;
  409. foreach ($buildsArr as $io => $each) {
  410. $query = "INSERT INTO `districtdata` (`id`,`districtid`,`cityid`,`streetid`,`buildid`) VALUES "
  411. . "(NULL,'" . $districtId . "','" . $cityId . "','" . $streetId . "','" . $io . "');";
  412. nr_query($query);
  413. $buildCount++;
  414. }
  415. log_register('DISTRICT DATACREATE [' . $districtId . '] CITY [' . $cityId . '] STREET [' . $streetId . '] BUILDCOUNT `' . $buildCount . '`');
  416. }
  417. }
  418. }
  419. }
  420. /**
  421. * Returns district name by its ID
  422. *
  423. * @param int $districtId
  424. *
  425. * @return string
  426. */
  427. public function getDistrictName($districtId) {
  428. $districtId = vf($districtId, 3);
  429. $result = '';
  430. if (isset($this->allDistricts[$districtId])) {
  431. $result = $this->allDistricts[$districtId];
  432. }
  433. return ($result);
  434. }
  435. /**
  436. * Returns array of available districts as id=>name
  437. *
  438. * @return array
  439. */
  440. public function getDistricts() {
  441. return ($this->allDistricts);
  442. }
  443. /**
  444. * Renders available district data with some controls
  445. *
  446. * @param int $districtId
  447. *
  448. * @return string
  449. */
  450. public function renderDistrictData($districtId) {
  451. $districtId = vf($districtId, 3);
  452. $result = '';
  453. if (!empty($this->allDistrictData)) {
  454. $cells = wf_TableCell(__('ID'));
  455. $cells.=wf_TableCell(__('District'));
  456. $cells.=wf_TableCell(__('City'));
  457. $cells.=wf_TableCell(__('Street'));
  458. $cells.=wf_TableCell(__('Build'));
  459. $cells.=wf_TableCell(__('Actions'));
  460. $rows = wf_TableRow($cells, 'row1');
  461. foreach ($this->allDistrictData as $io => $each) {
  462. if ($each['districtid'] == $districtId) {
  463. $cells = wf_TableCell($each['id']);
  464. $cells.=wf_TableCell(@$this->allDistricts[$each['districtid']]);
  465. $cells.=wf_TableCell(@$this->allCities[$each['cityid']]['cityname']);
  466. $cells.=wf_TableCell(@$this->allStreets[$each['streetid']]['streetname']);
  467. $cells.=wf_TableCell(@$this->allBuilds[$each['buildid']]['buildnum']);
  468. $actLinks = wf_JSAlert(self::URL_ME . '&editdistrict=' . $districtId . '&deletedata=' . $each['id'], web_delete_icon(), $this->messages->getDeleteAlert());
  469. $cells.=wf_TableCell($actLinks);
  470. $rows.= wf_TableRow($cells, 'row5');
  471. }
  472. }
  473. $result.=wf_TableBody($rows, '100%', 0, 'sortable');
  474. } else {
  475. $result.=$this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  476. }
  477. return ($result);
  478. }
  479. /**
  480. * Deletes some district data row from database
  481. *
  482. * @param int $dataId
  483. *
  484. * @return void
  485. */
  486. public function deleteDistrictData($dataId) {
  487. $dataId = vf($dataId, 3);
  488. if (isset($this->allDistrictData[$dataId])) {
  489. $districtId = $this->allDistrictData[$dataId]['districtid'];
  490. $query = "DELETE from `districtdata` WHERE `id`='" . $dataId . "';";
  491. nr_query($query);
  492. log_register('DISTRICT DATADELETE [' . $districtId . '] DATAID [' . $dataId . ']');
  493. }
  494. }
  495. /**
  496. * Renders districts users report container
  497. *
  498. * @param int $districtId
  499. *
  500. * @return string
  501. */
  502. public function renderDistrictUsersContainer($districtId) {
  503. $result = '';
  504. $columns = array('Login', 'Address', 'Real Name', 'IP', 'Tariff', 'Active', 'Balance', 'Credit');
  505. $result.=wf_JqDtLoader($columns, self::URL_ME . '&viewusers=' . $districtId . '&ajax=true', false, 'Users', 100);
  506. return ($result);
  507. }
  508. /**
  509. * Returns is user active or not. Customizable in future.
  510. *
  511. * @param string $login
  512. *
  513. * @return bool
  514. */
  515. protected function isUserActive($login) {
  516. $result = false;
  517. if (isset($this->allUserData[$login])) {
  518. if ($this->accurateActivityDetection) {
  519. if (($this->allUserData[$login]['Cash'] >= '-' . $this->allUserData[$login]['Credit']) AND ( $this->allUserData[$login]['Passive'] == 0) AND ( $this->allUserData[$login]['AlwaysOnline'] == 1)) {
  520. $result = true;
  521. } else {
  522. $result = false;
  523. }
  524. } else {
  525. $result = ($this->allUserData[$login]['Cash'] >= '-' . $this->allUserData[$login]['Credit']) ? true : false;
  526. }
  527. }
  528. return ($result);
  529. }
  530. /**
  531. * Checks is user in some district or not
  532. *
  533. * @param string $login
  534. * @param int $districtId
  535. *
  536. * @return bool
  537. */
  538. protected function isUserInDistrict($login, $districtId) {
  539. $result = false;
  540. if (isset($this->allAddress[$login])) {
  541. if (isset($this->allDistricts[$districtId])) {
  542. if (!empty($this->allDistrictData)) {
  543. $userAptId = $this->allAddress[$login];
  544. $userApt = $this->allApts[$userAptId];
  545. $userBuildId = $userApt['buildid'];
  546. $userBuild = $this->allBuilds[$userBuildId];
  547. $userStreetId = $userBuild['streetid'];
  548. $userStreet = $this->allStreets[$userStreetId];
  549. $userCityId = $userStreet['cityid'];
  550. foreach ($this->allDistrictData as $io => $each) {
  551. if ($each['districtid'] == $districtId) {
  552. if ($userCityId == $each['cityid']) {
  553. $result = true;
  554. if (!empty($each['streetid'])) {
  555. if ($userStreetId == $each['streetid']) {
  556. $result = true;
  557. if (!empty($each['buildid'])) {
  558. if ($userBuildId == $each['buildid']) {
  559. $result = true;
  560. return ($result);
  561. } else {
  562. $result = false;
  563. }
  564. } else {
  565. return ($result);
  566. }
  567. } else {
  568. $result = false;
  569. }
  570. } else {
  571. return ($result);
  572. }
  573. }
  574. }
  575. }
  576. }
  577. }
  578. }
  579. return ($result);
  580. }
  581. /**
  582. * Renders datatables report JSON data
  583. *
  584. * @param int $districtId
  585. *
  586. * @return void
  587. */
  588. public function renderDistrictUsersAjaxData($districtId) {
  589. $districtId = vf($districtId, 3);
  590. $json = new wf_JqDtHelper();
  591. if (isset($this->allDistricts[$districtId])) {
  592. if (!empty($this->allAddress)) {
  593. foreach ($this->allAddress as $login => $aptId) {
  594. if ($this->isUserInDistrict($login, $districtId)) {
  595. $userLink = wf_Link(self::URL_PROFILE . $login, web_profile_icon() . ' ' . $login);
  596. $data[] = $userLink;
  597. $data[] = @$this->allUserData[$login]['fulladress'];
  598. $data[] = @$this->allUserData[$login]['realname'];
  599. $data[] = @$this->allUserData[$login]['ip'];
  600. $data[] = @$this->allUserData[$login]['Tariff'];
  601. $actFlag = ($this->isUserActive($login)) ? web_bool_led(true) . ' ' . __('Active') : web_bool_led(false) . ' ' . __('Not really');
  602. $data[] = $actFlag;
  603. $data[] = @$this->allUserData[$login]['Cash'];
  604. $data[] = @$this->allUserData[$login]['Credit'];
  605. $json->addRow($data);
  606. unset($data);
  607. }
  608. }
  609. }
  610. }
  611. $json->getJson();
  612. }
  613. /**
  614. * Fills districts cache for further fast usage
  615. *
  616. * @return void
  617. */
  618. public function fillDistrictsCache() {
  619. $tmpArr = array();
  620. if (!empty($this->allDistricts)) {
  621. if (!empty($this->allAddress)) {
  622. foreach ($this->allAddress as $login => $aptId) {
  623. foreach ($this->allDistricts as $districtId => $districtName) {
  624. if ($this->isUserInDistrict($login, $districtId)) {
  625. $tmpArr[$login][$districtId] = $districtName;
  626. }
  627. }
  628. }
  629. }
  630. }
  631. $this->cache->set('DISTRICTS', $tmpArr, self::CACHE_TIME);
  632. }
  633. /**
  634. * Returns some user districts array as id=>name from cache
  635. *
  636. * @param string $login
  637. *
  638. * @return array
  639. */
  640. public function getUserDistrictsFast($login) {
  641. $result = array();
  642. if (!empty($this->cachedData)) {
  643. if (isset($this->cachedData[$login])) {
  644. $result = $this->cachedData[$login];
  645. }
  646. }
  647. return ($result);
  648. }
  649. /**
  650. * Check user district based on cached data
  651. *
  652. * @param string $login
  653. * @param int $districtId
  654. *
  655. * @return bool
  656. */
  657. public function checkUserDistrictFast($login, $districtId) {
  658. $result = false;
  659. if (isset($this->cachedData[$login])) {
  660. if (isset($this->cachedData[$login][$districtId])) {
  661. $result = true;
  662. deb($login.'->'.$districtId);
  663. }
  664. }
  665. return ($result);
  666. }
  667. /**
  668. * Returns list of user districts text list from cache
  669. *
  670. * @param string $login
  671. *
  672. * @return string
  673. */
  674. public function getUserDistrictsListFast($login) {
  675. $result = '';
  676. $userDistricts = $this->getUserDistrictsFast($login);
  677. if (!empty($userDistricts)) {
  678. $result.=implode(', ', $userDistricts);
  679. }
  680. return ($result);
  681. }
  682. }
  683. ?>