<?php
namespace Claromentis\People\Repository;

$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"] ?: array()) + array("i" . "d" => base64_decode("aW" . "Q="), "_df7900be4aa7cd41b" . "6508893a3243c2d" => base64_decode("cHJp" . "bWFy" . "eV9h" . "cmVh"), "_3485471e3a3" . "6e65fb5fc93a" . "4bd99c347" => base64_decode("cHJp" . "bWFy" . "eQ=="), "_948976cc86b" . "fda1b4ba9629" . "a8e31d55f" => base64_decode("IT" . "0="));
use Analogue\ORM\EntityCollection;
use Analogue\ORM\Exceptions\MappingException;
use Analogue\ORM\System\Mapper;
use Analogue\ORM\System\Query;
use Claromentis\People\Entity\Extranet;
use Claromentis\People\Entity\User;
use Claromentis\People\Filter\ExtranetFilter;
use Claromentis\People\Filter\Filter;
class ExtranetRepository extends Repository
{
    
    
    
    
    protected $mapper;
    
    
    
    
    private $user_mapper;
    public function __construct(Mapper $_dabd1eb8030f2c29327a192cddfd85a9, Mapper $_d62fda0dfcd699fadd97214e9645add7)
    {
        $this->mapper = $_dabd1eb8030f2c29327a192cddfd85a9;
        $this->user_mapper = $_d62fda0dfcd699fadd97214e9645add7;
        parent::__construct($_dabd1eb8030f2c29327a192cddfd85a9);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function updateUserExtranet(int $extranet_id, array $_17247f55ce15f647f57c3ef8bb3a474a) : EntityCollection
    {
        try {
            
            
            
            
            $_e4543e131c67c631b14751cc849d1310 = $this->user_mapper->findMany($_17247f55ce15f647f57c3ef8bb3a474a);
            foreach ($_e4543e131c67c631b14751cc849d1310 as $_24e0e36600d6af77406a44bb618a6253) {
                $_24e0e36600d6af77406a44bb618a6253->extranet_id = $extranet_id;
            }
            $this->user_mapper->store($_e4543e131c67c631b14751cc849d1310);
        } catch (MappingException $e) {
            throw new MappingException($e->getMessage());
        }
        return $_e4543e131c67c631b14751cc849d1310;
    }
    
    
    
    
    
    
    
    
    
    public function getPrimaryExtranet()
    {
        
        
        
        
        $_9a2ef4ae6a5745ffe5fac33c88a222fa = $this->mapper->where($this->getColumnName($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_df7900be" . "4aa7cd41b" . "6508893a3" . "243c2d"]), 1)->first();
        return $_9a2ef4ae6a5745ffe5fac33c88a222fa;
    }
    
    
    
    
    
    
    
    public function setPrimaryExtranet(Extranet $_9a2ef4ae6a5745ffe5fac33c88a222fa)
    {
        
        
        $_9a2ef4ae6a5745ffe5fac33c88a222fa->primary = true;
        $this->store($_9a2ef4ae6a5745ffe5fac33c88a222fa);
        
        
        $_09b016526a9df52fb2fdd56fa1d9e520 = $this->mapper->getEntityMap()->getQualifiedKeyName();
        $this->query()->where($_09b016526a9df52fb2fdd56fa1d9e520, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_948976cc" . "86bfda1b4" . "ba9629a8e" . "31d55f"], $_9a2ef4ae6a5745ffe5fac33c88a222fa->id)->update([$this->getColumnName($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_3485471e3a36e65f" . "b5fc93a4bd99c347"]) => 0]);
    }
    protected function applyFilterConditions(Filter $_03e9164d0a343b742df4793268b80767, Query $_7f5aa4e96d4b415a86ed72ebff677cbe)
    {
        parent::applyFilterConditions($_03e9164d0a343b742df4793268b80767, $_7f5aa4e96d4b415a86ed72ebff677cbe);
        if ($_03e9164d0a343b742df4793268b80767 instanceof ExtranetFilter) {
            $this->applyExtranetFilterConditions($_03e9164d0a343b742df4793268b80767, $_7f5aa4e96d4b415a86ed72ebff677cbe);
        }
    }
    protected function applyExtranetFilterConditions(ExtranetFilter $_03e9164d0a343b742df4793268b80767, Query $_7f5aa4e96d4b415a86ed72ebff677cbe)
    {
        $context = $_03e9164d0a343b742df4793268b80767->GetContext();
        $acl = $_03e9164d0a343b742df4793268b80767->GetPeopleAcl();
        if (!$acl->IsPeopleAdmin($context) && !$acl->IsExtranetAdmin($context)) {
            $_7f5aa4e96d4b415a86ed72ebff677cbe->whereIn($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["i" . "d"], $acl->GetViewableExtranets($context));
        }
    }
}