Skip to content

Commit

Permalink
[update] introduce Model::FIELD_FILTER_ONLY_FIELDS and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov committed Aug 6, 2020
1 parent 5857342 commit d5de024
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Model implements \IteratorAggregate
public const FIELD_FILTER_EDITABLE = 'editable';
/** @const string */
public const FIELD_FILTER_PERSIST = 'persist';
/** @const string */
public const FIELD_FILTER_ONLY_FIELDS = 'only fields';

// {{{ Properties of the class

Expand Down Expand Up @@ -811,16 +813,8 @@ public function get(string $field = null)
if ($field === null) {
// Collect list of eligible fields
$data = [];
if ($this->only_fields) {
// collect data for actual fields
foreach ($this->only_fields as $field) {
$data[$field] = $this->get($field);
}
} else {
// get all fields
foreach ($this->getFields() as $field => $f) {
$data[$field] = $this->get($field);
}
foreach ($this->getFields(self::FIELD_FILTER_ONLY_FIELDS) as $field) {
$data[$field] = $this->get($field);
}

return $data;
Expand Down

0 comments on commit d5de024

Please sign in to comment.