Record.php 43.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<?php
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.com>.
 */
Doctrine::autoload('Doctrine_Access');
/**
 * Doctrine_Record
 * All record classes should inherit this super class
 *
 * @author      Konsta Vesterinen
 * @license     LGPL
 * @package     Doctrine
 */

abstract class Doctrine_Record extends Doctrine_Access implements Countable, IteratorAggregate, Serializable {
    /**
     * STATE CONSTANTS
     */

    /**
     * DIRTY STATE
     * a Doctrine_Record is in dirty state when its properties are changed
     */
    const STATE_DIRTY       = 1;
    /**
     * TDIRTY STATE
     * a Doctrine_Record is in transient dirty state when it is created and some of its fields are modified
     * but it is NOT yet persisted into database
     */
    const STATE_TDIRTY      = 2;
    /**
     * CLEAN STATE
     * a Doctrine_Record is in clean state when all of its properties are loaded from the database
     * and none of its properties are changed
     */
    const STATE_CLEAN       = 3;
    /**
     * PROXY STATE
     * a Doctrine_Record is in proxy state when its properties are not fully loaded
     */
    const STATE_PROXY       = 4;
    /**
     * NEW TCLEAN
     * a Doctrine_Record is in transient clean state when it is created and none of its fields are modified
     */
    const STATE_TCLEAN      = 5;
    /**
     * DELETED STATE
     * a Doctrine_Record turns into deleted state when it is deleted
     */
    const STATE_DELETED     = 6;
zYne's avatar
zYne committed
68 69 70 71 72
    /**
     * the following protected variables use '_' prefixes, the reason for this is to allow child
     * classes call for example $this->id, $this->state for getting the values of columns named 'id' and 'state'
     * rather than the values of these protected variables
     */
73 74 75
    /**
     * @var object Doctrine_Table $table    the factory that created this data access object
     */
zYne's avatar
zYne committed
76
    protected $_table;
77 78 79
    /**
     * @var integer $id                     the primary keys of this object
     */
zYne's avatar
zYne committed
80
    protected $_id           = array();
81 82 83
    /**
     * @var array $data                     the record data
     */
zYne's avatar
zYne committed
84
    protected $_data         = array();
85 86 87 88
    /**
     * @var integer $state                  the state of this record
     * @see STATE_* constants
     */
zYne's avatar
zYne committed
89
    protected $_state;
90 91 92
    /**
     * @var array $modified                 an array containing properties that have been modified
     */
zYne's avatar
zYne committed
93 94 95 96 97
    protected $_modified     = array();
    /**
     * @var Doctrine_Validator_ErrorStack   error stack object
     */
    protected $_errorStack;
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    /**
     * @var array $references               an array containing all the references
     */
    private $references     = array();
    /**
     * @var array $originals                an array containing all the original references
     */
    private $originals      = array();
    /**
     * @var integer $index                  this index is used for creating object identifiers
     */
    private static $index   = 1;
    /**
     * @var Doctrine_Null $null             a Doctrine_Null object used for extremely fast
     *                                      null value testing
     */
    private static $null;
    /**
     * @var integer $oid                    object identifier
     */
    private $oid;

    /**
     * constructor
     * @param Doctrine_Table|null $table       a Doctrine_Table object or null, 
     *                                         if null the table object is retrieved from current connection
     *
     * @throws Doctrine_Connection_Exception   if object is created using the new operator and there are no
     *                                         open connections
     * @throws Doctrine_Record_Exception       if the cleanData operation fails somehow
     */
chtito's avatar
chtito committed
129
    public function __construct($table = null, $isNewEntry = false) {
130
        if(isset($table) && $table instanceof Doctrine_Table) {
zYne's avatar
zYne committed
131
            $this->_table = $table;
chtito's avatar
chtito committed
132
        $exists = !$isNewEntry;
133
        } else {
zYne's avatar
zYne committed
134
            $this->_table = Doctrine_Manager::getInstance()->getCurrentConnection()->getTable(get_class($this));
chtito's avatar
chtito committed
135
            $exists = false;
136 137 138 139 140 141
        }

        // Check if the current connection has the records table in its registry
        // If not this record is only used for creating table definition and setting up
        // relations.

zYne's avatar
zYne committed
142
        if($this->_table->getConnection()->hasTable($this->_table->getComponentName())) {
143 144 145 146 147

            $this->oid = self::$index;

            self::$index++;

zYne's avatar
zYne committed
148
            $keys = $this->_table->getPrimaryKeys();
149 150 151

            if( ! $exists) {
                // listen the onPreCreate event
zYne's avatar
zYne committed
152
                $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onPreCreate($this);
153 154 155
            } else {

                // listen the onPreLoad event
zYne's avatar
zYne committed
156
                $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onPreLoad($this);
157 158
            }
            // get the data array
zYne's avatar
zYne committed
159
            $this->_data = $this->_table->getData();
160 161 162


            // get the column count
zYne's avatar
zYne committed
163
            $count = count($this->_data);
164 165 166 167 168 169 170 171 172

            // clean data array
            $this->cleanData();

            $this->prepareIdentifiers($exists);

            if( ! $exists) {

                if($count > 0)
zYne's avatar
zYne committed
173
                    $this->_state = Doctrine_Record::STATE_TDIRTY;
174
                else
zYne's avatar
zYne committed
175
                    $this->_state = Doctrine_Record::STATE_TCLEAN;
176 177 178 179 180

                // set the default values for this record
                $this->setDefaultValues();

                // listen the onCreate event
zYne's avatar
zYne committed
181
                $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onCreate($this);
182 183

            } else {
zYne's avatar
zYne committed
184
                $this->_state      = Doctrine_Record::STATE_CLEAN;
185

zYne's avatar
zYne committed
186 187
                if($count < $this->_table->getColumnCount()) {
                    $this->_state  = Doctrine_Record::STATE_PROXY;
188 189 190
                }

                // listen the onLoad event
zYne's avatar
zYne committed
191
                $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this);
192 193
            }

zYne's avatar
zYne committed
194
            $this->_errorStack = new Doctrine_Validator_ErrorStack();
195

zYne's avatar
zYne committed
196
            $repository = $this->_table->getRepository();
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
            $repository->add($this);
        }
    }
    /**
     * initNullObject
     *
     * @param Doctrine_Null $null
     * @return void
     */
    public static function initNullObject(Doctrine_Null $null) {
        self::$null = $null;
    }
    /**
     * @return Doctrine_Null
     */
    public static function getNullObject() {
        return self::$null;
    }
    /**
     * setUp
     * this method is used for setting up relations and attributes
     * it should be implemented by child classes
     *
     * @return void
     */
    public function setUp() { }
    /**
     * getOID
     * returns the object identifier
     *
     * @return integer
     */
    public function getOID() {
        return $this->oid;
    }
    /**
     * isValid
     *
     * @return boolean                          whether or not this record passes all column validations
     */
    public function isValid() {
zYne's avatar
zYne committed
238
        if( ! $this->_table->getAttribute(Doctrine::ATTR_VLD))
239
            return true;
240 241
        
        // Clear the stack from any previous errors.
zYne's avatar
zYne committed
242
        $this->_errorStack->clear();
243 244
        
        // Run validation process  
245 246 247
        $validator = new Doctrine_Validator();
        $validator->validateRecord($this);
        $this->validate();
zYne's avatar
zYne committed
248
        if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) {
249 250 251 252
            $this->validateOnInsert();
        } else {
            $this->validateOnUpdate();
        }
