74 lines
1.9 KiB
PHP
74 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Setting\Repositories;
|
|
|
|
use Modules\Setting\app\Models\Setting;
|
|
use Modules\FileManagement\Entities\FileManagement;
|
|
use Modules\FileManagement\Services\FileManagementService;
|
|
|
|
class SettingDaoImpl implements SettingDao
|
|
{
|
|
|
|
// protected $fileManagementService;
|
|
|
|
// public function __construct(FileManagementService $fileManagementService)
|
|
// {
|
|
// $this->fileManagementService = $fileManagementService;
|
|
// }
|
|
|
|
|
|
|
|
public function findAll($limit = null, $filter = [], $sort = ['id', 'DESC'])
|
|
{
|
|
$result = Setting::when(array_keys($filter, true), function ($query) use ($filter) {
|
|
if (isset($filter['client_id']) && !empty($filter['client_id'])) {
|
|
$query->where('client_id', $filter['client_id']);
|
|
}
|
|
})
|
|
->orderBy($sort[0], $sort[1])
|
|
->paginate($limit ? $limit : env('DEF_PAGE_LIMIT', 999));
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function findOne($id)
|
|
{
|
|
return Setting::where('id', $id)->first();
|
|
}
|
|
|
|
public function create($data)
|
|
{
|
|
$model = Setting::create($data);
|
|
return $model;
|
|
}
|
|
|
|
public function update($id, $data)
|
|
{
|
|
// $model = Setting::find($id);
|
|
$model = Setting::with('files')->where('id', $id)->first();
|
|
$result = $model->update($data);
|
|
return $result;
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$model = Setting::find($id);
|
|
$result = $model->delete();
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function upload($file)
|
|
{
|
|
$fileExtension = $file->getSettingOriginalExtension();
|
|
$fileName = 'NRJ' . time() . '.' . $fileExtension;
|
|
$file->move(public_path() . '/' . Setting::FILE_PATH, $fileName);
|
|
return $fileName;
|
|
}
|
|
|
|
public function getLatest()
|
|
{
|
|
return Setting::orderBy('id', 'DESC')->first();
|
|
}
|
|
}
|