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