phpvms/app/Services/ImportExport/AircraftExporter.php

44 lines
922 B
PHP
Raw Normal View History

2018-03-23 01:55:56 +08:00
<?php
namespace App\Services\ImportExport;
use App\Contracts\ImportExport;
2018-03-23 01:55:56 +08:00
use App\Models\Aircraft;
/**
* The flight importer can be imported or export. Operates on rows
*/
class AircraftExporter extends ImportExport
{
public $assetType = 'aircraft';
/**
* Set the current columns and other setup
*/
public function __construct()
{
self::$columns = array_keys(AircraftImporter::$columns);
2018-03-23 01:55:56 +08:00
}
/**
* Import a flight, parse out the different rows
2018-08-27 00:40:04 +08:00
*
2018-03-23 01:55:56 +08:00
* @param Aircraft $aircraft
2018-08-27 00:40:04 +08:00
*
2018-03-23 01:55:56 +08:00
* @return array
*/
2018-04-23 21:46:28 +08:00
public function export($aircraft): array
2018-03-23 01:55:56 +08:00
{
$ret = [];
2018-08-27 00:40:04 +08:00
foreach (self::$columns as $column) {
if ($column === 'subfleet') {
$ret['subfleet'] = $aircraft->subfleet->type;
} else {
$ret[$column] = $aircraft->{$column};
}
2018-03-23 01:55:56 +08:00
}
return $ret;
}
}