/** * find out what the scheme's FK field for this relationship is called. * By default, this is formed by * ROLENAME_NAMEOFTARGETIDCOLUMN, * but this can be overridden by the FK setting in the meta description. * * @param One_Relation_Adapter $adapter * @param One_Scheme $source * @param One_Relation_Adapter $backlink * @return string */ public function remoteFK(One_Relation_Adapter $adapter, One_Scheme $source, One_Relation_Adapter $backlink) { if ($adapter->meta['fk:remote']) { return $adapter->meta['fk:remote']; } $column = $source->getIdentityAttribute()->getName(); return $backlink->getName() . "_" . $column; }
/** * This will show the identity-attribute when the model is loaded * * @param One_Scheme $scheme * @param One_Model $model */ public function afterLoadModel(One_Scheme $scheme, One_Model $model) { echo '<div style="display: inline; padding: 1px 3px;background-color: darkgreen;margin: 1px 2px;border: 1px solid green;">'; echo $scheme->getName(); echo ':'; $at = $scheme->getIdentityAttribute()->getName(); echo $model->{$at}; echo '</div>'; }
/** * Convert an array to an instance of the specified scheme * * @param One_Scheme $scheme * @param array $row * @return One_Model */ private function &arrayToInstance(&$scheme, &$row) { // check the scheme cache $idAttribute = $scheme->getIdentityAttribute(); $id = $row[$idAttribute->getName()]; $cached = One_Model_IdentityMap::find($scheme->getName(), $id); if ($cached) { return $cached; } // not found : create a new instance // @TODO: use a specific class specified in the scheme $model = One::make($scheme->getName()); $model->fromArray($row); // fire afterLoad event for model $model->afterLoad(); One_Model_IdentityMap::add($model); return $model; }
static function addObligatedWidgets(One_Form_Container_Form $form, One_Scheme $scheme) { // the form should always have a (hidden) widget with the value of the identityAttribute unless there is no identityAttribute if (!is_null($scheme->getIdentityAttribute()) && !$form->hasWidget($scheme->getIdentityAttribute()->getName())) { $form->addWidget(new One_Form_Widget_Scalar_Hidden($scheme->getIdentityAttribute()->getName(), $scheme->getIdentityAttribute()->getName(), NULL, array('one' => 'one', 'language' => strtolower(One_Config::get('app.language'))))); } if (!$form->hasWidget('task')) { $form->addWidget(new One_Form_Widget_Scalar_Hidden('task', 'task', NULL, array('default' => 'edit', 'one' => 'one', 'language' => strtolower(One_Config::get('app.language'))))); } if (!$form->hasWidget('scheme')) { $form->addWidget(new One_Form_Widget_Scalar_Hidden('scheme', 'scheme', NULL, array('default' => $scheme->getName(), 'one' => 'one', 'language' => strtolower(One_Config::get('app.language'))))); } }
/** * Convert an array to an instance of the specified scheme * * @param One_Scheme $scheme * @param array $row * @return One_Model */ protected function arrayToInstance(One_Scheme $scheme, $row) { // check the scheme cache $idAttribute = $scheme->getIdentityAttribute(); $id = $row[$idAttribute->getName()]; $cached = One_Model_IdentityMap::find($scheme->getName(), $id); if ($cached) { return $cached; } // not found : create a new instance //TODO: use a specific class specified in the scheme $model = One::make($scheme->getName()); // PD17OCT08: for optimal performance, raw-store the data row entirely $model->fromArray($row); // fire afterLoad event for model $model->afterLoad(); One_Model_IdentityMap::add($model); return $model; }