<?php
namespace Claromentis\People\Repository;

$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"] ?: array()) + array("i" . "d" => base64_decode("aW" . "Q="), "_df7900be4aa7c" . "d41b6508893a32" . "43c2d" => base64_decode("cHJpbW" . "FyeV9h" . "cmVh"), "_3485471e" . "3a36e65fb" . "5fc93a4bd" . "99c347" => base64_decode("cHJpbWFyeQ=" . "="), "_948976cc86bfda1b4ba" . "9629a8e31d55f" => base64_decode("IT0" . "="));
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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_df7900be4aa7cd41b650889" . "3a3243c2d"]), 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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_948976cc" . "86bfda1b4" . "ba9629a8e" . "31d55f"], $_9a2ef4ae6a5745ffe5fac33c88a222fa->id)->update([$this->getColumnName($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_3485471e3a36e65fb5fc93a4b" . "d99c347"]) => 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["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["i" . "d"], $acl->GetViewableExtranets($context));
        }
    }
}