mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 04:53:26 +00:00
Allow retrieve collection by a collection of base ids
This commit is contained in:
@@ -72,6 +72,25 @@ class ArrayCacheCollectionReferenceRepository implements CollectionReferenceRepo
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $baseIds
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findMany(array $baseIds)
|
||||
{
|
||||
$references = $this->findAll();
|
||||
|
||||
$requested = [];
|
||||
|
||||
foreach ($baseIds as $baseId) {
|
||||
if (isset($references[$baseId])) {
|
||||
$requested[] = $references[$baseId];
|
||||
}
|
||||
}
|
||||
|
||||
return $requested;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
@@ -90,6 +109,10 @@ class ArrayCacheCollectionReferenceRepository implements CollectionReferenceRepo
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $baseIdsSubset
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findHavingOrderMaster(array $baseIdsSubset = null)
|
||||
{
|
||||
return $this->repository->findHavingOrderMaster($baseIdsSubset);
|
||||
|
@@ -29,6 +29,12 @@ interface CollectionReferenceRepository
|
||||
*/
|
||||
public function find($baseId);
|
||||
|
||||
/**
|
||||
* @param int[] $baseIds
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findMany(array $baseIds);
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
|
@@ -95,6 +95,25 @@ WHERE base_id = :baseId';
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $basesId
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findMany(array $basesId)
|
||||
{
|
||||
if (empty($basesId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = $this->connection->fetchAll(
|
||||
self::$selectQuery . ' WHERE base_id IN (:baseIds)',
|
||||
['baseIds' => $basesId],
|
||||
['baseIds' => Connection::PARAM_INT_ARRAY]
|
||||
);
|
||||
|
||||
return $this->createManyReferences($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
|
@@ -1763,20 +1763,39 @@ class ACL implements cache_cacheableInterface
|
||||
/**
|
||||
* Returns an array of collections on which the user is 'order master'
|
||||
*
|
||||
* @return array
|
||||
* @return collection[]
|
||||
*/
|
||||
public function get_order_master_collections()
|
||||
{
|
||||
$sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id';
|
||||
$stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql);
|
||||
$stmt->execute([':usr_id' => $this->user->getId()]);
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$result = $this->app->getApplicationBox()
|
||||
->get_connection()
|
||||
->executeQuery($sql, [':usr_id' => $this->user->getId()])
|
||||
->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
$baseIds = [];
|
||||
|
||||
foreach ($result as $item) {
|
||||
$baseIds[] = $item['base_id'];
|
||||
}
|
||||
|
||||
$groups = [];
|
||||
|
||||
foreach ($this->app['repo.collection-references']->findHavingOrderMaster($baseIds) as $index => $reference) {
|
||||
$databoxId = $reference->getDataboxId();
|
||||
$group = isset($groups[$databoxId]) ? $groups[$databoxId] : [];
|
||||
|
||||
$group[$reference->getCollectionId()] = $index;
|
||||
$groups[$databoxId] = $group;
|
||||
}
|
||||
|
||||
$collections = [];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$collections[] = \collection::getByBaseId($this->app, $row['base_id']);
|
||||
foreach ($groups as $databoxId => $group) {
|
||||
foreach ($group as $collectionId => $index) {
|
||||
$collections[$index] = \collection::getByCollectionId($this->app, $databoxId, $collectionId);
|
||||
}
|
||||
}
|
||||
|
||||
return $collections;
|
||||
|
@@ -192,16 +192,17 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param databox $databox
|
||||
* @param int $collectionId
|
||||
* @param Application $app
|
||||
* @param databox|int $databox
|
||||
* @param int $collectionId
|
||||
* @return collection
|
||||
*/
|
||||
public static function getByCollectionId(Application $app, databox $databox, $collectionId)
|
||||
public static function getByCollectionId(Application $app, $databox, $collectionId)
|
||||
{
|
||||
assert(is_int($collectionId));
|
||||
$databoxId = $databox instanceof databox ? $databox->get_sbas_id() : (int)$databox;
|
||||
|
||||
return self::getAvailableCollection($app, $databox->get_sbas_id(), $collectionId);
|
||||
return self::getAvailableCollection($app, $databoxId, $collectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user