<?php
namespace Claromentis\People\Repository;

$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] ?: array()) + array("_3485471e3a" . "36e65fb5fc9" . "3a4bd99c347" => base64_decode("cHJ" . "pbW" . "Fye" . "Q=="), "_948976cc86bfda1b4b" . "a9629a8e31d55f" => base64_decode("I" . "T" . "0" . "="), "i" . "d" => base64_decode("a" . "W" . "Q" . "="), "_df7900be4aa7cd41b6" . "508893a3243c2d" => base64_decode("cHJpbW" . "FyeV9h" . "cmVh"));
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["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_df7900b" . "e4aa7cd4" . "1b650889" . "3a3243c2" . "d"]), 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["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_948976cc86bf" . "da1b4ba9629a8" . "e31d55f"], $_9a2ef4ae6a5745ffe5fac33c88a222fa->id)->update([$this->getColumnName($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_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["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["i" . "d"], $acl->GetViewableExtranets($context));
        }
    }
}