Skip to content

Commit

Permalink
Add orderBy and limit; Bugfix Entity parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Apr 13, 2020
1 parent b272d38 commit 2318a27
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,39 @@ public function get(int $limit = null, int $offset = 0, bool $reset = true)

//--------------------------------------------------------------------

/**
* ORDER BY
*
* @param string $orderBy
* @param string $direction ASC, DESC or RANDOM
* @param boolean $escape
*
* @return $this
*/
public function orderBy(string $orderBy, string $direction = 'ASC', bool $escape = null)
{
$this->builder = $this->builder()->orderBy($orderBy, $direction);

return $this;
}

/**
* LIMIT
*
* @param integer $value LIMIT value
* @param integer $offset OFFSET value
*
* @return $this
*/
public function limit(int $value = null, ?int $offset = 0)
{
$this->builder = $this->builder()->limit($value);

return $this;
}

//--------------------------------------------------------------------

/**
* Format the results of the query. Returns an array of
* individual data rows, which can be either an 'array', an
Expand Down Expand Up @@ -440,7 +473,7 @@ public function insert($data = null, bool $returnID = true)
// Convert to an array
if (is_object($data))
{
$data = (array) $data;
$data = self::classToArray($data);
}

// Check if an ID was provided
Expand Down Expand Up @@ -508,7 +541,7 @@ public function update(string $id, $data): bool
// Convert to an array
if (is_object($data))
{
$data = (array) $data;
$data = self::classToArray($data);
}

// Must be called first so we don't strip out updated_at values
Expand Down Expand Up @@ -672,7 +705,7 @@ protected function doProtectFields(array $data): array
//--------------------------------------------------------------------

/**
* Takes a class an returns an array of it's public and protected
* Takes a class and returns an array of it's public and protected
* properties as an array suitable for use in creates and updates.
*
* @param string|object $data
Expand All @@ -681,7 +714,6 @@ protected function doProtectFields(array $data): array
* @param boolean $onlyChanged
*
* @return array
* @throws \ReflectionException
*/
public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime'): array
{
Expand Down

0 comments on commit 2318a27

Please sign in to comment.