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