<?php
namespace Claromentis\People;

$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] ?: array()) + array("_680cc2b8220e94c8c32b8b" . "c7c65519b4" => base64_decode("aX" . "Nf" . "aW" . "50"), "_736432b3f9e1c" . "d2ec77cd6f2ba0" . "c3bdb" => base64_decode("U0VMRUNUIGJvc3NfaWQgRlJPTSBvcmdfY2hhcnQgV0hFUkUgaWQ9aW50OnVpZCBBTkQgYm9zc19pZDw+aW50OnVpZCB" . "PUkRFUiBCWSBpc19wcmltYXJ5"), "_62d701c3c53404f063" . "45eb35720a47b4" => base64_decode("aXNfbn" . "VtZXJp" . "Yw=="), "_98966bfaa" . "ccbeb4658a" . "87a97e8faf" . "b11" => base64_decode("REVMRVRFIEZST00gb3JnX2NoYXJ0IFdIRVJ" . "FIGlkPWludDp1aWQ="), "_2f700090654ea4" . "3a4fec1f8ca5084" . "d38" => base64_decode("REVMRVRFIEZST00gb3JnX2NoYXJ0IFdIRVJF" . "IGJvc3NfaWQ9aW50OnVpZA=="), "_7f628626dd1d55c71b1fc0932ff" . "d1d2c" => base64_decode("aXNfYXJyYX" . "k="), "_88aa4158" . "bbda1ad77" . "d138780ea" . "68e38b" => base64_decode("U0VMRUNUIGlkLCBpc19wcmltYXJ" . "5IEZST00gb3JnX2NoYXJ0IFdIRV" . "JFIGJvc3NfaWQ9aW50OnVpZA=="), "_e02488992f8ce8" . "6b71d9f32b29fe2" . "15c" => base64_decode("SU5TRVJUIElOVE8gb3JnX2NoYXJ0IChpZCwgYm9zc19pZCwgaXNfcHJpbWFyeSkgVkFMVUVTIChpbnQ6dWlkLCBpbn" . "Q6bWFuYWdlcl9pZCwgMSk="));
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["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_62d701c3c534" . "04f06345eb357" . "20a47b4"]($user_id) || !$user_id) {
            return false;
        }
        
        
        $this->db->query($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_98966bfaaccbe" . "b4658a87a97e8f" . "afb11"], $user_id);
        if ($_b324f64f5346fe6cd20483e208d94430 === null) {
            return true;
        }
        if (!$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_680cc2b8220e94c8" . "c32b8bc7c65519b4"]($_b324f64f5346fe6cd20483e208d94430)) {
            return false;
        }
        $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_e02488992f" . "8ce86b71d9f" . "32b29fe215c"], $user_id, $_b324f64f5346fe6cd20483e208d94430);
        return true;
    }
    
    
    
    
    
    
    
    public function SetSubordinates($user_id, $_9b25bd1f846ab3177a43069b54248349)
    {
        
        
        $this->db->query($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_2f700090654ea43a" . "4fec1f8ca5084d38"], $user_id);
        
        
        if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_7f628626dd1d55c71b" . "1fc0932ffd1d2c"]($_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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_736432b3f9e" . "1cd2ec77cd6f" . "2ba0c3bdb"], $user_id, $user_id);
        return $_b324f64f5346fe6cd20483e208d94430 ?? 0;
    }
    
    
    
    
    
    
    
    public function GetSubordinates($user_id)
    {
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_88aa415" . "8bbda1ad" . "77d13878" . "0ea68e38" . "b"], $user_id);
        $_5bbedf94f4628faff30d9e300695d342 = array();
        while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
            if (!$row[1] && self::GetManager($row[0]) != $user_id) {
                continue;
            }
            $_5bbedf94f4628faff30d9e300695d342[] = $row[0];
        }
        return $_5bbedf94f4628faff30d9e300695d342;
    }
}