253
        
zYne's avatar
zYne committed
254
        return $this->_errorStack->count() == 0 ? true : false;
255 256 257 258 259 260 261
    }
    /**
     * Emtpy template method to provide concrete Record classes with the possibility
     * to hook into the validation procedure, doing any custom / specialized
     * validations that are neccessary.
     */
    protected function validate() {}
262 263 264 265 266 267 268 269 270 271 272 273
    /**
     * Empty tempalte method to provide concrete Record classes with the possibility
     * to hook into the validation procedure only when the record is going to be
     * updated.
     */
    protected function validateOnUpdate() {}
    /**
     * Empty tempalte method to provide concrete Record classes with the possibility
     * to hook into the validation procedure only when the record is going to be
     * inserted into the data store the first time.
     */
    protected function validateOnInsert() {}
274 275 276 277 278 279
    /**
     * getErrorStack
     *
     * @return Doctrine_Validator_ErrorStack    returns the errorStack associated with this record
     */
    public function getErrorStack() {
zYne's avatar
zYne committed
280
        return $this->_errorStack;
281 282 283 284 285 286 287 288 289
    }
    /**
     * setDefaultValues
     * sets the default values for records internal data
     *
     * @param boolean $overwrite                whether or not to overwrite the already set values
     * @return boolean
     */
    public function setDefaultValues($overwrite = false) {
zYne's avatar
zYne committed
290
        if( ! $this->_table->hasDefaultValues())
291 292
            return false;
            
zYne's avatar
zYne committed
293 294
        foreach($this->_data as $column => $value) {
            $default = $this->_table->getDefaultValueOf($column);
295 296 297 298 299

            if($default === null)
                $default = self::$null;

            if($value === self::$null || $overwrite) {
zYne's avatar
zYne committed
300 301 302
                $this->_data[$column] = $default;
                $this->_modified[]    = $column;
                $this->_state = Doctrine_Record::STATE_TDIRTY;
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
            }
        }
    }
    /**
     * cleanData
     * this method does several things to records internal data
     *
     * 1. It unserializes array and object typed columns
     * 2. Uncompresses gzip typed columns
     * 3. Gets the appropriate enum values for enum typed columns
     * 4. Initializes special null object pointer for null values (for fast column existence checking purposes)
     *
     *
     * example:
     *
     * $data = array("name"=>"John","lastname"=> null, "id" => 1,"unknown" => "unknown");
     * $names = array("name", "lastname", "id");
     * $data after operation:
     * $data = array("name"=>"John","lastname" => Object(Doctrine_Null));
     *
     * here column 'id' is removed since its auto-incremented primary key (read-only)
     *
     * @throws Doctrine_Record_Exception        if unserialization of array/object typed column fails or 
     *                                          if uncompression of gzip typed column fails
     *
     * @return integer
     */
    private function cleanData($debug = false) {
zYne's avatar
zYne committed
331
        $tmp = $this->_data;
332

zYne's avatar
zYne committed
333
        $this->_data = array();
334 335 336

        $count = 0;

zYne's avatar
zYne committed
337 338
        foreach($this->_table->getColumnNames() as $name) {
            $type = $this->_table->getTypeOf($name);
339 340

            if( ! isset($tmp[$name])) {
zYne's avatar
zYne committed
341
                $this->_data[$name] = self::$null;
342 343 344 345 346 347 348 349 350 351 352 353 354 355
            } else {
                switch($type):
                    case "array":
                    case "object":

                        if($tmp[$name] !== self::$null) {
                            if(is_string($tmp[$name])) {
                                $value = unserialize($tmp[$name]);

                                if($value === false)
                                    throw new Doctrine_Record_Exception("Unserialization of $name failed. ".var_dump(substr($tmp[$lower],0,30)."...",true));
                            } else
                                $value = $tmp[$name];

zYne's avatar
zYne committed
356
                            $this->_data[$name] = $value;
357 358 359 360 361 362 363 364 365 366 367
                        }
                    break;
                    case "gzip":

                        if($tmp[$name] !== self::$null) {
                            $value = gzuncompress($tmp[$name]);
                            

                            if($value === false)
                                throw new Doctrine_Record_Exception("Uncompressing of $name failed.");

zYne's avatar
zYne committed
368
                            $this->_data[$name] = $value;
369 370 371
                        }
                    break;
                    case "enum":
zYne's avatar
zYne committed
372
                        $this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]);
373 374
                    break;
                    default:
zYne's avatar
zYne committed
375
                        $this->_data[$name] = $tmp[$name];
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
                endswitch;
                $count++;
            }
        }


        return $count;
    }
    /**       
     * prepareIdentifiers
     * prepares identifiers for later use
     *
     * @param boolean $exists               whether or not this record exists in persistent data store
     * @return void
     */
    private function prepareIdentifiers($exists = true) {
zYne's avatar
zYne committed
392
        switch($this->_table->getIdentifierType()):
393 394
            case Doctrine_Identifier::AUTO_INCREMENT:
            case Doctrine_Identifier::SEQUENCE:
zYne's avatar
zYne committed
395
                $name = $this->_table->getIdentifier();
396 397

                if($exists) {
zYne's avatar
zYne committed
398 399
                    if(isset($this->_data[$name]) && $this->_data[$name] !== self::$null)
                        $this->_id[$name] = $this->_data[$name];
400 401
                }

zYne's avatar
zYne committed
402
                unset($this->_data[$name]);
403 404 405

            break;
            case Doctrine_Identifier::NORMAL:
zYne's avatar
zYne committed
406 407
                 $this->_id   = array();
                 $name       = $this->_table->getIdentifier();
408

zYne's avatar
zYne committed
409 410
                 if(isset($this->_data[$name]) && $this->_data[$name] !== self::$null)
                    $this->_id[$name] = $this->_data[$name];
411 412
            break;
            case Doctrine_Identifier::COMPOSITE:
zYne's avatar
zYne committed
413
                $names      = $this->_table->getIdentifier();
414 415 416


                foreach($names as $name) {
zYne's avatar
zYne committed
417 418
                    if($this->_data[$name] === self::$null)
                        $this->_id[$name] = null;
419
                    else
zYne's avatar
zYne committed
420
                        $this->_id[$name] = $this->_data[$name];
421 422 423 424 425 426 427 428 429 430 431
                }
            break;
        endswitch;
    }
    /**
     * serialize
     * this method is automatically called when this Doctrine_Record is serialized
     *
     * @return array
     */
    public function serialize() {
zYne's avatar
zYne committed
432
        $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onSleep($this);
433 434 435 436 437

        $vars = get_object_vars($this);

        unset($vars['references']);
        unset($vars['originals']);
zYne's avatar
zYne committed
438
        unset($vars['_table']);
439

zYne's avatar
zYne committed
440 441
        $name = $this->_table->getIdentifier();
        $this->_data = array_merge($this->_data, $this->_id);
442

zYne's avatar
zYne committed
443
        foreach($this->_data as $k => $v) {
444
            if($v instanceof Doctrine_Record)
zYne's avatar
zYne committed
445
                unset($vars['_data'][$k]);
446
            elseif($v === self::$null) {
zYne's avatar
zYne committed
447
                unset($vars['_data'][$k]);
448
            } else {
zYne's avatar
zYne committed
449
                switch($this->_table->getTypeOf($k)):
450 451
                    case "array":
                    case "object":
zYne's avatar
zYne committed
452
                        $vars['_data'][$k] = serialize($vars['_data'][$k]);
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
                    break;
                endswitch;
            }
        }

        return serialize($vars);
    }
    /**
     * unseralize
     * this method is automatically called everytime a Doctrine_Record object is unserialized
     *
     * @param string $serialized                Doctrine_Record as serialized string
     * @throws Doctrine_Record_Exception        if the cleanData operation fails somehow
     * @return void
     */
    public function unserialize($serialized) {
        $manager    = Doctrine_Manager::getInstance();
        $connection    = $manager->getCurrentConnection();

        $this->oid  = self::$index;
        self::$index++;

zYne's avatar
zYne committed
475
        $this->_table = $connection->getTable(get_class($this));
476 477 478 479 480 481 482 483


        $array = unserialize($serialized);

        foreach($array as $name => $values) {
            $this->$name = $values;
        }

zYne's avatar
zYne committed
484
        $this->_table->getRepository()->add($this);
485 486 487 488 489

        $this->cleanData();

        $this->prepareIdentifiers($this->exists());

zYne's avatar
zYne committed
490
        $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onWakeUp($this);
491 492 493 494 495 496 497 498
    }
    /**
     * getState
     * returns the current state of the object
     *
     * @see Doctrine_Record::STATE_* constants
     * @return integer
     */
