/** * Form choice text function * @return array $lines */ private function getFormChoiceTextFunction() { // default function only works for tables with a lone primary key $columns = $this->pgClass->getAttributes(); // find columns tagged 'form-choicetext' $columnsSelected = array(); foreach ($columns as $column) { $tags = \Bond\extract_tags($column, 'normality'); if (isset($tags['form-choicetext'])) { $columnsSelected[] = $column; } } switch (count($columnsSelected)) { case 0: return; case 1: $columnName = array_pop($columnsSelected)->name; break; default: throw new \FormChoiceTextConfigurationException("Multiple columns with tag 'form-choicetext'. Only one column per table can have this tag."); } $this->class->classComponents[] = new FunctionDeclaration('form_choiceText', new Sformatf(<<<'PHP' /** * Function called by \Bond\Bridge\Normality\Form\Type\Normality when displaying text for this entity * @return scalar */ public function form_choiceText() { return $this->get('%s'); } PHP , addslashes($columnName))); }
/** * Generate a array of DataTypes from a Bond\Pg\Catalog\PgClass object * @param Bond\Pg\Catalog\PgRelation $relation * @return array */ public static function makeFromRelation(PgClass $relation) { $output = array(); foreach ($relation->getAttributes() as $attribute) { $dataType = static::makeFromAttribute($attribute); $output[$dataType->name] = $dataType; } return $output; }