Commit 90276d30 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Merge master

parents 2c9e3b66 f6dbddef
Loading
Loading
Loading
Loading
+31 −73
Changes for module/Oscar/src/Oscar/Service/OrganizationService.php: 31 added lines, 73 removed lines.
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ use Oscar\Entity\OrganizationType;
use Oscar\Entity\ProjectPartner;
use Oscar\Exception\OscarException;
use Oscar\Import\Organization\ImportOrganizationLdapStrategy;
use Oscar\Strategy\Search\OrganizationSearchStrategy;
use Oscar\Utils\UnicaenDoctrinePaginator;
use UnicaenApp\Mapper\Ldap\Structure;
use UnicaenApp\Service\EntityManagerAwareInterface;
@@ -41,54 +40,6 @@ class OrganizationService implements ServiceLocatorAwareInterface, EntityManager
    private $cacheCountries = null;
    private $cacheConnectors = null;

    /**
     * @return OrganizationSearchStrategy
     */
    public function getSearchEngineStrategy()
    {
        static $searchStrategy;
        if( $searchStrategy === null ){
            $opt = $this->getServiceLocator()->get('OscarConfig')->getConfiguration('strategy.organization.search_engine');
            $class = new \ReflectionClass($opt['class']);
            $searchStrategy = $class->newInstanceArgs($opt['params']);
        }
        return $searchStrategy;
    }

    public function search($expression)
    {
        $ids = $this->getSearchEngineStrategy()->search($expression);
        if( count($ids) ){
            $query = $this->getEntityManager()->getRepository(Organization::class)->createQueryBuilder('o');
            $query->where('o.id IN(:ids)')->setParameter('ids', $ids);
            return $query->getQuery()->getResult();
        } else {
            return [];
        }
    }


    public function searchDelete( $id )
    {
        $this->getSearchEngineStrategy()->remove($id);
    }

    public function searchUpdate( Person $person )
    {
        $this->getSearchEngineStrategy()->update($person);
    }

    public function searchIndex_reset()
    {
        $this->getSearchEngineStrategy()->resetIndex();
    }

    public function searchIndexRebuild(){
        $this->searchIndex_reset();
        $persons = $this->getEntityManager()->getRepository(Organization::class)->findAll();
        return $this->getSearchEngineStrategy()->rebuildIndex($persons);
    }

    /**
     * Retourne la liste des Roles disponible pour une organisation dans une activité.
     */
@@ -237,8 +188,6 @@ class OrganizationService implements ServiceLocatorAwareInterface, EntityManager
    public function getOrganizationsSearchPaged($search, $page, $filter=[])
    {
        $qb = $this->getBaseQuery();
        $ids = [];

        if ($search) {

            // Recherche sur le connector
@@ -255,11 +204,6 @@ class OrganizationService implements ServiceLocatorAwareInterface, EntityManager
            }
            else {

                if( $this->getSearchEngineStrategy() ){
                    $ids = $this->getSearchEngineStrategy()->search($search);
                    $qb->where('o.id IN(:ids)')->setParameter('ids', $ids);
                }
                else {
                $qb
                    ->orWhere('LOWER(o.shortName) LIKE :search')
                    ->orWhere('LOWER(o.fullName) LIKE :search')
@@ -277,7 +221,7 @@ class OrganizationService implements ServiceLocatorAwareInterface, EntityManager
                    ]
                );
            }
            }

        }

        // -------------------------------------------------------------------------------------------------------------
@@ -331,21 +275,6 @@ class OrganizationService implements ServiceLocatorAwareInterface, EntityManager
            ->setParameter('ids', $ids);
        }

        if( count($ids) ){
            // On ne trie que les 30 premiers
            $limit = 30;
            $nbr = 0;
            $case = '(CASE ';
            $i = 0;
            foreach ($ids as $id) {
                if( $nbr++ < $limit )
                    $case .= sprintf('WHEN o.id = \'%s\' THEN %s ', $id, $i++);
            }
            $case .= " ELSE $id END) AS HIDDEN ORD";
            $qb->addSelect($case);
            $qb->orderBy("ORD", 'ASC');
        }

        return new UnicaenDoctrinePaginator($qb, $page);
    }

@@ -378,8 +307,37 @@ class OrganizationService implements ServiceLocatorAwareInterface, EntityManager
    {
        $queryBuilder = $this->getEntityManager()->createQueryBuilder();
        $queryBuilder->select('o')
            ->from(Organization::class, 'o');
            ->from(Organization::class, 'o')
            ->orderBy('o.shortName')
            ->addOrderBy('o.fullName');
        return $queryBuilder;
    }

    const STRUCTURES_BASE_DN = 'ou=structures,dc=unicaen,dc=fr';
    const STAFF_ACTIVE_OR_DISABLED                = 'ou=people,dc=unicaen,dc=fr';

    private function areSameOrganization( Organization $organizationA, Organization $organizationB ){
        if( $organizationA->getCentaureId() == $organizationB->getCentaureId() ){
            return true;
        }
        ?><pre>;
        <?= $organizationA ?>
        <?= $organizationB ?>
        </pre>
        <?php
    }
    
    public function syncLdap($router)
    {
        $sync = new ImportOrganizationLdapStrategy($this->getServiceLdap(), $this->getEntityManager(), $router);
        return $sync->importAll();
    }

    /**
     * @return \UnicaenApp\Mapper\Ldap\Structure
     */
    protected function getServiceLdap()
    {
        return $this->getServiceLocator()->get('ldap_structure_service')->getMapper();
    }
}