private function newModel($dataset) { $model = new DataObject($this->getTablename($dataset->name)); $model->setTitle(prettify($dataset->name)); $display_fields = array(); // Clear the cached fields to make sure we get the latest $dataset->clear('fields'); // Need to load FK definitions foreach ($dataset->fields as $field) { if (!is_null($field->module_component_id)) { if (substr($field->name, -3) == '_id') { $name = str_replace('_id', '', $field->name); } else { $name = strtolower(str_replace(' ', '_', $field->title)); } $model->belongsTo($field->fk_link, $field->name, $name); } else { $name = $field->name; } if ($field->display_in_list == 't') { $display_fields[$name] = $field->title; } // Note: DataObject::getFields does a sort into alphabetic field name order // which was required to dislpay the field list in alphabetic order when looking // at DataObject model components - need to get the order of fields from the // dataset fields definition (ordered on popsition) so store in the dataset // $_fields private array here. Also, the field title is only added to DataObject // display fields and we need the title as the field label on the edit data form. $this->_fields[$field->name] = $field->title; } if (!empty($display_fields)) { $model->setDisplayFields($model->setDefaultDisplayFields($display_fields)); } return $model; }