499
    public function getState() {
zYne's avatar
zYne committed
500
        return $this->_state;
501
    }
zYne's avatar
zYne committed
502 503 504 505 506
    /**
     * state
     * returns / assigns the state of this record
     *
     * @param integer|string $state                 if set, this method tries to set the record state to $state
507
     * @see Doctrine_Record::STATE_* constants
zYne's avatar
zYne committed
508 509 510 511 512 513 514 515
     *
     * @throws Doctrine_Record_State_Exception      if trying to set an unknown state
     * @return null|integer
     */
    public function state($state = null) {
        if($state == null) {
            return $this->_state;
        }
516
        $err = false;
zYne's avatar
zYne committed
517
        if(is_integer($state)) {
518

zYne's avatar
zYne committed
519 520
            if($state >= 1 && $state <= 6)
                $this->_state = $state;
521 522 523
            else
                $err = true;

zYne's avatar
zYne committed
524 525 526 527 528 529 530 531 532 533 534
        } elseif(is_string($state)) {
            $upper = strtoupper($state);
            switch($upper) {
                case 'DIRTY':
                case 'CLEAN':
                case 'TDIRTY':
                case 'TCLEAN':
                case 'PROXY':
                case 'DELETED':
                    $this->_state = constant('Doctrine_Record::STATE_' . $upper);
                break;
535 536
                default:
                    $err = true;
zYne's avatar
zYne committed
537
            }
538
        } 
zYne's avatar
zYne committed
539
        
540 541
        if($err)
            throw new Doctrine_Record_State_Exception('Unknown record state ' . $state);
zYne's avatar
zYne committed
542
    }
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
    /**
     * refresh
     * refresh internal data from the database
     *
     * @throws Doctrine_Record_Exception        When the refresh operation fails (when the database row 
     *                                          this record represents does not exist anymore)
     * @return boolean
     */
    final public function refresh() {
        $id = $this->obtainIdentifier();
        if( ! is_array($id))
            $id = array($id);

        if(empty($id))
            return false;

        $id = array_values($id);

zYne's avatar
zYne committed
561 562
        $query          = $this->_table->getQuery()." WHERE ".implode(" = ? AND ",$this->_table->getPrimaryKeys())." = ?";
        $stmt           = $this->_table->getConnection()->execute($query,$id);
563

zYne's avatar
zYne committed
564
        $this->_data     = $stmt->fetch(PDO::FETCH_ASSOC);
565 566


zYne's avatar
zYne committed
567
        if( ! $this->_data)
568 569
            throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist anymore');

zYne's avatar
zYne committed
570
        $this->_data     = array_change_key_case($this->_data, CASE_LOWER);
571

zYne's avatar
zYne committed
572
        $this->_modified = array();
573 574 575 576
        $this->cleanData(true);

        $this->prepareIdentifiers();

zYne's avatar
zYne committed
577
        $this->_state    = Doctrine_Record::STATE_CLEAN;
578

zYne's avatar
zYne committed
579
        $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this);
