Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 232fcc8845 | |||
| 9d5d4dd930 | |||
| c507dc6031 |
+2
-1
@@ -14,7 +14,8 @@
|
|||||||
"intervention/image": "^2.7",
|
"intervention/image": "^2.7",
|
||||||
"phpoption/phpoption": "^1.9",
|
"phpoption/phpoption": "^1.9",
|
||||||
"spatie/image-optimizer": "^1.6",
|
"spatie/image-optimizer": "^1.6",
|
||||||
"staudenmeir/laravel-cte": "^1.0"
|
"staudenmeir/laravel-cte": "^1.0",
|
||||||
|
"mustache/mustache": "^2.14"
|
||||||
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|||||||
Generated
+3
-3
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "71cf4c1de3d614ce2f9607763bf5687f",
|
"content-hash": "e8fb1bee28ad339453d50110f7fea2f5",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
@@ -5729,8 +5729,8 @@
|
|||||||
"ext-zip": "*",
|
"ext-zip": "*",
|
||||||
"ext-sqlite3": "*",
|
"ext-sqlite3": "*",
|
||||||
"ext-imagick": "*",
|
"ext-imagick": "*",
|
||||||
"php": "^8.3",
|
"ext-pdo": "*",
|
||||||
"ext-pdo": "*"
|
"php": "^8.3"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.3.0"
|
"plugin-api-version": "2.3.0"
|
||||||
|
|||||||
@@ -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,8 +17,10 @@ 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 Lucent\ViewModel\ViewModel;
|
||||||
use function Lucent\Response\fail;
|
use function Lucent\Response\fail;
|
||||||
use function Lucent\Response\ok;
|
use function Lucent\Response\ok;
|
||||||
|
|
||||||
@@ -31,7 +33,8 @@ class RecordController extends Controller
|
|||||||
private readonly Svelte $svelte,
|
private readonly Svelte $svelte,
|
||||||
private readonly Query $query,
|
private readonly Query $query,
|
||||||
private readonly Manager $recordManager,
|
private readonly Manager $recordManager,
|
||||||
private readonly OperatorRegistry $operatorRegistry
|
private readonly OperatorRegistry $operatorRegistry,
|
||||||
|
private readonly ViewModel $viewModel,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -134,18 +137,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 +161,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[] = $this->viewModel->getRecordName($fieldRecords[0]);
|
||||||
|
}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())) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class ViewModel
|
|||||||
public function getRecordName(QueryRecord $record): string
|
public function getRecordName(QueryRecord $record): string
|
||||||
{
|
{
|
||||||
$schema = $this->channelService->getSchema($record->schema)->get();
|
$schema = $this->channelService->getSchema($record->schema)->get();
|
||||||
if (empty($schema->titleTemplate)) {
|
if (empty($schema->cardTitle)) {
|
||||||
$title = match (get_class($schema)) {
|
$title = match (get_class($schema)) {
|
||||||
CollectionSchema::class => $record->data[$schema->fields->filter(fn(FieldInterface $f) => $f->info->name === "text")->first()->name],
|
CollectionSchema::class => $record->data[$schema->fields->filter(fn(FieldInterface $f) => $f->info->name === "text")->first()->name],
|
||||||
FilesSchema::class => $record->_file->path,
|
FilesSchema::class => $record->_file->path,
|
||||||
|
|||||||
Reference in New Issue
Block a user