Example #1
0
 /**
  * Get tag
  *
  * @param int|int[]	$id
  *
  * @return array|array[]|bool
  */
 function get($id)
 {
     if (is_array($id)) {
         foreach ($id as &$i) {
             $i = $this->get($i);
         }
         return $id;
     }
     $id = (int) $id;
     return $this->cache->get($id, function () use($id) {
         return $this->db()->qf(["SELECT\n\t\t\t\t\t`id`,\n\t\t\t\t\t`title`\n\t\t\t\tFROM `{$this->table}`\n\t\t\t\tWHERE `id` = '%s'\n\t\t\t\tLIMIT 1", $id]) ?: false;
     });
 }
Example #2
0
 /**
  * Get array of pages structure
  *
  * @return array|bool
  */
 function get_structure()
 {
     $L = Language::instance();
     return $this->cache->get("structure/{$L->clang}", function () {
         return $this->get_structure_internal();
     });
 }
Example #3
0
 /**
  * Get all events
  *
  * @return array|bool
  */
 function get_all()
 {
     $user_id = User::instance()->id;
     return $this->cache->get("all/{$user_id}", function () use($user_id) {
         return $this->get($this->get_all_internal());
     });
 }
Example #4
0
 /**
  * Check granted access for specified client
  *
  * @param string	$client
  * @param bool|int	$user	If not specified - current user assumed
  *
  * @return bool
  */
 function get_access($client, $user = false)
 {
     $user = (int) $user ?: User::instance()->id;
     if ($user == User::GUEST_ID) {
         return $this->guest_tokens;
     }
     $clients = $this->cache->get("grant_access/{$user}", function () use($user) {
         return $this->db()->qfas(["SELECT `id`\n\t\t\t\tFROM `[prefix]oauth2_clients_grant_access`\n\t\t\t\tWHERE `user`\t= '%s'", $user]);
     });
     return $clients ? in_array($client, $clients) : false;
 }