580 581 582 583 584 585 586 587 588 589 590

        return true;
    }
    /**
     * factoryRefresh
     * refreshes the data from outer source (Doctrine_Table)
     *
     * @throws Doctrine_Record_Exception        When the primary key of this record doesn't match the primary key fetched from a collection
     * @return void
     */
    final public function factoryRefresh() {
zYne's avatar
zYne committed
591 592
        $this->_data = $this->_table->getData();
        $old  = $this->_id;
593 594 595 596 597

        $this->cleanData();

        $this->prepareIdentifiers();

zYne's avatar
zYne committed
598
        if($this->_id != $old)
599 600
            throw new Doctrine_Record_Exception("The refreshed primary key doesn't match the one in the record memory.", Doctrine::ERR_REFRESH);

zYne's avatar
zYne committed
601 602
        $this->_state    = Doctrine_Record::STATE_CLEAN;
        $this->_modified = array();
603

zYne's avatar
zYne committed
604
        $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this);
605 606 607 608 609 610 611 612
    }
    /**
     * getTable
     * returns the table object for this record
     *
     * @return object Doctrine_Table        a Doctrine_Table object
     */
    final public function getTable() {
zYne's avatar
zYne committed
613
        return $this->_table;
614 615 616 617 618 619 620 621
    }
    /**
     * getData
     * return all the internal data
     *
     * @return array                        an array containing all the properties
     */
    final public function getData() {
zYne's avatar
zYne committed
622
        return $this->_data;
623 624 625 626 627 628 629 630 631 632 633 634
    }
    /**
     * rawGet
     * returns the value of a property, if the property is not yet loaded
     * this method does NOT load it
     *
     * @param $name                         name of the property
     * @throws Doctrine_Record_Exception    if trying to get an unknown property
     * @return mixed
     */

    public function rawGet($name) {
zYne's avatar
zYne committed
635
        if( ! isset($this->_data[$name]))
636 637
            throw new Doctrine_Record_Exception('Unknown property '. $name);

zYne's avatar
zYne committed
638
        if($this->_data[$name] === self::$null)
639 640
            return null;

zYne's avatar
zYne committed
641
        return $this->_data[$name];
642 643 644 645 646 647 648 649 650 651
    }

    /**
     * load
     * loads all the unitialized properties from the database
     *
     * @return boolean
     */
    public function load() {
        // only load the data from database if the Doctrine_Record is in proxy state
zYne's avatar
zYne committed
652
        if($this->_state == Doctrine_Record::STATE_PROXY) {
653
            $this->refresh();
654

zYne's avatar
zYne committed
655
            $this->_state = Doctrine_Record::STATE_CLEAN;
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671

            return true;
        }
        return false;
    }
    /**
     * get
     * returns a value of a property or a related component
     *
     * @param mixed $name                       name of the property or related component
     * @param boolean $invoke                   whether or not to invoke the onGetProperty listener
     * @throws Doctrine_Record_Exception        if trying to get a value of unknown property / related component
     * @return mixed
     */
    public function get($name, $invoke = true) {
        
zYne's avatar
zYne committed
672
        $listener = $this->_table->getAttribute(Doctrine::ATTR_LISTENER);
673 674 675
        $value    = self::$null;
        $lower    = strtolower($name);

zYne's avatar
zYne committed
676
        if(isset($this->_data[$lower])) {
677 678

            // check if the property is null (= it is the Doctrine_Null object located in self::$null)
679
            if($this->_data[$lower] === self::$null)
680
                $this->load();
zYne's avatar
zYne committed
681

682

zYne's avatar
zYne committed
683
            if($this->_data[$lower] === self::$null)
684 685
                $value = null;
            else
zYne's avatar
zYne committed
686
                $value = $this->_data[$lower];
687 688 689 690 691 692

        }


        if($value !== self::$null) {

zYne's avatar
zYne committed
693
            $value = $this->_table->invokeGet($this, $name, $value);
694

zYne's avatar
zYne committed
695 696
            if($invoke && $name !== $this->_table->getIdentifier())
                return $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onGetProperty($this, $name, $value);
697 698 699 700 701 702 703
            else
                return $value;

            return $value;
        }


zYne's avatar
zYne committed
704 705
        if(isset($this->_id[$lower]))
            return $this->_id[$lower];
706

zYne's avatar
zYne committed
707
        if($name === $this->_table->getIdentifier())
708 709
            return null;

zYne's avatar
zYne committed
710
        $rel = $this->_table->getRelation($name);
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738

        try {
            if( ! isset($this->references[$name]))
                $this->loadReference($name);
        } catch(Doctrine_Table_Exception $e) {
            throw new Doctrine_Record_Exception("Unknown property / related component '$name'.");
        }

        return $this->references[$name];
    }

    /**
     * set
     * method for altering properties and Doctrine_Record references
     * if the load parameter is set to false this method will not try to load uninitialized record data
     *
     * @param mixed $name                   name of the property or reference
     * @param mixed $value                  value of the property or reference
     * @param boolean $load                 whether or not to refresh / load the uninitialized record data
     *
     * @throws Doctrine_Record_Exception    if trying to set a value for unknown property / related component
     * @throws Doctrine_Record_Exception    if trying to set a value of wrong type for related component
     *
     * @return Doctrine_Record
     */
    public function set($name, $value, $load = true) {
        $lower = strtolower($name);

zYne's avatar
zYne committed
739
        if(isset($this->_data[$lower])) {
740 741 742 743 744 745 746 747 748 749 750

            if($value instanceof Doctrine_Record) {
                $id = $value->getIncremented();

                if($id !== null)
                    $value = $id;
            }

            if($load)
                $old = $this->get($lower, false);
            else
zYne's avatar
zYne committed
751
                $old = $this->_data[$lower];
752 753 754

            if($old !== $value) {

zYne's avatar
zYne committed
755
                $value = $this->_table->invokeSet($this, $name, $value);
756
                
zYne's avatar
zYne committed
757
                $value = $this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onSetProperty($this, $name, $value);
758 759 760 761

                if($value === null)
                    $value = self::$null;

zYne's avatar
zYne committed
762 763 764
                $this->_data[$lower] = $value;
                $this->_modified[]   = $lower;
                switch($this->_state):
765
                    case Doctrine_Record::STATE_CLEAN:
zYne's avatar
zYne committed
766
                        $this->_state = Doctrine_Record::STATE_DIRTY;
767 768
                    break;
                    case Doctrine_Record::STATE_TCLEAN:
zYne's avatar
zYne committed
769
                        $this->_state = Doctrine_Record::STATE_TDIRTY;
770 771 772 773 774 775 776 777 778 779 780 781 782
                    break;
                endswitch;
            }
        } else {
            try {
                $this->coreSetRelated($name, $value);
            } catch(Doctrine_Table_Exception $e) {
                throw new Doctrine_Record_Exception("Unknown property / related component '$name'.");
            }
        }
    }
    
    public function coreSetRelated($name, $value) {
zYne's avatar
zYne committed
783
        $rel = $this->_table->getRelation($name);
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823

        // one-to-many or one-to-one relation
        if($rel instanceof Doctrine_Relation_ForeignKey ||
           $rel instanceof Doctrine_Relation_LocalKey) {
            if( ! $rel->isOneToOne()) {
                // one-to-many relation found
                if( ! ($value instanceof Doctrine_Collection))
                    throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references.");

                $value->setReference($this,$rel);
            } else {
                // one-to-one relation found
                if( ! ($value instanceof Doctrine_Record))
                    throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Record when setting one-to-one references.");

                if($rel instanceof Doctrine_Relation_LocalKey) {
                    $this->set($rel->getLocal(), $value, false);
                } else {
                    $value->set($rel->getForeign(), $this, false);
                }
            }

        } elseif($rel instanceof Doctrine_Relation_Association) {
            // join table relation found
            if( ! ($value instanceof Doctrine_Collection))
                throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting many-to-many references.");
        
        }

        $this->references[$name] = $value;
    }
    /**
     * contains
     *
     * @param string $name
     * @return boolean
     */
    public function contains($name) {
        $lower = strtolower($name);

zYne's avatar
zYne committed
824
        if(isset($this->_data[$lower]))
825 826
            return true;

zYne's avatar
zYne committed
827
        if(isset($this->_id[$lower]))
828 829 830 831 832 833 834 835 836 837 838 839
            return true;

        if(isset($this->references[$name]))
            return true;

        return false;
    }
    /**
     * @param string $name
     * @return void
     */
    public function __unset($name) {
zYne's avatar
zYne committed
840 841
        if(isset($this->_data[$name]))
            $this->_data[$name] = array();
842 843 844 845 846 847 848 849

        // todo: what to do with references ?
    }
    /**
     * applies the changes made to this object into database
     * this method is smart enough to know if any changes are made
     * and whether to use INSERT or UPDATE statement
     *
850
     * this method also saves the related components
851
     *
852
     * @param Doctrine_Connection $conn
853 854
     * @return void
     */
