Merge branch 'master' of https://github.com/alchemy-fr/Phraseanet into PHRAS-2741-worker-service-part1

This commit is contained in:
aynsix
2019-12-19 16:09:47 +04:00
135 changed files with 5869 additions and 2251 deletions

View File

@@ -1685,6 +1685,43 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $records;
}
public static function getRecordsByOriginalnameWithExcludedCollIds(databox $databox, $original_name, $caseSensitive = false, $offset_start = 0, $how_many = 10, $excludedCollIds = [])
{
$offset_start = max(0, (int)$offset_start);
$how_many = max(1, (int)$how_many);
$collate = $caseSensitive ? 'utf8_bin' : 'utf8_unicode_ci';
$qb = $databox->get_connection()->createQueryBuilder()
->select('record_id')
->from('record')
->where('originalname = :original_name COLLATE :collate')
;
$params = ['original_name' => $original_name, 'collate' => $collate];
$types = [];
if (!empty($excludedCollIds)) {
$qb->andWhere($qb->expr()->notIn('coll_id', ':coll_id'));
$params['coll_id'] = $excludedCollIds;
$types[':coll_id'] = Connection::PARAM_INT_ARRAY;
}
$sql = $qb->setFirstResult($offset_start)
->setMaxResults($how_many)
->getSQL()
;
$rs = $databox->get_connection()->fetchAll($sql, $params, $types);
$records = [];
foreach ($rs as $row) {
$records[] = $databox->get_record($row['record_id']);
}
return $records;
}
/**
* @return set_selection|record_adapter[]
* @throws Exception
@@ -1697,17 +1734,20 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
}
/**
* @param int $offset
* @param null|int $max_items
*
* @return set_selection|record_adapter[]
* @throws Exception
* @throws \Doctrine\DBAL\DBALException
*/
public function getChildren()
public function getChildren($offset = 1, $max_items = null)
{
if (!$this->isStory()) {
throw new Exception('This record is not a grouping');
}
$selections = $this->getDatabox()->getRecordRepository()->findChildren([$this->getRecordId()]);
$selections = $this->getDatabox()->getRecordRepository()->findChildren([$this->getRecordId()], null, $offset, $max_items);
return reset($selections);
}