Пример #1
0
 /**
  * Gets the model fields to use in this form.
  * @param zibo\library\orm\model\meta\ModelMeta $meta Meta of the model
  * @param array $fields Array with the names of the fields which need to be added to the form. If not provided, all the fields of the model will be returned
  * @param boolean $skipFields Set to true to skip the provided fields instead of adding them
  * @return array Array with the name of the field as key and a ModelField object as value
  */
 protected function getModelFields(ModelMeta $meta, array $fieldNames = null, $skipFields = false)
 {
     if (!$fieldNames) {
         $fields = $meta->getFields();
     } elseif ($skipFields) {
         $fields = $meta->getFields();
         foreach ($fieldNames as $fieldName) {
             if ($fieldName == ModelTable::PRIMARY_KEY) {
                 continue;
             }
             if (array_key_exists($fieldName, $fields)) {
                 unset($fields[$fieldName]);
             }
         }
     } else {
         $fields = array();
         $fields[ModelTable::PRIMARY_KEY] = $meta->getField(ModelTable::PRIMARY_KEY);
         foreach ($fieldNames as $fieldName) {
             $fields[$fieldName] = $meta->getField($fieldName);
         }
     }
     $this->dataFieldLabels = array();
     foreach ($fields as $fieldName => $field) {
         $label = $field->getLabel();
         if ($label) {
             $this->dataFieldLabels[$fieldName] = $label;
         }
     }
     return $fields;
 }