diff --git a/app/Filters/BankIntegrationFilters.php b/app/Filters/BankIntegrationFilters.php index 85924f463d..1932b0995d 100644 --- a/app/Filters/BankIntegrationFilters.php +++ b/app/Filters/BankIntegrationFilters.php @@ -26,10 +26,11 @@ class BankIntegrationFilters extends QueryFilters */ public function name(string $name = ''): Builder { - if(strlen($name) >=1) - return $this->builder->where('bank_account_name', 'like', '%'.$name.'%'); + if (strlen($name) == 0) { + return $this->builder; + } - return $this->builder; + return $this->builder->where('bank_account_name', 'like', '%'.$name.'%'); } /** @@ -90,9 +91,13 @@ class BankIntegrationFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/BankTransactionFilters.php b/app/Filters/BankTransactionFilters.php index 778d3ba4ac..4830277be8 100644 --- a/app/Filters/BankTransactionFilters.php +++ b/app/Filters/BankTransactionFilters.php @@ -27,10 +27,11 @@ class BankTransactionFilters extends QueryFilters */ public function name(string $name = ''): Builder { - if(strlen($name) >=1) - return $this->builder->where('bank_account_name', 'like', '%'.$name.'%'); - - return $this->builder; + if (strlen($name) == 0) { + return $this->builder; + } + + return $this->builder->where('bank_account_name', 'like', '%'.$name.'%'); } /** @@ -40,7 +41,7 @@ class BankTransactionFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -66,7 +67,7 @@ class BankTransactionFilters extends QueryFilters * * @return Builder */ - public function client_status(string $value = '') :Builder + public function client_status(string $value = ''): Builder { if (strlen($value) == 0) { return $this->builder; @@ -123,12 +124,13 @@ class BankTransactionFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); - if(!is_array($sort_col)) + if (!is_array($sort_col) || count($sort_col) != 2) { return $this->builder; + } if($sort_col[0] == 'deposit') return $this->builder->where('base_type', 'CREDIT')->orderBy('amount', $sort_col[1]); diff --git a/app/Filters/BankTransactionRuleFilters.php b/app/Filters/BankTransactionRuleFilters.php index 0ec8773d4b..ce8d1c58d8 100644 --- a/app/Filters/BankTransactionRuleFilters.php +++ b/app/Filters/BankTransactionRuleFilters.php @@ -30,10 +30,11 @@ class BankTransactionRuleFilters extends QueryFilters */ public function name(string $name = ''): Builder { - if(strlen($name) >=1) - return $this->builder->where('name', 'like', '%'.$name.'%'); - - return $this->builder; + if (strlen($name) == 0) { + return $this->builder; + } + + return $this->builder->where('name', 'like', '%'.$name.'%'); } /** @@ -43,7 +44,7 @@ class BankTransactionRuleFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -61,9 +62,13 @@ class BankTransactionRuleFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : 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]); } @@ -76,7 +81,7 @@ class BankTransactionRuleFilters extends QueryFilters * @return Builder * @deprecated */ - public function baseQuery(int $company_id, User $user) : Builder + public function baseQuery(int $company_id, User $user): Builder { } diff --git a/app/Filters/ClientFilters.php b/app/Filters/ClientFilters.php index d34bc2b808..513551b2e0 100644 --- a/app/Filters/ClientFilters.php +++ b/app/Filters/ClientFilters.php @@ -30,10 +30,11 @@ class ClientFilters extends QueryFilters */ public function name(string $name = ''): Builder { - if(strlen($name) >=1) - return $this->builder->where('name', 'like', '%'.$name.'%'); + if (strlen($name) == 0) { + return $this->builder; + } - return $this->builder; + return $this->builder->where('name', 'like', '%'.$name.'%'); } /** @@ -42,8 +43,12 @@ class ClientFilters extends QueryFilters * @param string $balance * @return Builder */ - public function balance(string $balance): Builder + public function balance(string $balance = ''): Builder { + if (strlen($balance) == 0) { + return $this->builder; + } + $parts = $this->split($balance); return $this->builder->where('balance', $parts->operator, $parts->value); @@ -55,27 +60,29 @@ class ClientFilters extends QueryFilters * @param string balance * @return Builder */ - public function between_balance(string $balance): Builder + public function between_balance(string $balance = ''): Builder { $parts = explode(':', $balance); - if (! is_array($parts)) { + if (!is_array($parts) || count($parts) != 2) { return $this->builder; } return $this->builder->whereBetween('balance', [$parts[0], $parts[1]]); } - public function email(string $email = ''):Builder + public function email(string $email = ''): Builder { - return + if (strlen($email) == 0) { + return $this->builder; + } - $this->builder->whereHas('contacts', function ($query) use ($email) { + return $this->builder->whereHas('contacts', function ($query) use ($email) { $query->where('email', $email); }); } - public function client_id(string $client_id = '') :Builder + public function client_id(string $client_id = ''): Builder { if (strlen($client_id) == 0) { return $this->builder; @@ -84,13 +91,21 @@ class ClientFilters extends QueryFilters return $this->builder->where('id', $this->decodePrimaryKey($client_id)); } - public function id_number(string $id_number = ''):Builder + public function id_number(string $id_number = ''): Builder { + if (strlen($id_number) == 0) { + return $this->builder; + } + return $this->builder->where('id_number', $id_number); } - public function number(string $number = ''):Builder + public function number(string $number = ''): Builder { + if (strlen($number) == 0) { + return $this->builder; + } + return $this->builder->where('number', $number); } @@ -101,7 +116,7 @@ class ClientFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -128,10 +143,14 @@ class ClientFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } + if($sort_col[0] == 'display_name') $sort_col[0] = 'name'; diff --git a/app/Filters/CompanyGatewayFilters.php b/app/Filters/CompanyGatewayFilters.php index fcb44bec93..fd7ec9c5f1 100644 --- a/app/Filters/CompanyGatewayFilters.php +++ b/app/Filters/CompanyGatewayFilters.php @@ -26,7 +26,7 @@ class CompanyGatewayFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -43,10 +43,14 @@ class CompanyGatewayFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : 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]); } diff --git a/app/Filters/CreditFilters.php b/app/Filters/CreditFilters.php index f2df87ac31..b95e18b143 100644 --- a/app/Filters/CreditFilters.php +++ b/app/Filters/CreditFilters.php @@ -30,7 +30,7 @@ class CreditFilters extends QueryFilters * @param string credit_status The credit status as seen by the client * @return Builder */ - public function credit_status(string $value = '') :Builder + public function credit_status(string $value = ''): Builder { if (strlen($value) == 0) { return $this->builder; @@ -66,7 +66,7 @@ class CreditFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -85,16 +85,29 @@ class CreditFilters extends QueryFilters }); } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : 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]); } @@ -123,7 +136,7 @@ class CreditFilters extends QueryFilters * * @return Builder */ - private function contactViewFilter() : Builder + private function contactViewFilter(): Builder { return $this->builder ->whereCompanyId(auth()->guard('contact')->user()->company->id) diff --git a/app/Filters/DesignFilters.php b/app/Filters/DesignFilters.php index 7cd323ef8e..3985fb6a16 100644 --- a/app/Filters/DesignFilters.php +++ b/app/Filters/DesignFilters.php @@ -32,7 +32,7 @@ class DesignFilters extends QueryFilters return $this->builder; } - return $this->builder->where(function ($query) use ($filter) { + return $this->builder->where(function ($query) use ($filter) { $query->where('designs.name', 'like', '%'.$filter.'%'); }); } @@ -44,14 +44,15 @@ class DesignFilters extends QueryFilters * * @return Builder */ - public function sort(string $sort): Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); - if(is_array($sort_col)) - return $this->builder->orderBy($sort_col[0], $sort_col[1]); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } - return $this->builder; + return $this->builder->orderBy($sort_col[0], $sort_col[1]); } /** diff --git a/app/Filters/DocumentFilters.php b/app/Filters/DocumentFilters.php index d36e4ead46..575e471bfd 100644 --- a/app/Filters/DocumentFilters.php +++ b/app/Filters/DocumentFilters.php @@ -54,14 +54,15 @@ class DocumentFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort = '') : Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); - if(is_array($sort_col)) - return $this->builder->orderBy($sort_col[0], $sort_col[1]); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } - return $this->builder; + return $this->builder->orderBy($sort_col[0], $sort_col[1]); } diff --git a/app/Filters/ExpenseCategoryFilters.php b/app/Filters/ExpenseCategoryFilters.php index 33e7e05b42..3ed24beac6 100644 --- a/app/Filters/ExpenseCategoryFilters.php +++ b/app/Filters/ExpenseCategoryFilters.php @@ -25,7 +25,7 @@ class ExpenseCategoryFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -41,10 +41,14 @@ class ExpenseCategoryFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } + if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['name'])) return $this->builder->orderBy($sort_col[0], $sort_col[1]); diff --git a/app/Filters/ExpenseFilters.php b/app/Filters/ExpenseFilters.php index 13d07ca853..e04cc216e9 100644 --- a/app/Filters/ExpenseFilters.php +++ b/app/Filters/ExpenseFilters.php @@ -25,7 +25,7 @@ class ExpenseFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -53,7 +53,7 @@ class ExpenseFilters extends QueryFilters * * @return Builder */ - public function client_status(string $value = '') :Builder + public function client_status(string $value = ''): Builder { if (strlen($value) == 0) { return $this->builder; @@ -132,16 +132,29 @@ class ExpenseFilters extends QueryFilters return $this->builder; } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } + if (is_array($sort_col) && in_array($sort_col[1], ['asc', 'desc']) && in_array($sort_col[0], ['public_notes', 'date', 'id_number', 'custom_value1', 'custom_value2', 'custom_value3', 'custom_value4'])) { return $this->builder->orderBy($sort_col[0], $sort_col[1]); } diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index d1456f2c26..55d2d2097f 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -179,8 +179,7 @@ class InvoiceFilters extends QueryFilters { $sort_col = explode('|', $sort); - //catch invalid explode array count - if (count($sort_col) == 1) { + if (!is_array($sort_col) || count($sort_col) != 2) { return $this->builder; } @@ -224,7 +223,7 @@ class InvoiceFilters extends QueryFilters * * @return Builder */ - private function contactViewFilter() : Builder + private function contactViewFilter(): Builder { return $this->builder ->whereCompanyId(auth()->guard('contact')->user()->company->id) diff --git a/app/Filters/PaymentFilters.php b/app/Filters/PaymentFilters.php index 09aafd2885..f3c21072d1 100644 --- a/app/Filters/PaymentFilters.php +++ b/app/Filters/PaymentFilters.php @@ -62,25 +62,30 @@ class PaymentFilters extends QueryFilters return $this->builder; } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); - if(is_array($sort_col)) - return $this->builder->orderBy($sort_col[0], $sort_col[1]); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } - return true; - } - - public function number(string $number = ''): Builder - { - return $this->builder->where('number', $number); + return $this->builder->orderBy($sort_col[0], $sort_col[1]); } /** diff --git a/app/Filters/PaymentTermFilters.php b/app/Filters/PaymentTermFilters.php index f9d87955d7..26400394c9 100644 --- a/app/Filters/PaymentTermFilters.php +++ b/app/Filters/PaymentTermFilters.php @@ -42,10 +42,14 @@ class PaymentTermFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/ProductFilters.php b/app/Filters/ProductFilters.php index 3a976a9c96..5357073f34 100644 --- a/app/Filters/ProductFilters.php +++ b/app/Filters/ProductFilters.php @@ -58,12 +58,13 @@ class ProductFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); - if(!is_array($sort_col)) + if (!is_array($sort_col) || count($sort_col) != 2) { return $this->builder; + } return $this->builder->orderBy($sort_col[0], $sort_col[1]); } diff --git a/app/Filters/ProjectFilters.php b/app/Filters/ProjectFilters.php index d76bab948a..c154546448 100644 --- a/app/Filters/ProjectFilters.php +++ b/app/Filters/ProjectFilters.php @@ -25,7 +25,7 @@ class ProjectFilters extends QueryFilters * @return Illuminate\Eloquent\Query\Builder * @deprecated */ - public function filter(string $filter = '') :Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -37,6 +37,15 @@ class ProjectFilters extends QueryFilters ->orWhere('private_notes', 'like', '%'.$filter.'%'); }); } + + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } /** * Sorts the list based on $sort. @@ -44,10 +53,14 @@ class ProjectFilters extends QueryFilters * @param string sort formatted as column|asc * @return Illuminate\Eloquent\Query\Builder */ - public function sort(string $sort) :Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } + if(is_array($sort_col)) return $this->builder->orderBy($sort_col[0], $sort_col[1]); } @@ -57,7 +70,7 @@ class ProjectFilters extends QueryFilters * * @return Illuminate\Eloquent\Query\Builder */ - public function entityFilter() :Builder + public function entityFilter(): Builder { return $this->builder->company(); } diff --git a/app/Filters/PurchaseOrderFilters.php b/app/Filters/PurchaseOrderFilters.php index cf33241dc7..7fb0c75949 100644 --- a/app/Filters/PurchaseOrderFilters.php +++ b/app/Filters/PurchaseOrderFilters.php @@ -100,16 +100,29 @@ class PurchaseOrderFilters extends QueryFilters }); } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } @@ -136,7 +149,7 @@ class PurchaseOrderFilters extends QueryFilters * * @return Builder */ - private function contactViewFilter() : Builder + private function contactViewFilter(): Builder { return $this->builder ->whereCompanyId(auth()->guard('contact')->user()->company->id) diff --git a/app/Filters/QueryFilters.php b/app/Filters/QueryFilters.php index a0ab3e9a88..3eb1b8964c 100644 --- a/app/Filters/QueryFilters.php +++ b/app/Filters/QueryFilters.php @@ -136,7 +136,7 @@ abstract class QueryFilters * @param string filter * @return Builder */ - public function status(string $filter = '') : Builder + public function status(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -241,7 +241,7 @@ abstract class QueryFilters return $this->builder->where('is_deleted', $value); } - public function client_id(string $client_id = '') :Builder + public function client_id(string $client_id = ''): Builder { if (strlen($client_id) == 0) { return $this->builder; @@ -250,7 +250,7 @@ abstract class QueryFilters return $this->builder->where('client_id', $this->decodePrimaryKey($client_id)); } - public function vendor_id(string $vendor_id = '') :Builder + public function vendor_id(string $vendor_id = ''): Builder { if (strlen($vendor_id) == 0) { return $this->builder; diff --git a/app/Filters/QuoteFilters.php b/app/Filters/QuoteFilters.php index 8f7138e9f6..23bb09ba8c 100644 --- a/app/Filters/QuoteFilters.php +++ b/app/Filters/QuoteFilters.php @@ -113,7 +113,11 @@ class QuoteFilters extends QueryFilters public function number($number = ''): Builder { - return $this->builder->where('number', 'like', '%'.$number.'%'); + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); } /** @@ -122,10 +126,14 @@ class QuoteFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): Builder + public function sort(string $sort = ''): Builder { $sort_col = explode('|', $sort); + if (!is_array($sort_col) || count($sort_col) != 2) { + return $this->builder; + } + if($sort_col[0] == 'valid_until') $sort_col[0] = 'due_date'; diff --git a/app/Filters/RecurringExpenseFilters.php b/app/Filters/RecurringExpenseFilters.php index 120e799242..f8e0c2ba66 100644 --- a/app/Filters/RecurringExpenseFilters.php +++ b/app/Filters/RecurringExpenseFilters.php @@ -40,16 +40,29 @@ class RecurringExpenseFilters extends QueryFilters }); } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/RecurringInvoiceFilters.php b/app/Filters/RecurringInvoiceFilters.php index abefee0c42..07884685e7 100644 --- a/app/Filters/RecurringInvoiceFilters.php +++ b/app/Filters/RecurringInvoiceFilters.php @@ -83,16 +83,29 @@ class RecurringInvoiceFilters extends QueryFilters } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/RecurringQuoteFilters.php b/app/Filters/RecurringQuoteFilters.php index accd731d90..eb9d593aa2 100644 --- a/app/Filters/RecurringQuoteFilters.php +++ b/app/Filters/RecurringQuoteFilters.php @@ -39,16 +39,29 @@ class RecurringQuoteFilters extends QueryFilters }); } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Illuminate\Database\Eloquent\Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/SubscriptionFilters.php b/app/Filters/SubscriptionFilters.php index 1ff2051c63..d9722e46ce 100644 --- a/app/Filters/SubscriptionFilters.php +++ b/app/Filters/SubscriptionFilters.php @@ -42,10 +42,14 @@ class SubscriptionFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/SystemLogFilters.php b/app/Filters/SystemLogFilters.php index 0a97968636..3fb6c80b08 100644 --- a/app/Filters/SystemLogFilters.php +++ b/app/Filters/SystemLogFilters.php @@ -18,18 +18,30 @@ use Illuminate\Database\Eloquent\Builder; */ class SystemLogFilters extends QueryFilters { - public function type_id(int $type_id) :Builder + public function type_id(string $type_id = ''): Builder { + if (strlen($type_id) == 0) { + return $this->builder; + } + return $this->builder->where('type_id', $type_id); } - public function category_id(int $category_id) :Builder + public function category_id(string $category_id = ''): Builder { + if (strlen($category_id) == 0) { + return $this->builder; + } + return $this->builder->where('category_id', $category_id); } - public function event_id(int $event_id) :Builder + public function event_id(string $event_id = ''): Builder { + if (strlen($event_id) == 0) { + return $this->builder; + } + return $this->builder->where('event_id', $event_id); } @@ -40,7 +52,7 @@ class SystemLogFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -55,10 +67,14 @@ class SystemLogFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort) : 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]); } diff --git a/app/Filters/TaskFilters.php b/app/Filters/TaskFilters.php index f36ec3a852..9e732fcf97 100644 --- a/app/Filters/TaskFilters.php +++ b/app/Filters/TaskFilters.php @@ -81,6 +81,15 @@ class TaskFilters extends QueryFilters return $this->builder->where('project_id', $this->decodePrimaryKey($project)); } + + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } /** * Sorts the list based on $sort. @@ -88,10 +97,14 @@ class TaskFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/TaskStatusFilters.php b/app/Filters/TaskStatusFilters.php index ee2d87a10c..35ef91a028 100644 --- a/app/Filters/TaskStatusFilters.php +++ b/app/Filters/TaskStatusFilters.php @@ -42,10 +42,14 @@ class TaskStatusFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/TaxRateFilters.php b/app/Filters/TaxRateFilters.php index 2f5bc51e28..8d225d3db2 100644 --- a/app/Filters/TaxRateFilters.php +++ b/app/Filters/TaxRateFilters.php @@ -25,7 +25,7 @@ class TaxRateFilters extends QueryFilters * @return Builder * @deprecated */ - public function filter(string $filter = '') : Builder + public function filter(string $filter = ''): Builder { if (strlen($filter) == 0) { return $this->builder; @@ -42,10 +42,14 @@ class TaxRateFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/TokenFilters.php b/app/Filters/TokenFilters.php index c98601dc2e..60e43faec4 100644 --- a/app/Filters/TokenFilters.php +++ b/app/Filters/TokenFilters.php @@ -42,10 +42,14 @@ class TokenFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/UserFilters.php b/app/Filters/UserFilters.php index ef2e257d59..a53b2eded0 100644 --- a/app/Filters/UserFilters.php +++ b/app/Filters/UserFilters.php @@ -46,10 +46,14 @@ class UserFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } @@ -76,8 +80,9 @@ class UserFilters extends QueryFilters public function with(string $value = ''): Builder { - if(strlen($value) == 0) + if(strlen($value) == 0) { return $this->builder; + } return $this->builder ->orWhere($this->with_property, $value) diff --git a/app/Filters/VendorFilters.php b/app/Filters/VendorFilters.php index 61d8fd753e..4937a75133 100644 --- a/app/Filters/VendorFilters.php +++ b/app/Filters/VendorFilters.php @@ -46,16 +46,29 @@ class VendorFilters extends QueryFilters }); } + public function number(string $number = ''): Builder + { + if (strlen($number) == 0) { + return $this->builder; + } + + return $this->builder->where('number', $number); + } + /** * Sorts the list based on $sort. * * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); } diff --git a/app/Filters/WebhookFilters.php b/app/Filters/WebhookFilters.php index 606a9984fc..6ab0927495 100644 --- a/app/Filters/WebhookFilters.php +++ b/app/Filters/WebhookFilters.php @@ -42,10 +42,14 @@ class WebhookFilters extends QueryFilters * @param string sort formatted as column|asc * @return Builder */ - public function sort(string $sort): 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]); }