/** * Returns a PHP string representing options to pass to a validator for a given column. * * @param ColumnMap $column A ColumnMap object * * @return string The options to pass to the validator as a PHP string */ public function getValidatorOptionsForColumn(ColumnMap $column) { $options = array(); if ($column->isForeignKey()) { $map = call_user_func(array(constant($this->getForeignTable($column)->getClassname() . '::PEER'), 'getTableMap')); foreach ($map->getColumns() as $primaryKey) { if ($primaryKey->isPrimaryKey()) { break; } } $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), strtolower($primaryKey->getColumnName())); } else { if ($column->isPrimaryKey()) { $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $column->getTable()->getClassname(), strtolower($column->getColumnName())); } else { switch ($column->getType()) { case PropelColumnTypes::CLOB: case PropelColumnTypes::CHAR: case PropelColumnTypes::VARCHAR: case PropelColumnTypes::LONGVARCHAR: if ($column->getSize()) { $options[] = sprintf('\'max_length\' => %s', $column->getSize()); } break; } } } if (!$column->isNotNull() || $column->isPrimaryKey()) { $options[] = '\'required\' => false'; } return count($options) ? sprintf('array(%s)', implode(', ', $options)) : ''; }
public function getType(ColumnMap $column) { if ($column->isForeignKey()) { return 'ForeignKey'; } switch ($column->getType()) { case PropelColumnTypes::BOOLEAN: return 'Boolean'; case PropelColumnTypes::DATE: case PropelColumnTypes::TIME: case PropelColumnTypes::TIMESTAMP: return 'Date'; case PropelColumnTypes::DOUBLE: case PropelColumnTypes::FLOAT: case PropelColumnTypes::NUMERIC: case PropelColumnTypes::DECIMAL: case PropelColumnTypes::REAL: case PropelColumnTypes::INTEGER: case PropelColumnTypes::SMALLINT: case PropelColumnTypes::TINYINT: case PropelColumnTypes::BIGINT: return 'Number'; default: return 'Text'; } }
/** * Returns a PHP string representing options to pass to a validator for a given column. * * @param ColumnMap $column A ColumnMap object * * @return string The options to pass to the validator as a PHP string */ public function getValidatorOptionsForColumn(ColumnMap $column) { $options = array(); if ($column->isForeignKey()) { $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), $this->translateColumnName($column, true)); } else { if ($column->isPrimaryKey()) { $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $column->getTable()->getClassname(), $this->translateColumnName($column)); } else { switch ($column->getType()) { case PropelColumnTypes::CLOB: case PropelColumnTypes::CHAR: case PropelColumnTypes::VARCHAR: case PropelColumnTypes::LONGVARCHAR: if ($column->getSize()) { $options[] = sprintf('\'max_length\' => %s', $column->getSize()); } break; case PropelColumnTypes::TINYINT: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -128, 127); break; case PropelColumnTypes::SMALLINT: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -32768, 32767); break; case PropelColumnTypes::INTEGER: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -2147483648, 2147483647); break; case PropelColumnTypes::BIGINT: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -9.223372036854776E+18, 9223372036854775807); break; } } } if (!$column->isNotNull() || $column->isPrimaryKey()) { $options[] = '\'required\' => false'; } if (null !== $column->getDefaultValue()) { $options[] = sprintf('\'empty_value\' => \'%s\'', $column->getDefaultValue()); } return count($options) ? sprintf('array(%s)', implode(', ', $options)) : ''; }
/** * Returns a PHP string representing options to pass to a validator for a given column. * * @param ColumnMap $column A ColumnMap object * * @return string The options to pass to the validator as a PHP string */ public function getValidatorOptionsForColumn(ColumnMap $column) { $options = array(); if ($column->isForeignKey()) { $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), $this->translateColumnName($column, true)); } else { if ($column->isPrimaryKey()) { $options[] = sprintf('\'choices\' => array($this->getObject()->get%s()), \'empty_value\' => $this->getObject()->get%1$s()', $this->translateColumnName($column, false, BasePeer::TYPE_PHPNAME)); } else { switch ($column->getType()) { case PropelColumnTypes::CLOB: case PropelColumnTypes::CHAR: case PropelColumnTypes::VARCHAR: case PropelColumnTypes::LONGVARCHAR: if ($column->getSize()) { $options[] = sprintf('\'max_length\' => %s', $column->getSize()); } break; case PropelColumnTypes::TINYINT: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -128, 127); break; case PropelColumnTypes::SMALLINT: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -32768, 32767); break; case PropelColumnTypes::INTEGER: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -2147483648, 2147483647); break; case PropelColumnTypes::BIGINT: $options[] = sprintf('\'min\' => %s, \'max\' => %s', -9.223372036854776E+18, 9223372036854775807); break; case PropelColumnTypes::ENUM: $valueSet = $column->getValueSet(); $options[] = sprintf("'choices' => %s", preg_replace('/[\\n\\r]+/', '', var_export($valueSet, true))); break; } } } if (!$column->isNotNull() || $column->isPrimaryKey()) { $options[] = '\'required\' => false'; } return count($options) ? sprintf('array(%s)', implode(', ', $options)) : ''; }
/** * Returns HTML code for a column in edit mode. * * @param ColumnMap $column The column name * @param array $params The parameters * * @return string HTML code */ public function getCrudColumnEditTag($column, $params = array()) { $type = $column->getCreoleType(); if ($column->isForeignKey()) { if (!$column->isNotNull() && !isset($params['include_blank'])) { $params['include_blank'] = true; } return $this->getPHPObjectHelper('select_tag', $column, $params, array('related_class' => $this->getRelatedClassName($column))); } else if ($type == CreoleTypes::DATE) { // rich=false not yet implemented return $this->getPHPObjectHelper('input_date_tag', $column, $params, array('rich' => true)); } else if ($type == CreoleTypes::TIMESTAMP) { // rich=false not yet implemented return $this->getPHPObjectHelper('input_date_tag', $column, $params, array('rich' => true, 'withtime' => true)); } else if ($type == CreoleTypes::BOOLEAN) { return $this->getPHPObjectHelper('checkbox_tag', $column, $params); } else if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR) { $fieldMin = $this->getParameterValue('defaults.edit.char_min', 20); $fieldMax = $this->getParameterValue('defaults.edit.char_max', 80); $size = ($column->getSize() > $fieldMin ? ($column->getSize() < $fieldMax ? $column->getSize() : $fieldMax) : $fieldMin); return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => $size)); } else if ($type == CreoleTypes::INTEGER || $type == CreoleTypes::TINYINT || $type == CreoleTypes::SMALLINT || $type == CreoleTypes::BIGINT) { $size = $this->getParameterValue('defaults.edit.int_size', 7); return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => $size)); } else if ($type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL) { $size = $this->getParameterValue('defaults.edit.float_size', 7); return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => $size)); } else if ($type == CreoleTypes::TEXT || $type == CreoleTypes::LONGVARCHAR) { $size = $this->getParameterValue('defaults.edit.text_size', '80x5'); return $this->getPHPObjectHelper('textarea_tag', $column, $params, array('size' => $size)); } else { return $this->getPHPObjectHelper('input_tag', $column, $params, array('disabled' => true)); } }
/** * Returns a PHP string representing options to pass to a validator for a given column. * * @param ColumnMap $column A ColumnMap object * * @return string The options to pass to the validator as a PHP string */ public function getValidatorOptionsForColumn(ColumnMap $column) { $options = array(); if ($column->isForeignKey()) { $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), $this->translateColumnName($column, true)); } else { if ($column->isPrimaryKey()) { $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $column->getTable()->getClassname(), $this->translateColumnName($column)); } else { switch ($column->getType()) { case PropelColumnTypes::CLOB: case PropelColumnTypes::CHAR: case PropelColumnTypes::VARCHAR: case PropelColumnTypes::LONGVARCHAR: if ($column->getSize()) { $options[] = sprintf('\'max_length\' => %s', $column->getSize()); } break; } } } if (!$column->isNotNull() || $column->isPrimaryKey()) { $options[] = '\'required\' => false'; } return count($options) ? sprintf('array(%s)', implode(', ', $options)) : ''; }
/** * Gets value for row table * * Swaps foreign creator_node_id values for their unique FQDN value. Note that the other * part(s) to a primary or foreign key is set by the creator and is the same in all nodes, * so may be hashed without causing difference problems between nodes. * * @todo Better node table detection required (should use known prefix) * @todo Fix column name hardwiring * * @param MeshingBaseObject $object * @param ColumnMap $columnMap * @return mixed */ protected function getRowValue(MeshingBaseObject $object, ColumnMap $columnMap) { // Get value for this column $columnName = $columnMap->getName(); $value = $object->getByName($columnName, BasePeer::TYPE_RAW_COLNAME); // If the related table name ends with '_known_node' then we assume this is a // FK to a creator node ID. if ($columnMap->isForeignKey()) { $match = '_known_node'; $isNodeTable = $match == substr($columnMap->getRelatedTableName(), -strlen($match)); if ($isNodeTable && $columnMap->getRelatedColumnName() == 'ID') { $nodePeerName = $columnMap->getRelation()->getForeignTable()->getPeerClassname(); $node = call_user_func(array($nodePeerName, 'retrieveByPK'), $value, $this->con); // If there is no related node, we really do have problems! if (!$node) { $primaryKey = $object->getPrimaryKey(); if (is_array($primaryKey)) { $primaryKey = '{' . implode(',', $primaryKey) . '}'; } $type = get_class($object); throw new Exception("Row {$primaryKey} in table '{$type}' points to a non-existent node row"); } $value = $node->getFqdn(); } } return $value; }