mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-19 16:01:34 +02:00
81 lines
2.0 KiB
PHP
81 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace App\Filters;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
/**
|
|
* ProductFilters.
|
|
*/
|
|
class ProductFilters extends QueryFilters
|
|
{
|
|
protected $with_property = 'product_key';
|
|
|
|
/**
|
|
* Filter based on search text.
|
|
*
|
|
* @param string $filter
|
|
* @return Builder
|
|
*/
|
|
public function filter(string $filter = ''): Builder
|
|
{
|
|
if (strlen($filter) == 0) {
|
|
return $this->builder;
|
|
}
|
|
|
|
return $this->builder->where(function ($query) use ($filter) {
|
|
$query->where('product_key', 'like', '%'.$filter.'%')
|
|
->orWhere('notes', 'like', '%'.$filter.'%')
|
|
->orWhere('custom_value1', 'like', '%'.$filter.'%')
|
|
->orWhere('custom_value2', 'like', '%'.$filter.'%')
|
|
->orWhere('custom_value3', 'like', '%'.$filter.'%')
|
|
->orWhere('custom_value4', 'like', '%'.$filter.'%');
|
|
});
|
|
}
|
|
|
|
public function product_key(string $filter = ''): Builder
|
|
{
|
|
if (strlen($filter) == 0) {
|
|
return $this->builder;
|
|
}
|
|
|
|
return $this->builder->where('product_key', $filter);
|
|
}
|
|
|
|
/**
|
|
* Sorts the list based on $sort.
|
|
*
|
|
* @param string $sort formatted as column|asc
|
|
* @return Builder
|
|
*/
|
|
public function sort(string $sort = ''): Builder
|
|
{
|
|
$sort_col = explode('|', $sort);
|
|
|
|
if (!is_array($sort_col) || count($sort_col) != 2) {
|
|
return $this->builder;
|
|
}
|
|
|
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
|
}
|
|
|
|
/**
|
|
* Filters the query by the users company ID.
|
|
*
|
|
* @return Builder
|
|
*/
|
|
public function entityFilter(): Builder
|
|
{
|
|
return $this->builder->company();
|
|
}
|
|
}
|