<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] ?: array()) + array("_c7254c0da8f99d" . "40788436b019325" . "fcb" => base64_decode("aXNfbWV0YWRhd" . "GE="), "_0910ceca0" . "d6dca1ce9e" . "2289a2918d" . "904" => base64_decode("U0VMRUNUIERJU1RJTkNUIGZpZWxkX25hbWUsIGlzX21ldGFkYXRhCiAJCQkJRlJPTSB1c2Vyc19maWVsZHNfcGVybXMKIAkJCQlXSEVSRSBpc19lZGl0X3Blcm09aW50OmlzX2V" . "kaXQKIAkJCQlBTkQgcGVybV90YXJnZXQ9MQ=="), "_cccbf72fdd00aeb3489588124d7137c" . "3" => base64_decode("W2" . "1d"), "i" . "d" => base64_decode("a" . "W" . "Q" . "="), "_66dc8b21e83" . "9a9a4739443a" . "621ecc45a" => base64_decode("ZmllbGR" . "fbmFtZQ" . "=="), "_246e3d0615c6b4997eea1d7" . "dd583a8a0" => base64_decode("U0VMRUNUIGlkLCBmaWVsZF9uYW1lLCBpc19tZXRhZGF0YQoJCQkJRlJPTSB1c2Vyc19maWVsZHNfcGVybXMKCQkJCVdIRVJFIGlzX2VkaXRfcGVybT1pbnQ6aXNfZWRpdAoJCQkJ" . "QU5EIHBlcm1fd2hvPTEKCQkJCUFORCBwZXJtX3RhcmdldD0w"));
use Claromentis\Core\Acl\Acl;
use Claromentis\Core\Acl\AclRepository;
use Claromentis\Core\DAL\Interfaces\DbInterface;
class UserFieldsAclRepository
{
    protected $edit_id_cache;
    protected $view_id_cache;
    protected $view_acl_cache = [];
    protected $edit_acl_cache = [];
    
    
    
    
    protected $has_advanced_view_perms;
    
    
    
    
    protected $has_advanced_edit_perms;
    
    
    
    
    protected $db;
    
    
    
    
    protected $acl_repository;
    
    
    
    
    protected $fields_name_transformer;
    public function __construct(DbInterface $db, AclRepository $_ecd42e37de77b33f13a2c4d09f59d78f, UserFieldsNameTransformer $_b8bd81e74c0c083e968b8789a4d959a2)
    {
        $this->db = $db;
        $this->acl_repository = $_ecd42e37de77b33f13a2c4d09f59d78f;
        $this->fields_name_transformer = $_b8bd81e74c0c083e968b8789a4d959a2;
    }
    
    
    
    
    
    public function GetViewAcls(string $_66dc8b21e839a9a4739443a621ecc45a) : array
    {
        return $this->GetAcls($_66dc8b21e839a9a4739443a621ecc45a, false);
    }
    
    
    
    
    
    public function GetEditAcls(string $_66dc8b21e839a9a4739443a621ecc45a) : array
    {
        return $this->GetAcls($_66dc8b21e839a9a4739443a621ecc45a, true);
    }
    protected function GetAcls(string $_66dc8b21e839a9a4739443a621ecc45a, bool $_2bd573592d12126d3aa08c722788c86a) : array
    {
        $_66dc8b21e839a9a4739443a621ecc45a = $this->fields_name_transformer->toLegacy($_66dc8b21e839a9a4739443a621ecc45a);
        $_300d0090c7d95c334b4f6d20578f1f34 = $this->CacheIds($_2bd573592d12126d3aa08c722788c86a);
        $ids = $_300d0090c7d95c334b4f6d20578f1f34[$_66dc8b21e839a9a4739443a621ecc45a] ?? [];
        if ($_2bd573592d12126d3aa08c722788c86a) {
            $cache =& $this->edit_acl_cache;
        } else {
            $cache =& $this->view_acl_cache;
        }
        if (!$ids) {
            return [];
        }
        if ($cache[$_66dc8b21e839a9a4739443a621ecc45a] ?? null) {
            return $cache[$_66dc8b21e839a9a4739443a621ecc45a];
        }
        $_6bee501c49427dad88c8e53168963259 = [];
        foreach ($ids as $id) {
            $_6bee501c49427dad88c8e53168963259[] = $this->acl_repository->Get(PERM_CLASS_USR_WHO, $id);
        }
        $cache[$_66dc8b21e839a9a4739443a621ecc45a] = $_6bee501c49427dad88c8e53168963259;
        return $_6bee501c49427dad88c8e53168963259;
    }
    protected function CacheIds(bool $_2bd573592d12126d3aa08c722788c86a) : array
    {
        if ($_2bd573592d12126d3aa08c722788c86a) {
            $cache =& $this->edit_id_cache;
        } else {
            $cache =& $this->view_id_cache;
        }
        if (isset($cache)) {
            return $cache;
        }
        $cache = [];
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query(
            
            
            $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_246e3d0" . "615c6b49" . "97eea1d7" . "dd583a8a" . "0"],
            $_2bd573592d12126d3aa08c722788c86a ? 1 : 0
        );
        while ($row = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $name = $row[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_66dc8b21e839a9a4739443a" . "621ecc45a"]];
            if ($row[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_c7254c0da8f99d40788436b" . "019325fcb"]]) {
                $name = $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_cccbf72fdd00aeb3489588124d7137" . "c3"] . $name;
            }
            if (!isset($cache[$name])) {
                $cache[$name] = [];
            }
            $cache[$name][] = $row[$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["i" . "d"]];
        }
        return $cache;
    }
    public function HasAdvancedViewPerms(string $_66dc8b21e839a9a4739443a621ecc45a)
    {
        return $this->HasAdvancedPerms($_66dc8b21e839a9a4739443a621ecc45a, false);
    }
    public function HasAdvancedEditPerms(string $_66dc8b21e839a9a4739443a621ecc45a)
    {
        return $this->HasAdvancedPerms($_66dc8b21e839a9a4739443a621ecc45a, false);
    }
    public function HasAdvancedPerms(string $_66dc8b21e839a9a4739443a621ecc45a, bool $_2bd573592d12126d3aa08c722788c86a)
    {
        $_16e904583014a98ae3677f33f097518d = $this->fields_name_transformer->toLegacy($_66dc8b21e839a9a4739443a621ecc45a);
        $_cd32cee6e5836ae05dc7b722f2ec21e9 = $this->CacheAdvancedPerms($_2bd573592d12126d3aa08c722788c86a);
        return isset($_cd32cee6e5836ae05dc7b722f2ec21e9[$_16e904583014a98ae3677f33f097518d]);
    }
    protected function CacheAdvancedPerms(bool $_2bd573592d12126d3aa08c722788c86a)
    {
        if ($_2bd573592d12126d3aa08c722788c86a) {
            $cache =& $this->has_advanced_edit_perms;
        } else {
            $cache =& $this->has_advanced_view_perms;
        }
        if (isset($cache)) {
            return $cache;
        }
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query(
            
            
            $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0910ceca0d6dca1ce" . "9e2289a2918d904"],
            $_2bd573592d12126d3aa08c722788c86a ? 1 : 0
        );
        while ($row = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $name = $row[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_66dc8b21e839a9a" . "4739443a621ecc45" . "a"]];
            if ($row[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_c7254c0da8f99d40788436" . "b019325fcb"]]) {
                $name = $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_cccbf72f" . "dd00aeb34" . "89588124d" . "7137c3"] . $name;
            }
            $cache[$name] = 1;
        }
        return $cache;
    }
}