mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
More code for Spectre import.
This commit is contained in:
76
app/Support/Import/Configuration/Spectre/SelectBank.php
Normal file
76
app/Support/Import/Configuration/Spectre/SelectBank.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Import\Configuration\Spectre;
|
||||
|
||||
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\SpectreProvider;
|
||||
use FireflyIII\Support\Import\Configuration\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* Class SelectBank
|
||||
*/
|
||||
class SelectBank implements ConfigurationInterface
|
||||
{
|
||||
/** @var ImportJob */
|
||||
private $job;
|
||||
|
||||
/**
|
||||
* Get the data necessary to show the configuration screen.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
$config = $this->job->configuration;
|
||||
$selection = SpectreProvider::where('country_code', $config['country'])->where('status', 'active')->get();
|
||||
$providers = [];
|
||||
/** @var SpectreProvider $provider */
|
||||
foreach ($selection as $provider) {
|
||||
$providerId = $provider->spectre_id;
|
||||
$name = $provider->data['name'];
|
||||
$providers[$providerId] = $name;
|
||||
}
|
||||
|
||||
return compact('providers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return possible warning to user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWarningMessage(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return ConfigurationInterface
|
||||
*/
|
||||
public function setJob(ImportJob $job)
|
||||
{
|
||||
$this->job = $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the result.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function storeConfiguration(array $data): bool
|
||||
{
|
||||
$config = $this->job->configuration;
|
||||
$config['bank'] = intval($data['bank_code']) ?? 0; // default to fake country.
|
||||
$config['selected-bank'] = true;
|
||||
$this->job->configuration = $config;
|
||||
$this->job->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user