# File core/lib/Thelia/Model/om/BaseMessageVersion.php | thelia

       1: <?php
       2:
       3: namespace Thelia\Model\om;
       4:
       5: use \BaseObject;
       6: use \BasePeer;
       7: use \Criteria;
       8: use \DateTime;
       9: use \Exception;
      10: use \PDO;
      11: use \Persistent;
      12: use \Propel;
      13: use \PropelDateTime;
      14: use \PropelException;
      15: use \PropelPDO;
      16: use Thelia\Model\Message;
      17: use Thelia\Model\MessageQuery;
      18: use Thelia\Model\MessageVersion;
      19: use Thelia\Model\MessageVersionPeer;
      20: use Thelia\Model\MessageVersionQuery;
      21:
      22: /**
      23:  * Base class that represents a row from the 'message_version' table.
      24:  *
      25:  *
      26:  *
      27:  * @package    propel.generator.Thelia.Model.om
      28:  */
      29: abstract class BaseMessageVersion extends BaseObject implements Persistent
      30: {
      31:     /**
      32:      * Peer class name
      33:      */
      34:     const PEER = 'Thelia\\Model\\MessageVersionPeer';
      35:
      36:     /**
      37:      * The Peer class.
      38:      * Instance provides a convenient way of calling static methods on a class
      39:      * that calling code may not be able to identify.
      40:      * @var        MessageVersionPeer
      41:      */
      42:     protected static $peer;
      43:
      44:     /**
      45:      * The flag var to prevent infinit loop in deep copy
      46:      * @var       boolean
      47:      */
      48:     protected $startCopy = false;
      49:
      50:     /**
      51:      * The value for the id field.
      52:      * @var        int
      53:      */
      54:     protected $id;
      55:
      56:     /**
      57:      * The value for the code field.
      58:      * @var        string
      59:      */
      60:     protected $code;
      61:
      62:     /**
      63:      * The value for the secured field.
      64:      * @var        int
      65:      */
      66:     protected $secured;
      67:
      68:     /**
      69:      * The value for the ref field.
      70:      * @var        string
      71:      */
      72:     protected $ref;
      73:
      74:     /**
      75:      * The value for the created_at field.
      76:      * @var        string
      77:      */
      78:     protected $created_at;
      79:
      80:     /**
      81:      * The value for the updated_at field.
      82:      * @var        string
      83:      */
      84:     protected $updated_at;
      85:
      86:     /**
      87:      * The value for the version field.
      88:      * Note: this column has a database default value of: 0
      89:      * @var        int
      90:      */
      91:     protected $version;
      92:
      93:     /**
      94:      * The value for the version_created_at field.
      95:      * @var        string
      96:      */
      97:     protected $version_created_at;
      98:
      99:     /**
     100:      * The value for the version_created_by field.
     101:      * @var        string
     102:      */
     103:     protected $version_created_by;
     104:
     105:     /**
     106:      * @var        Message
     107:      */
     108:     protected $aMessage;
     109:
     110:     /**
     111:      * Flag to prevent endless save loop, if this object is referenced
     112:      * by another object which falls in this transaction.
     113:      * @var        boolean
     114:      */
     115:     protected $alreadyInSave = false;
     116:
     117:     /**
     118:      * Flag to prevent endless validation loop, if this object is referenced
     119:      * by another object which falls in this transaction.
     120:      * @var        boolean
     121:      */
     122:     protected $alreadyInValidation = false;
     123:
     124:     /**
     125:      * Applies default values to this object.
     126:      * This method should be called from the object's constructor (or
     127:      * equivalent initialization method).
     128:      * @see        __construct()
     129:      */
     130:     public function applyDefaultValues()
     131:     {
     132:         $this->version = 0;
     133:     }
     134:
     135:     /**
     136:      * Initializes internal state of BaseMessageVersion object.
     137:      * @see        applyDefaults()
     138:      */
     139:     public function __construct()
     140:     {
     141:         parent::__construct();
     142:         $this->applyDefaultValues();
     143:     }
     144:
     145:     /**
     146:      * Get the [id] column value.
     147:      *
     148:      * @return int
     149:      */
     150:     public function getId()
     151:     {
     152:         return $this->id;
     153:     }
     154:
     155:     /**
     156:      * Get the [code] column value.
     157:      *
     158:      * @return string
     159:      */
     160:     public function getCode()
     161:     {
     162:         return $this->code;
     163:     }
     164:
     165:     /**
     166:      * Get the [secured] column value.
     167:      *
     168:      * @return int
     169:      */
     170:     public function getSecured()
     171:     {
     172:         return $this->secured;
     173:     }
     174:
     175:     /**
     176:      * Get the [ref] column value.
     177:      *
     178:      * @return string
     179:      */
     180:     public function getRef()
     181:     {
     182:         return $this->ref;
     183:     }
     184:
     185:     /**
     186:      * Get the [optionally formatted] temporal [created_at] column value.
     187:      *
     188:      *
     189:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     190:      *               If format is null, then the raw DateTime object will be returned.
     191:      * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
     192:      * @throws PropelException - if unable to parse/validate the date/time value.
     193:      */
     194:     public function getCreatedAt($format = 'Y-m-d H:i:s')
     195:     {
     196:         if ($this->created_at === null) {
     197:             return null;
     198:         }
     199:
     200:         if ($this->created_at === '0000-00-00 00:00:00') {
     201:             // while technically this is not a default value of null,
     202:             // this seems to be closest in meaning.
     203:             return null;
     204:         } else {
     205:             try {
     206:                 $dt = new DateTime($this->created_at);
     207:             } catch (Exception $x) {
     208:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
     209:             }
     210:         }
     211:
     212:         if ($format === null) {
     213:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     214:             return $dt;
     215:         } elseif (strpos($format, '%') !== false) {
     216:             return strftime($format, $dt->format('U'));
     217:         } else {
     218:             return $dt->format($format);
     219:         }
     220:     }
     221:
     222:     /**
     223:      * Get the [optionally formatted] temporal [updated_at] column value.
     224:      *
     225:      *
     226:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     227:      *               If format is null, then the raw DateTime object will be returned.
     228:      * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
     229:      * @throws PropelException - if unable to parse/validate the date/time value.
     230:      */
     231:     public function getUpdatedAt($format = 'Y-m-d H:i:s')
     232:     {
     233:         if ($this->updated_at === null) {
     234:             return null;
     235:         }
     236:
     237:         if ($this->updated_at === '0000-00-00 00:00:00') {
     238:             // while technically this is not a default value of null,
     239:             // this seems to be closest in meaning.
     240:             return null;
     241:         } else {
     242:             try {
     243:                 $dt = new DateTime($this->updated_at);
     244:             } catch (Exception $x) {
     245:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
     246:             }
     247:         }
     248:
     249:         if ($format === null) {
     250:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     251:             return $dt;
     252:         } elseif (strpos($format, '%') !== false) {
     253:             return strftime($format, $dt->format('U'));
     254:         } else {
     255:             return $dt->format($format);
     256:         }
     257:     }
     258:
     259:     /**
     260:      * Get the [version] column value.
     261:      *
     262:      * @return int
     263:      */
     264:     public function getVersion()
     265:     {
     266:         return $this->version;
     267:     }
     268:
     269:     /**
     270:      * Get the [optionally formatted] temporal [version_created_at] column value.
     271:      *
     272:      *
     273:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     274:      *               If format is null, then the raw DateTime object will be returned.
     275:      * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
     276:      * @throws PropelException - if unable to parse/validate the date/time value.
     277:      */
     278:     public function getVersionCreatedAt($format = 'Y-m-d H:i:s')
     279:     {
     280:         if ($this->version_created_at === null) {
     281:             return null;
     282:         }
     283:
     284:         if ($this->version_created_at === '0000-00-00 00:00:00') {
     285:             // while technically this is not a default value of null,
     286:             // this seems to be closest in meaning.
     287:             return null;
     288:         } else {
     289:             try {
     290:                 $dt = new DateTime($this->version_created_at);
     291:             } catch (Exception $x) {
     292:                 throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->version_created_at, true), $x);
     293:             }
     294:         }
     295:
     296:         if ($format === null) {
     297:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     298:             return $dt;
     299:         } elseif (strpos($format, '%') !== false) {
     300:             return strftime($format, $dt->format('U'));
     301:         } else {
     302:             return $dt->format($format);
     303:         }
     304:     }
     305:
     306:     /**
     307:      * Get the [version_created_by] column value.
     308:      *
     309:      * @return string
     310:      */
     311:     public function getVersionCreatedBy()
     312:     {
     313:         return $this->version_created_by;
     314:     }
     315:
     316:     /**
     317:      * Set the value of [id] column.
     318:      *
     319:      * @param int $v new value
     320:      * @return MessageVersion The current object (for fluent API support)
     321:      */
     322:     public function setId($v)
     323:     {
     324:         if ($v !== null) {
     325:             $v = (int) $v;
     326:         }
     327:
     328:         if ($this->id !== $v) {
     329:             $this->id = $v;
     330:             $this->modifiedColumns[] = MessageVersionPeer::ID;
     331:         }
     332:
     333:         if ($this->aMessage !== null && $this->aMessage->getId() !== $v) {
     334:             $this->aMessage = null;
     335:         }
     336:
     337:
     338:         return $this;
     339:     } // setId()
     340:
     341:     /**
     342:      * Set the value of [code] column.
     343:      *
     344:      * @param string $v new value
     345:      * @return MessageVersion The current object (for fluent API support)
     346:      */
     347:     public function setCode($v)
     348:     {
     349:         if ($v !== null) {
     350:             $v = (string) $v;
     351:         }
     352:
     353:         if ($this->code !== $v) {
     354:             $this->code = $v;
     355:             $this->modifiedColumns[] = MessageVersionPeer::CODE;
     356:         }
     357:
     358:
     359:         return $this;
     360:     } // setCode()
     361:
     362:     /**
     363:      * Set the value of [secured] column.
     364:      *
     365:      * @param int $v new value
     366:      * @return MessageVersion The current object (for fluent API support)
     367:      */
     368:     public function setSecured($v)
     369:     {
     370:         if ($v !== null) {
     371:             $v = (int) $v;
     372:         }
     373:
     374:         if ($this->secured !== $v) {
     375:             $this->secured = $v;
     376:             $this->modifiedColumns[] = MessageVersionPeer::SECURED;
     377:         }
     378:
     379:
     380:         return $this;
     381:     } // setSecured()
     382:
     383:     /**
     384:      * Set the value of [ref] column.
     385:      *
     386:      * @param string $v new value
     387:      * @return MessageVersion The current object (for fluent API support)
     388:      */
     389:     public function setRef($v)
     390:     {
     391:         if ($v !== null) {
     392:             $v = (string) $v;
     393:         }
     394:
     395:         if ($this->ref !== $v) {
     396:             $this->ref = $v;
     397:             $this->modifiedColumns[] = MessageVersionPeer::REF;
     398:         }
     399:
     400:
     401:         return $this;
     402:     } // setRef()
     403:
     404:     /**
     405:      * Sets the value of [created_at] column to a normalized version of the date/time value specified.
     406:      *
     407:      * @param mixed $v string, integer (timestamp), or DateTime value.
     408:      *               Empty strings are treated as null.
     409:      * @return MessageVersion The current object (for fluent API support)
     410:      */
     411:     public function setCreatedAt($v)
     412:     {
     413:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     414:         if ($this->created_at !== null || $dt !== null) {
     415:             $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     416:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     417:             if ($currentDateAsString !== $newDateAsString) {
     418:                 $this->created_at = $newDateAsString;
     419:                 $this->modifiedColumns[] = MessageVersionPeer::CREATED_AT;
     420:             }
     421:         } // if either are not null
     422:
     423:
     424:         return $this;
     425:     } // setCreatedAt()
     426:
     427:     /**
     428:      * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
     429:      *
     430:      * @param mixed $v string, integer (timestamp), or DateTime value.
     431:      *               Empty strings are treated as null.
     432:      * @return MessageVersion The current object (for fluent API support)
     433:      */
     434:     public function setUpdatedAt($v)
     435:     {
     436:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     437:         if ($this->updated_at !== null || $dt !== null) {
     438:             $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     439:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     440:             if ($currentDateAsString !== $newDateAsString) {
     441:                 $this->updated_at = $newDateAsString;
     442:                 $this->modifiedColumns[] = MessageVersionPeer::UPDATED_AT;
     443:             }
     444:         } // if either are not null
     445:
     446:
     447:         return $this;
     448:     } // setUpdatedAt()
     449:
     450:     /**
     451:      * Set the value of [version] column.
     452:      *
     453:      * @param int $v new value
     454:      * @return MessageVersion The current object (for fluent API support)
     455:      */
     456:     public function setVersion($v)
     457:     {
     458:         if ($v !== null) {
     459:             $v = (int) $v;
     460:         }
     461:
     462:         if ($this->version !== $v) {
     463:             $this->version = $v;
     464:             $this->modifiedColumns[] = MessageVersionPeer::VERSION;
     465:         }
     466:
     467:
     468:         return $this;
     469:     } // setVersion()
     470:
     471:     /**
     472:      * Sets the value of [version_created_at] column to a normalized version of the date/time value specified.
     473:      *
     474:      * @param mixed $v string, integer (timestamp), or DateTime value.
     475:      *               Empty strings are treated as null.
     476:      * @return MessageVersion The current object (for fluent API support)
     477:      */
     478:     public function setVersionCreatedAt($v)
     479:     {
     480:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     481:         if ($this->version_created_at !== null || $dt !== null) {
     482:             $currentDateAsString = ($this->version_created_at !== null && $tmpDt = new DateTime($this->version_created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     483:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     484:             if ($currentDateAsString !== $newDateAsString) {
     485:                 $this->version_created_at = $newDateAsString;
     486:                 $this->modifiedColumns[] = MessageVersionPeer::VERSION_CREATED_AT;
     487:             }
     488:         } // if either are not null
     489:
     490:
     491:         return $this;
     492:     } // setVersionCreatedAt()
     493:
     494:     /**
     495:      * Set the value of [version_created_by] column.
     496:      *
     497:      * @param string $v new value
     498:      * @return MessageVersion The current object (for fluent API support)
     499:      */
     500:     public function setVersionCreatedBy($v)
     501:     {
     502:         if ($v !== null) {
     503:             $v = (string) $v;
     504:         }
     505:
     506:         if ($this->version_created_by !== $v) {
     507:             $this->version_created_by = $v;
     508:             $this->modifiedColumns[] = MessageVersionPeer::VERSION_CREATED_BY;
     509:         }
     510:
     511:
     512:         return $this;
     513:     } // setVersionCreatedBy()
     514:
     515:     /**
     516:      * Indicates whether the columns in this object are only set to default values.
     517:      *
     518:      * This method can be used in conjunction with isModified() to indicate whether an object is both
     519:      * modified _and_ has some values set which are non-default.
     520:      *
     521:      * @return boolean Whether the columns in this object are only been set with default values.
     522:      */
     523:     public function hasOnlyDefaultValues()
     524:     {
     525:             if ($this->version !== 0) {
     526:                 return false;
     527:             }
     528:
     529:         // otherwise, everything was equal, so return true
     530:         return true;
     531:     } // hasOnlyDefaultValues()
     532:
     533:     /**
     534:      * Hydrates (populates) the object variables with values from the database resultset.
     535:      *
     536:      * An offset (0-based "start column") is specified so that objects can be hydrated
     537:      * with a subset of the columns in the resultset rows.  This is needed, for example,
     538:      * for results of JOIN queries where the resultset row includes columns from two or
     539:      * more tables.
     540:      *
     541:      * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     542:      * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     543:      * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     544:      * @return int             next starting column
     545:      * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     546:      */
     547:     public function hydrate($row, $startcol = 0, $rehydrate = false)
     548:     {
     549:         try {
     550:
     551:             $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
     552:             $this->code = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
     553:             $this->secured = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
     554:             $this->ref = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
     555:             $this->created_at = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
     556:             $this->updated_at = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
     557:             $this->version = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
     558:             $this->version_created_at = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
     559:             $this->version_created_by = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
     560:             $this->resetModified();
     561:
     562:             $this->setNew(false);
     563:
     564:             if ($rehydrate) {
     565:                 $this->ensureConsistency();
     566:             }
     567:
     568:             return $startcol + 9; // 9 = MessageVersionPeer::NUM_HYDRATE_COLUMNS.
     569:
     570:         } catch (Exception $e) {
     571:             throw new PropelException("Error populating MessageVersion object", $e);
     572:         }
     573:     }
     574:
     575:     /**
     576:      * Checks and repairs the internal consistency of the object.
     577:      *
     578:      * This method is executed after an already-instantiated object is re-hydrated
     579:      * from the database.  It exists to check any foreign keys to make sure that
     580:      * the objects related to the current object are correct based on foreign key.
     581:      *
     582:      * You can override this method in the stub class, but you should always invoke
     583:      * the base method from the overridden method (i.e. parent::ensureConsistency()),
     584:      * in case your model changes.
     585:      *
     586:      * @throws PropelException
     587:      */
     588:     public function ensureConsistency()
     589:     {
     590:
     591:         if ($this->aMessage !== null && $this->id !== $this->aMessage->getId()) {
     592:             $this->aMessage = null;
     593:         }
     594:     } // ensureConsistency
     595:
     596:     /**
     597:      * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     598:      *
     599:      * This will only work if the object has been saved and has a valid primary key set.
     600:      *
     601:      * @param boolean $deep (optional) Whether to also de-associated any related objects.
     602:      * @param PropelPDO $con (optional) The PropelPDO connection to use.
     603:      * @return void
     604:      * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     605:      */
     606:     public function reload($deep = false, PropelPDO $con = null)
     607:     {
     608:         if ($this->isDeleted()) {
     609:             throw new PropelException("Cannot reload a deleted object.");
     610:         }
     611:
     612:         if ($this->isNew()) {
     613:             throw new PropelException("Cannot reload an unsaved object.");
     614:         }
     615:
     616:         if ($con === null) {
     617:             $con = Propel::getConnection(MessageVersionPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     618:         }
     619:
     620:         // We don't need to alter the object instance pool; we're just modifying this instance
     621:         // already in the pool.
     622:
     623:         $stmt = MessageVersionPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     624:         $row = $stmt->fetch(PDO::FETCH_NUM);
     625:         $stmt->closeCursor();
     626:         if (!$row) {
     627:             throw new PropelException('Cannot find matching row in the database to reload object values.');
     628:         }
     629:         $this->hydrate($row, 0, true); // rehydrate
     630:
     631:         if ($deep) {  // also de-associate any related objects?
     632:
     633:             $this->aMessage = null;
     634:         } // if (deep)
     635:     }
     636:
     637:     /**
     638:      * Removes this object from datastore and sets delete attribute.
     639:      *
     640:      * @param PropelPDO $con
     641:      * @return void
     642:      * @throws PropelException
     643:      * @throws Exception
     644:      * @see        BaseObject::setDeleted()
     645:      * @see        BaseObject::isDeleted()
     646:      */
     647:     public function delete(PropelPDO $con = null)
     648:     {
     649:         if ($this->isDeleted()) {
     650:             throw new PropelException("This object has already been deleted.");
     651:         }
     652:
     653:         if ($con === null) {
     654:             $con = Propel::getConnection(MessageVersionPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     655:         }
     656:
     657:         $con->beginTransaction();
     658:         try {
     659:             $deleteQuery = MessageVersionQuery::create()
     660:                 ->filterByPrimaryKey($this->getPrimaryKey());
     661:             $ret = $this->preDelete($con);
     662:             if ($ret) {
     663:                 $deleteQuery->delete($con);
     664:                 $this->postDelete($con);
     665:                 $con->commit();
     666:                 $this->setDeleted(true);
     667:             } else {
     668:                 $con->commit();
     669:             }
     670:         } catch (Exception $e) {
     671:             $con->rollBack();
     672:             throw $e;
     673:         }
     674:     }
     675:
     676:     /**
     677:      * Persists this object to the database.
     678:      *
     679:      * If the object is new, it inserts it; otherwise an update is performed.
     680:      * All modified related objects will also be persisted in the doSave()
     681:      * method.  This method wraps all precipitate database operations in a
     682:      * single transaction.
     683:      *
     684:      * @param PropelPDO $con
     685:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     686:      * @throws PropelException
     687:      * @throws Exception
     688:      * @see        doSave()
     689:      */
     690:     public function save(PropelPDO $con = null)
     691:     {
     692:         if ($this->isDeleted()) {
     693:             throw new PropelException("You cannot save an object that has been deleted.");
     694:         }
     695:
     696:         if ($con === null) {
     697:             $con = Propel::getConnection(MessageVersionPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     698:         }
     699:
     700:         $con->beginTransaction();
     701:         $isInsert = $this->isNew();
     702:         try {
     703:             $ret = $this->preSave($con);
     704:             if ($isInsert) {
     705:                 $ret = $ret && $this->preInsert($con);
     706:             } else {
     707:                 $ret = $ret && $this->preUpdate($con);
     708:             }
     709:             if ($ret) {
     710:                 $affectedRows = $this->doSave($con);
     711:                 if ($isInsert) {
     712:                     $this->postInsert($con);
     713:                 } else {
     714:                     $this->postUpdate($con);
     715:                 }
     716:                 $this->postSave($con);
     717:                 MessageVersionPeer::addInstanceToPool($this);
     718:             } else {
     719:                 $affectedRows = 0;
     720:             }
     721:             $con->commit();
     722:
     723:             return $affectedRows;
     724:         } catch (Exception $e) {
     725:             $con->rollBack();
     726:             throw $e;
     727:         }
     728:     }
     729:
     730:     /**
     731:      * Performs the work of inserting or updating the row in the database.
     732:      *
     733:      * If the object is new, it inserts it; otherwise an update is performed.
     734:      * All related objects are also updated in this method.
     735:      *
     736:      * @param PropelPDO $con
     737:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     738:      * @throws PropelException
     739:      * @see        save()
     740:      */
     741:     protected function doSave(PropelPDO $con)
     742:     {
     743:         $affectedRows = 0; // initialize var to track total num of affected rows
     744:         if (!$this->alreadyInSave) {
     745:             $this->alreadyInSave = true;
     746:
     747:             // We call the save method on the following object(s) if they
     748:             // were passed to this object by their coresponding set
     749:             // method.  This object relates to these object(s) by a
     750:             // foreign key reference.
     751:
     752:             if ($this->aMessage !== null) {
     753:                 if ($this->aMessage->isModified() || $this->aMessage->isNew()) {
     754:                     $affectedRows += $this->aMessage->save($con);
     755:                 }
     756:                 $this->setMessage($this->aMessage);
     757:             }
     758:
     759:             if ($this->isNew() || $this->isModified()) {
     760:                 // persist changes
     761:                 if ($this->isNew()) {
     762:                     $this->doInsert($con);
     763:                 } else {
     764:                     $this->doUpdate($con);
     765:                 }
     766:                 $affectedRows += 1;
     767:                 $this->resetModified();
     768:             }
     769:
     770:             $this->alreadyInSave = false;
     771:
     772:         }
     773:
     774:         return $affectedRows;
     775:     } // doSave()
     776:
     777:     /**
     778:      * Insert the row in the database.
     779:      *
     780:      * @param PropelPDO $con
     781:      *
     782:      * @throws PropelException
     783:      * @see        doSave()
     784:      */
     785:     protected function doInsert(PropelPDO $con)
     786:     {
     787:         $modifiedColumns = array();
     788:         $index = 0;
     789:
     790:
     791:          // check the columns in natural order for more readable SQL queries
     792:         if ($this->isColumnModified(MessageVersionPeer::ID)) {
     793:             $modifiedColumns[':p' . $index++]  = '`ID`';
     794:         }
     795:         if ($this->isColumnModified(MessageVersionPeer::CODE)) {
     796:             $modifiedColumns[':p' . $index++]  = '`CODE`';
     797:         }
     798:         if ($this->isColumnModified(MessageVersionPeer::SECURED)) {
     799:             $modifiedColumns[':p' . $index++]  = '`SECURED`';
     800:         }
     801:         if ($this->isColumnModified(MessageVersionPeer::REF)) {
     802:             $modifiedColumns[':p' . $index++]  = '`REF`';
     803:         }
     804:         if ($this->isColumnModified(MessageVersionPeer::CREATED_AT)) {
     805:             $modifiedColumns[':p' . $index++]  = '`CREATED_AT`';
     806:         }
     807:         if ($this->isColumnModified(MessageVersionPeer::UPDATED_AT)) {
     808:             $modifiedColumns[':p' . $index++]  = '`UPDATED_AT`';
     809:         }
     810:         if ($this->isColumnModified(MessageVersionPeer::VERSION)) {
     811:             $modifiedColumns[':p' . $index++]  = '`VERSION`';
     812:         }
     813:         if ($this->isColumnModified(MessageVersionPeer::VERSION_CREATED_AT)) {
     814:             $modifiedColumns[':p' . $index++]  = '`VERSION_CREATED_AT`';
     815:         }
     816:         if ($this->isColumnModified(MessageVersionPeer::VERSION_CREATED_BY)) {
     817:             $modifiedColumns[':p' . $index++]  = '`VERSION_CREATED_BY`';
     818:         }
     819:
     820:         $sql = sprintf(
     821:             'INSERT INTO `message_version` (%s) VALUES (%s)',
     822:             implode(', ', $modifiedColumns),
     823:             implode(', ', array_keys($modifiedColumns))
     824:         );
     825:
     826:         try {
     827:             $stmt = $con->prepare($sql);
     828:             foreach ($modifiedColumns as $identifier => $columnName) {
     829:                 switch ($columnName) {
     830:                     case '`ID`':
     831:                         $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
     832:                         break;
     833:                     case '`CODE`':
     834:                         $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
     835:                         break;
     836:                     case '`SECURED`':
     837:                         $stmt->bindValue($identifier, $this->secured, PDO::PARAM_INT);
     838:                         break;
     839:                     case '`REF`':
     840:                         $stmt->bindValue($identifier, $this->ref, PDO::PARAM_STR);
     841:                         break;
     842:                     case '`CREATED_AT`':
     843:                         $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
     844:                         break;
     845:                     case '`UPDATED_AT`':
     846:                         $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
     847:                         break;
     848:                     case '`VERSION`':
     849:                         $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT);
     850:                         break;
     851:                     case '`VERSION_CREATED_AT`':
     852:                         $stmt->bindValue($identifier, $this->version_created_at, PDO::PARAM_STR);
     853:                         break;
     854:                     case '`VERSION_CREATED_BY`':
     855:                         $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR);
     856:                         break;
     857:                 }
     858:             }
     859:             $stmt->execute();
     860:         } catch (Exception $e) {
     861:             Propel::log($e->getMessage(), Propel::LOG_ERR);
     862:             throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
     863:         }
     864:
     865:         $this->setNew(false);
     866:     }
     867:
     868:     /**
     869:      * Update the row in the database.
     870:      *
     871:      * @param PropelPDO $con
     872:      *
     873:      * @see        doSave()
     874:      */
     875:     protected function doUpdate(PropelPDO $con)
     876:     {
     877:         $selectCriteria = $this->buildPkeyCriteria();
     878:         $valuesCriteria = $this->buildCriteria();
     879:         BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
     880:     }
     881:
     882:     /**
     883:      * Array of ValidationFailed objects.
     884:      * @var        array ValidationFailed[]
     885:      */
     886:     protected $validationFailures = array();
     887:
     888:     /**
     889:      * Gets any ValidationFailed objects that resulted from last call to validate().
     890:      *
     891:      *
     892:      * @return array ValidationFailed[]
     893:      * @see        validate()
     894:      */
     895:     public function getValidationFailures()
     896:     {
     897:         return $this->validationFailures;
     898:     }
     899:
     900:     /**
     901:      * Validates the objects modified field values and all objects related to this table.
     902:      *
     903:      * If $columns is either a column name or an array of column names
     904:      * only those columns are validated.
     905:      *
     906:      * @param mixed $columns Column name or an array of column names.
     907:      * @return boolean Whether all columns pass validation.
     908:      * @see        doValidate()
     909:      * @see        getValidationFailures()
     910:      */
     911:     public function validate($columns = null)
     912:     {
     913:         $res = $this->doValidate($columns);
     914:         if ($res === true) {
     915:             $this->validationFailures = array();
     916:
     917:             return true;
     918:         } else {
     919:             $this->validationFailures = $res;
     920:
     921:             return false;
     922:         }
     923:     }
     924:
     925:     /**
     926:      * This function performs the validation work for complex object models.
     927:      *
     928:      * In addition to checking the current object, all related objects will
     929:      * also be validated.  If all pass then <code>true</code> is returned; otherwise
     930:      * an aggreagated array of ValidationFailed objects will be returned.
     931:      *
     932:      * @param array $columns Array of column names to validate.
     933:      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
     934:      */
     935:     protected function doValidate($columns = null)
     936:     {
     937:         if (!$this->alreadyInValidation) {
     938:             $this->alreadyInValidation = true;
     939:             $retval = null;
     940:
     941:             $failureMap = array();
     942:
     943:
     944:             // We call the validate method on the following object(s) if they
     945:             // were passed to this object by their coresponding set
     946:             // method.  This object relates to these object(s) by a
     947:             // foreign key reference.
     948:
     949:             if ($this->aMessage !== null) {
     950:                 if (!$this->aMessage->validate($columns)) {
     951:                     $failureMap = array_merge($failureMap, $this->aMessage->getValidationFailures());
     952:                 }
     953:             }
     954:
     955:
     956:             if (($retval = MessageVersionPeer::doValidate($this, $columns)) !== true) {
     957:                 $failureMap = array_merge($failureMap, $retval);
     958:             }
     959:
     960:
     961:
     962:             $this->alreadyInValidation = false;
     963:         }
     964:
     965:         return (!empty($failureMap) ? $failureMap : true);
     966:     }
     967:
     968:     /**
     969:      * Retrieves a field from the object by name passed in as a string.
     970:      *
     971:      * @param string $name name
     972:      * @param string $type The type of fieldname the $name is of:
     973:      *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     974:      *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     975:      *               Defaults to BasePeer::TYPE_PHPNAME
     976:      * @return mixed Value of field.
     977:      */
     978:     public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
     979:     {
     980:         $pos = MessageVersionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
     981:         $field = $this->getByPosition($pos);
     982:
     983:         return $field;
     984:     }
     985:
     986:     /**
     987:      * Retrieves a field from the object by Position as specified in the xml schema.
     988:      * Zero-based.
     989:      *
     990:      * @param int $pos position in xml schema
     991:      * @return mixed Value of field at $pos
     992:      */
     993:     public function getByPosition($pos)
     994:     {
     995:         switch ($pos) {
     996:             case 0:
     997:                 return $this->getId();
     998:                 break;
     999:             case 1:
    1000:                 return $this->getCode();
    1001:                 break;
    1002:             case 2:
    1003:                 return $this->getSecured();
    1004:                 break;
    1005:             case 3:
    1006:                 return $this->getRef();
    1007:                 break;
    1008:             case 4:
    1009:                 return $this->getCreatedAt();
    1010:                 break;
    1011:             case 5:
    1012:                 return $this->getUpdatedAt();
    1013:                 break;
    1014:             case 6:
    1015:                 return $this->getVersion();
    1016:                 break;
    1017:             case 7:
    1018:                 return $this->getVersionCreatedAt();
    1019:                 break;
    1020:             case 8:
    1021:                 return $this->getVersionCreatedBy();
    1022:                 break;
    1023:             default:
    1024:                 return null;
    1025:                 break;
    1026:         } // switch()
    1027:     }
    1028:
    1029:     /**
    1030:      * Exports the object as an array.
    1031:      *
    1032:      * You can specify the key type of the array by passing one of the class
    1033:      * type constants.
    1034:      *
    1035:      * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    1036:      *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1037:      *                    Defaults to BasePeer::TYPE_PHPNAME.
    1038:      * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
    1039:      * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
    1040:      * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
    1041:      *
    1042:      * @return array an associative array containing the field names (as keys) and field values
    1043:      */
    1044:     public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
    1045:     {
    1046:         if (isset($alreadyDumpedObjects['MessageVersion'][serialize($this->getPrimaryKey())])) {
    1047:             return '*RECURSION*';
    1048:         }
    1049:         $alreadyDumpedObjects['MessageVersion'][serialize($this->getPrimaryKey())] = true;
    1050:         $keys = MessageVersionPeer::getFieldNames($keyType);
    1051:         $result = array(
    1052:             $keys[0] => $this->getId(),
    1053:             $keys[1] => $this->getCode(),
    1054:             $keys[2] => $this->getSecured(),
    1055:             $keys[3] => $this->getRef(),
    1056:             $keys[4] => $this->getCreatedAt(),
    1057:             $keys[5] => $this->getUpdatedAt(),
    1058:             $keys[6] => $this->getVersion(),
    1059:             $keys[7] => $this->getVersionCreatedAt(),
    1060:             $keys[8] => $this->getVersionCreatedBy(),
    1061:         );
    1062:         if ($includeForeignObjects) {
    1063:             if (null !== $this->aMessage) {
    1064:                 $result['Message'] = $this->aMessage->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
    1065:             }
    1066:         }
    1067:
    1068:         return $result;
    1069:     }
    1070:
    1071:     /**
    1072:      * Sets a field from the object by name passed in as a string.
    1073:      *
    1074:      * @param string $name peer name
    1075:      * @param mixed $value field value
    1076:      * @param string $type The type of fieldname the $name is of:
    1077:      *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
    1078:      *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1079:      *                     Defaults to BasePeer::TYPE_PHPNAME
    1080:      * @return void
    1081:      */
    1082:     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
    1083:     {
    1084:         $pos = MessageVersionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
    1085:
    1086:         $this->setByPosition($pos, $value);
    1087:     }
    1088:
    1089:     /**
    1090:      * Sets a field from the object by Position as specified in the xml schema.
    1091:      * Zero-based.
    1092:      *
    1093:      * @param int $pos position in xml schema
    1094:      * @param mixed $value field value
    1095:      * @return void
    1096:      */
    1097:     public function setByPosition($pos, $value)
    1098:     {
    1099:         switch ($pos) {
    1100:             case 0:
    1101:                 $this->setId($value);
    1102:                 break;
    1103:             case 1:
    1104:                 $this->setCode($value);
    1105:                 break;
    1106:             case 2:
    1107:                 $this->setSecured($value);
    1108:                 break;
    1109:             case 3:
    1110:                 $this->setRef($value);
    1111:                 break;
    1112:             case 4:
    1113:                 $this->setCreatedAt($value);
    1114:                 break;
    1115:             case 5:
    1116:                 $this->setUpdatedAt($value);
    1117:                 break;
    1118:             case 6:
    1119:                 $this->setVersion($value);
    1120:                 break;
    1121:             case 7:
    1122:                 $this->setVersionCreatedAt($value);
    1123:                 break;
    1124:             case 8:
    1125:                 $this->setVersionCreatedBy($value);
    1126:                 break;
    1127:         } // switch()
    1128:     }
    1129:
    1130:     /**
    1131:      * Populates the object using an array.
    1132:      *
    1133:      * This is particularly useful when populating an object from one of the
    1134:      * request arrays (e.g. $_POST).  This method goes through the column
    1135:      * names, checking to see whether a matching key exists in populated
    1136:      * array. If so the setByName() method is called for that column.
    1137:      *
    1138:      * You can specify the key type of the array by additionally passing one
    1139:      * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    1140:      * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1141:      * The default key type is the column's BasePeer::TYPE_PHPNAME
    1142:      *
    1143:      * @param array  $arr     An array to populate the object from.
    1144:      * @param string $keyType The type of keys the array uses.
    1145:      * @return void
    1146:      */
    1147:     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    1148:     {
    1149:         $keys = MessageVersionPeer::getFieldNames($keyType);
    1150:
    1151:         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
    1152:         if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]);
    1153:         if (array_key_exists($keys[2], $arr)) $this->setSecured($arr[$keys[2]]);
    1154:         if (array_key_exists($keys[3], $arr)) $this->setRef($arr[$keys[3]]);
    1155:         if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]);
    1156:         if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]);
    1157:         if (array_key_exists($keys[6], $arr)) $this->setVersion($arr[$keys[6]]);
    1158:         if (array_key_exists($keys[7], $arr)) $this->setVersionCreatedAt($arr[$keys[7]]);
    1159:         if (array_key_exists($keys[8], $arr)) $this->setVersionCreatedBy($arr[$keys[8]]);
    1160:     }
    1161:
    1162:     /**
    1163:      * Build a Criteria object containing the values of all modified columns in this object.
    1164:      *
    1165:      * @return Criteria The Criteria object containing all modified values.
    1166:      */
    1167:     public function buildCriteria()
    1168:     {
    1169:         $criteria = new Criteria(MessageVersionPeer::DATABASE_NAME);
    1170:
    1171:         if ($this->isColumnModified(MessageVersionPeer::ID)) $criteria->add(MessageVersionPeer::ID, $this->id);
    1172:         if ($this->isColumnModified(MessageVersionPeer::CODE)) $criteria->add(MessageVersionPeer::CODE, $this->code);
    1173:         if ($this->isColumnModified(MessageVersionPeer::SECURED)) $criteria->add(MessageVersionPeer::SECURED, $this->secured);
    1174:         if ($this->isColumnModified(MessageVersionPeer::REF)) $criteria->add(MessageVersionPeer::REF, $this->ref);
    1175:         if ($this->isColumnModified(MessageVersionPeer::CREATED_AT)) $criteria->add(MessageVersionPeer::CREATED_AT, $this->created_at);
    1176:         if ($this->isColumnModified(MessageVersionPeer::UPDATED_AT)) $criteria->add(MessageVersionPeer::UPDATED_AT, $this->updated_at);
    1177:         if ($this->isColumnModified(MessageVersionPeer::VERSION)) $criteria->add(MessageVersionPeer::VERSION, $this->version);
    1178:         if ($this->isColumnModified(MessageVersionPeer::VERSION_CREATED_AT)) $criteria->add(MessageVersionPeer::VERSION_CREATED_AT, $this->version_created_at);
    1179:         if ($this->isColumnModified(MessageVersionPeer::VERSION_CREATED_BY)) $criteria->add(MessageVersionPeer::VERSION_CREATED_BY, $this->version_created_by);
    1180:
    1181:         return $criteria;
    1182:     }
    1183:
    1184:     /**
    1185:      * Builds a Criteria object containing the primary key for this object.
    1186:      *
    1187:      * Unlike buildCriteria() this method includes the primary key values regardless
    1188:      * of whether or not they have been modified.
    1189:      *
    1190:      * @return Criteria The Criteria object containing value(s) for primary key(s).
    1191:      */
    1192:     public function buildPkeyCriteria()
    1193:     {
    1194:         $criteria = new Criteria(MessageVersionPeer::DATABASE_NAME);
    1195:         $criteria->add(MessageVersionPeer::ID, $this->id);
    1196:         $criteria->add(MessageVersionPeer::VERSION, $this->version);
    1197:
    1198:         return $criteria;
    1199:     }
    1200:
    1201:     /**
    1202:      * Returns the composite primary key for this object.
    1203:      * The array elements will be in same order as specified in XML.
    1204:      * @return array
    1205:      */
    1206:     public function getPrimaryKey()
    1207:     {
    1208:         $pks = array();
    1209:         $pks[0] = $this->getId();
    1210:         $pks[1] = $this->getVersion();
    1211:
    1212:         return $pks;
    1213:     }
    1214:
    1215:     /**
    1216:      * Set the [composite] primary key.
    1217:      *
    1218:      * @param array $keys The elements of the composite key (order must match the order in XML file).
    1219:      * @return void
    1220:      */
    1221:     public function setPrimaryKey($keys)
    1222:     {
    1223:         $this->setId($keys[0]);
    1224:         $this->setVersion($keys[1]);
    1225:     }
    1226:
    1227:     /**
    1228:      * Returns true if the primary key for this object is null.
    1229:      * @return boolean
    1230:      */
    1231:     public function isPrimaryKeyNull()
    1232:     {
    1233:
    1234:         return (null === $this->getId()) && (null === $this->getVersion());
    1235:     }
    1236:
    1237:     /**
    1238:      * Sets contents of passed object to values from current object.
    1239:      *
    1240:      * If desired, this method can also make copies of all associated (fkey referrers)
    1241:      * objects.
    1242:      *
    1243:      * @param object $copyObj An object of MessageVersion (or compatible) type.
    1244:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1245:      * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
    1246:      * @throws PropelException
    1247:      */
    1248:     public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    1249:     {
    1250:         $copyObj->setId($this->getId());
    1251:         $copyObj->setCode($this->getCode());
    1252:         $copyObj->setSecured($this->getSecured());
    1253:         $copyObj->setRef($this->getRef());
    1254:         $copyObj->setCreatedAt($this->getCreatedAt());
    1255:         $copyObj->setUpdatedAt($this->getUpdatedAt());
    1256:         $copyObj->setVersion($this->getVersion());
    1257:         $copyObj->setVersionCreatedAt($this->getVersionCreatedAt());
    1258:         $copyObj->setVersionCreatedBy($this->getVersionCreatedBy());
    1259:
    1260:         if ($deepCopy && !$this->startCopy) {
    1261:             // important: temporarily setNew(false) because this affects the behavior of
    1262:             // the getter/setter methods for fkey referrer objects.
    1263:             $copyObj->setNew(false);
    1264:             // store object hash to prevent cycle
    1265:             $this->startCopy = true;
    1266:
    1267:             //unflag object copy
    1268:             $this->startCopy = false;
    1269:         } // if ($deepCopy)
    1270:
    1271:         if ($makeNew) {
    1272:             $copyObj->setNew(true);
    1273:         }
    1274:     }
    1275:
    1276:     /**
    1277:      * Makes a copy of this object that will be inserted as a new row in table when saved.
    1278:      * It creates a new object filling in the simple attributes, but skipping any primary
    1279:      * keys that are defined for the table.
    1280:      *
    1281:      * If desired, this method can also make copies of all associated (fkey referrers)
    1282:      * objects.
    1283:      *
    1284:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1285:      * @return MessageVersion Clone of current object.
    1286:      * @throws PropelException
    1287:      */
    1288:     public function copy($deepCopy = false)
    1289:     {
    1290:         // we use get_class(), because this might be a subclass
    1291:         $clazz = get_class($this);
    1292:         $copyObj = new $clazz();
    1293:         $this->copyInto($copyObj, $deepCopy);
    1294:
    1295:         return $copyObj;
    1296:     }
    1297:
    1298:     /**
    1299:      * Returns a peer instance associated with this om.
    1300:      *
    1301:      * Since Peer classes are not to have any instance attributes, this method returns the
    1302:      * same instance for all member of this class. The method could therefore
    1303:      * be static, but this would prevent one from overriding the behavior.
    1304:      *
    1305:      * @return MessageVersionPeer
    1306:      */
    1307:     public function getPeer()
    1308:     {
    1309:         if (self::$peer === null) {
    1310:             self::$peer = new MessageVersionPeer();
    1311:         }
    1312:
    1313:         return self::$peer;
    1314:     }
    1315:
    1316:     /**
    1317:      * Declares an association between this object and a Message object.
    1318:      *
    1319:      * @param             Message $v
    1320:      * @return MessageVersion The current object (for fluent API support)
    1321:      * @throws PropelException
    1322:      */
    1323:     public function setMessage(Message $v = null)
    1324:     {
    1325:         if ($v === null) {
    1326:             $this->setId(NULL);
    1327:         } else {
    1328:             $this->setId($v->getId());
    1329:         }
    1330:
    1331:         $this->aMessage = $v;
    1332:
    1333:         // Add binding for other direction of this n:n relationship.
    1334:         // If this object has already been added to the Message object, it will not be re-added.
    1335:         if ($v !== null) {
    1336:             $v->addMessageVersion($this);
    1337:         }
    1338:
    1339:
    1340:         return $this;
    1341:     }
    1342:
    1343:
    1344:     /**
    1345:      * Get the associated Message object
    1346:      *
    1347:      * @param PropelPDO $con Optional Connection object.
    1348:      * @return Message The associated Message object.
    1349:      * @throws PropelException
    1350:      */
    1351:     public function getMessage(PropelPDO $con = null)
    1352:     {
    1353:         if ($this->aMessage === null && ($this->id !== null)) {
    1354:             $this->aMessage = MessageQuery::create()->findPk($this->id, $con);
    1355:             /* The following can be used additionally to
    1356:                 guarantee the related object contains a reference
    1357:                 to this object.  This level of coupling may, however, be
    1358:                 undesirable since it could result in an only partially populated collection
    1359:                 in the referenced object.
    1360:                 $this->aMessage->addMessageVersions($this);
    1361:              */
    1362:         }
    1363:
    1364:         return $this->aMessage;
    1365:     }
    1366:
    1367:     /**
    1368:      * Clears the current object and sets all attributes to their default values
    1369:      */
    1370:     public function clear()
    1371:     {
    1372:         $this->id = null;
    1373:         $this->code = null;
    1374:         $this->secured = null;
    1375:         $this->ref = null;
    1376:         $this->created_at = null;
    1377:         $this->updated_at = null;
    1378:         $this->version = null;
    1379:         $this->version_created_at = null;
    1380:         $this->version_created_by = null;
    1381:         $this->alreadyInSave = false;
    1382:         $this->alreadyInValidation = false;
    1383:         $this->clearAllReferences();
    1384:         $this->applyDefaultValues();
    1385:         $this->resetModified();
    1386:         $this->setNew(true);
    1387:         $this->setDeleted(false);
    1388:     }
    1389:
    1390:     /**
    1391:      * Resets all references to other model objects or collections of model objects.
    1392:      *
    1393:      * This method is a user-space workaround for PHP's inability to garbage collect
    1394:      * objects with circular references (even in PHP 5.3). This is currently necessary
    1395:      * when using Propel in certain daemon or large-volumne/high-memory operations.
    1396:      *
    1397:      * @param boolean $deep Whether to also clear the references on all referrer objects.
    1398:      */
    1399:     public function clearAllReferences($deep = false)
    1400:     {
    1401:         if ($deep) {
    1402:         } // if ($deep)
    1403:
    1404:         $this->aMessage = null;
    1405:     }
    1406:
    1407:     /**
    1408:      * return the string representation of this object
    1409:      *
    1410:      * @return string
    1411:      */
    1412:     public function __toString()
    1413:     {
    1414:         return (string) $this->exportTo(MessageVersionPeer::DEFAULT_STRING_FORMAT);
    1415:     }
    1416:
    1417:     /**
    1418:      * return true is the object is in saving state
    1419:      *
    1420:      * @return boolean
    1421:      */
    1422:     public function isAlreadyInSave()
    1423:     {
    1424:         return $this->alreadyInSave;
    1425:     }
    1426:
    1427: }
    1428: