Added exists() to check for existence of data, getColumnCount() as alias to count() and renamed has() to hasRelation() for clarity
This commit is contained in:
parent
cc94b9392a
commit
11efc8e7cc
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
@ -29,7 +29,7 @@ require_once("Access.php");
|
|||||||
* @license LGPL
|
* @license LGPL
|
||||||
* @package Doctrine
|
* @package Doctrine
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class Doctrine_Record extends Doctrine_Access implements Countable, IteratorAggregate, Serializable {
|
abstract class Doctrine_Record extends Doctrine_Access implements Countable, IteratorAggregate, Serializable {
|
||||||
/**
|
/**
|
||||||
* STATE CONSTANTS
|
* STATE CONSTANTS
|
||||||
@ -271,7 +271,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
|
|
||||||
if($tmp[$name] !== self::$null) {
|
if($tmp[$name] !== self::$null) {
|
||||||
$value = unserialize($tmp[$name]);
|
$value = unserialize($tmp[$name]);
|
||||||
if($value === false)
|
if($value === false)
|
||||||
throw new Doctrine_Exception("Unserialization of $name failed. ".var_dump($tmp[$name],true));
|
throw new Doctrine_Exception("Unserialization of $name failed. ".var_dump($tmp[$name],true));
|
||||||
|
|
||||||
$this->data[$name] = $value;
|
$this->data[$name] = $value;
|
||||||
@ -312,7 +312,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
case Doctrine_Identifier::NORMAL:
|
case Doctrine_Identifier::NORMAL:
|
||||||
$this->id = array();
|
$this->id = array();
|
||||||
$name = $this->table->getIdentifier();
|
$name = $this->table->getIdentifier();
|
||||||
|
|
||||||
if(isset($this->data[$name]) && $this->data[$name] !== self::$null)
|
if(isset($this->data[$name]) && $this->data[$name] !== self::$null)
|
||||||
$this->id[$name] = $this->data[$name];
|
$this->id[$name] = $this->data[$name];
|
||||||
break;
|
break;
|
||||||
@ -618,19 +618,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
$this->modified[] = $name;
|
$this->modified[] = $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* has
|
|
||||||
* method for checking existence of properties and Doctrine_Record references
|
|
||||||
*
|
|
||||||
* @param mixed $name name of the property or reference
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function has($name) {
|
|
||||||
if(isset($this->data[$name]) || isset($this->id[$name]))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return $this->table->hasForeignKey($name);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* set
|
* set
|
||||||
* method for altering properties and Doctrine_Record references
|
* method for altering properties and Doctrine_Record references
|
||||||
@ -826,6 +814,29 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
public function count() {
|
public function count() {
|
||||||
return count($this->data);
|
return count($this->data);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* alias for count()
|
||||||
|
*/
|
||||||
|
public function getColumnCount() {
|
||||||
|
return $this->count();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* checks if record has data
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function exists() {
|
||||||
|
return $this->state !== Doctrine_Record::STATE_TCLEAN;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* method for checking existence of properties and Doctrine_Record references
|
||||||
|
* @param mixed $name name of the property or reference
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function hasRelation($name) {
|
||||||
|
if(isset($this->data[$name]) || isset($this->id[$name]))
|
||||||
|
return true;
|
||||||
|
return $this->table->hasForeignKey($name);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* getIterator
|
* getIterator
|
||||||
* @return Doctrine_Record_Iterator a Doctrine_Record_Iterator that iterates through the data
|
* @return Doctrine_Record_Iterator a Doctrine_Record_Iterator that iterates through the data
|
||||||
@ -1261,7 +1272,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
$a[0] = $this->get($column);
|
$a[0] = $this->get($column);
|
||||||
|
|
||||||
$newvalue = call_user_func_array($m, $a);
|
$newvalue = call_user_func_array($m, $a);
|
||||||
|
|
||||||
$this->data[$column] = $newvalue;
|
$this->data[$column] = $newvalue;
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user