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