Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d5d4dd930 | |||
| c507dc6031 |
@@ -79,7 +79,10 @@ class FileService
|
|||||||
throw new LucentException("File $filename not uploaded");
|
throw new LucentException("File $filename not uploaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->createTemplates($disk, $path, $file);
|
if($this->isImage($mimetype)){
|
||||||
|
$this->createTemplates($disk, $path, $file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
|
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
|
||||||
$recordFile = new RecordFile(
|
$recordFile = new RecordFile(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use Lucent\Record\QueryRecord;
|
|||||||
use Lucent\Record\RecordService;
|
use Lucent\Record\RecordService;
|
||||||
use Lucent\Record\Status;
|
use Lucent\Record\Status;
|
||||||
use Lucent\Schema\System;
|
use Lucent\Schema\System;
|
||||||
|
use Lucent\Schema\Ui\Reference;
|
||||||
use Lucent\Schema\Validator\ValidatorException;
|
use Lucent\Schema\Validator\ValidatorException;
|
||||||
use Lucent\Svelte\Svelte;
|
use Lucent\Svelte\Svelte;
|
||||||
use function Lucent\Response\fail;
|
use function Lucent\Response\fail;
|
||||||
@@ -134,18 +135,22 @@ class RecordController extends Controller
|
|||||||
->filter($arguments)
|
->filter($arguments)
|
||||||
->limit(-1)
|
->limit(-1)
|
||||||
->status(explode(",", $arguments["status_in"]))
|
->status(explode(",", $arguments["status_in"]))
|
||||||
|
->childrenDepth(1)
|
||||||
// ->skip($skip)
|
// ->skip($skip)
|
||||||
->sort($sort)
|
->sort($sort)
|
||||||
->run()
|
->run()
|
||||||
->records;
|
->tree();
|
||||||
|
|
||||||
header('Content-Type: application/csv');
|
header('Content-Type: application/csv');
|
||||||
header('Content-Disposition: attachment; filename="' . $schemaName . '.csv";');
|
header('Content-Disposition: attachment; filename="' . $schemaName . '.csv";');
|
||||||
$handle = fopen('php://output', 'w');
|
$handle = fopen('php://output', 'w');
|
||||||
$csvRow = ["id", ...array_keys($records[0]->data->toArray())];
|
$relationColumns = $this->makeCsvRelationColumns($schema);
|
||||||
|
$csvRow = ["id", ...array_keys($records[0]->data->toArray()),...$relationColumns];
|
||||||
fputcsv($handle, $csvRow, ',');
|
fputcsv($handle, $csvRow, ',');
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
|
|
||||||
$csvRow = [$record->id, ...$record->data->toArray()];
|
$csvRow = [$record->id, ...$record->data->toArray()];
|
||||||
|
$csvRow = array_merge($csvRow,$this->makeCsvRelationColumnValues($schema,$record->_children));
|
||||||
$csvRow = array_values($csvRow);
|
$csvRow = array_values($csvRow);
|
||||||
fputcsv($handle, $csvRow, ',');
|
fputcsv($handle, $csvRow, ',');
|
||||||
}
|
}
|
||||||
@@ -154,6 +159,32 @@ class RecordController extends Controller
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function makeCsvRelationColumns($schema):array{
|
||||||
|
return $schema->fields->filter(fn($f) => get_class($f) === Reference::class)->reduce(function($c,$f){
|
||||||
|
$c[] = $f->name." id";
|
||||||
|
$c[] = $f->name." name";
|
||||||
|
return $c;
|
||||||
|
},[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeCsvRelationColumnValues($schema, $children):array{
|
||||||
|
return $schema->fields->filter(fn($f) => get_class($f) === Reference::class)->reduce(function($c,$f) use($children){
|
||||||
|
|
||||||
|
$fieldRecords = data_get($children,$f->name);
|
||||||
|
if(empty($fieldRecords)){
|
||||||
|
$c[] = "";
|
||||||
|
$c[] = "";
|
||||||
|
}elseif (count($fieldRecords) === 1){
|
||||||
|
$c[] = data_get($fieldRecords,"0.id");
|
||||||
|
$c[] = data_get($fieldRecords,"0.data.name");
|
||||||
|
}else{
|
||||||
|
$c[] = collect($fieldRecords)->pluck("id")->join("::");
|
||||||
|
$c[] = collect($fieldRecords)->pluck("data.name")->join("::");
|
||||||
|
}
|
||||||
|
return $c;
|
||||||
|
},[]);
|
||||||
|
}
|
||||||
|
|
||||||
public function new(Request $request)
|
public function new(Request $request)
|
||||||
{
|
{
|
||||||
if (!in_array($request->input("schema"), $this->accountService->currentWritableSchemas())) {
|
if (!in_array($request->input("schema"), $this->accountService->currentWritableSchemas())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user