2020-10-08 09:25:39 +11:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2023-01-29 09:21:40 +11:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-10-08 09:25:39 +11:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-10-08 09:25:39 +11:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Filters;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ProjectFilters.
|
|
|
|
|
*/
|
|
|
|
|
class ProjectFilters extends QueryFilters
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Filter based on search text.
|
|
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @param string query filter
|
2023-01-22 19:24:35 +11:00
|
|
|
* @return Illuminate\Eloquent\Query\Builder
|
2020-10-08 09:25:39 +11:00
|
|
|
* @deprecated
|
|
|
|
|
*/
|
2023-01-30 07:08:26 +01:00
|
|
|
public function filter(string $filter = ''): Builder
|
2020-10-08 09:25:39 +11:00
|
|
|
{
|
|
|
|
|
if (strlen($filter) == 0) {
|
|
|
|
|
return $this->builder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->builder->where(function ($query) use ($filter) {
|
2023-01-22 19:24:35 +11:00
|
|
|
$query->where('name', 'like', '%'.$filter.'%')
|
|
|
|
|
->orWhere('public_notes', 'like', '%'.$filter.'%')
|
|
|
|
|
->orWhere('private_notes', 'like', '%'.$filter.'%');
|
2020-10-08 09:25:39 +11:00
|
|
|
});
|
|
|
|
|
}
|
2023-01-29 09:52:40 +01:00
|
|
|
|
2023-01-30 07:08:26 +01:00
|
|
|
public function number(string $number = ''): Builder
|
2023-01-29 09:52:40 +01:00
|
|
|
{
|
2023-01-30 10:36:13 +01:00
|
|
|
if (strlen($number) == 0) {
|
|
|
|
|
return $this->builder;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-29 09:52:40 +01:00
|
|
|
return $this->builder->where('number', $number);
|
|
|
|
|
}
|
2020-10-08 09:25:39 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sorts the list based on $sort.
|
|
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @param string sort formatted as column|asc
|
2023-01-22 19:24:35 +11:00
|
|
|
* @return Illuminate\Eloquent\Query\Builder
|
2020-10-08 09:25:39 +11:00
|
|
|
*/
|
2023-01-30 12:08:39 +01:00
|
|
|
public function sort(string $sort = ''): Builder
|
2020-10-08 09:25:39 +11:00
|
|
|
{
|
|
|
|
|
$sort_col = explode('|', $sort);
|
|
|
|
|
|
2023-01-30 11:04:55 +01:00
|
|
|
if (!is_array($sort_col) || count($sort_col) != 2) {
|
|
|
|
|
return $this->builder;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 12:36:09 +11:00
|
|
|
if (is_array($sort_col)) {
|
2023-01-19 11:52:07 +11:00
|
|
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
2023-02-16 12:36:09 +11:00
|
|
|
}
|
2020-10-08 09:25:39 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filters the query by the users company ID.
|
|
|
|
|
*
|
2023-01-22 19:24:35 +11:00
|
|
|
* @return Illuminate\Eloquent\Query\Builder
|
2020-10-08 09:25:39 +11:00
|
|
|
*/
|
2023-01-30 07:08:26 +01:00
|
|
|
public function entityFilter(): Builder
|
2020-10-08 09:25:39 +11:00
|
|
|
{
|
2022-01-11 09:31:08 +11:00
|
|
|
return $this->builder->company();
|
2020-10-08 09:25:39 +11:00
|
|
|
}
|
|
|
|
|
}
|