855
    public function save(Doctrine_Connection $conn = null) {
856
        if ($conn === null) {
zYne's avatar
zYne committed
857
            $conn = $this->_table->getConnection();
858 859
        }
        $conn->beginTransaction();
860 861 862


        $saveLater = $conn->getUnitOfWork()->saveRelated($this);
863 864 865 866 867 868 869 870 871

        if ($this->isValid()) {
            $conn->save($this);
        } else {
            $conn->getTransaction()->addInvalid($this);
        }

        foreach($saveLater as $fk) {
            $table   = $fk->getTable();
zYne's avatar
zYne committed
872
            $alias   = $this->_table->getAlias($table->getComponentName());
873 874 875 876 877 878 879 880 881

            if(isset($this->references[$alias])) {
                $obj = $this->references[$alias];
                $obj->save();
            }
        }

        // save the MANY-TO-MANY associations

882 883
        $conn->getUnitOfWork()->saveAssociations($this);
        //$this->saveAssociations();
884 885 886 887 888 889 890

        $conn->commit();
    }
    /**
     * returns an array of modified fields and associated values
     * @return array
     */
891
    public function getModified() {
892 893
        $a = array();

zYne's avatar
zYne committed
894 895
        foreach($this->_modified as $k => $v) {
            $a[$v] = $this->_data[$v];
896 897 898 899
        }
        return $a;
    }
    /**
zYne's avatar
zYne committed
900 901
     * getPrepared
     *
902 903 904
     * returns an array of modified fields and values with data preparation
     * adds column aggregation inheritance and converts Records into primary key values
     *
zYne's avatar
zYne committed
905
     * @param array $array
906 907
     * @return array
     */
