Skip to content

Commit

Permalink
Export fields of model as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
wilcorrea committed Mar 26, 2017
1 parent cf24bc3 commit bd8e591
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"homepage": "https://github.com/phpzm/model",
"license": "MIT",
"version": "1.0.0",
"version": "1.0.1",
"type": "package",
"authors": [
{
Expand Down
30 changes: 30 additions & 0 deletions src/DataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Simples\Data\Collection;
use Simples\Data\Error\SimplesResourceError;
use Simples\Data\Record;
use Simples\Helper\JSON;
use Simples\Model\Error\SimplesActionError;
use Simples\Model\Error\SimplesHookError;
use Simples\Model\Resources\ModelParser;
Expand Down Expand Up @@ -318,4 +319,33 @@ protected function getActionFields(string $action, bool $strict = true)
}
return $fields;
}

/**
* @return string
*/
public function getJSON()
{
$fields = [];
/** @var Field $field */
foreach ($this->fields as $field) {
$fields[] = [
'field' => $field->getName(),
'type' => $field->getType(),
'label' => $field->option('label'),
'grid' => true,
'form' => ['create', 'show', 'edit'],
'search' => true,
'grids' => [
'width' => ''
],
'forms' => [
'component' => '',
'width' => '',
'disabled' => false,
'order' => 0
]
];
}
return JSON::encode($fields);
}
}

0 comments on commit bd8e591

Please sign in to comment.