mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-07 10:28:22 +00:00
Update form for linking.
This commit is contained in:
@@ -12,6 +12,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\LinkType;
|
||||
|
||||
/**
|
||||
* Class JournalLink
|
||||
*
|
||||
@@ -29,12 +31,44 @@ class JournalLinkRequest extends Request
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLinkInfo(): array
|
||||
{
|
||||
$return = [];
|
||||
$linkType = $this->get('link_type');
|
||||
$parts = explode('_', $linkType);
|
||||
$return['link_type_id'] = intval($parts[0]);
|
||||
$return['transaction_journal_id'] = $this->integer('link_journal_id');
|
||||
$return['comments'] = strlen($this->string('comments')) > 0 ? $this->string('comments') : null;
|
||||
$return['direction'] = $parts[1];
|
||||
if ($return['transaction_journal_id'] === 0 && ctype_digit($this->string('link_other'))) {
|
||||
$return['transaction_journal_id'] = $this->integer('link_other');
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
// all possible combinations of link types and inward / outward:
|
||||
$combinations = [];
|
||||
$linkTypes = LinkType::get(['id']);
|
||||
/** @var LinkType $type */
|
||||
foreach ($linkTypes as $type) {
|
||||
$combinations[] = sprintf('%d_inward', $type->id);
|
||||
$combinations[] = sprintf('%d_outward', $type->id);
|
||||
}
|
||||
$string = join(',', $combinations);
|
||||
|
||||
return [
|
||||
'link_type' => sprintf('required|in:%s', $string),
|
||||
'link_other' => 'belongsToUser:transaction_journals',
|
||||
'link_journal_id' => 'belongsToUser:transaction_journals',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user