mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Preparing newest for more functionality
This commit is contained in:
parent
d4321df72f
commit
4c9fca4f62
|
|
@ -512,22 +512,25 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
*
|
||||
* This will fall back to the insert id if no datetime column is present.
|
||||
*
|
||||
* @param \int $limit Newest limit
|
||||
* @param Builder $query Pre-defined query
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getNewest()
|
||||
public function getNewest(\int $limit = 1, Builder $query = null)
|
||||
{
|
||||
if (!isset(static::$createdAt) || !isset(static::$columns[static::$createdAt])) {
|
||||
throw new \BadMethodCallException('Method "' . __METHOD__ . '" is not supported.');
|
||||
}
|
||||
|
||||
$query = new Builder($this->db);
|
||||
$query = $query ?? new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->select('*')
|
||||
->from(static::$table)
|
||||
->limit(1);
|
||||
->limit($limit); /* todo: limit is not working, setting this to 2 doesn't have any effect!!! */
|
||||
|
||||
if (isset(static::$createdAt)) {
|
||||
$query->orderBy(static::$table . '.' . static::$columns[static::$createdAt]['name'], 'DESC');
|
||||
|
|
@ -540,6 +543,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
$results = $sth->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
/* todo: if limit get's used this has to call populateIterable */
|
||||
return $this->populate(is_bool($results) ? [] : $results);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user