From 8676764513f03611b73c56efbd945e45fec4aecc Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 4 May 2019 20:58:43 +0200 Subject: [PATCH] Remove various sort routines. --- app/Helpers/Collection/Bill.php | 11 +- app/Helpers/Report/BudgetReportHelper.php | 5 - .../Controllers/Account/IndexController.php | 15 +- app/Http/Controllers/BillController.php | 5 - app/Http/Controllers/Chart/BillController.php | 1 + app/Http/Controllers/CurrencyController.php | 7 - .../Json/AutoCompleteController.php | 134 +++++++++++++++++- .../Transaction/CreateController.php | 56 ++++++++ app/Http/Middleware/SecureHeaders.php | 2 +- .../Account/AccountRepository.php | 34 ++--- app/Repositories/Bill/BillRepository.php | 26 +--- app/Repositories/Budget/BudgetRepository.php | 32 +---- .../Category/CategoryRepository.php | 5 - app/Repositories/Tag/TagRepository.php | 36 +++-- .../Tag/TagRepositoryInterface.php | 9 ++ app/Support/Binder/AccountList.php | 9 +- .../Http/Controllers/RenderPartialViews.php | 6 +- .../Http/Controllers/RequestInformation.php | 2 +- app/Support/Twig/General.php | 17 ++- 19 files changed, 261 insertions(+), 151 deletions(-) diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.php index f950a93914..7b50e12c2d 100644 --- a/app/Helpers/Collection/Bill.php +++ b/app/Helpers/Collection/Bill.php @@ -103,16 +103,7 @@ class Bill */ public function getBills(): Collection { - $set = $this->bills->sortBy( - function (BillLine $bill) { - $active = 0 === (int)$bill->getBill()->active ? 1 : 0; - $name = $bill->getBill()->name; - - return $active . $name; - } - ); - - return $set; + return $this->bills; } /** diff --git a/app/Helpers/Report/BudgetReportHelper.php b/app/Helpers/Report/BudgetReportHelper.php index 6f64024634..41b56af8fe 100644 --- a/app/Helpers/Report/BudgetReportHelper.php +++ b/app/Helpers/Report/BudgetReportHelper.php @@ -144,11 +144,6 @@ class BudgetReportHelper implements BudgetReportHelperInterface $set->push($budget); } } - $set = $set->sortBy( - function (Budget $budget) { - return $budget->name; - } - ); return $set; } diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.php index 6c9e8a19eb..1e49e808e0 100644 --- a/app/Http/Controllers/Account/IndexController.php +++ b/app/Http/Controllers/Account/IndexController.php @@ -77,18 +77,9 @@ class IndexController extends Controller $types = config('firefly.accountTypesByIdentifier.' . $what); $collection = $this->repository->getAccountsByType($types); $total = $collection->count(); - - // sort collection: - $collection = $collection->sortBy( - function (Account $account) { - return ($account->active ? '0' : '1') . $account->name; - } - ); - - - $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; - $accounts = $collection->slice(($page - 1) * $pageSize, $pageSize); + $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); + $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $accounts = $collection->slice(($page - 1) * $pageSize, $pageSize); unset($collection); /** @var Carbon $start */ $start = clone session('start', Carbon::now()->startOfMonth()); diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index 2251706607..d8f5a183c6 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -212,11 +212,6 @@ class BillController extends Controller return $return; } ); - $bills = $bills->sortBy( - function (array $bill) { - return (int)!$bill['active'] . strtolower($bill['name']); - } - ); // add info about rules: $rules = $this->billRepository->getRulesForBills($paginator->getCollection()); diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index e0af3ad201..fbbfd3695c 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -114,6 +114,7 @@ class BillController extends Controller } $results = $collector->setAllAssetAccounts()->setBills(new Collection([$bill]))->getTransactions(); + // TODO remove me /** @var Collection $results */ $results = $results->sortBy( function (Transaction $transaction) { diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php index 45d932919b..ca34315bb8 100644 --- a/app/Http/Controllers/CurrencyController.php +++ b/app/Http/Controllers/CurrencyController.php @@ -311,13 +311,6 @@ class CurrencyController extends Controller $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $collection = $this->repository->getAll(); $total = $collection->count(); - $collection = $collection->sortBy( - function (TransactionCurrency $currency) { - $intEnabled = $currency->enabled ? 0 : 1; - - return $intEnabled . $currency->name; - } - ); $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); $currencies = new LengthAwarePaginator($collection, $total, $pageSize, $page); $currencies->setPath(route('currencies.index')); diff --git a/app/Http/Controllers/Json/AutoCompleteController.php b/app/Http/Controllers/Json/AutoCompleteController.php index 6ca6d052a4..1a82e2cf24 100644 --- a/app/Http/Controllers/Json/AutoCompleteController.php +++ b/app/Http/Controllers/Json/AutoCompleteController.php @@ -25,12 +25,21 @@ namespace FireflyIII\Http\Controllers\Json; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Collector\TransactionCollectorInterface; use FireflyIII\Http\Controllers\Controller; +use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; +use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; +use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; +use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; +use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Support\CacheProperties; use FireflyIII\Support\Http\Controllers\AutoCompleteCollector; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Log; /** * Class AutoCompleteController. @@ -41,6 +50,51 @@ class AutoCompleteController extends Controller { use AutoCompleteCollector; + /** + * @param Request $request + * + * @return JsonResponse + */ + public function accounts(Request $request): JsonResponse + { + $accountTypes = explode(',', $request->get('types') ?? ''); + $search = $request->get('query'); + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + + // filter the account types: + $allowedAccountTypes = [AccountType::ASSET, AccountType::EXPENSE, AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,]; + $filteredAccountTypes = []; + foreach ($accountTypes as $type) { + if (in_array($type, $allowedAccountTypes, true)) { + $filteredAccountTypes[] = $type; + } + } + Log::debug('Now in accounts(). Filtering results.', $filteredAccountTypes); + + $return = []; + $result = $repository->searchAccount((string)$search, $filteredAccountTypes); + $defaultCurrency = app('amount')->getDefaultCurrency(); + + /** @var Account $account */ + foreach ($result as $account) { + $currency = $repository->getAccountCurrency($account); + $currency = $currency ?? $defaultCurrency; + $return[] = [ + 'id' => $account->id, + 'name' => $account->name, + 'type' => $account->accountType->type, + 'currency_id' => $currency->id, + 'currency_name' => $currency->name, + 'currency_code' => $currency->code, + 'currency_decimal_places' => $currency->decimal_places, + ]; + } + + + return response()->json($return); + } + /** * List of all journals. * @@ -84,8 +138,8 @@ class AutoCompleteController extends Controller * @param Request $request * @param string $subject * - * @throws FireflyException * @return JsonResponse + * @throws FireflyException */ public function autoComplete(Request $request, string $subject): JsonResponse { @@ -140,6 +194,59 @@ class AutoCompleteController extends Controller return response()->json($filtered); } + /** + * @return JsonResponse + */ + public function budgets(): JsonResponse + { + /** @var BudgetRepositoryInterface $repository */ + $repository = app(BudgetRepositoryInterface::class); + + return response()->json($repository->getActiveBudgets()->toArray()); + } + + /** + * @param Request $request + * + * @return JsonResponse + */ + public function categories(Request $request): JsonResponse + { + $query = (string)$request->get('query'); + /** @var CategoryRepositoryInterface $repository */ + $repository = app(CategoryRepositoryInterface::class); + $result = $repository->searchCategory($query); + + return response()->json($result->toArray()); + } + + /** + * @param Request $request + * + * @return JsonResponse + */ + public function currencies(Request $request): JsonResponse + { + /** @var CurrencyRepositoryInterface $repository */ + $repository = app(CurrencyRepositoryInterface::class); + $return = []; + $collection = $repository->getAll(); + + /** @var TransactionCurrency $currency */ + foreach ($collection as $currency) { + $return[] = [ + 'id' => $currency->id, + 'name' => $currency->name, + 'code' => $currency->code, + 'symbol' => $currency->symbol, + 'enabled' => $currency->enabled, + 'decimal_places' => $currency->decimal_places, + ]; + } + + return response()->json($return); + } + /** * List of journals with their ID. * @@ -192,6 +299,31 @@ class AutoCompleteController extends Controller return response()->json($return); } + /** + * @return JsonResponse + */ + public function piggyBanks(): JsonResponse + { + /** @var PiggyBankRepositoryInterface $repository */ + $repository = app(PiggyBankRepositoryInterface::class); + + return response()->json($repository->getPiggyBanks()->toArray()); + } + + /** + * @return JsonResponse + */ + public function tags(Request $request): JsonResponse + { + $query = (string)$request->get('query'); + /** @var TagRepositoryInterface $repository */ + $repository = app(TagRepositoryInterface::class); + $result = $repository->searchTags($query); + + + return response()->json($result->toArray()); + } + /** * List of journals by type. * diff --git a/app/Http/Controllers/Transaction/CreateController.php b/app/Http/Controllers/Transaction/CreateController.php index 0b635372a5..e0b3c39871 100644 --- a/app/Http/Controllers/Transaction/CreateController.php +++ b/app/Http/Controllers/Transaction/CreateController.php @@ -25,11 +25,67 @@ namespace FireflyIII\Http\Controllers\Transaction; use FireflyIII\Http\Controllers\Controller; +use FireflyIII\Models\TransactionType; +use Illuminate\Http\Request; /** * Class CreateController */ class CreateController extends Controller { + /** + * CreateController constructor. + */ + public function __construct() + { + parent::__construct(); + + $maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize')); + $maxPostSize = app('steam')->phpBytes(ini_get('post_max_size')); + $uploadSize = min($maxFileSize, $maxPostSize); + app('view')->share('uploadSize', $uploadSize); + $this->middleware( + static function ($request, $next) { + + app('view')->share('title', (string)trans('firefly.transactions')); + app('view')->share('mainTitleIcon', 'fa-repeat'); + + return $next($request); + } + ); + } + + /** + * Create a new transaction group. + * + * @param Request $request + * @param string|null objectType + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function create(Request $request, string $objectType = null) + { + $objectType = strtolower($objectType ?? TransactionType::WITHDRAWAL); + $preFilled = session()->has('preFilled') ? session('preFilled') : []; + $subTitle = (string)trans('breadcrumbs.create_new_transaction'); + $subTitleIcon = 'fa-plus'; + $optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data; + $source = (int)$request->get('source'); + $allowedOpposingTypes = config('firefly.allowed_opposing_types'); + $accountToTypes = config('firefly.account_to_transaction'); + $defaultCurrency = app('amount')->getDefaultCurrency(); + session()->put('preFilled', $preFilled); + + // put previous url in session if not redirect from store (not "create another"). + if (true !== session('transactions.create.fromStore')) { + $this->rememberPreviousUri('transactions.create.uri'); + } + session()->forget('transactions.create.fromStore'); + + return view( + 'transactions.create', + compact('subTitleIcon', 'objectType', 'subTitle', 'defaultCurrency', 'optionalFields', 'preFilled', 'allowedOpposingTypes', 'accountToTypes') + ); + } } \ No newline at end of file diff --git a/app/Http/Middleware/SecureHeaders.php b/app/Http/Middleware/SecureHeaders.php index e7e9bfc3ae..274cd1a7b2 100644 --- a/app/Http/Middleware/SecureHeaders.php +++ b/app/Http/Middleware/SecureHeaders.php @@ -54,7 +54,7 @@ class SecureHeaders sprintf("script-src 'self' 'unsafe-eval' 'unsafe-inline' %s", $google), "style-src 'self' 'unsafe-inline'", "base-uri 'self'", - "font-src 'self'", + "font-src 'self' data:", "connect-src 'self'", "img-src 'self' data: https://api.tiles.mapbox.com", "manifest-src 'self'", diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 89848b5fe0..0b5a68d548 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -226,17 +226,12 @@ class AccountRepository implements AccountRepositoryInterface /** @var Collection $result */ $query = $this->user->accounts(); - if (\count($accountIds) > 0) { + if (count($accountIds) > 0) { $query->whereIn('accounts.id', $accountIds); } + $query->orderBy('accounts.name','ASC'); $result = $query->get(['accounts.*']); - $result = $result->sortBy( - function (Account $account) { - return strtolower($account->name); - } - ); - return $result; } @@ -252,13 +247,9 @@ class AccountRepository implements AccountRepositoryInterface if (\count($types) > 0) { $query->accountTypeIn($types); } - + $query->orderBy('accounts.name','ASC'); $result = $query->get(['accounts.*']); - $result = $result->sortBy( - function (Account $account) { - return strtolower($account->name); - } - ); + return $result; } @@ -280,12 +271,9 @@ class AccountRepository implements AccountRepositoryInterface $query->accountTypeIn($types); } $query->where('active', 1); + $query->orderBy('accounts.account_type_id','ASC'); + $query->orderBy('accounts.name','ASC'); $result = $query->get(['accounts.*']); - $result = $result->sortBy( - function (Account $account) { - return sprintf('%02d', $account->account_type_id) . strtolower($account->name); - } - ); return $result; } @@ -564,13 +552,15 @@ class AccountRepository implements AccountRepositoryInterface */ public function searchAccount(string $query, array $types): Collection { - $dbQuery = $this->user->accounts(); - $search = sprintf('%%%s%%', $query); - if (\count($types) > 0) { + $dbQuery = $this->user->accounts()->with(['accountType']); + if ('' !== $query) { + $search = sprintf('%%%s%%', $query); + $dbQuery->where('name', 'LIKE', $search); + } + if (count($types) > 0) { $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $dbQuery->whereIn('account_types.type', $types); } - $dbQuery->where('name', 'LIKE', $search); return $dbQuery->get(['accounts.*']); } diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 6ebd1563d6..d5c723cb82 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -94,7 +94,7 @@ class BillRepository implements BillRepositoryInterface * * @return Bill|null */ - public function findBill( ?int $billId, ?string $billName): ?Bill + public function findBill(?int $billId, ?string $billName): ?Bill { if (null !== $billId) { $searchResult = $this->find((int)$billId); @@ -146,8 +146,8 @@ class BillRepository implements BillRepositoryInterface /** @var Collection $set */ $set = $this->user->bills() ->where('active', 1) - ->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]) - ->sortBy('name'); + ->orderBy('bills.name', 'ASC') + ->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]); return $set; } @@ -170,15 +170,7 @@ class BillRepository implements BillRepositoryInterface public function getBills(): Collection { /** @var Collection $set */ - $set = $this->user->bills()->orderBy('name', 'ASC')->get(); - - $set = $set->sortBy( - function (Bill $bill) { - $int = $bill->active ? 0 : 1; - - return $int . strtolower($bill->name); - } - ); + $set = $this->user->bills()->orderBy('active', 'DESC')->orderBy('name', 'ASC')->get(); return $set; } @@ -210,17 +202,11 @@ class BillRepository implements BillRepositoryInterface ) ->whereIn('transactions.account_id', $ids) ->whereNull('transaction_journals.deleted_at') + ->orderBy('bills.active', 'DESC') + ->orderBy('bills.name', 'ASC') ->groupBy($fields) ->get($fields); - $set = $set->sortBy( - function (Bill $bill) { - $int = $bill->active ? 0 : 1; - - return $int . strtolower($bill->name); - } - ); - return $set; } diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 7a32f925ce..ece9abada8 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -312,16 +312,10 @@ class BudgetRepository implements BudgetRepositoryInterface { /** @var Collection $set */ $set = $this->user->budgets()->where('active', 1) + ->orderBy('order','DESC') + ->orderBy('name', 'ASC') ->get(); - $set = $set->sortBy( - function (Budget $budget) { - $str = str_pad((string)$budget->order, 4, '0', STR_PAD_LEFT) . strtolower($budget->name); - - return $str; - } - ); - return $set; } @@ -596,15 +590,8 @@ class BudgetRepository implements BudgetRepositoryInterface public function getBudgets(): Collection { /** @var Collection $set */ - $set = $this->user->budgets()->get(); - - $set = $set->sortBy( - function (Budget $budget) { - $str = str_pad((string)$budget->order, 4, '0', STR_PAD_LEFT) . strtolower($budget->name); - - return $str; - } - ); + $set = $this->user->budgets()->orderBy('order','DESC') + ->orderBy('name', 'ASC')->get(); return $set; } @@ -629,15 +616,8 @@ class BudgetRepository implements BudgetRepositoryInterface public function getInactiveBudgets(): Collection { /** @var Collection $set */ - $set = $this->user->budgets()->where('active', 0)->get(); - - $set = $set->sortBy( - function (Budget $budget) { - $str = str_pad((string)$budget->order, 4, '0', STR_PAD_LEFT) . strtolower($budget->name); - - return $str; - } - ); + $set = $this->user->budgets()->orderBy('order','DESC') + ->orderBy('name', 'ASC')->where('active', 0)->get(); return $set; } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index e06c8cd4ce..723e113dd6 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -344,11 +344,6 @@ class CategoryRepository implements CategoryRepositoryInterface { /** @var Collection $set */ $set = $this->user->categories()->orderBy('name', 'ASC')->get(); - $set = $set->sortBy( - function (Category $category) { - return strtolower($category->name); - } - ); return $set; } diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 9bca4cb58e..ad792d742f 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -117,15 +117,7 @@ class TagRepository implements TagRepositoryInterface */ public function findByTag(string $tag): ?Tag { - $tags = $this->user->tags()->get(); - /** @var Tag $databaseTag */ - foreach ($tags as $databaseTag) { - if ($databaseTag->tag === $tag) { - return $databaseTag; - } - } - - return null; + return $this->user->tags()->where('tag', $tag)->first(); } /** @@ -159,12 +151,7 @@ class TagRepository implements TagRepositoryInterface public function get(): Collection { /** @var Collection $tags */ - $tags = $this->user->tags()->get(); - $tags = $tags->sortBy( - function (Tag $tag) { - return strtolower($tag->tag); - } - ); + $tags = $this->user->tags()->orderBy('tag', 'ASC')->get(); return $tags; } @@ -219,6 +206,25 @@ class TagRepository implements TagRepositoryInterface return $this->user->tags()->whereNotNull('date')->orderBy('date', 'ASC')->first(); } + /** + * Search the users tags. + * + * @param string $query + * + * @return Collection + */ + public function searchTags(string $query): Collection + { + /** @var Collection $tags */ + $tags = $this->user->tags()->orderBy('tag', 'ASC'); + if ('' !== $query) { + $search = sprintf('%%%s%%', $query); + $tags->where('tag', 'LIKE', $search); + } + + return $tags->get(); + } + /** * @param User $user */ diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php index 223b61e22c..44f49059c9 100644 --- a/app/Repositories/Tag/TagRepositoryInterface.php +++ b/app/Repositories/Tag/TagRepositoryInterface.php @@ -122,6 +122,15 @@ interface TagRepositoryInterface */ public function oldestTag(): ?Tag; + /** + * Search the users tags. + * + * @param string $query + * + * @return Collection + */ + public function searchTags(string $query): Collection; + /** * @param User $user */ diff --git a/app/Support/Binder/AccountList.php b/app/Support/Binder/AccountList.php index 3c0cca2618..500d6e1aed 100644 --- a/app/Support/Binder/AccountList.php +++ b/app/Support/Binder/AccountList.php @@ -22,7 +22,6 @@ declare(strict_types=1); namespace FireflyIII\Support\Binder; -use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use Illuminate\Routing\Route; use Illuminate\Support\Collection; @@ -52,6 +51,7 @@ class AccountList implements BinderInterface $collection = auth()->user()->accounts() ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->where('account_types.type', AccountType::ASSET) + ->orderBy('accounts.name', 'ASC') ->get(['accounts.*']); } if ('allAssetAccounts' !== $value) { @@ -61,16 +61,11 @@ class AccountList implements BinderInterface $collection = auth()->user()->accounts() ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->whereIn('accounts.id', $list) + ->orderBy('accounts.name', 'ASC') ->get(['accounts.*']); } if ($collection->count() > 0) { - $collection = $collection->sortBy( - function (Account $account) { - return $account->name; - } - ); - return $collection; } } diff --git a/app/Support/Http/Controllers/RenderPartialViews.php b/app/Support/Http/Controllers/RenderPartialViews.php index 2b74f5d64e..e4bec9f9aa 100644 --- a/app/Support/Http/Controllers/RenderPartialViews.php +++ b/app/Support/Http/Controllers/RenderPartialViews.php @@ -394,11 +394,7 @@ trait RenderPartialViews { /** @var TagRepositoryInterface $repository */ $repository = app(TagRepositoryInterface::class); - $tags = $repository->get()->sortBy( - function (Tag $tag) { - return $tag->tag; - } - ); + $tags = $repository->get(); try { $result = view('reports.options.tag', compact('tags'))->render(); } catch (Throwable $e) { diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php index 4cb20510cd..6e6f832668 100644 --- a/app/Support/Http/Controllers/RequestInformation.php +++ b/app/Support/Http/Controllers/RequestInformation.php @@ -208,7 +208,7 @@ trait RequestInformation */ protected function getSpecificPageName(): string // get request info { - return null === RouteFacade::current()->parameter('what') ? '' : '_' . RouteFacade::current()->parameter('what'); + return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType'); } /** diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index eb59b9783b..35b95f102b 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -59,7 +59,7 @@ class General extends Twig_Extension $this->phpdate(), $this->activeRouteStrict(), $this->activeRoutePartial(), - $this->activeRoutePartialWhat(), + $this->activeRoutePartialObjectType(), $this->formatDate(), $this->getMetaField(), $this->hasRole(), @@ -77,7 +77,7 @@ class General extends Twig_Extension return new Twig_SimpleFunction( 'activeRoutePartial', function (): string { - $args = \func_get_args(); + $args = func_get_args(); $route = $args[0]; // name of the route. $name = Route::getCurrentRoute()->getName() ?? ''; if (!(false === strpos($name, $route))) { @@ -95,15 +95,15 @@ class General extends Twig_Extension * * @return Twig_SimpleFunction */ - protected function activeRoutePartialWhat(): Twig_SimpleFunction + protected function activeRoutePartialObjectType(): Twig_SimpleFunction { return new Twig_SimpleFunction( - 'activeRoutePartialWhat', - function ($context): string { - [, $route, $what] = func_get_args(); - $activeWhat = $context['what'] ?? false; + 'activeRoutePartialObjectType', + static function ($context): string { + [, $route, $objectType] = func_get_args(); + $activeObjectType = $context['objectType'] ?? false; - if ($what === $activeWhat && !(false === stripos(Route::getCurrentRoute()->getName(), $route))) { + if ($objectType === $activeObjectType && !(false === stripos(Route::getCurrentRoute()->getName(), $route))) { return 'active'; } @@ -347,5 +347,4 @@ class General extends Twig_Extension } ); } - }