mirror of
https://github.com/friendica/friendica
synced 2025-04-27 23:10:12 +00:00
Add new paradigm classes for notification and introduction notifications
- Add support for bounded select in BaseDepository
This commit is contained in:
parent
3e6fea30f2
commit
43e5b317ed
8 changed files with 990 additions and 0 deletions
|
@ -5,6 +5,7 @@ namespace Friendica;
|
|||
use Exception;
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
@ -43,6 +44,67 @@ abstract class BaseDepository
|
|||
$this->factory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the collection according to the condition. Retrieves a limited subset of entities depending on the
|
||||
* boundaries and the limit. The total count of rows matching the condition is stored in the collection.
|
||||
*
|
||||
* Depends on the corresponding table featuring a numerical auto incremented column called `id`.
|
||||
*
|
||||
* max_id and min_id are susceptible to the query order:
|
||||
* - min_id alone only reliably works with ASC order
|
||||
* - max_id alone only reliably works with DESC order
|
||||
* If the wrong order is detected in either case, we reverse the query order and the entity list order after the query
|
||||
*
|
||||
* Chainable.
|
||||
*
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @param int|null $min_id Retrieve models with an id no fewer than this, as close to it as possible
|
||||
* @param int|null $max_id Retrieve models with an id no greater than this, as close to it as possible
|
||||
* @param int $limit
|
||||
* @return BaseCollection
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function _selectByBoundaries(
|
||||
array $condition = [],
|
||||
array $params = [],
|
||||
int $min_id = null,
|
||||
int $max_id = null,
|
||||
int $limit = self::LIMIT
|
||||
): BaseCollection {
|
||||
$totalCount = $this->count($condition);
|
||||
|
||||
$boundCondition = $condition;
|
||||
|
||||
$reverseOrder = false;
|
||||
|
||||
if (isset($min_id)) {
|
||||
$boundCondition = DBA::mergeConditions($boundCondition, ['`id` > ?', $min_id]);
|
||||
if (!isset($max_id) && isset($params['order']['id']) && ($params['order']['id'] === true || $params['order']['id'] === 'DESC')) {
|
||||
$reverseOrder = true;
|
||||
|
||||
$params['order']['id'] = 'ASC';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($max_id)) {
|
||||
$boundCondition = DBA::mergeConditions($boundCondition, ['`id` < ?', $max_id]);
|
||||
if (!isset($min_id) && (!isset($params['order']['id']) || $params['order']['id'] === false || $params['order']['id'] === 'ASC')) {
|
||||
$reverseOrder = true;
|
||||
|
||||
$params['order']['id'] = 'DESC';
|
||||
}
|
||||
}
|
||||
|
||||
$params['limit'] = $limit;
|
||||
|
||||
$Entities = $this->_select($boundCondition, $params);
|
||||
if ($reverseOrder) {
|
||||
$Entities->reverse();
|
||||
}
|
||||
|
||||
return new BaseCollection($Entities->getArrayCopy(), $totalCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue