| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Models; |
| 4 |
|
| 5 |
use FluentBooking\Framework\Database\Orm\Model as BaseModel; |
| 6 |
|
| 7 |
class Model extends BaseModel |
| 8 |
{ |
| 9 |
public function __construct($attributes = []) |
| 10 |
{ |
| 11 |
parent::__construct($attributes); |
| 12 |
} |
| 13 |
|
| 14 |
public function scopeLatest($query, $field = 'created_at') |
| 15 |
{ |
| 16 |
return $query->orderBy($field, 'DESC'); |
| 17 |
} |
| 18 |
|
| 19 |
public function scopeNewest($query, $field = 'created_at') |
| 20 |
{ |
| 21 |
return $query->orderBy($field, 'ASC'); |
| 22 |
} |
| 23 |
|
| 24 |
public function getPerPage() |
| 25 |
{ |
| 26 |
return (isset($_REQUEST['per_page'])) ? intval($_REQUEST['per_page']) : 15; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get a fresh timestamp for the model. |
| 31 |
* |
| 32 |
* @return \DateTime |
| 33 |
*/ |
| 34 |
public function freshTimestamp() |
| 35 |
{ |
| 36 |
return new \DateTime(gmdate('Y-m-d H:i:s')); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 37 |
} |
| 38 |
|
| 39 |
public function getTimezone() |
| 40 |
{ |
| 41 |
return new \DateTimeZone('UTC'); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Determine if the new and old values for a given key are numerically equivalent. |
| 46 |
* |
| 47 |
* @param string $key |
| 48 |
* @return bool |
| 49 |
*/ |
| 50 |
protected function originalIsNumericallyEquivalent($key) |
| 51 |
{ |
| 52 |
$current = $this->attributes[$key]; |
| 53 |
|
| 54 |
$original = $this->original[$key]; |
| 55 |
|
| 56 |
return is_numeric($current) && is_numeric($original) && strcmp((string) $current, (string) $original) === 0; |
| 57 |
} |
| 58 |
} |
| 59 |
|