Initial code base for new CSV import.

This commit is contained in:
James Cole
2016-06-10 21:00:00 +02:00
parent beda6ec3a9
commit 5a79bc0a99
21 changed files with 646 additions and 123 deletions

View File

@@ -0,0 +1,81 @@
<?php
/**
* CsvImporter.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Import\Importer;
use ExpandedForm;
use FireflyIII\Import\Role\Map;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\ImportJob;
/**
* Class CsvImporter
*
* @package FireflyIII\Import\Importer
*/
class CsvImporter implements ImporterInterface
{
/** @var ImportJob */
public $job;
/**
* @return bool
*/
public function configure(): bool
{
// need to do nothing, for now.
return true;
}
/**
* @return array
*/
public function getConfigurationData(): array
{
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$delimiters = [
',' => trans('form.csv_comma'),
';' => trans('form.csv_semicolon'),
'tab' => trans('form.csv_tab'),
];
$data = [
'accounts' => ExpandedForm::makeSelectList($accounts),
'specifix' => [],
'delimiters' => $delimiters,
];
return $data;
}
/**
* @param ImportJob $job
*/
public function setJob(ImportJob $job)
{
$this->job = $job;
}
/**
* Returns a Map thing used to allow the user to
* define roles for each entry.
*
* @return Map
*/
public function prepareRoles(): Map
{
return 'do not work';
exit;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* ImporterInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Import\Importer;
use FireflyIII\Import\Role\Map;
use FireflyIII\Models\ImportJob;
/**
* Interface ImporterInterface
*
* @package FireflyIII\Import\Importer
*/
interface ImporterInterface
{
/**
* After uploading, and after setJob(), prepare anything that is
* necessary for the configure() line.
*
* @return bool
*/
public function configure(): bool;
/**
* Returns any data necessary to do the configuration.
*
* @return array
*/
public function getConfigurationData(): array;
/**
* Returns a Map thing used to allow the user to
* define roles for each entry.
*
* @return Map
*/
public function prepareRoles(): Map;
/**
* @param ImportJob $job
*
*/
public function setJob(ImportJob $job);
}