| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Api\Resource; |
| 4 |
|
| 5 |
use FluentCart\Framework\Database\Orm\Builder; |
| 6 |
use FluentCart\App\Models\Activity; |
| 7 |
use FluentCart\Framework\Support\Arr; |
| 8 |
|
| 9 |
class ActivityResource extends BaseResourceApi |
| 10 |
{ |
| 11 |
public static function get(array $params = []) |
| 12 |
{ |
| 13 |
$logsQuery = Activity::query() |
| 14 |
->orderBy( |
| 15 |
sanitize_sql_orderby(Arr::get($params, 'order_by', 'id')), |
| 16 |
sanitize_sql_orderby(Arr::get($params, 'order_type', 'DESC')) |
| 17 |
); |
| 18 |
$status = Arr::get($params, 'status'); |
| 19 |
|
| 20 |
if (!empty($status) && $status !== 'all') { |
| 21 |
if ($status === 'api') { |
| 22 |
$logsQuery->where('log_type', 'api'); |
| 23 |
} else { |
| 24 |
$logsQuery->where('status', $status); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
return $logsQuery->paginate( |
| 29 |
Arr::get($params, 'per_page', 15), |
| 30 |
['*'], |
| 31 |
'page', |
| 32 |
Arr::get($params, 'page', 1) |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
public static function find($id, $params = []) |
| 37 |
{ |
| 38 |
return Activity::query()->find($id); |
| 39 |
} |
| 40 |
|
| 41 |
public static function create($data, $params = []) |
| 42 |
{ |
| 43 |
return Activity::query()->create($data); |
| 44 |
} |
| 45 |
|
| 46 |
public static function update($data, $id, $params = []) |
| 47 |
{ |
| 48 |
return Activity::query()->where('id', $id)->update($data); |
| 49 |
} |
| 50 |
|
| 51 |
public static function delete($id, $params = []) |
| 52 |
{ |
| 53 |
return Activity::query()->where('id', $id)->delete(); |
| 54 |
} |
| 55 |
|
| 56 |
static function getQuery(): Builder |
| 57 |
{ |
| 58 |
return Activity::query(); |
| 59 |
} |
| 60 |
} |