Merge branch 'master' into PHRAS-2196-api-stories-pagination

This commit is contained in:
Nicolas Maillat
2019-12-12 12:56:48 +01:00
committed by GitHub
8 changed files with 173 additions and 6 deletions

View File

@@ -1673,6 +1673,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