Example #5
0
    /**
     * Returns array of all permissions grouped by permissions groups
     *
     * @return array	Format of array: ['group']['label'] = <i>permission_id</i>
     */
    function get_all()
    {
        if (empty($this->permissions_table)) {
            $this->permissions_table = $this->cache->get('all', function () {
                $all_permissions = [];
                $data = $this->db()->qfa('SELECT
						`id`,
						`label`,
						`group`
					FROM `[prefix]permissions`');
                foreach ($data as $item) {
                    if (!isset($all_permissions[$item['group']])) {
                        $all_permissions[$item['group']] = [];
                    }
                    $all_permissions[$item['group']][$item['label']] = $item['id'];
                }
                unset($data, $item);
                return $all_permissions;
            });
        }
        return $this->permissions_table;
    }
Example #6
0
 function get_districts()
 {
     return $this->cache->get('all/group_by_district', function () {
         $districts = $this->db()->qfa("SELECT\n\t\t\t\t\t`district`,\n\t\t\t\t\tCOUNT(`id`) AS `count`,\n\t\t\t\t\tSUM(`violations`) AS `violations`\n\t\t\t\tFROM `{$this->table}`\n\t\t\t\tWHERE `district` > 0\n\t\t\t\tGROUP BY `district`");
         $locations = $this->db()->qfa("SELECT\n\t\t\t\t\t`number`,\n\t\t\t\t\t`lat`,\n\t\t\t\t\t`lng`\n\t\t\t\tFROM `{$this->table}`\n\t\t\t\tWHERE `district` = 0");
         $lats = array_column($locations, 'lat', 'number');
         $lngs = array_column($locations, 'lng', 'number');
         unset($locations);
         foreach ($districts as $i => &$d) {
             if (!isset($lats[$d['district']])) {
                 unset($districts[$i]);
                 continue;
             }
             $d['district'] = (int) $d['district'];
             $d['count'] = (int) $d['count'];
             $d['lat'] = (double) $lats[$d['district']];
             $d['lng'] = (double) $lngs[$d['district']];
             $d['violations'] = (int) $d['violations'];
         }
         unset($i, $d);
         return array_values($districts);
     });
 }
Example #7
0
 /**
  * Get array of id of all violation for precinct
  *
  * @param int $precinct
  *
  * @return bool|int[]
  */
 function get_all_for_precinct($precinct)
 {
     return $this->cache->get("all_for_precincts/{$precinct}", function () use($precinct) {
         return $this->db()->qfas(["SELECT `id`\n\t\t\t\tFROM `{$this->table}`\n\t\t\t\tWHERE\n\t\t\t\t\t`precinct`\t= '%s' AND\n\t\t\t\t\t`status`\t!= '%s'", $precinct, self::STATUS_DECLINED]);
     });
 }
Example #8
0
 * @author         Nazar Mokrynskyi <*****@*****.**>
 * @copyright      Copyright (c) 2014, Nazar Mokrynskyi
 * @license        MIT License, see license.txt
 */
namespace cs\modules\Precincts;

use cs\Cache\Prefix, cs\Index, cs\Language, cs\Page;
$Index = Index::instance();
$Page = Page::instance();
$Precincts = Precincts::instance();
if (isset($Index->route_ids[0])) {
    $Page->json($Precincts->get($Index->route_ids[0]));
    header('Cache-Control: max-age=60, public');
    header('Expires: access plus 1 minute');
} else {
    $Cache = new Prefix('precincts');
    $precincts = $Cache->get('all/ids_api/' . Language::instance()->clang, function () use($Precincts) {
        return $Precincts->get($Precincts->get_all());
    });
    if (isset($_GET['id'])) {
        $id = array_unique(_int(explode(',', $_GET['id'])));
        if ($id) {
            $precincts = array_filter($precincts, function ($precinct) use($id) {
                return in_array($precinct['id'], $id);
            });
            $precincts = array_values($precincts);
        }
    }
    if (isset($_GET['number'])) {
        if (isset($_GET['page'])) {
            $page = max((int) $_GET['page'], 1);
Example #9
0
 /**
  * Get list of all groups
  *
  * @return array|bool		Every item in form of array('id' => <i>id</i>, 'title' => <i>title</i>, 'description' => <i>description</i>)
  */
 function get_all()
 {
     return $this->cache->get('all', function () {
         return $this->db()->qfa("SELECT\n\t\t\t\t\t`id`,\n\t\t\t\t\t`title`,\n\t\t\t\t\t`description`\n\t\t\t\tFROM `[prefix]groups`");
     });
 }
Example #10
0
 /**
  * Delete data, stored with session
  *
  * @param string		$item
  * @param null|string	$session_id
  *
  * @return bool
  *
  */
 function del_session_data($item, $session_id = null)
 {
     $session_id = $session_id ?: $this->current['session'];
     if (!is_md5($session_id)) {
         return false;
     }
     $data = $this->cache->get("sessions/data/{$session_id}", function () use($session_id) {
         return _json_decode($this->db()->qfs(["SELECT `data`\n\t\t\t\t\tFROM `[prefix]sessions`\n\t\t\t\t\tWHERE `id` = '%s'\n\t\t\t\t\tLIMIT 1", $session_id])) ?: false;
     }) ?: [];
     if (!isset($data[$item])) {
         return true;
     }
     unset($data[$item]);
     if ($this->db()->q("UPDATE `[prefix]sessions`\n\t\t\tSET `data` = '%s'\n\t\t\tWHERE `id` = '%s'\n\t\t\tLIMIT 1", _json_encode($data), $session_id)) {
         unset($this->cache->{"sessions/data/{$session_id}"});
         return true;
     }
     return false;
 }
Example #11
0
 /**
  * Get all events categories
  *
  * @return array|bool
  */
 function get_all()
 {
     return $this->cache->get('all', function () {
         return $this->db()->qfa("SELECT *\n\t\t\t\tFROM `{$this->table}`");
     });
 }
Example #12
0
 /**
  * Get all streams
  *
  * @return array|bool
  */
 function get_all()
 {
     return $this->cache->get('all', function () {
         return $this->db()->qfas("SELECT `id`\n\t\t\t\tFROM `{$this->table}`\n\t\t\t\tWHERE\n\t\t\t\t\t`approved`\t= 1 AND\n\t\t\t\t\t`abuse`\t\t< 5");
     });
 }