mirror of
				https://github.com/alchemy-fr/Phraseanet.git
				synced 2025-10-24 18:33:13 +00:00 
			
		
		
		
	 5cdf473c7f
			
		
	
	5cdf473c7f
	
	
	
		
			
			* allow user to delete account * generate translation and add checkbox in the windows confirmation * change text an configuration key * update delete account fonctionality * rename variable * write in explicite condition * merge yarn.lock * regenerate translation
		
			
				
	
	
		
			117 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * This file is part of Phraseanet
 | |
|  *
 | |
|  * (c) 2005-2016 Alchemy
 | |
|  *
 | |
|  * For the full copyright and license information, please view the LICENSE
 | |
|  * file that was distributed with this source code.
 | |
|  */
 | |
| 
 | |
| namespace Alchemy\Phrasea\Collection;
 | |
| 
 | |
| use Alchemy\Phrasea\Application;
 | |
| use Alchemy\Phrasea\Collection\Reference\CollectionReferenceRepository;
 | |
| 
 | |
| class CollectionRepositoryRegistry
 | |
| {
 | |
| 
 | |
|     private $baseIdMap = null;
 | |
| 
 | |
|     /**
 | |
|      * @var Application
 | |
|      */
 | |
|     private $application;
 | |
| 
 | |
|     /**
 | |
|      * @var CollectionRepository[]
 | |
|      */
 | |
|     private $repositories = array();
 | |
| 
 | |
|     /**
 | |
|      * @var CollectionReferenceRepository
 | |
|      */
 | |
|     private $referenceRepository;
 | |
| 
 | |
|     /**
 | |
|      * @var CollectionRepositoryFactory
 | |
|      */
 | |
|     private $repositoryFactory;
 | |
| 
 | |
|     /**
 | |
|      * @param Application $app
 | |
|      * @param CollectionRepositoryFactory $collectionRepositoryFactory
 | |
|      * @param CollectionReferenceRepository $referenceRepository
 | |
|      */
 | |
|     public function __construct(
 | |
|         Application $app,
 | |
|         CollectionRepositoryFactory $collectionRepositoryFactory,
 | |
|         CollectionReferenceRepository $referenceRepository
 | |
|     ) {
 | |
|         $this->application = $app;
 | |
|         $this->repositoryFactory = $collectionRepositoryFactory;
 | |
|         $this->referenceRepository = $referenceRepository;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param $databoxId
 | |
|      * @return CollectionRepository
 | |
|      */
 | |
|     public function getRepositoryByDatabox($databoxId)
 | |
|     {
 | |
|         if (!isset($this->repositories[$databoxId])) {
 | |
|             $this->repositories[$databoxId] = $this->repositoryFactory->createRepositoryForDatabox($databoxId);
 | |
|         }
 | |
| 
 | |
|         return $this->repositories[$databoxId];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param int $baseId
 | |
|      * @return CollectionRepository
 | |
|      * @throws \OutOfBoundsException if no repository was found for the given baseId.
 | |
|      */
 | |
|     public function getRepositoryByBase($baseId)
 | |
|     {
 | |
|         if ($this->baseIdMap === null) {
 | |
|             $this->loadBaseIdMap();
 | |
|         }
 | |
| 
 | |
|         if (isset($this->baseIdMap[$baseId])) {
 | |
|             return $this->getRepositoryByDatabox($this->baseIdMap[$baseId]);
 | |
|         }
 | |
| 
 | |
|         throw new \OutOfBoundsException('No repository available for given base [baseId: ' . $baseId . ' ].');
 | |
|     }
 | |
| 
 | |
|     public function getBaseIdMap()
 | |
|     {
 | |
|         if ($this->baseIdMap === null) {
 | |
|             $this->loadBaseIdMap();
 | |
|         }
 | |
| 
 | |
|         return $this->baseIdMap;
 | |
|     }
 | |
| 
 | |
|     public function purgeRegistry()
 | |
|     {
 | |
|         $this->baseIdMap = null;
 | |
| 
 | |
|         $appBox = $this->application->getApplicationBox();
 | |
| 
 | |
|         \phrasea::reset_baseDatas($appBox);
 | |
|         \phrasea::reset_sbasDatas($appBox);
 | |
|     }
 | |
| 
 | |
|     private function loadBaseIdMap()
 | |
|     {
 | |
|         $references = $this->referenceRepository->findAll();
 | |
| 
 | |
|         $this->baseIdMap = [];
 | |
| 
 | |
|         foreach ($references as $reference) {
 | |
|             $this->baseIdMap[$reference->getBaseId()] = $reference->getDataboxId();
 | |
|         }
 | |
|     }
 | |
| }
 |