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