public function postSaveAction(Table $table) { $filters = $this->post()->get('fields', []); //$relationFilters = $this->post()->get('relations', []); $_SESSION['pckg']['dynamic']['view']['table_' . $table->id]['view']['fields'] = $filters; //$_SESSION['pckg']['dynamic']['view']['table_' . $table->id]['view']['relations'] = $relationFilters; return $this->response()->respondWithSuccessOrRedirect($table->getViewUrl()); }
public function initFields() { $this->addFieldset(); $fields = $this->table->listableFields(function (HasMany $fields) { $fields->getRightEntity()->orderBy('dynamic_field_group_id ASC, `order` ASC'); $fields->withFieldType(); $fields->withPermissions(); $fields->joinTranslation(); $fields->joinFallbackTranslation(); $fields->withHasOneSelectRelation(function (HasOne $relation) { $relation->withOnTable(); $relation->withShowTable(); }); $fields->withFieldGroup(function (BelongsTo $fieldGroup) { $fieldGroup->joinTranslation(); $fieldGroup->joinFallbackTranslation(); }); }); $prevGroup = null; foreach ($fields as $field) { if ($prevGroup && $prevGroup != $field->dynamic_field_group_id || !$prevGroup && $field->dynamic_field_group_id) { $fieldset = $this->addFieldset()->setAttribute('data-field-group', $field->dynamic_field_group_id); $fieldset->addChild('<hr /><h4>' . $field->fieldGroup->title . '</h4>'); $prevGroup = $field->dynamic_field_group_id; } $type = $field->fieldType->slug; $name = $field->field; $label = $field->label; if ($type == 'php') { /** * PHP field is not editable. * Should we display content? */ continue; } elseif ($type != 'hidden' && !$field->hasPermissionTo('write') && config('pckg.dynamic.permissions')) { $element = $this->addDiv()->addChild('<div class="form-group grouped" data-field-id="' . $field->id . '"><label class="col-sm-3">' . $label . ' </label> <div class="col-sm-9">' . $this->record->{$field->field} . '</div></div>'); continue; } elseif (!$this->editable) { // @T00D00 $element = $this->addDiv()->addChild('<div class="form-group grouped" data-field-id="' . $field->id . '"><label class="col-sm-3">' . $label . ' </label> <div class="col-sm-9">' . $this->record->{$field->field} . '</div></div>'); continue; } elseif ($field->id == $this->foreignFieldId) { $this->createElementByType('hidden', $name, $field); continue; } $element = $this->createElementByType($type, $name, $field); if ($label) { $element->setLabel($label); } $element->setHelp($field->help); $element->setAttribute('data-field-id', $field->id); } $this->addSubmit('submit'); $this->addSubmit('as_new')->setValue('As new')->setClass('btn-link'); return $this; }
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 postSaveAction(Table $table) { $groups = $this->post()->get('groups', []); $_SESSION['pckg']['dynamic']['view']['table_' . $table->id]['view']['group'] = $groups; return $this->response()->respondWithSuccessOrRedirect($table->getViewUrl()); }
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)]; }
protected function upDynamicTable($table) { return Table::getOrCreate(['table' => $table]); }