zYne's avatar
zYne committed
908
    public function getPrepared(array $array = array()) {
909 910 911
        $a = array();

        if(empty($array))
zYne's avatar
zYne committed
912
            $array = $this->_modified;
913 914

        foreach($array as $k => $v) {
zYne's avatar
zYne committed
915
            $type = $this->_table->getTypeOf($v);
916
            
zYne's avatar
zYne committed
917
            if($this->_data[$v] === self::$null) {
918 919 920 921 922 923 924
                $a[$v] = null;
                continue;
            }

            switch($type) {
                case 'array':
                case 'object':
zYne's avatar
zYne committed
925
                    $a[$v] = serialize($this->_data[$v]);
926 927
                break;
                case 'gzip':
zYne's avatar
zYne committed
928
                    $a[$v] = gzcompress($this->_data[$v],5);
929 930
                break;
                case 'boolean':
zYne's avatar
zYne committed
931
                    $a[$v] = (int) $this->_data[$v];
932 933
                break;
                case 'enum':
zYne's avatar
zYne committed
934
                    $a[$v] = $this->_table->enumIndex($v,$this->_data[$v]);
935 936
                break;
                default:
zYne's avatar
zYne committed
937 938
                    if($this->_data[$v] instanceof Doctrine_Record)
                        $this->_data[$v] = $this->_data[$v]->getIncremented();
939

zYne's avatar
zYne committed
940
                    $a[$v] = $this->_data[$v];
941 942 943
            }
        }

zYne's avatar
zYne committed
944
        foreach($this->_table->getInheritanceMap() as $k => $v) {
945 946 947 948
            $old = $this->get($k, false);

            if((string) $old !== (string) $v || $old === null) {
                $a[$k] = $v;
zYne's avatar
zYne committed
949
                $this->_data[$k] = $v;
950 951 952 953 954 955 956 957 958
            }
        }

        return $a;
    }
    /**
     * count
     * this class implements countable interface
     *
zYne's avatar
zYne committed
959
     * @return integer          the number of columns in this record
960 961
     */
    public function count() {
zYne's avatar
zYne committed
962
        return count($this->_data);
963 964 965 966
    }
    /**
     * alias for count()
     * 
zYne's avatar
zYne committed
967
     * @return integer          the number of columns in this record
968
     */
zYne's avatar
zYne committed
969
    public function columnCount() {
970 971 972 973 974 975 976 977 978 979 980 981 982 983
        return $this->count();
    }
    /**
     * toArray
     * returns the record as an array
     * 
     * @return array
     */
    public function toArray() {
        $a = array();

        foreach($this as $column => $value) {
            $a[$column] = $value;
        }
zYne's avatar
zYne committed
984 985
        if($this->_table->getIdentifierType() == Doctrine_Identifier::AUTO_INCREMENT) {
            $i      = $this->_table->getIdentifier();
986 987 988 989 990 991 992 993 994 995 996
            $a[$i]  = $this->getIncremented();
        }
        return $a;
    }
    /**
     * exists
     * returns true if this record is persistent, otherwise false
     *
     * @return boolean
     */
    public function exists() {
zYne's avatar
zYne committed
997 998
        return ($this->_state !== Doctrine_Record::STATE_TCLEAN &&
                $this->_state !== Doctrine_Record::STATE_TDIRTY);
999 1000 1001 1002 1003 1004 1005
    }
    /**
     * 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) {
zYne's avatar
zYne committed
1006
        if(isset($this->_data[$name]) || isset($this->_id[$name]))
1007
            return true;
zYne's avatar
zYne committed
1008
        return $this->_table->hasRelation($name);
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
    }
    /**
     * getIterator
     * @return Doctrine_Record_Iterator     a Doctrine_Record_Iterator that iterates through the data
     */
    public function getIterator() {
        return new Doctrine_Record_Iterator($this);
    }
    /**
     * getOriginals
     * returns an original collection of related component
     *
1021
     * @return Doctrine_Collection|false
1022
     */
