public function getExportTableAction(Table $table, Strategy $strategy, Dynamic $dynamicService) { $entity = $table->createEntity(); $this->dynamic->setTable($table); $this->dynamic->applyOnEntity($entity, false); $dynamicService->joinTranslationsIfTranslatable($entity); $dynamicService->joinPermissionsIfPermissionable($entity); /** * Get all relations for fields with type (select). */ $relations = (new Relations())->where('on_table_id', $table->id)->where('dynamic_relation_type_id', 1)->all(); foreach ($relations as $relation) { /** * Right table entity is created here. */ $relationEntity = $relation->showTable->createEntity(); /** * We need to add relations to select. * $tableRecord is for example users. * So entity is entity with table users. * We will fetch all users and related user_group_id and language_id * as user.relation_user_group_id and user.relation_language_id. */ $entity->with((new BelongsTo($entity, $relationEntity))->foreignKey($relation->onField->field)->fill('relation_' . $relation->onField->field)->after(function ($record) use($relation) { $record->setRelation('select_relation_' . $relation->onField->field, $relation); })); } $strategy->input($entity); /** * @T00D00 - hackish ... */ $tabelize = (new Tabelize($entity))->setRecords($entity->all())->setEntity($entity)->setFields($table->listableFields->reduce(function (Field $field) use($table) { $fields = $_SESSION['pckg']['dynamic']['view']['table_' . $table->id]['view']['fields'] ?? []; return !$fields || in_array($field->field, $fields); })); $tabelize->setDataOnly(); $strategy->setData($tabelize->transformRecords()); $strategy->setFileName($table->table . '-' . date('Ymd-his')); $strategy->prepare(); $strategy->output(); $this->response()->respond(); }
public function postUploadAction(Table $table, Record $record, Field $field) { $file = $_FILES['file']; if ($file['error']) { return ['success' => false, 'message' => 'Error uploading file ...']; } if (!$file['size']) { return ['success' => false, 'message' => 'Empty file size ...']; } $entity = $table->createEntity(); $record->setEntity($entity); $dir = $field->getAbsoluteDir($field->getSetting('pckg.dynamic.field.dir')); $name = Convention::url(substr($file['name'], 0, strrpos($file['name'], '.'))); $extension = substr($file['name'], strrpos($file['name'], '.')); $i = 0; do { $filename = $name . ($i ? '_' . $i : '') . $extension; $i++; } while (is_file($dir . $filename)); if (!is_dir($dir)) { mkdir($dir, 0777, true); } move_uploaded_file($file['tmp_name'], $dir . $filename); $record->{$field->field} = $filename; $record->save($entity); return ['success' => 'true', 'url' => img($record->{$field->field}, null, true, $dir)]; }