firefly-iii/app/Helpers/Csv/Converter/AccountId.php

43 lines
1.0 KiB
PHP
Raw Normal View History

2015-07-05 07:37:36 -05:00
<?php
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2015-07-05 07:37:36 -05:00
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Account;
2015-07-09 09:03:47 -05:00
use Log;
2015-07-05 07:37:36 -05:00
/**
* Class AccountId
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class AccountId extends BasicConverter implements ConverterInterface
{
/**
* @return Account
*/
public function convert(): Account
2015-07-05 07:37:36 -05:00
{
// is mapped? Then it's easy!
if (isset($this->mapped[$this->index][$this->value])) {
2015-07-09 09:03:47 -05:00
/** @var Account $account */
2015-07-05 07:37:36 -05:00
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
} else {
2015-07-09 09:03:47 -05:00
/** @var Account $account */
2015-07-05 07:37:36 -05:00
$account = Auth::user()->accounts()->find($this->value);
2015-07-09 09:03:47 -05:00
if (!is_null($account)) {
2015-07-15 14:06:26 -05:00
Log::debug('Found ' . $account->accountType->type . ' named "******" with ID: ' . $this->value . ' (not mapped) ');
2016-02-18 03:04:26 -06:00
} else {
// new account to prevent TypeErrors.
$account = new Account;
2015-07-09 09:03:47 -05:00
}
2015-07-05 07:37:36 -05:00
}
return $account;
}
2015-07-09 14:26:40 -05:00
}