mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-26 03:13:12 +00:00
change query
This commit is contained in:
@@ -1264,7 +1264,7 @@ class V1Controller extends Controller
|
|||||||
|
|
||||||
$selections = $this->findDataboxById($databoxId)
|
$selections = $this->findDataboxById($databoxId)
|
||||||
->getRecordRepository()
|
->getRecordRepository()
|
||||||
->findChildren($storyIds, $user,0, $story_max_items);
|
->findChildren($storyIds, $user,1, $story_max_items);
|
||||||
$children[$databoxId] = array_combine($storyIds, $selections);
|
$children[$databoxId] = array_combine($storyIds, $selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1655,7 +1655,7 @@ class V1Controller extends Controller
|
|||||||
$max_items = (int)$request->get('max_items')?:10;
|
$max_items = (int)$request->get('max_items')?:10;
|
||||||
$page = (int)$request->get('page')?:1;
|
$page = (int)$request->get('page')?:1;
|
||||||
|
|
||||||
$offset = $max_items * ($page - 1);
|
$offset = $max_items * ($page - 1) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$caption = $story->get_caption();
|
$caption = $story->get_caption();
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class LegacyRecordRepository implements RecordRepository
|
|||||||
return $this->mapRecordsFromResultSet($result);
|
return $this->mapRecordsFromResultSet($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findChildren(array $storyIds, $user = null, $offset = 0, $max_items = null)
|
public function findChildren(array $storyIds, $user = null, $offset = 1, $max_items = null)
|
||||||
{
|
{
|
||||||
if (!$storyIds) {
|
if (!$storyIds) {
|
||||||
return [];
|
return [];
|
||||||
@@ -129,9 +129,54 @@ class LegacyRecordRepository implements RecordRepository
|
|||||||
$connection = $this->databox->get_connection();
|
$connection = $this->databox->get_connection();
|
||||||
|
|
||||||
$selects = $this->getRecordSelects();
|
$selects = $this->getRecordSelects();
|
||||||
array_unshift($selects, 's.rid_parent as story_id', 's.ord');
|
|
||||||
|
if($max_items){
|
||||||
|
array_unshift($selects, 'sr.rid_parent as story_id');
|
||||||
|
|
||||||
|
$subBuilder = $connection->createQueryBuilder();
|
||||||
|
|
||||||
|
$subBuilder
|
||||||
|
->select('s.*,
|
||||||
|
IF(@old_rid_parent != s.rid_parent, @cpt := 1, @cpt := @cpt+1) AS CPT')
|
||||||
|
->addSelect("IF(@old_rid_parent != s.rid_parent, IF(@old_rid_parent:=s.rid_parent,'NEW PARENT',0), '----------') AS Y")
|
||||||
|
->from('regroup', 's')
|
||||||
|
->where('s.rid_parent IN (:storyIds)')
|
||||||
|
->setParameter('storyIds', $storyIds, Connection::PARAM_INT_ARRAY)
|
||||||
|
->orderBy('s.rid_parent, s.ord')
|
||||||
|
;
|
||||||
|
|
||||||
|
$builder = $subBuilder->getConnection()->createQueryBuilder();
|
||||||
|
|
||||||
|
$builder->select($selects)
|
||||||
|
->from(sprintf('( %s )', $subBuilder->getSQL()), 'sr')
|
||||||
|
->innerJoin('sr', 'record', 'r', 'r.record_id = sr.rid_child')
|
||||||
|
->where('sr.CPT BETWEEN :offset AND :maxresult')
|
||||||
|
->andWhere('r.parent_record_id = 0')
|
||||||
|
->setParameter('offset', $offset)
|
||||||
|
->setParameter('maxresult', ($offset + $max_items -1))
|
||||||
|
->orderBy('story_id, sr.CPT')
|
||||||
|
;
|
||||||
|
|
||||||
|
if (null !== $user) {
|
||||||
|
$this->addUserFilter($builder, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
$connection->executeQuery('SET @cpt = 1');
|
||||||
|
|
||||||
|
$connection->executeQuery('SET @old_rid_parent = -1');
|
||||||
|
|
||||||
|
|
||||||
|
$data = $connection->fetchAll(
|
||||||
|
$builder->getSQL(),
|
||||||
|
array_merge($subBuilder->getParameters(), $builder->getParameters()),
|
||||||
|
array_merge($subBuilder->getParameterTypes(), $builder->getParameterTypes())
|
||||||
|
);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
array_unshift($selects, 's.rid_parent as story_id');
|
||||||
|
|
||||||
$builder = $connection->createQueryBuilder();
|
$builder = $connection->createQueryBuilder();
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->select($selects)
|
->select($selects)
|
||||||
->from('regroup', 's')
|
->from('regroup', 's')
|
||||||
@@ -147,12 +192,8 @@ class LegacyRecordRepository implements RecordRepository
|
|||||||
$this->addUserFilter($builder, $user);
|
$this->addUserFilter($builder, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($max_items){
|
|
||||||
$builder->having('s.ord >= '. $offset .' and s.ord < '. ($offset + $max_items))
|
|
||||||
->addOrderBy('s.ord', 'ASC');
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $connection->fetchAll($builder->getSQL(), $builder->getParameters(), $builder->getParameterTypes());
|
$data = $connection->fetchAll($builder->getSQL(), $builder->getParameters(), $builder->getParameterTypes());
|
||||||
|
}
|
||||||
|
|
||||||
$records = $this->mapRecordsFromResultSet($data);
|
$records = $this->mapRecordsFromResultSet($data);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user