Adding method to get media for server side table with filtering & search

parent cc1c0edd
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Modules\Media\Repositories\Eloquent; namespace Modules\Media\Repositories\Eloquent;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository; use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Media\Entities\File; use Modules\Media\Entities\File;
use Modules\Media\Events\FileIsCreating; use Modules\Media\Events\FileIsCreating;
...@@ -121,4 +122,28 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos ...@@ -121,4 +122,28 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
return $fileNameOnly . '_' . $version . '.' . $extension; return $fileNameOnly . '_' . $version . '.' . $extension;
} }
/**
* @param Request $request
* @return mixed
*/
public function serverPaginationFilteringFor(Request $request)
{
$media = $this->allWithBuilder();
if ($request->get('search') !== null) {
$term = $request->get('search');
$media->where('filename', 'LIKE', "%{$term}%");
}
if ($request->get('order_by') !== null && $request->get('order') !== 'null') {
$order = $request->get('order') === 'ascending' ? 'asc' : 'desc';
$media->orderBy($request->get('order_by'), $order);
} else {
$media->orderBy('created_at', 'desc');
}
return $media->paginate($request->get('per_page', 10));
}
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Modules\Media\Repositories; namespace Modules\Media\Repositories;
use Illuminate\Http\Request;
use Modules\Core\Repositories\BaseRepository; use Modules\Core\Repositories\BaseRepository;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
...@@ -29,4 +30,10 @@ interface FileRepository extends BaseRepository ...@@ -29,4 +30,10 @@ interface FileRepository extends BaseRepository
* @return object * @return object
*/ */
public function findMultipleFilesByZoneForEntity($zone, $entity); public function findMultipleFilesByZoneForEntity($zone, $entity);
/**
* @param Request $request
* @return mixed
*/
public function serverPaginationFilteringFor(Request $request);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment