Enum datatype added
This commit is contained in:
parent
aacb279505
commit
04ca92b094
@ -428,6 +428,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
* populate
|
||||||
|
*
|
||||||
* @param Doctrine_Query $query
|
* @param Doctrine_Query $query
|
||||||
* @param integer $key
|
* @param integer $key
|
||||||
*/
|
*/
|
||||||
@ -458,6 +460,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
* getNormalIterator
|
||||||
|
* returns normal iterator - an iterator that will not expand this collection
|
||||||
|
*
|
||||||
* @return Doctrine_Iterator_Normal
|
* @return Doctrine_Iterator_Normal
|
||||||
*/
|
*/
|
||||||
public function getNormalIterator() {
|
public function getNormalIterator() {
|
||||||
@ -466,6 +471,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
/**
|
/**
|
||||||
* save
|
* save
|
||||||
* saves all records
|
* saves all records
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
$this->table->getSession()->saveCollection($this);
|
$this->table->getSession()->saveCollection($this);
|
||||||
|
@ -82,6 +82,8 @@ class Doctrine_DataDict {
|
|||||||
case "bool":
|
case "bool":
|
||||||
return "L";
|
return "L";
|
||||||
break;
|
break;
|
||||||
|
case "enum":
|
||||||
|
case "e":
|
||||||
case "integer":
|
case "integer":
|
||||||
case "int":
|
case "int":
|
||||||
case "i":
|
case "i":
|
||||||
|
@ -386,7 +386,7 @@ class Doctrine_Query extends Doctrine_Access {
|
|||||||
foreach($maps as $map) {
|
foreach($maps as $map) {
|
||||||
$b = array();
|
$b = array();
|
||||||
foreach($map as $field => $value) {
|
foreach($map as $field => $value) {
|
||||||
$b[] = $tname.".$field = $value";
|
$b[] = $tname.".$field = $value"; //OR $tname.$field IS NULL";
|
||||||
}
|
}
|
||||||
if( ! empty($b)) $a[] = implode(" AND ",$b);
|
if( ! empty($b)) $a[] = implode(" AND ",$b);
|
||||||
}
|
}
|
||||||
@ -526,9 +526,13 @@ class Doctrine_Query extends Doctrine_Access {
|
|||||||
|
|
||||||
if($emptyID) {
|
if($emptyID) {
|
||||||
|
|
||||||
|
|
||||||
$pointer = $this->joins[$name];
|
$pointer = $this->joins[$name];
|
||||||
$alias = $this->tables[$pointer]->getAlias($name);
|
$alias = $this->tables[$pointer]->getAlias($name);
|
||||||
$fk = $this->tables[$pointer]->getForeignKey($alias);
|
$fk = $this->tables[$pointer]->getForeignKey($alias);
|
||||||
|
if( ! $prev[$pointer])
|
||||||
|
continue;
|
||||||
|
|
||||||
$last = $prev[$pointer]->getLast();
|
$last = $prev[$pointer]->getLast();
|
||||||
|
|
||||||
switch($fk->getType()):
|
switch($fk->getType()):
|
||||||
|
@ -213,6 +213,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
* $data = array("name"=>"John","lastname" => Object(Doctrine_Null));
|
* $data = array("name"=>"John","lastname" => Object(Doctrine_Null));
|
||||||
*
|
*
|
||||||
* here column 'id' is removed since its auto-incremented primary key (protected)
|
* here column 'id' is removed since its auto-incremented primary key (protected)
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
*/
|
*/
|
||||||
private function cleanData() {
|
private function cleanData() {
|
||||||
$tmp = $this->data;
|
$tmp = $this->data;
|
||||||
@ -236,12 +238,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
case "object":
|
case "object":
|
||||||
if($tmp[$name] !== self::$null)
|
if($tmp[$name] !== self::$null)
|
||||||
$this->data[$name] = unserialize($tmp[$name]);
|
$this->data[$name] = unserialize($tmp[$name]);
|
||||||
|
break;
|
||||||
|
case "enum":
|
||||||
|
$this->data[$name] = $this->table->enumValue($name, $tmp[$name]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->data[$name] = $tmp[$name];
|
$this->data[$name] = $tmp[$name];
|
||||||
$count++;
|
|
||||||
endswitch;
|
endswitch;
|
||||||
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $count;
|
return $count;
|
||||||
@ -429,6 +433,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* factoryRefresh
|
* factoryRefresh
|
||||||
|
* refreshes the data from outer source (Doctrine_Table)
|
||||||
|
*
|
||||||
* @throws Doctrine_Exception
|
* @throws Doctrine_Exception
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -731,6 +737,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
|
|
||||||
$a[$v] = serialize($this->data[$v]);
|
$a[$v] = serialize($this->data[$v]);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
} elseif($type == 'enum') {
|
||||||
|
$a[$v] = $this->table->enumIndex($v,$this->data[$v]);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->data[$v] instanceof Doctrine_Record)
|
if($this->data[$v] instanceof Doctrine_Record)
|
||||||
@ -1127,6 +1137,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
break;
|
break;
|
||||||
endswitch;
|
endswitch;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* sets enumerated value array for given field
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param array $values
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
final public function setEnumValues($field, array $values) {
|
||||||
|
$this->table->setEnumValues($field, $values);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* binds One-to-One composite relation
|
* binds One-to-One composite relation
|
||||||
|
@ -102,6 +102,12 @@ class Doctrine_Table extends Doctrine_Configurable {
|
|||||||
* @var array $parents the parent classes of this component
|
* @var array $parents the parent classes of this component
|
||||||
*/
|
*/
|
||||||
private $parents = array();
|
private $parents = array();
|
||||||
|
/**
|
||||||
|
* @var array $enum enum value arrays
|
||||||
|
*/
|
||||||
|
private $enum = array();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the constructor
|
* the constructor
|
||||||
@ -742,11 +748,6 @@ class Doctrine_Table extends Doctrine_Configurable {
|
|||||||
if(isset($this->identityMap[$id]))
|
if(isset($this->identityMap[$id]))
|
||||||
$record = $this->identityMap[$id];
|
$record = $this->identityMap[$id];
|
||||||
else {
|
else {
|
||||||
/**
|
|
||||||
if($this->createsChildren) {
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
$record = new $this->name($this);
|
$record = new $this->name($this);
|
||||||
$this->identityMap[$id] = $record;
|
$this->identityMap[$id] = $record;
|
||||||
}
|
}
|
||||||
@ -814,12 +815,36 @@ class Doctrine_Table extends Doctrine_Configurable {
|
|||||||
}
|
}
|
||||||
return $coll;
|
return $coll;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* sets enumerated value array for given field
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param array $values
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
final public function setEnumValues($field, array $values) {
|
||||||
|
$this->enum[$field] = $values;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* enumValue
|
||||||
|
*/
|
||||||
|
final public function enumValue($field, $index) {
|
||||||
|
return isset($this->enum[$field][$index])?$this->enum[$field][$index]:$index;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* enumIndex
|
||||||
|
*/
|
||||||
|
final public function enumIndex($field, $value) {
|
||||||
|
$v = array_search($value, $this->enum[$field]);
|
||||||
|
return ($v !== false)?$v:$value;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
final public function getColumnCount() {
|
final public function getColumnCount() {
|
||||||
return $this->columnCount;
|
return $this->columnCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns all columns and their definitions
|
* returns all columns and their definitions
|
||||||
*
|
*
|
||||||
@ -836,6 +861,13 @@ class Doctrine_Table extends Doctrine_Configurable {
|
|||||||
public function getColumnNames() {
|
public function getColumnNames() {
|
||||||
return array_keys($this->columns);
|
return array_keys($this->columns);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* getDefinitionOf
|
||||||
|
*/
|
||||||
|
public function getDefinitionOf($column) {
|
||||||
|
if(isset($this->columns[$column]))
|
||||||
|
return $this->columns[$column];
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* getTypeOf
|
* getTypeOf
|
||||||
*/
|
*/
|
||||||
|
@ -2,6 +2,30 @@
|
|||||||
require_once("UnitTestCase.php");
|
require_once("UnitTestCase.php");
|
||||||
|
|
||||||
class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
||||||
|
public function prepareTables() {
|
||||||
|
$this->tables[] = "enumTest";
|
||||||
|
parent::prepareTables();
|
||||||
|
}
|
||||||
|
public function testEnumType() {
|
||||||
|
$enum = new EnumTest();
|
||||||
|
$enum->status = "open";
|
||||||
|
$this->assertEqual($enum->status, "open");
|
||||||
|
$enum->save();
|
||||||
|
$this->assertEqual($enum->status, "open");
|
||||||
|
$enum->refresh();
|
||||||
|
$this->assertEqual($enum->status, "open");
|
||||||
|
|
||||||
|
$enum->status = "closed";
|
||||||
|
|
||||||
|
$this->assertEqual($enum->status, "closed");
|
||||||
|
|
||||||
|
$enum->save();
|
||||||
|
$this->assertEqual($enum->status, "closed");
|
||||||
|
|
||||||
|
$enum->refresh();
|
||||||
|
$this->assertEqual($enum->status, "closed");
|
||||||
|
}
|
||||||
|
|
||||||
public function testSerialize() {
|
public function testSerialize() {
|
||||||
$user = $this->session->getTable("User")->find(4);
|
$user = $this->session->getTable("User")->find(4);
|
||||||
$str = serialize($user);
|
$str = serialize($user);
|
||||||
|
@ -312,6 +312,12 @@ class ORM_AccessControlsGroups extends Doctrine_Record {
|
|||||||
$this->setPrimaryKey(array("accessControlID", "accessGroupID"));
|
$this->setPrimaryKey(array("accessControlID", "accessGroupID"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class EnumTest extends Doctrine_Record {
|
||||||
|
public function setTableDefinition() {
|
||||||
|
$this->hasColumn("status","enum",11);
|
||||||
|
$this->setEnumValues("status", array("open","verified","closed"));
|
||||||
|
}
|
||||||
|
}
|
||||||
class Log_Entry extends Doctrine_Record {
|
class Log_Entry extends Doctrine_Record {
|
||||||
public function setTableDefinition() {
|
public function setTableDefinition() {
|
||||||
$this->hasColumn("stamp", "timestamp");
|
$this->hasColumn("stamp", "timestamp");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user