Ejemplo n.º 1
0
 /**
  * Get all the fields of a model.
  *
  * @param ModelInterface $model      The model to get fields from.
  * @param array|null     $properties Optional list of properties to get. If null, retrieve all (from metadata).
  * @return array
  * @todo Move this method in StorableTrait or AbstractModel
  */
 private function getModelFields(ModelInterface $model, $properties = null)
 {
     if ($properties === null) {
         // No custom properties; use all (from model metadata)
         $properties = array_keys($model->metadata()->properties());
     } else {
         // Ensure the key is always in the required fields.
         $properties = array_merge($properties, [$model->key()]);
     }
     $fields = [];
     foreach ($properties as $propertyIdent) {
         $p = $model->p($propertyIdent);
         if (!$p || !$p->active() || !$p->storable()) {
             continue;
         }
         $v = $model->propertyValue($propertyIdent);
         foreach ($p->fields($v) as $fieldIdent => $field) {
             $fields[$field->ident()] = $field;
         }
     }
     return $fields;
 }