1023 1024 1025 1026 1027
    public function obtainOriginals($name) {
        if(isset($this->originals[$name]))
            return $this->originals[$name];
    
        return false;
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
    }
    /**
     * deletes this data access object and all the related composites
     * this operation is isolated by a transaction
     *
     * this event can be listened by the onPreDelete and onDelete listeners
     *
     * @return boolean      true on success, false on failure
     */
    public function delete(Doctrine_Connection $conn = null) {
        if ($conn == null) {
zYne's avatar
zYne committed
1039
            $conn = $this->_table->getConnection();
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
        }
        return $conn->delete($this);
    }
    /**
     * copy
     * returns a copy of this object
     *
     * @return Doctrine_Record
     */
    public function copy() {
1050 1051 1052 1053 1054 1055
        $ret = $this->_table->create($this->_data);
        $modified = array();
        foreach($this->_data as $key => $val)
            if (!($val instanceof Doctrine_Null))
                $ret->_modified[] = $key;
        return $ret;
1056 1057 1058 1059 1060 1061 1062 1063 1064
    }
    /**
     * assignIdentifier
     *
     * @param integer $id
     * @return void
     */
    final public function assignIdentifier($id = false) {
        if($id === false) {
zYne's avatar
zYne committed
1065
            $this->_id       = array();
1066
            $this->cleanData();
zYne's avatar
zYne committed
1067 1068
            $this->_state    = Doctrine_Record::STATE_TCLEAN;
            $this->_modified = array();
1069 1070
        } elseif($id === true) {
            $this->prepareIdentifiers(false);
zYne's avatar
zYne committed
1071 1072
            $this->_state    = Doctrine_Record::STATE_CLEAN;
            $this->_modified = array();
1073
        } else {
zYne's avatar
zYne committed
1074
            $name            = $this->_table->getIdentifier();
1075

zYne's avatar
zYne committed
1076 1077 1078
            $this->_id[$name] = $id;
            $this->_state     = Doctrine_Record::STATE_CLEAN;
            $this->_modified  = array();
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
        }
    }
    /**
     * assignOriginals
     *
     * @param string $alias
     * @param Doctrine_Collection $coll
     * @return void
     */
    public function assignOriginals($alias, Doctrine_Collection $coll) {
        $this->originals[$alias] = $coll;
    }
    /**
     * returns the primary keys of this object
     *
     * @return array
     */
    final public function obtainIdentifier() {
zYne's avatar
zYne committed
1097
        return $this->_id;
1098 1099 1100 1101 1102 1103 1104
    }
    /**
     * returns the value of autoincremented primary key of this object (if any)
     *
     * @return integer
     */
    final public function getIncremented() {
zYne's avatar
zYne committed
1105
        $id = current($this->_id);
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
        if($id === false)
            return null;

        return $id;
    }
    /**
     * getLast
     * this method is used internally be Doctrine_Query
     * it is needed to provide compatibility between
     * records and collections
     *
     * @return Doctrine_Record
     */
    public function getLast() {
        return $this;
    }
    /**
     * hasRefence
     * @param string $name
     * @return boolean
     */
    public function hasReference($name) {
        return isset($this->references[$name]);
    }
    /**
     * obtainReference
     * 
     * @param string $name
     * @throws Doctrine_Record_Exception        if trying to get an unknown related component
     */
    public function obtainReference($name) {
        if(isset($this->references[$name]))
            return $this->references[$name];
    
        throw new Doctrine_Record_Exception("Unknown reference $name");
    }
    /**
     * initalizes a one-to-many / many-to-many relation
     *
     * @param Doctrine_Collection $coll
     * @param Doctrine_Relation $connector
     * @return boolean
     */
    public function initReference(Doctrine_Collection $coll, Doctrine_Relation $connector) {
        $alias = $connector->getAlias();

        if(isset($this->references[$alias]))
            return false;

        if( ! $connector->isOneToOne()) {
            if( ! ($connector instanceof Doctrine_Relation_Association))
                $coll->setReference($this, $connector);

            $this->references[$alias] = $coll;
            $this->originals[$alias]  = clone $coll;

            return true;
        }
        return false;
    }
    
    public function lazyInitRelated(Doctrine_Collection $coll, Doctrine_Relation $connector) {
                                      	
    }
    /**
     * addReference
     * @param Doctrine_Record $record
     * @param mixed $key
     * @return void
     */
    public function addReference(Doctrine_Record $record, Doctrine_Relation $connector, $key = null) {
        $alias = $connector->getAlias();

        $this->references[$alias]->add($record, $key);
        $this->originals[$alias]->add($record, $key);
    }
    /**
     * getReferences
     * @return array    all references
     */
    public function getReferences() {
        return $this->references;
    }
    /**
     * setRelated
     *
     * @param string $alias
     * @param Doctrine_Access $coll
     */
    final public function setRelated($alias, Doctrine_Access $coll) {
        $this->references[$alias] = $coll;
        $this->originals[$alias]  = $coll;
    }
    /**
     * loadReference
     * loads a related component
     *
     * @throws Doctrine_Table_Exception             if trying to load an unknown related component
     * @param string $name
     * @return void
     */
    final public function loadReference($name) {
zYne's avatar
zYne committed
1208
        $fk      = $this->_table->getRelation($name);
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225

        if($fk->isOneToOne()) {
            $this->references[$name] = $fk->fetchRelatedFor($this);
        } else {
            $coll = $fk->fetchRelatedFor($this);

            $this->references[$name] = $coll;
            $this->originals[$name]  = clone $coll;
        }
    }
    /**
     * binds One-to-One composite relation
     *
     * @param string $objTableName
     * @param string $fkField
     * @return void
     */
