123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- <?php
- class ColumnMap
- {
-
- protected $type;
-
- protected $size = 0;
-
- protected $pk = false;
-
- protected $notNull = false;
-
- protected $defaultValue;
-
- protected $relatedTableName = "";
-
- protected $relatedColumnName = "";
-
- protected $table;
-
- protected $columnName;
-
- protected $phpName;
-
- protected $validators = array();
-
- public function __construct($name, TableMap $containingTable)
- {
- $this->columnName = $name;
- $this->table = $containingTable;
- }
-
- public function getName()
- {
- return $this->columnName;
- }
-
- public function getTable()
- {
- return $this->table;
- }
-
- public function getTableName()
- {
- return $this->table->getName();
- }
-
-
- public function getFullyQualifiedName()
- {
- return $this->getTableName() . "." . $this->columnName;
- }
-
- public function setPhpName($phpName)
- {
- $this->phpName = $phpName;
- }
-
-
- public function getPhpName()
- {
- return $this->phpName;
- }
-
-
- public function setType($type)
- {
- $this->type = $type;
- }
-
-
- public function getType()
- {
- return $this->type;
- }
-
- public function getPdoType()
- {
- return PropelColumnTypes::getPdoType($this->type);
- }
-
- public function isLob()
- {
- return ($this->type == PropelColumnTypes::BLOB || $this->type == PropelColumnTypes::VARBINARY || $this->type == PropelColumnTypes::LONGVARBINARY);
- }
-
- public function isTemporal()
- {
- return ($this->type == PropelColumnTypes::TIMESTAMP || $this->type == PropelColumnTypes::DATE || $this->type == PropelColumnTypes::TIME || $this->type == PropelColumnTypes::BU_DATE || $this->type == PropelColumnTypes::BU_TIMESTAMP);
- }
-
-
- public function isEpochTemporal()
- {
- return ($this->type == PropelColumnTypes::TIMESTAMP || $this->type == PropelColumnTypes::DATE || $this->type == PropelColumnTypes::TIME);
- }
-
- public function isNumeric()
- {
- return ($this->type == PropelColumnTypes::NUMERIC || $this->type == PropelColumnTypes::DECIMAL || $this->type == PropelColumnTypes::TINYINT || $this->type == PropelColumnTypes::SMALLINT || $this->type == PropelColumnTypes::INTEGER || $this->type == PropelColumnTypes::BIGINT || $this->type == PropelColumnTypes::REAL || $this->type == PropelColumnTypes::FLOAT || $this->type == PropelColumnTypes::DOUBLE);
- }
-
- public function isText()
- {
- return ($this->type == PropelColumnTypes::VARCHAR || $this->type == PropelColumnTypes::LONGVARCHAR || $this->type == PropelColumnTypes::CHAR);
- }
-
- public function setSize($size)
- {
- $this->size = $size;
- }
-
-
- public function getSize()
- {
- return $this->size;
- }
-
- public function setPrimaryKey($pk)
- {
- $this->pk = $pk;
- }
-
-
- public function isPrimaryKey()
- {
- return $this->pk;
- }
-
- public function setNotNull($nn)
- {
- $this->notNull = $nn;
- }
-
-
- public function isNotNull()
- {
- return ($this->notNull || $this->isPrimaryKey());
- }
-
- public function setDefaultValue($defaultValue)
- {
- $this->defaultValue = $defaultValue;
- }
-
-
- public function getDefaultValue()
- {
- return $this->defaultValue;
- }
-
- public function setForeignKey($tableName, $columnName)
- {
- if ($tableName && $columnName) {
- $this->relatedTableName = $tableName;
- $this->relatedColumnName = $columnName;
- } else {
- $this->relatedTableName = "";
- $this->relatedColumnName = "";
- }
- }
-
- public function isForeignKey()
- {
- if ($this->relatedTableName) {
- return true;
- } else {
- return false;
- }
- }
-
-
- public function getRelation()
- {
- if(!$this->relatedTableName) return null;
- foreach ($this->getTable()->getRelations() as $name => $relation)
- {
- if($relation->getType() == RelationMap::MANY_TO_ONE)
- {
- if ($relation->getForeignTable()->getName() == $this->getRelatedTableName()
- && array_key_exists($this->getFullyQualifiedName(), $relation->getColumnMappings()))
- {
- return $relation;
- }
- }
- }
- }
-
-
- public function getRelatedName()
- {
- return $this->relatedTableName . "." . $this->relatedColumnName;
- }
-
- public function getRelatedTableName()
- {
- return $this->relatedTableName;
- }
-
- public function getRelatedColumnName()
- {
- return $this->relatedColumnName;
- }
-
-
- public function getRelatedTable()
- {
- if ($this->relatedTableName) {
- return $this->table->getDatabaseMap()->getTable($this->relatedTableName);
- } else {
- throw new PropelException("Cannot fetch RelatedTable for column with no foreign key: " . $this->columnName);
- }
- }
-
-
- public function getRelatedColumn()
- {
- return $this->getRelatedTable()->getColumn($this->relatedColumnName);
- }
- public function addValidator($validator)
- {
- $this->validators[] = $validator;
- }
- public function hasValidators()
- {
- return count($this->validators) > 0;
- }
- public function getValidators()
- {
- return $this->validators;
- }
-
-
- public function ignoreCase($str, DBAdapter $db)
- {
- if ($this->isText()) {
- return $db->ignoreCase($str);
- } else {
- return $str;
- }
- }
-
-
- public static function normalizeName($name)
- {
- if (false !== ($pos = strpos($name, '.'))) {
- $name = substr($name, $pos + 1);
- }
- $name = strtoupper($name);
- return $name;
- }
-
-
-
-
- public function getColumnName()
- {
- return $this->getName();
- }
- }
|