12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Repositories\Criteria\Exam;
- use App\Repositories\Enums\ModelStatusEnum;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- /**
- * Class TopicCriteria.
- *
- * @package namespace App\Repositories\Criteria\Exam;
- */
- class TopicCriteria implements CriteriaInterface
- {
- /**
- * Apply criteria in query repository
- *
- * @param string $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function __construct(Request $request = null)
- {
- if (is_null($request)) {
- $this->request = \request();
- } else {
- $this->request = $request;
- }
- }
- /**
- * Apply criteria in query repository
- *
- * @param string $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($this->request->filled('title')) {
- $title = $this->request->get('title');
- $model = $model->where('title', 'like', "%{$title}%");
- }
- if ($this->request->filled('status')) {
- $status = $this->request->get('status');
- $model = $model->where('status', '=', $status);
- } else {
- $model = $model->where('status', '=', ModelStatusEnum::OK);
- }
- if ($this->request->filled('category_id')) {
- $category_id = $this->request->get('category_id', false);
- $model = $model->where('category_id', '=', $category_id);
- }
- if ($this->request->filled('type')) {
- $type = $this->request->get('type', false);
- $model = $model->where('type', '=', $type);
- }
- if ($this->request->filled('level')) {
- $level = $this->request->get('level', false);
- $model = $model->where('level', '=', $level);
- }
- if ($this->request->filled('point')) {
- $point = $this->request->get('point', false);
- $model = $model->where('point', '=', $point);
- }
- $model = $model->orderByDesc('id');
- return $model;
- }
- }
|