1226 1227
    final public function ownsOne($componentName, $foreignKey, $localKey = null) {
        $this->_table->bind($componentName, $foreignKey, Doctrine_Relation::ONE_COMPOSITE, $localKey);
1228 1229 1230 1231 1232 1233 1234 1235 1236
    }
    /**
     * binds One-to-Many composite relation
     *
     * @param string $objTableName
     * @param string $fkField
     * @return void
     */
    final public function ownsMany($componentName,$foreignKey, $localKey = null) {
1237
        $this->_table->bind($componentName, $foreignKey, Doctrine_Relation::MANY_COMPOSITE, $localKey);
1238 1239 1240 1241 1242 1243 1244 1245 1246
    }
    /**
     * binds One-to-One aggregate relation
     *
     * @param string $objTableName
     * @param string $fkField
     * @return void
     */
    final public function hasOne($componentName,$foreignKey, $localKey = null) {
1247
        $this->_table->bind($componentName, $foreignKey, Doctrine_Relation::ONE_AGGREGATE, $localKey);
1248 1249 1250 1251 1252 1253 1254 1255 1256
    }
    /**
     * binds One-to-Many aggregate relation
     *
     * @param string $objTableName
     * @param string $fkField
     * @return void
     */
    final public function hasMany($componentName,$foreignKey, $localKey = null) {
1257
        $this->_table->bind($componentName, $foreignKey, Doctrine_Relation::MANY_AGGREGATE, $localKey);
1258 1259 1260 1261 1262 1263
    }
    /**
     * setPrimaryKey
     * @param mixed $key
     */
    final public function setPrimaryKey($key) {
zYne's avatar
zYne committed
1264
        $this->_table->setPrimaryKey($key);
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
    }
    /**
     * hasColumn
     * sets a column definition
     *
     * @param string $name
     * @param string $type
     * @param integer $length
     * @param mixed $options
     * @return void
     */
    final public function hasColumn($name, $type, $length = 2147483647, $options = "") {
zYne's avatar
zYne committed
1277
        $this->_table->setColumn($name, $type, $length, $options);
1278 1279 1280 1281 1282 1283 1284 1285
    }
    /**
     * countRelated
     *
     * @param string $name      the name of the related component
     * @return integer
     */
    public function countRelated($name) {
zYne's avatar
zYne committed
1286
        $rel            = $this->_table->getRelation($name);
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
        $componentName  = $rel->getTable()->getComponentName();
        $alias          = $rel->getTable()->getAlias(get_class($this));
        $query          = new Doctrine_Query();
        $query->from($componentName. '(' . 'COUNT(1)' . ')')->where($componentName. '.' .$alias. '.' . $this->getTable()->getIdentifier(). ' = ?');
        $array = $query->execute(array($this->getIncremented()));
        return $array[0]['COUNT(1)'];
    }
    /**
     * merge
     * merges this record with an array of values
     *
     * @param array $values
     * @return void
     */
    public function merge(array $values) {
zYne's avatar
zYne committed
1302
        foreach($this->_table->getColumnNames() as $value) {
1303 1304 1305 1306 1307 1308 1309 1310
            try {
                if(isset($values[$value]))
                    $this->set($value, $values[$value]);
            } catch(Exception $e) { 
                // silence all exceptions
            }
        }
    }
1311
    public function setAttribute($attr, $value) {
zYne's avatar
zYne committed
1312
        $this->_table->setAttribute($attr, $value);
1313 1314
    }
    public function setTableName($tableName) {
zYne's avatar
zYne committed
1315
        $this->_table->setTableName($tableName);                                            	
1316 1317
    }
    public function setInheritanceMap($map) {
zYne's avatar
zYne committed
1318
        $this->_table->setOption('inheritanceMap', $map);
1319 1320
    }
    public function setEnumValues($column, $values) {
zYne's avatar
zYne committed
1321
        $this->_table->setEnumValues($column, $values);
1322
    }
zYne's avatar
zYne committed
1323 1324 1325 1326 1327 1328
    public function option($name, $value = null) {
        if($value == null)
            $this->_table->getOption($name);
        else
            $this->_table->setOption($name, $value);
    }
1329
    /**
1330 1331
     * addListener
     *
1332 1333
     * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
     * @return Doctrine_Db
1334
     */
1335
    public function addListener($listener, $name = null) {
zYne's avatar
zYne committed
1336
        $this->_table->addListener($listener, $name = null);
1337 1338 1339 1340 1341
        return $this;
    }
    /**
     * getListener
     * 
1342
     * @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
1343 1344
     */
    public function getListener() {
zYne's avatar
zYne committed
1345
        return $this->_table->getListener();
1346 1347 1348 1349
    }
    /**
     * setListener
     *
1350 1351
     * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
     * @return Doctrine_Db
1352 1353
     */
    public function setListener($listener) {
zYne's avatar
zYne committed
1354
        $this->_table->setListener($listener);
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
        return $this;
    }
    /**
     * call
     *
     * @param string|array $callback    valid callback
     * @param string $column            column name
     * @param mixed arg1 ... argN       optional callback arguments
     * @return Doctrine_Record
     */
    public function call($callback, $column) {
        $args = func_get_args();
        array_shift($args);
1368

1369 1370 1371
        if(isset($args[0])) {
            $column = $args[0];
            $args[0] = $this->get($column);
1372

1373
            $newvalue = call_user_func_array($callback, $args);
1374

zYne's avatar
zYne committed
1375
            $this->_data[$column] = $newvalue;
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
        }
        return $this;
    }
    /**
     * returns a string representation of this object
     */
    public function __toString() {
        return Doctrine_Lib::getRecordAsString($this);
    }
}