12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Repositories\Criteria\Area;
- use App\Repositories\Enums\Base\RoleEnum;
- use App\Repositories\Enums\ModelStatusEnum;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- /**
- * Class PointCriteria.
- *
- * @package namespace App\Repositories\Criteria\Area;
- */
- class PointCriteria 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('name')) {
- $name = $this->request->get('name');
- $model = $model->where('name', 'like', "%{$name}%");
- }
- if ($this->request->filled('status')) {
- $status = $this->request->get('status');
- $model = $model->where('status', '=', $status);
- }
- if ($this->request->filled('project_id')) {
- $project_id = $this->request->get('project_id', false);
- $model = $model->where('project_id', '=', $project_id);
- }
- if ($this->request->filled('parent_id')) {
- $parent_id = $this->request->get('parent_id', false);
- $model = $model->where('parent_id', '=', $parent_id);
- }
- if ($this->request->filled('area_id')) {
- $area_id = $this->request->get('area_id', false);
- $model = $model->where('area_id', '=', $area_id);
- }
- if ($this->request->filled('type')) {
- $type = $this->request->get('type', false);
- $model = $model->where('type', '=', $type);
- }
- if (is_admin_login()) {
- $admin = login_admin();
- if ($admin->role_id > RoleEnum::ADMIN) {
- $model = $model->where('shop_id', $admin->shop_id);
- if ($admin->role_id == RoleEnum::PROJECT) {
- $model = $model->whereIn('project_id', $admin->project_ids);
- }
- }
- }
- $model = $model->orderByDesc('id');
- return $model;
- }
- }
|