Files
firefly-iii/app/Api/V2/Request/Chart/DashboardChartRequest.php

91 lines
2.8 KiB
PHP
Raw Normal View History

2023-12-02 15:56:17 +01:00
<?php
/*
* DashboardChartRequest.php
* Copyright (c) 2023 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/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Chart;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
/**
* Class DashboardChartRequest
2023-12-02 15:56:17 +01:00
*/
class DashboardChartRequest extends FormRequest
2023-12-02 15:56:17 +01:00
{
use ChecksLogin;
use ConvertsDataTypes;
use ValidatesUserGroupTrait;
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
return [
'accounts' => $this->getAccountList(),
'preselected' => $this->convertString('preselected'),
2023-12-02 15:56:17 +01:00
];
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
return [
'start' => 'required|date|after:1900-01-01|before:2099-12-31',
'end' => 'required|date|after_or_equal:start|before:2099-12-31|after:1900-01-01',
2023-12-03 08:14:32 +01:00
'preselected' => sprintf('in:%s', implode(',', config('firefly.preselected_accounts'))),
'accounts.*' => 'exists:accounts,id',
2023-12-02 15:56:17 +01:00
];
}
/**
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
static function (Validator $validator) {
// validate transaction query data.
$data = $validator->getData();
if (!array_key_exists('accounts', $data)) {
//$validator->errors()->add('accounts', trans('validation.filled', ['attribute' => 'accounts']));
return;
}
if (!is_array($data['accounts'])) {
$validator->errors()->add('accounts', trans('validation.filled', ['attribute' => 'accounts']));
}
}
);
}
}