$address = $district[2]; $location = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($address) . '&sensor=false')); if ($location['status'] == 'OK') { $location = $location['results'][0]['geometry']['location']; call_user_func_array([$Precincts, 'add'], [$district[1], $address, $location['lat'], $location['lng'], 0]); } } } unset($districts, $district, $address, $location); } unset($regions, $region); $Precincts->db_prime()->q("INSERT INTO `[prefix]precincts` (`id`, `number`, `address_uk`, `address_en`, `address_ru`, `lat`, `lng`, `district`, `violations`) VALUES (NULL, '0', '01196, м.Київ, площа Лесі Українки, 1, 2-й поверх, хол прес-центру ЦВК', '1196, Kyiv, Lesi Ukrainky square 1, 2nd Floor, Hall Press Center CEC', '01196, г.Киев, площадь Леси Украинки, 1, 2-й этаж, холл пресс-центра ЦИК', '50.428073', '30.541399', '0', '0')"); } if (isset($_POST['update_addresses'])) { time_limit_pause(); $Precincts = Precincts::instance(); $all_precincts = $Precincts->get_all(); $cdb = $Precincts->db_prime(); foreach ($all_precincts as $p) { if ($cdb->qfs("SELECT `address_en` FROM `[prefix]precincts` WHERE `id` = {$p}")) { continue; } $p = $Precincts->get($p); $en_address = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($p['address']) . '&sensor=false&language=en')); if ($en_address['status'] == 'OK') { $cdb->q("UPDATE `[prefix]precincts`\n\t\t\t\tSET `address_en` = '%s'\n\t\t\t\tWHERE `id` = '%s'", $en_address['results'][0]['formatted_address'], $p['id']); } unset($en_address); $ru_address = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($p['address']) . '&sensor=false&language=ru')); if ($ru_address['status'] == 'OK') { $cdb->q("UPDATE `[prefix]precincts`\n\t\t\t\tSET `address_ru` = '%s'\n\t\t\t\tWHERE `id` = '%s'", $ru_address['results'][0]['formatted_address'], $p['id']);
/** * Get last added violations * * @param int $number Max number of violations to return * @param int $last_id Id of oldest received violation * @param string $search * * @return array[]|bool */ function last_violations($number, $last_id, $search = '') { $number = (int) $number; $last_id = (int) $last_id; $where = []; if ($last_id) { $where[] = "`id` < {$last_id}"; } if ($search) { $precincts = Precincts::instance()->search($search, false, 10000); if ($precincts) { $where[] = "`precinct` IN (" . implode(',', $precincts) . ")"; } else { return false; } } $where[] = '`status` != ' . self::STATUS_DECLINED; if ($where) { $where = 'WHERE ' . implode(' AND ', $where); } else { $where = ''; } return $this->get($this->db()->qfas("SELECT `id`\n\t\t\t\tFROM `{$this->table}`\n\t\t\t\t{$where}\n\t\t\t\tORDER BY `id` DESC\n\t\t\t\tLIMIT {$number}")); }
<?php /** * @package Districts * @category modules * @author Nazar Mokrynskyi <*****@*****.**> * @copyright Copyright (c) 2014, Nazar Mokrynskyi * @license MIT License, see license.txt */ namespace cs\modules\Precincts; use cs\Page; $Page = Page::instance(); $districts = Precincts::instance()->get_districts(); if (isset($_GET['fields'])) { $fields = array_intersect(explode(',', $_GET['fields']), ['district', 'count', 'lat', 'lng', 'violations']); $fields[] = 'district'; $fields = array_flip(array_unique($fields)); //For usage in array_intersect_key() foreach ($districts as &$district) { $district = array_intersect_key($district, $fields); } if (!isset($fields['violations'])) { header('Cache-Control: max-age=86400, public'); header('Expires: access plus 1 day'); } else { header('Cache-Control: max-age=600, public'); header('Expires: access plus 10 minutes'); } } else { header('Cache-Control: max-age=600, public');