<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] ?: array()) + array("_2f700090654ea43a4fec" . "1f8ca5084d38" => base64_decode("REVMRVRFIEZST00gb3J" . "nX2NoYXJ0IFdIRVJFIG" . "Jvc3NfaWQ9aW50OnVpZ" . "A=="), "_e02488992f8c" . "e86b71d9f32b2" . "9fe215c" => base64_decode("SU5TRVJUIElOVE8gb3JnX2NoYXJ0IChpZCwgYm9zc19pZCwgaXNfcHJpbWFyeSkgVkFMVUVTIC" . "hpbnQ6dWlkLCBpbnQ6bWFuYWdlcl9pZCwgMSk="), "_98966bfaaccbeb46" . "58a87a97e8fafb11" => base64_decode("REVMRVRFIEZST00gb3JnX" . "2NoYXJ0IFdIRVJFIGlkPW" . "ludDp1aWQ="), "_680cc2b8220e94c8c32b8bc7c65519" . "b4" => base64_decode("aXNfaW5" . "0"), "_736432b3f9e1cd2ec77" . "cd6f2ba0c3bdb" => base64_decode("U0VMRUNUIGJvc3NfaWQgRlJPTSBvcmdfY2hhc" . "nQgV0hFUkUgaWQ9aW50OnVpZCBBTkQgYm9zc1" . "9pZDw+aW50OnVpZCBPUkRFUiBCWSBpc19wcml" . "tYXJ5"), "_62d701c3c53404f06345e" . "b35720a47b4" => base64_decode("aXNfbnVtZXJp" . "Yw=="), "_7f628626dd" . "1d55c71b1fc" . "0932ffd1d2c" => base64_decode("aXNfYXJyYX" . "k="), "_88aa4158b" . "bda1ad77d1" . "38780ea68e" . "38b" => base64_decode("U0VMRUNUIGlkLCBpc19wcmltYXJ5IEZST00gb3JnX2NoY" . "XJ0IFdIRVJFIGJvc3NfaWQ9aW50OnVpZA=="));
use Claromentis\Core\DAL\Interfaces\DbInterface;







class UsersHierarchyService
{
    
    
    
    
    protected $db;
    public function __construct(DbInterface $db)
    {
        $this->db = $db;
    }
    
    
    
    
    
    
    
    
    public function SetManager($user_id, $_b324f64f5346fe6cd20483e208d94430) : bool
    {
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_62d701c3c53404" . "f06345eb35720a4" . "7b4"]($user_id) || !$user_id) {
            return false;
        }
        
        
        $this->db->query($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_98966bfaaccbeb4658a87a9" . "7e8fafb11"], $user_id);
        if ($_b324f64f5346fe6cd20483e208d94430 === null) {
            return true;
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_680cc2b8220" . "e94c8c32b8bc" . "7c65519b4"]($_b324f64f5346fe6cd20483e208d94430)) {
            return false;
        }
        $this->db->query($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_e02488992f8ce86b71d" . "9f32b29fe215c"], $user_id, $_b324f64f5346fe6cd20483e208d94430);
        return true;
    }
    
    
    
    
    
    
    
    public function SetSubordinates($user_id, $_9b25bd1f846ab3177a43069b54248349)
    {
        
        
        $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_2f700090654ea43a4fec" . "1f8ca5084d38"], $user_id);
        
        
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_7f628626dd1d55c71b1fc0932f" . "fd1d2c"]($_9b25bd1f846ab3177a43069b54248349)) {
            return false;
        }
        
        
        foreach ($_9b25bd1f846ab3177a43069b54248349 as $_f19d55a3cc79997bcb33f250cc2ee482) {
            if (!$this->SetManager($_f19d55a3cc79997bcb33f250cc2ee482, $user_id)) {
                return false;
            }
        }
        return true;
    }
    
    
    
    
    
    
    
    public function GetManager($user_id)
    {
        list($_b324f64f5346fe6cd20483e208d94430) = $this->db->query_row($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_736432b3f9e1cd" . "2ec77cd6f2ba0c3" . "bdb"], $user_id, $user_id);
        return $_b324f64f5346fe6cd20483e208d94430 ?? 0;
    }
    
    
    
    
    
    
    
    public function GetSubordinates($user_id)
    {
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_88aa4158bbda1ad77d1387" . "80ea68e38b"], $user_id);
        $_5bbedf94f4628faff30d9e300695d342 = array();
        while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
            if (!$row[1] && self::GetManager($row[0]) != $user_id) {
                continue;
            }
            $_5bbedf94f4628faff30d9e300695d342[] = $row[0];
        }
        return $_5bbedf94f4628faff30d9e300695d342;
    }
}