123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Repositories\Criteria\Course;
- use App\Repositories\Enums\ModelStatusEnum;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class NodeCriteria implements CriteriaInterface
- {
- /**
- * @var \Illuminate\Http\Request
- */
- protected $request;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- /**
- * @param $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($this->request->filled('user_id')) {
- $user_id = $this->request->get('user_id');
- $model = $model->where('user_id', '=', $user_id);
- }
- if ($this->request->filled('course_id')) {
- $val = $this->request->get('course_id');
- $model = $model->where('course_id', '=', $val);
- }
- if ($this->request->filled('course_video_id')) {
- $val = $this->request->get('course_video_id');
- $model = $model->where('course_video_id', '=', $val);
- }
- if ($this->request->filled('title')) {
- $title = $this->request->get('title');
- $model = $model->where('title', 'like', "%{$title}%");
- }
- if ($this->request->filled('me')) {
- $model = $model->where('user_id', login_user_id());
- }
- if (!$this->request->filled('orderBy')) {
- $model = $model->orderByDesc('id');
- }
- if (isApiModule()) {
- $model = $model->where('status', ModelStatusEnum::OK);
- }
- return $model;
- }
- }
|