Files
firefly-iii/app/Http/Controllers/ObjectGroup/IndexController.php

92 lines
2.7 KiB
PHP
Raw Normal View History

2020-06-20 10:10:55 +02:00
<?php
2020-06-30 19:05:35 +02:00
/**
* IndexController.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-06-20 10:10:55 +02:00
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\ObjectGroup;
2021-03-28 11:46:23 +02:00
2020-06-20 10:10:55 +02:00
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
2021-03-28 11:46:23 +02:00
use Illuminate\Contracts\View\Factory;
2021-09-18 10:20:19 +02:00
use Illuminate\Http\JsonResponse;
2020-06-20 10:10:55 +02:00
use Illuminate\Http\Request;
use Log;
/**
* Class IndexController
*/
class IndexController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* IndexController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
// translations:
$this->middleware(
function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-envelope-o');
2021-03-28 11:46:23 +02:00
app('view')->share('title', (string)trans('firefly.object_groups_page_title'));
2020-06-20 10:10:55 +02:00
$this->repository = app(ObjectGroupRepositoryInterface::class);
return $next($request);
}
);
}
/**
2021-05-24 08:54:58 +02:00
* @return Factory|\Illuminate\Contracts\View\View
2020-06-20 10:10:55 +02:00
*/
public function index()
{
2020-06-30 19:05:35 +02:00
$this->repository->deleteEmpty();
2021-03-14 06:20:23 +01:00
$this->repository->resetOrder();
2021-03-28 11:46:23 +02:00
$subTitle = (string)trans('firefly.object_groups_index');
2020-06-20 10:10:55 +02:00
$objectGroups = $this->repository->get();
return prefixView('object-groups.index', compact('subTitle', 'objectGroups'));
2020-06-20 10:10:55 +02:00
}
/**
2021-05-24 08:54:58 +02:00
* @param Request $request
2020-06-20 10:10:55 +02:00
* @param ObjectGroup $objectGroup
2021-05-24 08:54:58 +02:00
*
2021-09-18 10:20:19 +02:00
* @return JsonResponse
2020-06-20 10:10:55 +02:00
*/
public function setOrder(Request $request, ObjectGroup $objectGroup)
{
Log::debug(sprintf('Found object group #%d "%s"', $objectGroup->id, $objectGroup->title));
2021-03-28 11:46:23 +02:00
$newOrder = (int)$request->get('order');
2020-06-20 10:10:55 +02:00
$this->repository->setOrder($objectGroup, $newOrder);
return response()->json([]);
}
}