<?php
namespace Claromentis\People\Repository;

$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] ?: array()) + array("_df7900be4aa7cd41b6508893" . "a3243c2d" => base64_decode("cHJpbWFyeV" . "9hcmVh"), "i" . "d" => base64_decode("aW" . "Q="), "_3485471e3a36e65fb5fc93a4bd99c3" . "47" => base64_decode("cHJpbWFye" . "Q=="), "_948976cc86bfda1b4ba9629a8e31d55" . "f" => 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["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_df7900be4aa7cd41b65088" . "93a3243c2d"]), 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["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_948976cc86bfda1b4" . "ba9629a8e31d55f"], $_9a2ef4ae6a5745ffe5fac33c88a222fa->id)->update([$this->getColumnName($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_3485471" . "e3a36e65" . "fb5fc93a" . "4bd99c34" . "7"]) => 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["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["i" . "d"], $acl->GetViewableExtranets($context));
        }
    }
}