firefly-iii/app/Http/Controllers/JsonController.php
2018-07-08 12:28:42 +02:00

75 lines
2.2 KiB
PHP

<?php
/**
* JsonController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* Class JsonController.
*/
class JsonController extends Controller
{
/**
* @param Request $request
*
* @return JsonResponse
* @throws \Throwable
*/
public function action(Request $request): JsonResponse
{
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1;
$keys = array_keys(config('firefly.rule-actions'));
$actions = [];
foreach ($keys as $key) {
$actions[$key] = trans('firefly.rule_action_' . $key . '_choice');
}
$view = view('rules.partials.action', compact('actions', 'count'))->render();
return response()->json(['html' => $view]);
}
/**
* @param Request $request
*
* @return JsonResponse
* @throws \Throwable
*/
public function trigger(Request $request): JsonResponse
{
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1;
$keys = array_keys(config('firefly.rule-triggers'));
$triggers = [];
foreach ($keys as $key) {
if ('user_action' !== $key) {
$triggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
}
}
asort($triggers);
$view = view('rules.partials.trigger', compact('triggers', 'count'))->render();
return response()->json(['html' => $view]);
}
}