mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Simplify method.
This commit is contained in:
parent
c136c60eae
commit
c90b26c181
@ -277,6 +277,111 @@ class TransactionUpdateRequest extends Request
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $current
|
||||||
|
* @param array $transaction
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getArrayData(array $current, array $transaction): array
|
||||||
|
{
|
||||||
|
foreach ($this->arrayFields as $fieldName) {
|
||||||
|
if (array_key_exists($fieldName, $transaction)) {
|
||||||
|
$current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $current
|
||||||
|
* @param array $transaction
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getBooleanData(array $current, array $transaction): array
|
||||||
|
{
|
||||||
|
foreach ($this->booleanFields as $fieldName) {
|
||||||
|
if (array_key_exists($fieldName, $transaction)) {
|
||||||
|
$current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $current
|
||||||
|
* @param array $transaction
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getDateData(array $current, array $transaction): array
|
||||||
|
{
|
||||||
|
foreach ($this->dateFields as $fieldName) {
|
||||||
|
Log::debug(sprintf('Now at date field %s', $fieldName));
|
||||||
|
if (array_key_exists($fieldName, $transaction)) {
|
||||||
|
$current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);
|
||||||
|
Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For each field, add it to the array if a reference is present in the request:
|
||||||
|
*
|
||||||
|
* @param array $current
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getIntegerData(array $current, array $transaction): array
|
||||||
|
{
|
||||||
|
foreach ($this->integerFields as $fieldName) {
|
||||||
|
if (array_key_exists($fieldName, $transaction)) {
|
||||||
|
$current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $current
|
||||||
|
* @param array $transaction
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getNlStringData(array $current, array $transaction): array
|
||||||
|
{
|
||||||
|
foreach ($this->textareaFields as $fieldName) {
|
||||||
|
if (array_key_exists($fieldName, $transaction)) {
|
||||||
|
$current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $current
|
||||||
|
* @param array $transaction
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getStringData(array $current, array $transaction): array
|
||||||
|
{
|
||||||
|
foreach ($this->stringFields as $fieldName) {
|
||||||
|
if (array_key_exists($fieldName, $transaction)) {
|
||||||
|
$current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get transaction data.
|
* Get transaction data.
|
||||||
*
|
*
|
||||||
@ -292,46 +397,13 @@ class TransactionUpdateRequest extends Request
|
|||||||
*/
|
*/
|
||||||
foreach ($this->get('transactions') as $index => $transaction) {
|
foreach ($this->get('transactions') as $index => $transaction) {
|
||||||
// default response is to update nothing in the transaction:
|
// default response is to update nothing in the transaction:
|
||||||
$current = [];
|
$current = [];
|
||||||
|
$current = $this->getIntegerData($current, $transaction);
|
||||||
// for each field, add it to the array if a reference is present in the request:
|
$current = $this->getStringData($current, $transaction);
|
||||||
foreach ($this->integerFields as $fieldName) {
|
$current = $this->getNlStringData($current, $transaction);
|
||||||
if (array_key_exists($fieldName, $transaction)) {
|
$current = $this->getDateData($current, $transaction);
|
||||||
$current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);
|
$current = $this->getBooleanData($current, $transaction);
|
||||||
}
|
$current = $this->getArrayData($current, $transaction);
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->stringFields as $fieldName) {
|
|
||||||
if (array_key_exists($fieldName, $transaction)) {
|
|
||||||
$current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->textareaFields as $fieldName) {
|
|
||||||
if (array_key_exists($fieldName, $transaction)) {
|
|
||||||
$current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->dateFields as $fieldName) {
|
|
||||||
Log::debug(sprintf('Now at date field %s', $fieldName));
|
|
||||||
if (array_key_exists($fieldName, $transaction)) {
|
|
||||||
$current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);
|
|
||||||
Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->booleanFields as $fieldName) {
|
|
||||||
if (array_key_exists($fieldName, $transaction)) {
|
|
||||||
$current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->arrayFields as $fieldName) {
|
|
||||||
if (array_key_exists($fieldName, $transaction)) {
|
|
||||||
$current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$return[] = $current;
|
$return[] = $current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user