/** * Field types prediction modifier method * * @param boolean $with_validator * @return afsWidgetEditPredictionModifier * @author Sergey Startsev */ public function fieldTypes($with_validator = true) { $definition = $this->getDefinition(); $fields = $this->getFields(); $peerClassName = afsWidgetEditModifierHelper::getDatasource($definition); if (!is_null($peerClassName)) { $tableMap = call_user_func("{$peerClassName}::getTableMap"); foreach ($fields as &$field) { $columnName = $field['attributes']['name']; if (!$tableMap->hasColumn($columnName)) { continue; } $column = $tableMap->getColumn($columnName); $field['attributes']['type'] = $this->getType($column->getType()); if ($with_validator) { if ($column->isForeignKey()) { $foreign_table = $column->getRelation()->getForeignTable(); $foreign_model = $foreign_table->getPhpName(); $foreign_field = strtolower($foreign_table->getColumn($column->getRelatedColumnName())->getName()); $field['i:validator'] = $this->getForeignValidator($foreign_model, $foreign_field, $column->isNotNull()); continue; } $method_name = 'get' . ucfirst(strtolower($column->getType())) . 'Validator'; if (method_exists($this, $method_name)) { $field['i:validator'] = call_user_func(array($this, $method_name), $column->getSize(), $column->isNotNull()); } } } } $this->setFields($fields); return $this; }
/** * Modify process * * @param afsBaseModel $model * @return afsBaseModel * @author Łukasz Wojciechowski * @author Sergey Startsev */ public function modify(afsBaseModel $model) { $definition = $model->getDefinition(); $this->datasource = afsWidgetEditModifierHelper::getDatasource($definition); if ($model->isNew()) { $definition = $this->checkAndCreateFieldsUrlAttribute($definition, $model); $definition = afsWidgetEditPredictionModifier::create($definition)->fieldTypes()->getDefinition(); $definition = $this->searchForAndModifyForeignTableFields($definition); $definition = $this->setFieldsDefaultValuePlaceholder($definition); } $model->setDefinition($definition); return $model; }