phpvms/app/Services/ImportExport/AircraftExporter.php

43 lines
868 B
PHP
Raw Normal View History

2018-03-23 01:55:56 +08:00
<?php
namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
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) {
2018-03-23 01:55:56 +08:00
$ret[$column] = $aircraft->{$column};
}
2018-08-27 00:40:04 +08:00
// Modify special fields
2018-03-23 01:55:56 +08:00
$ret['subfleet'] = $aircraft->subfleet->type;
return $ret;
}
}