       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 \PropelCollection;
      14: use \PropelDateTime;
      15: use \PropelException;
      16: use \PropelObjectCollection;
      17: use \PropelPDO;
      18: use Thelia\Model\Category;
      19: use Thelia\Model\CategoryQuery;
      20: use Thelia\Model\Content;
      21: use Thelia\Model\ContentQuery;
      22: use Thelia\Model\Document;
      23: use Thelia\Model\DocumentI18n;
      24: use Thelia\Model\DocumentI18nQuery;
      25: use Thelia\Model\DocumentPeer;
      26: use Thelia\Model\DocumentQuery;
      27: use Thelia\Model\Folder;
      28: use Thelia\Model\FolderQuery;
      29: use Thelia\Model\Product;
      30: use Thelia\Model\ProductQuery;
      31:
      32: /**
      33:  * Base class that represents a row from the 'document' table.
      34:  *
      35:  *
      36:  *
      37:  * @package    propel.generator.Thelia.Model.om
      38:  */
      39: abstract class BaseDocument extends BaseObject implements Persistent
      40: {
      41:     /**
      42:      * Peer class name
      43:      */
      44:     const PEER = 'Thelia\\Model\\DocumentPeer';
      45:
      46:     /**
      47:      * The Peer class.
      48:      * Instance provides a convenient way of calling static methods on a class
      49:      * that calling code may not be able to identify.
      50:      * @var        DocumentPeer
      51:      */
      52:     protected static $peer;
      53:
      54:     /**
      55:      * The flag var to prevent infinit loop in deep copy
      56:      * @var       boolean
      57:      */
      58:     protected $startCopy = false;
      59:
      60:     /**
      61:      * The value for the id field.
      62:      * @var        int
      63:      */
      64:     protected $id;
      65:
      66:     /**
      67:      * The value for the product_id field.
      68:      * @var        int
      69:      */
      70:     protected $product_id;
      71:
      72:     /**
      73:      * The value for the category_id field.
      74:      * @var        int
      75:      */
      76:     protected $category_id;
      77:
      78:     /**
      79:      * The value for the folder_id field.
      80:      * @var        int
      81:      */
      82:     protected $folder_id;
      83:
      84:     /**
      85:      * The value for the content_id field.
      86:      * @var        int
      87:      */
      88:     protected $content_id;
      89:
      90:     /**
      91:      * The value for the file field.
      92:      * @var        string
      93:      */
      94:     protected $file;
      95:
      96:     /**
      97:      * The value for the position field.
      98:      * @var        int
      99:      */
     100:     protected $position;
     101:
     102:     /**
     103:      * The value for the created_at field.
     104:      * @var        string
     105:      */
     106:     protected $created_at;
     107:
     108:     /**
     109:      * The value for the updated_at field.
     110:      * @var        string
     111:      */
     112:     protected $updated_at;
     113:
     114:     /**
     115:      * @var        Product
     116:      */
     117:     protected $aProduct;
     118:
     119:     /**
     120:      * @var        Category
     121:      */
     122:     protected $aCategory;
     123:
     124:     /**
     125:      * @var        Content
     126:      */
     127:     protected $aContent;
     128:
     129:     /**
     130:      * @var        Folder
     131:      */
     132:     protected $aFolder;
     133:
     134:     /**
     135:      * @var        PropelObjectCollection|DocumentI18n[] Collection to store aggregation of DocumentI18n objects.
     136:      */
     137:     protected $collDocumentI18ns;
     138:     protected $collDocumentI18nsPartial;
     139:
     140:     /**
     141:      * Flag to prevent endless save loop, if this object is referenced
     142:      * by another object which falls in this transaction.
     143:      * @var        boolean
     144:      */
     145:     protected $alreadyInSave = false;
     146:
     147:     /**
     148:      * Flag to prevent endless validation loop, if this object is referenced
     149:      * by another object which falls in this transaction.
     150:      * @var        boolean
     151:      */
     152:     protected $alreadyInValidation = false;
     153:
     154:     /**
     155:      * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
     156:      * @var        boolean
     157:      */
     158:     protected $alreadyInClearAllReferencesDeep = false;
     159:
     160:     // i18n behavior
     161:
     162:     /**
     163:      * Current locale
     164:      * @var        string
     165:      */
     166:     protected $currentLocale = 'en_US';
     167:
     168:     /**
     169:      * Current translation objects
     170:      * @var        array[DocumentI18n]
     171:      */
     172:     protected $currentTranslations;
     173:
     174:     /**
     175:      * An array of objects scheduled for deletion.
     176:      * @var     PropelObjectCollection
     177:      */
     178:     protected $documentI18nsScheduledForDeletion = null;
     179:
     180:     /**
     181:      * Get the [id] column value.
     182:      *
     183:      * @return int
     184:      */
     185:     public function getId()
     186:     {
     187:         return $this->id;
     188:     }
     189:
     190:     /**
     191:      * Get the [product_id] column value.
     192:      *
     193:      * @return int
     194:      */
     195:     public function getProductId()
     196:     {
     197:         return $this->product_id;
     198:     }
     199:
     200:     /**
     201:      * Get the [category_id] column value.
     202:      *
     203:      * @return int
     204:      */
     205:     public function getCategoryId()
     206:     {
     207:         return $this->category_id;
     208:     }
     209:
     210:     /**
     211:      * Get the [folder_id] column value.
     212:      *
     213:      * @return int
     214:      */
     215:     public function getFolderId()
     216:     {
     217:         return $this->folder_id;
     218:     }
     219:
     220:     /**
     221:      * Get the [content_id] column value.
     222:      *
     223:      * @return int
     224:      */
     225:     public function getContentId()
     226:     {
     227:         return $this->content_id;
     228:     }
     229:
     230:     /**
     231:      * Get the [file] column value.
     232:      *
     233:      * @return string
     234:      */
     235:     public function getFile()
     236:     {
     237:         return $this->file;
     238:     }
     239:
     240:     /**
     241:      * Get the [position] column value.
     242:      *
     243:      * @return int
     244:      */
     245:     public function getPosition()
     246:     {
     247:         return $this->position;
     248:     }
     249:
     250:     /**
     251:      * Get the [optionally formatted] temporal [created_at] column value.
     252:      *
     253:      *
     254:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     255:      *               If format is null, then the raw DateTime object will be returned.
     256:      * @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
     257:      * @throws PropelException - if unable to parse/validate the date/time value.
     258:      */
     259:     public function getCreatedAt($format = 'Y-m-d H:i:s')
     260:     {
     261:         if ($this->created_at === null) {
     262:             return null;
     263:         }
     264:
     265:         if ($this->created_at === '0000-00-00 00:00:00') {
     266:             // while technically this is not a default value of null,
     267:             // this seems to be closest in meaning.
     268:             return null;
     269:         }
     270:
     271:         try {
     272:             $dt = new DateTime($this->created_at);
     273:         } catch (Exception $x) {
     274:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
     275:         }
     276:
     277:         if ($format === null) {
     278:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     279:             return $dt;
     280:         }
     281:
     282:         if (strpos($format, '%') !== false) {
     283:             return strftime($format, $dt->format('U'));
     284:         }
     285:
     286:         return $dt->format($format);
     287:
     288:     }
     289:
     290:     /**
     291:      * Get the [optionally formatted] temporal [updated_at] column value.
     292:      *
     293:      *
     294:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     295:      *               If format is null, then the raw DateTime object will be returned.
     296:      * @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
     297:      * @throws PropelException - if unable to parse/validate the date/time value.
     298:      */
     299:     public function getUpdatedAt($format = 'Y-m-d H:i:s')
     300:     {
     301:         if ($this->updated_at === null) {
     302:             return null;
     303:         }
     304:
     305:         if ($this->updated_at === '0000-00-00 00:00:00') {
     306:             // while technically this is not a default value of null,
     307:             // this seems to be closest in meaning.
     308:             return null;
     309:         }
     310:
     311:         try {
     312:             $dt = new DateTime($this->updated_at);
     313:         } catch (Exception $x) {
     314:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
     315:         }
     316:
     317:         if ($format === null) {
     318:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     319:             return $dt;
     320:         }
     321:
     322:         if (strpos($format, '%') !== false) {
     323:             return strftime($format, $dt->format('U'));
     324:         }
     325:
     326:         return $dt->format($format);
     327:
     328:     }
     329:
     330:     /**
     331:      * Set the value of [id] column.
     332:      *
     333:      * @param int $v new value
     334:      * @return Document The current object (for fluent API support)
     335:      */
     336:     public function setId($v)
     337:     {
     338:         if ($v !== null && is_numeric($v)) {
     339:             $v = (int) $v;
     340:         }
     341:
     342:         if ($this->id !== $v) {
     343:             $this->id = $v;
     344:             $this->modifiedColumns[] = DocumentPeer::ID;
     345:         }
     346:
     347:
     348:         return $this;
     349:     } // setId()
     350:
     351:     /**
     352:      * Set the value of [product_id] column.
     353:      *
     354:      * @param int $v new value
     355:      * @return Document The current object (for fluent API support)
     356:      */
     357:     public function setProductId($v)
     358:     {
     359:         if ($v !== null && is_numeric($v)) {
     360:             $v = (int) $v;
     361:         }
     362:
     363:         if ($this->product_id !== $v) {
     364:             $this->product_id = $v;
     365:             $this->modifiedColumns[] = DocumentPeer::PRODUCT_ID;
     366:         }
     367:
     368:         if ($this->aProduct !== null && $this->aProduct->getId() !== $v) {
     369:             $this->aProduct = null;
     370:         }
     371:
     372:
     373:         return $this;
     374:     } // setProductId()
     375:
     376:     /**
     377:      * Set the value of [category_id] column.
     378:      *
     379:      * @param int $v new value
     380:      * @return Document The current object (for fluent API support)
     381:      */
     382:     public function setCategoryId($v)
     383:     {
     384:         if ($v !== null && is_numeric($v)) {
     385:             $v = (int) $v;
     386:         }
     387:
     388:         if ($this->category_id !== $v) {
     389:             $this->category_id = $v;
     390:             $this->modifiedColumns[] = DocumentPeer::CATEGORY_ID;
     391:         }
     392:
     393:         if ($this->aCategory !== null && $this->aCategory->getId() !== $v) {
     394:             $this->aCategory = null;
     395:         }
     396:
     397:
     398:         return $this;
     399:     } // setCategoryId()
     400:
     401:     /**
     402:      * Set the value of [folder_id] column.
     403:      *
     404:      * @param int $v new value
     405:      * @return Document The current object (for fluent API support)
     406:      */
     407:     public function setFolderId($v)
     408:     {
     409:         if ($v !== null && is_numeric($v)) {
     410:             $v = (int) $v;
     411:         }
     412:
     413:         if ($this->folder_id !== $v) {
     414:             $this->folder_id = $v;
     415:             $this->modifiedColumns[] = DocumentPeer::FOLDER_ID;
     416:         }
     417:
     418:         if ($this->aFolder !== null && $this->aFolder->getId() !== $v) {
     419:             $this->aFolder = null;
     420:         }
     421:
     422:
     423:         return $this;
     424:     } // setFolderId()
     425:
     426:     /**
     427:      * Set the value of [content_id] column.
     428:      *
     429:      * @param int $v new value
     430:      * @return Document The current object (for fluent API support)
     431:      */
     432:     public function setContentId($v)
     433:     {
     434:         if ($v !== null && is_numeric($v)) {
     435:             $v = (int) $v;
     436:         }
     437:
     438:         if ($this->content_id !== $v) {
     439:             $this->content_id = $v;
     440:             $this->modifiedColumns[] = DocumentPeer::CONTENT_ID;
     441:         }
     442:
     443:         if ($this->aContent !== null && $this->aContent->getId() !== $v) {
     444:             $this->aContent = null;
     445:         }
     446:
     447:
     448:         return $this;
     449:     } // setContentId()
     450:
     451:     /**
     452:      * Set the value of [file] column.
     453:      *
     454:      * @param string $v new value
     455:      * @return Document The current object (for fluent API support)
     456:      */
     457:     public function setFile($v)
     458:     {
     459:         if ($v !== null && is_numeric($v)) {
     460:             $v = (string) $v;
     461:         }
     462:
     463:         if ($this->file !== $v) {
     464:             $this->file = $v;
     465:             $this->modifiedColumns[] = DocumentPeer::FILE;
     466:         }
     467:
     468:
     469:         return $this;
     470:     } // setFile()
     471:
     472:     /**
     473:      * Set the value of [position] column.
     474:      *
     475:      * @param int $v new value
     476:      * @return Document The current object (for fluent API support)
     477:      */
     478:     public function setPosition($v)
     479:     {
     480:         if ($v !== null && is_numeric($v)) {
     481:             $v = (int) $v;
     482:         }
     483:
     484:         if ($this->position !== $v) {
     485:             $this->position = $v;
     486:             $this->modifiedColumns[] = DocumentPeer::POSITION;
     487:         }
     488:
     489:
     490:         return $this;
     491:     } // setPosition()
     492:
     493:     /**
     494:      * Sets the value of [created_at] column to a normalized version of the date/time value specified.
     495:      *
     496:      * @param mixed $v string, integer (timestamp), or DateTime value.
     497:      *               Empty strings are treated as null.
     498:      * @return Document The current object (for fluent API support)
     499:      */
     500:     public function setCreatedAt($v)
     501:     {
     502:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     503:         if ($this->created_at !== null || $dt !== null) {
     504:             $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     505:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     506:             if ($currentDateAsString !== $newDateAsString) {
     507:                 $this->created_at = $newDateAsString;
     508:                 $this->modifiedColumns[] = DocumentPeer::CREATED_AT;
     509:             }
     510:         } // if either are not null
     511:
     512:
     513:         return $this;
     514:     } // setCreatedAt()
     515:
     516:     /**
     517:      * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
     518:      *
     519:      * @param mixed $v string, integer (timestamp), or DateTime value.
     520:      *               Empty strings are treated as null.
     521:      * @return Document The current object (for fluent API support)
     522:      */
     523:     public function setUpdatedAt($v)
     524:     {
     525:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     526:         if ($this->updated_at !== null || $dt !== null) {
     527:             $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     528:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     529:             if ($currentDateAsString !== $newDateAsString) {
     530:                 $this->updated_at = $newDateAsString;
     531:                 $this->modifiedColumns[] = DocumentPeer::UPDATED_AT;
     532:             }
     533:         } // if either are not null
     534:
     535:
     536:         return $this;
     537:     } // setUpdatedAt()
     538:
     539:     /**
     540:      * Indicates whether the columns in this object are only set to default values.
     541:      *
     542:      * This method can be used in conjunction with isModified() to indicate whether an object is both
     543:      * modified _and_ has some values set which are non-default.
     544:      *
     545:      * @return boolean Whether the columns in this object are only been set with default values.
     546:      */
     547:     public function hasOnlyDefaultValues()
     548:     {
     549:         // otherwise, everything was equal, so return true
     550:         return true;
     551:     } // hasOnlyDefaultValues()
     552:
     553:     /**
     554:      * Hydrates (populates) the object variables with values from the database resultset.
     555:      *
     556:      * An offset (0-based "start column") is specified so that objects can be hydrated
     557:      * with a subset of the columns in the resultset rows.  This is needed, for example,
     558:      * for results of JOIN queries where the resultset row includes columns from two or
     559:      * more tables.
     560:      *
     561:      * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     562:      * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     563:      * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     564:      * @return int             next starting column
     565:      * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     566:      */
     567:     public function hydrate($row, $startcol = 0, $rehydrate = false)
     568:     {
     569:         try {
     570:
     571:             $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
     572:             $this->product_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
     573:             $this->category_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
     574:             $this->folder_id = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
     575:             $this->content_id = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
     576:             $this->file = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
     577:             $this->position = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
     578:             $this->created_at = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
     579:             $this->updated_at = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
     580:             $this->resetModified();
     581:
     582:             $this->setNew(false);
     583:
     584:             if ($rehydrate) {
     585:                 $this->ensureConsistency();
     586:             }
     587:             $this->postHydrate($row, $startcol, $rehydrate);
     588:             return $startcol + 9; // 9 = DocumentPeer::NUM_HYDRATE_COLUMNS.
     589:
     590:         } catch (Exception $e) {
     591:             throw new PropelException("Error populating Document object", $e);
     592:         }
     593:     }
     594:
     595:     /**
     596:      * Checks and repairs the internal consistency of the object.
     597:      *
     598:      * This method is executed after an already-instantiated object is re-hydrated
     599:      * from the database.  It exists to check any foreign keys to make sure that
     600:      * the objects related to the current object are correct based on foreign key.
     601:      *
     602:      * You can override this method in the stub class, but you should always invoke
     603:      * the base method from the overridden method (i.e. parent::ensureConsistency()),
     604:      * in case your model changes.
     605:      *
     606:      * @throws PropelException
     607:      */
     608:     public function ensureConsistency()
     609:     {
     610:
     611:         if ($this->aProduct !== null && $this->product_id !== $this->aProduct->getId()) {
     612:             $this->aProduct = null;
     613:         }
     614:         if ($this->aCategory !== null && $this->category_id !== $this->aCategory->getId()) {
     615:             $this->aCategory = null;
     616:         }
     617:         if ($this->aFolder !== null && $this->folder_id !== $this->aFolder->getId()) {
     618:             $this->aFolder = null;
     619:         }
     620:         if ($this->aContent !== null && $this->content_id !== $this->aContent->getId()) {
     621:             $this->aContent = null;
     622:         }
     623:     } // ensureConsistency
     624:
     625:     /**
     626:      * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     627:      *
     628:      * This will only work if the object has been saved and has a valid primary key set.
     629:      *
     630:      * @param boolean $deep (optional) Whether to also de-associated any related objects.
     631:      * @param PropelPDO $con (optional) The PropelPDO connection to use.
     632:      * @return void
     633:      * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     634:      */
     635:     public function reload($deep = false, PropelPDO $con = null)
     636:     {
     637:         if ($this->isDeleted()) {
     638:             throw new PropelException("Cannot reload a deleted object.");
     639:         }
     640:
     641:         if ($this->isNew()) {
     642:             throw new PropelException("Cannot reload an unsaved object.");
     643:         }
     644:
     645:         if ($con === null) {
     646:             $con = Propel::getConnection(DocumentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     647:         }
     648:
     649:         // We don't need to alter the object instance pool; we're just modifying this instance
     650:         // already in the pool.
     651:
     652:         $stmt = DocumentPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     653:         $row = $stmt->fetch(PDO::FETCH_NUM);
     654:         $stmt->closeCursor();
     655:         if (!$row) {
     656:             throw new PropelException('Cannot find matching row in the database to reload object values.');
     657:         }
     658:         $this->hydrate($row, 0, true); // rehydrate
     659:
     660:         if ($deep) {  // also de-associate any related objects?
     661:
     662:             $this->aProduct = null;
     663:             $this->aCategory = null;
     664:             $this->aContent = null;
     665:             $this->aFolder = null;
     666:             $this->collDocumentI18ns = null;
     667:
     668:         } // if (deep)
     669:     }
     670:
     671:     /**
     672:      * Removes this object from datastore and sets delete attribute.
     673:      *
     674:      * @param PropelPDO $con
     675:      * @return void
     676:      * @throws PropelException
     677:      * @throws Exception
     678:      * @see        BaseObject::setDeleted()
     679:      * @see        BaseObject::isDeleted()
     680:      */
     681:     public function delete(PropelPDO $con = null)
     682:     {
     683:         if ($this->isDeleted()) {
     684:             throw new PropelException("This object has already been deleted.");
     685:         }
     686:
     687:         if ($con === null) {
     688:             $con = Propel::getConnection(DocumentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     689:         }
     690:
     691:         $con->beginTransaction();
     692:         try {
     693:             $deleteQuery = DocumentQuery::create()
     694:                 ->filterByPrimaryKey($this->getPrimaryKey());
     695:             $ret = $this->preDelete($con);
     696:             if ($ret) {
     697:                 $deleteQuery->delete($con);
     698:                 $this->postDelete($con);
     699:                 $con->commit();
     700:                 $this->setDeleted(true);
     701:             } else {
     702:                 $con->commit();
     703:             }
     704:         } catch (Exception $e) {
     705:             $con->rollBack();
     706:             throw $e;
     707:         }
     708:     }
     709:
     710:     /**
     711:      * Persists this object to the database.
     712:      *
     713:      * If the object is new, it inserts it; otherwise an update is performed.
     714:      * All modified related objects will also be persisted in the doSave()
     715:      * method.  This method wraps all precipitate database operations in a
     716:      * single transaction.
     717:      *
     718:      * @param PropelPDO $con
     719:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     720:      * @throws PropelException
     721:      * @throws Exception
     722:      * @see        doSave()
     723:      */
     724:     public function save(PropelPDO $con = null)
     725:     {
     726:         if ($this->isDeleted()) {
     727:             throw new PropelException("You cannot save an object that has been deleted.");
     728:         }
     729:
     730:         if ($con === null) {
     731:             $con = Propel::getConnection(DocumentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     732:         }
     733:
     734:         $con->beginTransaction();
     735:         $isInsert = $this->isNew();
     736:         try {
     737:             $ret = $this->preSave($con);
     738:             if ($isInsert) {
     739:                 $ret = $ret && $this->preInsert($con);
     740:                 // timestampable behavior
     741:                 if (!$this->isColumnModified(DocumentPeer::CREATED_AT)) {
     742:                     $this->setCreatedAt(time());
     743:                 }
     744:                 if (!$this->isColumnModified(DocumentPeer::UPDATED_AT)) {
     745:                     $this->setUpdatedAt(time());
     746:                 }
     747:             } else {
     748:                 $ret = $ret && $this->preUpdate($con);
     749:                 // timestampable behavior
     750:                 if ($this->isModified() && !$this->isColumnModified(DocumentPeer::UPDATED_AT)) {
     751:                     $this->setUpdatedAt(time());
     752:                 }
     753:             }
     754:             if ($ret) {
     755:                 $affectedRows = $this->doSave($con);
     756:                 if ($isInsert) {
     757:                     $this->postInsert($con);
     758:                 } else {
     759:                     $this->postUpdate($con);
     760:                 }
     761:                 $this->postSave($con);
     762:                 DocumentPeer::addInstanceToPool($this);
     763:             } else {
     764:                 $affectedRows = 0;
     765:             }
     766:             $con->commit();
     767:
     768:             return $affectedRows;
     769:         } catch (Exception $e) {
     770:             $con->rollBack();
     771:             throw $e;
     772:         }
     773:     }
     774:
     775:     /**
     776:      * Performs the work of inserting or updating the row in the database.
     777:      *
     778:      * If the object is new, it inserts it; otherwise an update is performed.
     779:      * All related objects are also updated in this method.
     780:      *
     781:      * @param PropelPDO $con
     782:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     783:      * @throws PropelException
     784:      * @see        save()
     785:      */
     786:     protected function doSave(PropelPDO $con)
     787:     {
     788:         $affectedRows = 0; // initialize var to track total num of affected rows
     789:         if (!$this->alreadyInSave) {
     790:             $this->alreadyInSave = true;
     791:
     792:             // We call the save method on the following object(s) if they
     793:             // were passed to this object by their coresponding set
     794:             // method.  This object relates to these object(s) by a
     795:             // foreign key reference.
     796:
     797:             if ($this->aProduct !== null) {
     798:                 if ($this->aProduct->isModified() || $this->aProduct->isNew()) {
     799:                     $affectedRows += $this->aProduct->save($con);
     800:                 }
     801:                 $this->setProduct($this->aProduct);
     802:             }
     803:
     804:             if ($this->aCategory !== null) {
     805:                 if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
     806:                     $affectedRows += $this->aCategory->save($con);
     807:                 }
     808:                 $this->setCategory($this->aCategory);
     809:             }
     810:
     811:             if ($this->aContent !== null) {
     812:                 if ($this->aContent->isModified() || $this->aContent->isNew()) {
     813:                     $affectedRows += $this->aContent->save($con);
     814:                 }
     815:                 $this->setContent($this->aContent);
     816:             }
     817:
     818:             if ($this->aFolder !== null) {
     819:                 if ($this->aFolder->isModified() || $this->aFolder->isNew()) {
     820:                     $affectedRows += $this->aFolder->save($con);
     821:                 }
     822:                 $this->setFolder($this->aFolder);
     823:             }
     824:
     825:             if ($this->isNew() || $this->isModified()) {
     826:                 // persist changes
     827:                 if ($this->isNew()) {
     828:                     $this->doInsert($con);
     829:                 } else {
     830:                     $this->doUpdate($con);
     831:                 }
     832:                 $affectedRows += 1;
     833:                 $this->resetModified();
     834:             }
     835:
     836:             if ($this->documentI18nsScheduledForDeletion !== null) {
     837:                 if (!$this->documentI18nsScheduledForDeletion->isEmpty()) {
     838:                     DocumentI18nQuery::create()
     839:                         ->filterByPrimaryKeys($this->documentI18nsScheduledForDeletion->getPrimaryKeys(false))
     840:                         ->delete($con);
     841:                     $this->documentI18nsScheduledForDeletion = null;
     842:                 }
     843:             }
     844:
     845:             if ($this->collDocumentI18ns !== null) {
     846:                 foreach ($this->collDocumentI18ns as $referrerFK) {
     847:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     848:                         $affectedRows += $referrerFK->save($con);
     849:                     }
     850:                 }
     851:             }
     852:
     853:             $this->alreadyInSave = false;
     854:
     855:         }
     856:
     857:         return $affectedRows;
     858:     } // doSave()
     859:
     860:     /**
     861:      * Insert the row in the database.
     862:      *
     863:      * @param PropelPDO $con
     864:      *
     865:      * @throws PropelException
     866:      * @see        doSave()
     867:      */
     868:     protected function doInsert(PropelPDO $con)
     869:     {
     870:         $modifiedColumns = array();
     871:         $index = 0;
     872:
     873:         $this->modifiedColumns[] = DocumentPeer::ID;
     874:         if (null !== $this->id) {
     875:             throw new PropelException('Cannot insert a value for auto-increment primary key (' . DocumentPeer::ID . ')');
     876:         }
     877:
     878:          // check the columns in natural order for more readable SQL queries
     879:         if ($this->isColumnModified(DocumentPeer::ID)) {
     880:             $modifiedColumns[':p' . $index++]  = '`id`';
     881:         }
     882:         if ($this->isColumnModified(DocumentPeer::PRODUCT_ID)) {
     883:             $modifiedColumns[':p' . $index++]  = '`product_id`';
     884:         }
     885:         if ($this->isColumnModified(DocumentPeer::CATEGORY_ID)) {
     886:             $modifiedColumns[':p' . $index++]  = '`category_id`';
     887:         }
     888:         if ($this->isColumnModified(DocumentPeer::FOLDER_ID)) {
     889:             $modifiedColumns[':p' . $index++]  = '`folder_id`';
     890:         }
     891:         if ($this->isColumnModified(DocumentPeer::CONTENT_ID)) {
     892:             $modifiedColumns[':p' . $index++]  = '`content_id`';
     893:         }
     894:         if ($this->isColumnModified(DocumentPeer::FILE)) {
     895:             $modifiedColumns[':p' . $index++]  = '`file`';
     896:         }
     897:         if ($this->isColumnModified(DocumentPeer::POSITION)) {
     898:             $modifiedColumns[':p' . $index++]  = '`position`';
     899:         }
     900:         if ($this->isColumnModified(DocumentPeer::CREATED_AT)) {
     901:             $modifiedColumns[':p' . $index++]  = '`created_at`';
     902:         }
     903:         if ($this->isColumnModified(DocumentPeer::UPDATED_AT)) {
     904:             $modifiedColumns[':p' . $index++]  = '`updated_at`';
     905:         }
     906:
     907:         $sql = sprintf(
     908:             'INSERT INTO `document` (%s) VALUES (%s)',
     909:             implode(', ', $modifiedColumns),
     910:             implode(', ', array_keys($modifiedColumns))
     911:         );
     912:
     913:         try {
     914:             $stmt = $con->prepare($sql);
     915:             foreach ($modifiedColumns as $identifier => $columnName) {
     916:                 switch ($columnName) {
     917:                     case '`id`':
     918:                         $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
     919:                         break;
     920:                     case '`product_id`':
     921:                         $stmt->bindValue($identifier, $this->product_id, PDO::PARAM_INT);
     922:                         break;
     923:                     case '`category_id`':
     924:                         $stmt->bindValue($identifier, $this->category_id, PDO::PARAM_INT);
     925:                         break;
     926:                     case '`folder_id`':
     927:                         $stmt->bindValue($identifier, $this->folder_id, PDO::PARAM_INT);
     928:                         break;
     929:                     case '`content_id`':
     930:                         $stmt->bindValue($identifier, $this->content_id, PDO::PARAM_INT);
     931:                         break;
     932:                     case '`file`':
     933:                         $stmt->bindValue($identifier, $this->file, PDO::PARAM_STR);
     934:                         break;
     935:                     case '`position`':
     936:                         $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
     937:                         break;
     938:                     case '`created_at`':
     939:                         $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
     940:                         break;
     941:                     case '`updated_at`':
     942:                         $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
     943:                         break;
     944:                 }
     945:             }
     946:             $stmt->execute();
     947:         } catch (Exception $e) {
     948:             Propel::log($e->getMessage(), Propel::LOG_ERR);
     949:             throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
     950:         }
     951:
     952:         try {
     953:             $pk = $con->lastInsertId();
     954:         } catch (Exception $e) {
     955:             throw new PropelException('Unable to get autoincrement id.', $e);
     956:         }
     957:         $this->setId($pk);
     958:
     959:         $this->setNew(false);
     960:     }
     961:
     962:     /**
     963:      * Update the row in the database.
     964:      *
     965:      * @param PropelPDO $con
     966:      *
     967:      * @see        doSave()
     968:      */
     969:     protected function doUpdate(PropelPDO $con)
     970:     {
     971:         $selectCriteria = $this->buildPkeyCriteria();
     972:         $valuesCriteria = $this->buildCriteria();
     973:         BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
     974:     }
     975:
     976:     /**
     977:      * Array of ValidationFailed objects.
     978:      * @var        array ValidationFailed[]
     979:      */
     980:     protected $validationFailures = array();
     981:
     982:     /**
     983:      * Gets any ValidationFailed objects that resulted from last call to validate().
     984:      *
     985:      *
     986:      * @return array ValidationFailed[]
     987:      * @see        validate()
     988:      */
     989:     public function getValidationFailures()
     990:     {
     991:         return $this->validationFailures;
     992:     }
     993:
     994:     /**
     995:      * Validates the objects modified field values and all objects related to this table.
     996:      *
     997:      * If $columns is either a column name or an array of column names
     998:      * only those columns are validated.
     999:      *
    1000:      * @param mixed $columns Column name or an array of column names.
    1001:      * @return boolean Whether all columns pass validation.
    1002:      * @see        doValidate()
    1003:      * @see        getValidationFailures()
    1004:      */
    1005:     public function validate($columns = null)
    1006:     {
    1007:         $res = $this->doValidate($columns);
    1008:         if ($res === true) {
    1009:             $this->validationFailures = array();
    1010:
    1011:             return true;
    1012:         }
    1013:
    1014:         $this->validationFailures = $res;
    1015:
    1016:         return false;
    1017:     }
    1018:
    1019:     /**
    1020:      * This function performs the validation work for complex object models.
    1021:      *
    1022:      * In addition to checking the current object, all related objects will
    1023:      * also be validated.  If all pass then <code>true</code> is returned; otherwise
    1024:      * an aggreagated array of ValidationFailed objects will be returned.
    1025:      *
    1026:      * @param array $columns Array of column names to validate.
    1027:      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
    1028:      */
    1029:     protected function doValidate($columns = null)
    1030:     {
    1031:         if (!$this->alreadyInValidation) {
    1032:             $this->alreadyInValidation = true;
    1033:             $retval = null;
    1034:
    1035:             $failureMap = array();
    1036:
    1037:
    1038:             // We call the validate method on the following object(s) if they
    1039:             // were passed to this object by their coresponding set
    1040:             // method.  This object relates to these object(s) by a
    1041:             // foreign key reference.
    1042:
    1043:             if ($this->aProduct !== null) {
    1044:                 if (!$this->aProduct->validate($columns)) {
    1045:                     $failureMap = array_merge($failureMap, $this->aProduct->getValidationFailures());
    1046:                 }
    1047:             }
    1048:
    1049:             if ($this->aCategory !== null) {
    1050:                 if (!$this->aCategory->validate($columns)) {
    1051:                     $failureMap = array_merge($failureMap, $this->aCategory->getValidationFailures());
    1052:                 }
    1053:             }
    1054:
    1055:             if ($this->aContent !== null) {
    1056:                 if (!$this->aContent->validate($columns)) {
    1057:                     $failureMap = array_merge($failureMap, $this->aContent->getValidationFailures());
    1058:                 }
    1059:             }
    1060:
    1061:             if ($this->aFolder !== null) {
    1062:                 if (!$this->aFolder->validate($columns)) {
    1063:                     $failureMap = array_merge($failureMap, $this->aFolder->getValidationFailures());
    1064:                 }
    1065:             }
    1066:
    1067:
    1068:             if (($retval = DocumentPeer::doValidate($this, $columns)) !== true) {
    1069:                 $failureMap = array_merge($failureMap, $retval);
    1070:             }
    1071:
    1072:
    1073:                 if ($this->collDocumentI18ns !== null) {
    1074:                     foreach ($this->collDocumentI18ns as $referrerFK) {
    1075:                         if (!$referrerFK->validate($columns)) {
    1076:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
    1077:                         }
    1078:                     }
    1079:                 }
    1080:
    1081:
    1082:             $this->alreadyInValidation = false;
    1083:         }
    1084:
    1085:         return (!empty($failureMap) ? $failureMap : true);
    1086:     }
    1087:
    1088:     /**
    1089:      * Retrieves a field from the object by name passed in as a string.
    1090:      *
    1091:      * @param string $name name
    1092:      * @param string $type The type of fieldname the $name is of:
    1093:      *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
    1094:      *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1095:      *               Defaults to BasePeer::TYPE_PHPNAME
    1096:      * @return mixed Value of field.
    1097:      */
    1098:     public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
    1099:     {
    1100:         $pos = DocumentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
    1101:         $field = $this->getByPosition($pos);
    1102:
    1103:         return $field;
    1104:     }
    1105:
    1106:     /**
    1107:      * Retrieves a field from the object by Position as specified in the xml schema.
    1108:      * Zero-based.
    1109:      *
    1110:      * @param int $pos position in xml schema
    1111:      * @return mixed Value of field at $pos
    1112:      */
    1113:     public function getByPosition($pos)
    1114:     {
    1115:         switch ($pos) {
    1116:             case 0:
    1117:                 return $this->getId();
    1118:                 break;
    1119:             case 1:
    1120:                 return $this->getProductId();
    1121:                 break;
    1122:             case 2:
    1123:                 return $this->getCategoryId();
    1124:                 break;
    1125:             case 3:
    1126:                 return $this->getFolderId();
    1127:                 break;
    1128:             case 4:
    1129:                 return $this->getContentId();
    1130:                 break;
    1131:             case 5:
    1132:                 return $this->getFile();
    1133:                 break;
    1134:             case 6:
    1135:                 return $this->getPosition();
    1136:                 break;
    1137:             case 7:
    1138:                 return $this->getCreatedAt();
    1139:                 break;
    1140:             case 8:
    1141:                 return $this->getUpdatedAt();
    1142:                 break;
    1143:             default:
    1144:                 return null;
    1145:                 break;
    1146:         } // switch()
    1147:     }
    1148:
    1149:     /**
    1150:      * Exports the object as an array.
    1151:      *
    1152:      * You can specify the key type of the array by passing one of the class
    1153:      * type constants.
    1154:      *
    1155:      * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    1156:      *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1157:      *                    Defaults to BasePeer::TYPE_PHPNAME.
    1158:      * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
    1159:      * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
    1160:      * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
    1161:      *
    1162:      * @return array an associative array containing the field names (as keys) and field values
    1163:      */
    1164:     public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
    1165:     {
    1166:         if (isset($alreadyDumpedObjects['Document'][$this->getPrimaryKey()])) {
    1167:             return '*RECURSION*';
    1168:         }
    1169:         $alreadyDumpedObjects['Document'][$this->getPrimaryKey()] = true;
    1170:         $keys = DocumentPeer::getFieldNames($keyType);
    1171:         $result = array(
    1172:             $keys[0] => $this->getId(),
    1173:             $keys[1] => $this->getProductId(),
    1174:             $keys[2] => $this->getCategoryId(),
    1175:             $keys[3] => $this->getFolderId(),
    1176:             $keys[4] => $this->getContentId(),
    1177:             $keys[5] => $this->getFile(),
    1178:             $keys[6] => $this->getPosition(),
    1179:             $keys[7] => $this->getCreatedAt(),
    1180:             $keys[8] => $this->getUpdatedAt(),
    1181:         );
    1182:         if ($includeForeignObjects) {
    1183:             if (null !== $this->aProduct) {
    1184:                 $result['Product'] = $this->aProduct->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
    1185:             }
    1186:             if (null !== $this->aCategory) {
    1187:                 $result['Category'] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
    1188:             }
    1189:             if (null !== $this->aContent) {
    1190:                 $result['Content'] = $this->aContent->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
    1191:             }
    1192:             if (null !== $this->aFolder) {
    1193:                 $result['Folder'] = $this->aFolder->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
    1194:             }
    1195:             if (null !== $this->collDocumentI18ns) {
    1196:                 $result['DocumentI18ns'] = $this->collDocumentI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1197:             }
    1198:         }
    1199:
    1200:         return $result;
    1201:     }
    1202:
    1203:     /**
    1204:      * Sets a field from the object by name passed in as a string.
    1205:      *
    1206:      * @param string $name peer name
    1207:      * @param mixed $value field value
    1208:      * @param string $type The type of fieldname the $name is of:
    1209:      *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
    1210:      *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1211:      *                     Defaults to BasePeer::TYPE_PHPNAME
    1212:      * @return void
    1213:      */
    1214:     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
    1215:     {
    1216:         $pos = DocumentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
    1217:
    1218:         $this->setByPosition($pos, $value);
    1219:     }
    1220:
    1221:     /**
    1222:      * Sets a field from the object by Position as specified in the xml schema.
    1223:      * Zero-based.
    1224:      *
    1225:      * @param int $pos position in xml schema
    1226:      * @param mixed $value field value
    1227:      * @return void
    1228:      */
    1229:     public function setByPosition($pos, $value)
    1230:     {
    1231:         switch ($pos) {
    1232:             case 0:
    1233:                 $this->setId($value);
    1234:                 break;
    1235:             case 1:
    1236:                 $this->setProductId($value);
    1237:                 break;
    1238:             case 2:
    1239:                 $this->setCategoryId($value);
    1240:                 break;
    1241:             case 3:
    1242:                 $this->setFolderId($value);
    1243:                 break;
    1244:             case 4:
    1245:                 $this->setContentId($value);
    1246:                 break;
    1247:             case 5:
    1248:                 $this->setFile($value);
    1249:                 break;
    1250:             case 6:
    1251:                 $this->setPosition($value);
    1252:                 break;
    1253:             case 7:
    1254:                 $this->setCreatedAt($value);
    1255:                 break;
    1256:             case 8:
    1257:                 $this->setUpdatedAt($value);
    1258:                 break;
    1259:         } // switch()
    1260:     }
    1261:
    1262:     /**
    1263:      * Populates the object using an array.
    1264:      *
    1265:      * This is particularly useful when populating an object from one of the
    1266:      * request arrays (e.g. $_POST).  This method goes through the column
    1267:      * names, checking to see whether a matching key exists in populated
    1268:      * array. If so the setByName() method is called for that column.
    1269:      *
    1270:      * You can specify the key type of the array by additionally passing one
    1271:      * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    1272:      * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1273:      * The default key type is the column's BasePeer::TYPE_PHPNAME
    1274:      *
    1275:      * @param array  $arr     An array to populate the object from.
    1276:      * @param string $keyType The type of keys the array uses.
    1277:      * @return void
    1278:      */
    1279:     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    1280:     {
    1281:         $keys = DocumentPeer::getFieldNames($keyType);
    1282:
    1283:         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
    1284:         if (array_key_exists($keys[1], $arr)) $this->setProductId($arr[$keys[1]]);
    1285:         if (array_key_exists($keys[2], $arr)) $this->setCategoryId($arr[$keys[2]]);
    1286:         if (array_key_exists($keys[3], $arr)) $this->setFolderId($arr[$keys[3]]);
    1287:         if (array_key_exists($keys[4], $arr)) $this->setContentId($arr[$keys[4]]);
    1288:         if (array_key_exists($keys[5], $arr)) $this->setFile($arr[$keys[5]]);
    1289:         if (array_key_exists($keys[6], $arr)) $this->setPosition($arr[$keys[6]]);
    1290:         if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]);
    1291:         if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]);
    1292:     }
    1293:
    1294:     /**
    1295:      * Build a Criteria object containing the values of all modified columns in this object.
    1296:      *
    1297:      * @return Criteria The Criteria object containing all modified values.
    1298:      */
    1299:     public function buildCriteria()
    1300:     {
    1301:         $criteria = new Criteria(DocumentPeer::DATABASE_NAME);
    1302:
    1303:         if ($this->isColumnModified(DocumentPeer::ID)) $criteria->add(DocumentPeer::ID, $this->id);
    1304:         if ($this->isColumnModified(DocumentPeer::PRODUCT_ID)) $criteria->add(DocumentPeer::PRODUCT_ID, $this->product_id);
    1305:         if ($this->isColumnModified(DocumentPeer::CATEGORY_ID)) $criteria->add(DocumentPeer::CATEGORY_ID, $this->category_id);
    1306:         if ($this->isColumnModified(DocumentPeer::FOLDER_ID)) $criteria->add(DocumentPeer::FOLDER_ID, $this->folder_id);
    1307:         if ($this->isColumnModified(DocumentPeer::CONTENT_ID)) $criteria->add(DocumentPeer::CONTENT_ID, $this->content_id);
    1308:         if ($this->isColumnModified(DocumentPeer::FILE)) $criteria->add(DocumentPeer::FILE, $this->file);
    1309:         if ($this->isColumnModified(DocumentPeer::POSITION)) $criteria->add(DocumentPeer::POSITION, $this->position);
    1310:         if ($this->isColumnModified(DocumentPeer::CREATED_AT)) $criteria->add(DocumentPeer::CREATED_AT, $this->created_at);
    1311:         if ($this->isColumnModified(DocumentPeer::UPDATED_AT)) $criteria->add(DocumentPeer::UPDATED_AT, $this->updated_at);
    1312:
    1313:         return $criteria;
    1314:     }
    1315:
    1316:     /**
    1317:      * Builds a Criteria object containing the primary key for this object.
    1318:      *
    1319:      * Unlike buildCriteria() this method includes the primary key values regardless
    1320:      * of whether or not they have been modified.
    1321:      *
    1322:      * @return Criteria The Criteria object containing value(s) for primary key(s).
    1323:      */
    1324:     public function buildPkeyCriteria()
    1325:     {
    1326:         $criteria = new Criteria(DocumentPeer::DATABASE_NAME);
    1327:         $criteria->add(DocumentPeer::ID, $this->id);
    1328:
    1329:         return $criteria;
    1330:     }
    1331:
    1332:     /**
    1333:      * Returns the primary key for this object (row).
    1334:      * @return int
    1335:      */
    1336:     public function getPrimaryKey()
    1337:     {
    1338:         return $this->getId();
    1339:     }
    1340:
    1341:     /**
    1342:      * Generic method to set the primary key (id column).
    1343:      *
    1344:      * @param  int $key Primary key.
    1345:      * @return void
    1346:      */
    1347:     public function setPrimaryKey($key)
    1348:     {
    1349:         $this->setId($key);
    1350:     }
    1351:
    1352:     /**
    1353:      * Returns true if the primary key for this object is null.
    1354:      * @return boolean
    1355:      */
    1356:     public function isPrimaryKeyNull()
    1357:     {
    1358:
    1359:         return null === $this->getId();
    1360:     }
    1361:
    1362:     /**
    1363:      * Sets contents of passed object to values from current object.
    1364:      *
    1365:      * If desired, this method can also make copies of all associated (fkey referrers)
    1366:      * objects.
    1367:      *
    1368:      * @param object $copyObj An object of Document (or compatible) type.
    1369:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1370:      * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
    1371:      * @throws PropelException
    1372:      */
    1373:     public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    1374:     {
    1375:         $copyObj->setProductId($this->getProductId());
    1376:         $copyObj->setCategoryId($this->getCategoryId());
    1377:         $copyObj->setFolderId($this->getFolderId());
    1378:         $copyObj->setContentId($this->getContentId());
    1379:         $copyObj->setFile($this->getFile());
    1380:         $copyObj->setPosition($this->getPosition());
    1381:         $copyObj->setCreatedAt($this->getCreatedAt());
    1382:         $copyObj->setUpdatedAt($this->getUpdatedAt());
    1383:
    1384:         if ($deepCopy && !$this->startCopy) {
    1385:             // important: temporarily setNew(false) because this affects the behavior of
    1386:             // the getter/setter methods for fkey referrer objects.
    1387:             $copyObj->setNew(false);
    1388:             // store object hash to prevent cycle
    1389:             $this->startCopy = true;
    1390:
    1391:             foreach ($this->getDocumentI18ns() as $relObj) {
    1392:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1393:                     $copyObj->addDocumentI18n($relObj->copy($deepCopy));
    1394:                 }
    1395:             }
    1396:
    1397:             //unflag object copy
    1398:             $this->startCopy = false;
    1399:         } // if ($deepCopy)
    1400:
    1401:         if ($makeNew) {
    1402:             $copyObj->setNew(true);
    1403:             $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
    1404:         }
    1405:     }
    1406:
    1407:     /**
    1408:      * Makes a copy of this object that will be inserted as a new row in table when saved.
    1409:      * It creates a new object filling in the simple attributes, but skipping any primary
    1410:      * keys that are defined for the table.
    1411:      *
    1412:      * If desired, this method can also make copies of all associated (fkey referrers)
    1413:      * objects.
    1414:      *
    1415:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1416:      * @return Document Clone of current object.
    1417:      * @throws PropelException
    1418:      */
    1419:     public function copy($deepCopy = false)
    1420:     {
    1421:         // we use get_class(), because this might be a subclass
    1422:         $clazz = get_class($this);
    1423:         $copyObj = new $clazz();
    1424:         $this->copyInto($copyObj, $deepCopy);
    1425:
    1426:         return $copyObj;
    1427:     }
    1428:
    1429:     /**
    1430:      * Returns a peer instance associated with this om.
    1431:      *
    1432:      * Since Peer classes are not to have any instance attributes, this method returns the
    1433:      * same instance for all member of this class. The method could therefore
    1434:      * be static, but this would prevent one from overriding the behavior.
    1435:      *
    1436:      * @return DocumentPeer
    1437:      */
    1438:     public function getPeer()
    1439:     {
    1440:         if (self::$peer === null) {
    1441:             self::$peer = new DocumentPeer();
    1442:         }
    1443:
    1444:         return self::$peer;
    1445:     }
    1446:
    1447:     /**
    1448:      * Declares an association between this object and a Product object.
    1449:      *
    1450:      * @param             Product $v
    1451:      * @return Document The current object (for fluent API support)
    1452:      * @throws PropelException
    1453:      */
    1454:     public function setProduct(Product $v = null)
    1455:     {
    1456:         if ($v === null) {
    1457:             $this->setProductId(NULL);
    1458:         } else {
    1459:             $this->setProductId($v->getId());
    1460:         }
    1461:
    1462:         $this->aProduct = $v;
    1463:
    1464:         // Add binding for other direction of this n:n relationship.
    1465:         // If this object has already been added to the Product object, it will not be re-added.
    1466:         if ($v !== null) {
    1467:             $v->addDocument($this);
    1468:         }
    1469:
    1470:
    1471:         return $this;
    1472:     }
    1473:
    1474:
    1475:     /**
    1476:      * Get the associated Product object
    1477:      *
    1478:      * @param PropelPDO $con Optional Connection object.
    1479:      * @param $doQuery Executes a query to get the object if required
    1480:      * @return Product The associated Product object.
    1481:      * @throws PropelException
    1482:      */
    1483:     public function getProduct(PropelPDO $con = null, $doQuery = true)
    1484:     {
    1485:         if ($this->aProduct === null && ($this->product_id !== null) && $doQuery) {
    1486:             $this->aProduct = ProductQuery::create()->findPk($this->product_id, $con);
    1487:             /* The following can be used additionally to
    1488:                 guarantee the related object contains a reference
    1489:                 to this object.  This level of coupling may, however, be
    1490:                 undesirable since it could result in an only partially populated collection
    1491:                 in the referenced object.
    1492:                 $this->aProduct->addDocuments($this);
    1493:              */
    1494:         }
    1495:
    1496:         return $this->aProduct;
    1497:     }
    1498:
    1499:     /**
    1500:      * Declares an association between this object and a Category object.
    1501:      *
    1502:      * @param             Category $v
    1503:      * @return Document The current object (for fluent API support)
    1504:      * @throws PropelException
    1505:      */
    1506:     public function setCategory(Category $v = null)
    1507:     {
    1508:         if ($v === null) {
    1509:             $this->setCategoryId(NULL);
    1510:         } else {
    1511:             $this->setCategoryId($v->getId());
    1512:         }
    1513:
    1514:         $this->aCategory = $v;
    1515:
    1516:         // Add binding for other direction of this n:n relationship.
    1517:         // If this object has already been added to the Category object, it will not be re-added.
    1518:         if ($v !== null) {
    1519:             $v->addDocument($this);
    1520:         }
    1521:
    1522:
    1523:         return $this;
    1524:     }
    1525:
    1526:
    1527:     /**
    1528:      * Get the associated Category object
    1529:      *
    1530:      * @param PropelPDO $con Optional Connection object.
    1531:      * @param $doQuery Executes a query to get the object if required
    1532:      * @return Category The associated Category object.
    1533:      * @throws PropelException
    1534:      */
    1535:     public function getCategory(PropelPDO $con = null, $doQuery = true)
    1536:     {
    1537:         if ($this->aCategory === null && ($this->category_id !== null) && $doQuery) {
    1538:             $this->aCategory = CategoryQuery::create()->findPk($this->category_id, $con);
    1539:             /* The following can be used additionally to
    1540:                 guarantee the related object contains a reference
    1541:                 to this object.  This level of coupling may, however, be
    1542:                 undesirable since it could result in an only partially populated collection
    1543:                 in the referenced object.
    1544:                 $this->aCategory->addDocuments($this);
    1545:              */
    1546:         }
    1547:
    1548:         return $this->aCategory;
    1549:     }
    1550:
    1551:     /**
    1552:      * Declares an association between this object and a Content object.
    1553:      *
    1554:      * @param             Content $v
    1555:      * @return Document The current object (for fluent API support)
    1556:      * @throws PropelException
    1557:      */
    1558:     public function setContent(Content $v = null)
    1559:     {
    1560:         if ($v === null) {
    1561:             $this->setContentId(NULL);
    1562:         } else {
    1563:             $this->setContentId($v->getId());
    1564:         }
    1565:
    1566:         $this->aContent = $v;
    1567:
    1568:         // Add binding for other direction of this n:n relationship.
    1569:         // If this object has already been added to the Content object, it will not be re-added.
    1570:         if ($v !== null) {
    1571:             $v->addDocument($this);
    1572:         }
    1573:
    1574:
    1575:         return $this;
    1576:     }
    1577:
    1578:
    1579:     /**
    1580:      * Get the associated Content object
    1581:      *
    1582:      * @param PropelPDO $con Optional Connection object.
    1583:      * @param $doQuery Executes a query to get the object if required
    1584:      * @return Content The associated Content object.
    1585:      * @throws PropelException
    1586:      */
    1587:     public function getContent(PropelPDO $con = null, $doQuery = true)
    1588:     {
    1589:         if ($this->aContent === null && ($this->content_id !== null) && $doQuery) {
    1590:             $this->aContent = ContentQuery::create()->findPk($this->content_id, $con);
    1591:             /* The following can be used additionally to
    1592:                 guarantee the related object contains a reference
    1593:                 to this object.  This level of coupling may, however, be
    1594:                 undesirable since it could result in an only partially populated collection
    1595:                 in the referenced object.
    1596:                 $this->aContent->addDocuments($this);
    1597:              */
    1598:         }
    1599:
    1600:         return $this->aContent;
    1601:     }
    1602:
    1603:     /**
    1604:      * Declares an association between this object and a Folder object.
    1605:      *
    1606:      * @param             Folder $v
    1607:      * @return Document The current object (for fluent API support)
    1608:      * @throws PropelException
    1609:      */
    1610:     public function setFolder(Folder $v = null)
    1611:     {
    1612:         if ($v === null) {
    1613:             $this->setFolderId(NULL);
    1614:         } else {
    1615:             $this->setFolderId($v->getId());
    1616:         }
    1617:
    1618:         $this->aFolder = $v;
    1619:
    1620:         // Add binding for other direction of this n:n relationship.
    1621:         // If this object has already been added to the Folder object, it will not be re-added.
    1622:         if ($v !== null) {
    1623:             $v->addDocument($this);
    1624:         }
    1625:
    1626:
    1627:         return $this;
    1628:     }
    1629:
    1630:
    1631:     /**
    1632:      * Get the associated Folder object
    1633:      *
    1634:      * @param PropelPDO $con Optional Connection object.
    1635:      * @param $doQuery Executes a query to get the object if required
    1636:      * @return Folder The associated Folder object.
    1637:      * @throws PropelException
    1638:      */
    1639:     public function getFolder(PropelPDO $con = null, $doQuery = true)
    1640:     {
    1641:         if ($this->aFolder === null && ($this->folder_id !== null) && $doQuery) {
    1642:             $this->aFolder = FolderQuery::create()->findPk($this->folder_id, $con);
    1643:             /* The following can be used additionally to
    1644:                 guarantee the related object contains a reference
    1645:                 to this object.  This level of coupling may, however, be
    1646:                 undesirable since it could result in an only partially populated collection
    1647:                 in the referenced object.
    1648:                 $this->aFolder->addDocuments($this);
    1649:              */
    1650:         }
    1651:
    1652:         return $this->aFolder;
    1653:     }
    1654:
    1655:
    1656:     /**
    1657:      * Initializes a collection based on the name of a relation.
    1658:      * Avoids crafting an 'init[$relationName]s' method name
    1659:      * that wouldn't work when StandardEnglishPluralizer is used.
    1660:      *
    1661:      * @param string $relationName The name of the relation to initialize
    1662:      * @return void
    1663:      */
    1664:     public function initRelation($relationName)
    1665:     {
    1666:         if ('DocumentI18n' == $relationName) {
    1667:             $this->initDocumentI18ns();
    1668:         }
    1669:     }
    1670:
    1671:     /**
    1672:      * Clears out the collDocumentI18ns collection
    1673:      *
    1674:      * This does not modify the database; however, it will remove any associated objects, causing
    1675:      * them to be refetched by subsequent calls to accessor method.
    1676:      *
    1677:      * @return Document The current object (for fluent API support)
    1678:      * @see        addDocumentI18ns()
    1679:      */
    1680:     public function clearDocumentI18ns()
    1681:     {
    1682:         $this->collDocumentI18ns = null; // important to set this to null since that means it is uninitialized
    1683:         $this->collDocumentI18nsPartial = null;
    1684:
    1685:         return $this;
    1686:     }
    1687:
    1688:     /**
    1689:      * reset is the collDocumentI18ns collection loaded partially
    1690:      *
    1691:      * @return void
    1692:      */
    1693:     public function resetPartialDocumentI18ns($v = true)
    1694:     {
    1695:         $this->collDocumentI18nsPartial = $v;
    1696:     }
    1697:
    1698:     /**
    1699:      * Initializes the collDocumentI18ns collection.
    1700:      *
    1701:      * By default this just sets the collDocumentI18ns collection to an empty array (like clearcollDocumentI18ns());
    1702:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1703:      * to your application -- for example, setting the initial array to the values stored in database.
    1704:      *
    1705:      * @param boolean $overrideExisting If set to true, the method call initializes
    1706:      *                                        the collection even if it is not empty
    1707:      *
    1708:      * @return void
    1709:      */
    1710:     public function initDocumentI18ns($overrideExisting = true)
    1711:     {
    1712:         if (null !== $this->collDocumentI18ns && !$overrideExisting) {
    1713:             return;
    1714:         }
    1715:         $this->collDocumentI18ns = new PropelObjectCollection();
    1716:         $this->collDocumentI18ns->setModel('DocumentI18n');
    1717:     }
    1718:
    1719:     /**
    1720:      * Gets an array of DocumentI18n objects which contain a foreign key that references this object.
    1721:      *
    1722:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1723:      * Otherwise the results are fetched from the database the first time, then cached.
    1724:      * Next time the same method is called without $criteria, the cached collection is returned.
    1725:      * If this Document is new, it will return
    1726:      * an empty collection or the current collection; the criteria is ignored on a new object.
    1727:      *
    1728:      * @param Criteria $criteria optional Criteria object to narrow the query
    1729:      * @param PropelPDO $con optional connection object
    1730:      * @return PropelObjectCollection|DocumentI18n[] List of DocumentI18n objects
    1731:      * @throws PropelException
    1732:      */
    1733:     public function getDocumentI18ns($criteria = null, PropelPDO $con = null)
    1734:     {
    1735:         $partial = $this->collDocumentI18nsPartial && !$this->isNew();
    1736:         if (null === $this->collDocumentI18ns || null !== $criteria  || $partial) {
    1737:             if ($this->isNew() && null === $this->collDocumentI18ns) {
    1738:                 // return empty collection
    1739:                 $this->initDocumentI18ns();
    1740:             } else {
    1741:                 $collDocumentI18ns = DocumentI18nQuery::create(null, $criteria)
    1742:                     ->filterByDocument($this)
    1743:                     ->find($con);
    1744:                 if (null !== $criteria) {
    1745:                     if (false !== $this->collDocumentI18nsPartial && count($collDocumentI18ns)) {
    1746:                       $this->initDocumentI18ns(false);
    1747:
    1748:                       foreach($collDocumentI18ns as $obj) {
    1749:                         if (false == $this->collDocumentI18ns->contains($obj)) {
    1750:                           $this->collDocumentI18ns->append($obj);
    1751:                         }
    1752:                       }
    1753:
    1754:                       $this->collDocumentI18nsPartial = true;
    1755:                     }
    1756:
    1757:                     $collDocumentI18ns->getInternalIterator()->rewind();
    1758:                     return $collDocumentI18ns;
    1759:                 }
    1760:
    1761:                 if($partial && $this->collDocumentI18ns) {
    1762:                     foreach($this->collDocumentI18ns as $obj) {
    1763:                         if($obj->isNew()) {
    1764:                             $collDocumentI18ns[] = $obj;
    1765:                         }
    1766:                     }
    1767:                 }
    1768:
    1769:                 $this->collDocumentI18ns = $collDocumentI18ns;
    1770:                 $this->collDocumentI18nsPartial = false;
    1771:             }
    1772:         }
    1773:
    1774:         return $this->collDocumentI18ns;
    1775:     }
    1776:
    1777:     /**
    1778:      * Sets a collection of DocumentI18n objects related by a one-to-many relationship
    1779:      * to the current object.
    1780:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    1781:      * and new objects from the given Propel collection.
    1782:      *
    1783:      * @param PropelCollection $documentI18ns A Propel collection.
    1784:      * @param PropelPDO $con Optional connection object
    1785:      * @return Document The current object (for fluent API support)
    1786:      */
    1787:     public function setDocumentI18ns(PropelCollection $documentI18ns, PropelPDO $con = null)
    1788:     {
    1789:         $documentI18nsToDelete = $this->getDocumentI18ns(new Criteria(), $con)->diff($documentI18ns);
    1790:
    1791:         $this->documentI18nsScheduledForDeletion = unserialize(serialize($documentI18nsToDelete));
    1792:
    1793:         foreach ($documentI18nsToDelete as $documentI18nRemoved) {
    1794:             $documentI18nRemoved->setDocument(null);
    1795:         }
    1796:
    1797:         $this->collDocumentI18ns = null;
    1798:         foreach ($documentI18ns as $documentI18n) {
    1799:             $this->addDocumentI18n($documentI18n);
    1800:         }
    1801:
    1802:         $this->collDocumentI18ns = $documentI18ns;
    1803:         $this->collDocumentI18nsPartial = false;
    1804:
    1805:         return $this;
    1806:     }
    1807:
    1808:     /**
    1809:      * Returns the number of related DocumentI18n objects.
    1810:      *
    1811:      * @param Criteria $criteria
    1812:      * @param boolean $distinct
    1813:      * @param PropelPDO $con
    1814:      * @return int             Count of related DocumentI18n objects.
    1815:      * @throws PropelException
    1816:      */
    1817:     public function countDocumentI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    1818:     {
    1819:         $partial = $this->collDocumentI18nsPartial && !$this->isNew();
    1820:         if (null === $this->collDocumentI18ns || null !== $criteria || $partial) {
    1821:             if ($this->isNew() && null === $this->collDocumentI18ns) {
    1822:                 return 0;
    1823:             }
    1824:
    1825:             if($partial && !$criteria) {
    1826:                 return count($this->getDocumentI18ns());
    1827:             }
    1828:             $query = DocumentI18nQuery::create(null, $criteria);
    1829:             if ($distinct) {
    1830:                 $query->distinct();
    1831:             }
    1832:
    1833:             return $query
    1834:                 ->filterByDocument($this)
    1835:                 ->count($con);
    1836:         }
    1837:
    1838:         return count($this->collDocumentI18ns);
    1839:     }
    1840:
    1841:     /**
    1842:      * Method called to associate a DocumentI18n object to this object
    1843:      * through the DocumentI18n foreign key attribute.
    1844:      *
    1845:      * @param    DocumentI18n $l DocumentI18n
    1846:      * @return Document The current object (for fluent API support)
    1847:      */
    1848:     public function addDocumentI18n(DocumentI18n $l)
    1849:     {
    1850:         if ($l && $locale = $l->getLocale()) {
    1851:             $this->setLocale($locale);
    1852:             $this->currentTranslations[$locale] = $l;
    1853:         }
    1854:         if ($this->collDocumentI18ns === null) {
    1855:             $this->initDocumentI18ns();
    1856:             $this->collDocumentI18nsPartial = true;
    1857:         }
    1858:         if (!in_array($l, $this->collDocumentI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    1859:             $this->doAddDocumentI18n($l);
    1860:         }
    1861:
    1862:         return $this;
    1863:     }
    1864:
    1865:     /**
    1866:      * @param   DocumentI18n $documentI18n The documentI18n object to add.
    1867:      */
    1868:     protected function doAddDocumentI18n($documentI18n)
    1869:     {
    1870:         $this->collDocumentI18ns[]= $documentI18n;
    1871:         $documentI18n->setDocument($this);
    1872:     }
    1873:
    1874:     /**
    1875:      * @param   DocumentI18n $documentI18n The documentI18n object to remove.
    1876:      * @return Document The current object (for fluent API support)
    1877:      */
    1878:     public function removeDocumentI18n($documentI18n)
    1879:     {
    1880:         if ($this->getDocumentI18ns()->contains($documentI18n)) {
    1881:             $this->collDocumentI18ns->remove($this->collDocumentI18ns->search($documentI18n));
    1882:             if (null === $this->documentI18nsScheduledForDeletion) {
    1883:                 $this->documentI18nsScheduledForDeletion = clone $this->collDocumentI18ns;
    1884:                 $this->documentI18nsScheduledForDeletion->clear();
    1885:             }
    1886:             $this->documentI18nsScheduledForDeletion[]= clone $documentI18n;
    1887:             $documentI18n->setDocument(null);
    1888:         }
    1889:
    1890:         return $this;
    1891:     }
    1892:
    1893:     /**
    1894:      * Clears the current object and sets all attributes to their default values
    1895:      */
    1896:     public function clear()
    1897:     {
    1898:         $this->id = null;
    1899:         $this->product_id = null;
    1900:         $this->category_id = null;
    1901:         $this->folder_id = null;
    1902:         $this->content_id = null;
    1903:         $this->file = null;
    1904:         $this->position = null;
    1905:         $this->created_at = null;
    1906:         $this->updated_at = null;
    1907:         $this->alreadyInSave = false;
    1908:         $this->alreadyInValidation = false;
    1909:         $this->alreadyInClearAllReferencesDeep = false;
    1910:         $this->clearAllReferences();
    1911:         $this->resetModified();
    1912:         $this->setNew(true);
    1913:         $this->setDeleted(false);
    1914:     }
    1915:
    1916:     /**
    1917:      * Resets all references to other model objects or collections of model objects.
    1918:      *
    1919:      * This method is a user-space workaround for PHP's inability to garbage collect
    1920:      * objects with circular references (even in PHP 5.3). This is currently necessary
    1921:      * when using Propel in certain daemon or large-volumne/high-memory operations.
    1922:      *
    1923:      * @param boolean $deep Whether to also clear the references on all referrer objects.
    1924:      */
    1925:     public function clearAllReferences($deep = false)
    1926:     {
    1927:         if ($deep && !$this->alreadyInClearAllReferencesDeep) {
    1928:             $this->alreadyInClearAllReferencesDeep = true;
    1929:             if ($this->collDocumentI18ns) {
    1930:                 foreach ($this->collDocumentI18ns as $o) {
    1931:                     $o->clearAllReferences($deep);
    1932:                 }
    1933:             }
    1934:             if ($this->aProduct instanceof Persistent) {
    1935:               $this->aProduct->clearAllReferences($deep);
    1936:             }
    1937:             if ($this->aCategory instanceof Persistent) {
    1938:               $this->aCategory->clearAllReferences($deep);
    1939:             }
    1940:             if ($this->aContent instanceof Persistent) {
    1941:               $this->aContent->clearAllReferences($deep);
    1942:             }
    1943:             if ($this->aFolder instanceof Persistent) {
    1944:               $this->aFolder->clearAllReferences($deep);
    1945:             }
    1946:
    1947:             $this->alreadyInClearAllReferencesDeep = false;
    1948:         } // if ($deep)
    1949:
    1950:         // i18n behavior
    1951:         $this->currentLocale = 'en_US';
    1952:         $this->currentTranslations = null;
    1953:
    1954:         if ($this->collDocumentI18ns instanceof PropelCollection) {
    1955:             $this->collDocumentI18ns->clearIterator();
    1956:         }
    1957:         $this->collDocumentI18ns = null;
    1958:         $this->aProduct = null;
    1959:         $this->aCategory = null;
    1960:         $this->aContent = null;
    1961:         $this->aFolder = null;
    1962:     }
    1963:
    1964:     /**
    1965:      * return the string representation of this object
    1966:      *
    1967:      * @return string
    1968:      */
    1969:     public function __toString()
    1970:     {
    1971:         return (string) $this->exportTo(DocumentPeer::DEFAULT_STRING_FORMAT);
    1972:     }
    1973:
    1974:     /**
    1975:      * return true is the object is in saving state
    1976:      *
    1977:      * @return boolean
    1978:      */
    1979:     public function isAlreadyInSave()
    1980:     {
    1981:         return $this->alreadyInSave;
    1982:     }
    1983:
    1984:     // timestampable behavior
    1985:
    1986:     /**
    1987:      * Mark the current object so that the update date doesn't get updated during next save
    1988:      *
    1989:      * @return     Document The current object (for fluent API support)
    1990:      */
    1991:     public function keepUpdateDateUnchanged()
    1992:     {
    1993:         $this->modifiedColumns[] = DocumentPeer::UPDATED_AT;
    1994:
    1995:         return $this;
    1996:     }
    1997:
    1998:     // i18n behavior
    1999:
    2000:     /**
    2001:      * Sets the locale for translations
    2002:      *
    2003:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2004:      *
    2005:      * @return    Document The current object (for fluent API support)
    2006:      */
    2007:     public function setLocale($locale = 'en_US')
    2008:     {
    2009:         $this->currentLocale = $locale;
    2010:
    2011:         return $this;
    2012:     }
    2013:
    2014:     /**
    2015:      * Gets the locale for translations
    2016:      *
    2017:      * @return    string $locale Locale to use for the translation, e.g. 'fr_FR'
    2018:      */
    2019:     public function getLocale()
    2020:     {
    2021:         return $this->currentLocale;
    2022:     }
    2023:
    2024:     /**
    2025:      * Returns the current translation for a given locale
    2026:      *
    2027:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2028:      * @param     PropelPDO $con an optional connection object
    2029:      *
    2030:      * @return DocumentI18n */
    2031:     public function getTranslation($locale = 'en_US', PropelPDO $con = null)
    2032:     {
    2033:         if (!isset($this->currentTranslations[$locale])) {
    2034:             if (null !== $this->collDocumentI18ns) {
    2035:                 foreach ($this->collDocumentI18ns as $translation) {
    2036:                     if ($translation->getLocale() == $locale) {
    2037:                         $this->currentTranslations[$locale] = $translation;
    2038:
    2039:                         return $translation;
    2040:                     }
    2041:                 }
    2042:             }
    2043:             if ($this->isNew()) {
    2044:                 $translation = new DocumentI18n();
    2045:                 $translation->setLocale($locale);
    2046:             } else {
    2047:                 $translation = DocumentI18nQuery::create()
    2048:                     ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    2049:                     ->findOneOrCreate($con);
    2050:                 $this->currentTranslations[$locale] = $translation;
    2051:             }
    2052:             $this->addDocumentI18n($translation);
    2053:         }
    2054:
    2055:         return $this->currentTranslations[$locale];
    2056:     }
    2057:
    2058:     /**
    2059:      * Remove the translation for a given locale
    2060:      *
    2061:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2062:      * @param     PropelPDO $con an optional connection object
    2063:      *
    2064:      * @return    Document The current object (for fluent API support)
    2065:      */
    2066:     public function removeTranslation($locale = 'en_US', PropelPDO $con = null)
    2067:     {
    2068:         if (!$this->isNew()) {
    2069:             DocumentI18nQuery::create()
    2070:                 ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    2071:                 ->delete($con);
    2072:         }
    2073:         if (isset($this->currentTranslations[$locale])) {
    2074:             unset($this->currentTranslations[$locale]);
    2075:         }
    2076:         foreach ($this->collDocumentI18ns as $key => $translation) {
    2077:             if ($translation->getLocale() == $locale) {
    2078:                 unset($this->collDocumentI18ns[$key]);
    2079:                 break;
    2080:             }
    2081:         }
    2082:
    2083:         return $this;
    2084:     }
    2085:
    2086:     /**
    2087:      * Returns the current translation
    2088:      *
    2089:      * @param     PropelPDO $con an optional connection object
    2090:      *
    2091:      * @return DocumentI18n */
    2092:     public function getCurrentTranslation(PropelPDO $con = null)
    2093:     {
    2094:         return $this->getTranslation($this->getLocale(), $con);
    2095:     }
    2096:
    2097:
    2098:         /**
    2099:          * Get the [title] column value.
    2100:          *
    2101:          * @return string
    2102:          */
    2103:         public function getTitle()
    2104:         {
    2105:         return $this->getCurrentTranslation()->getTitle();
    2106:     }
    2107:
    2108:
    2109:         /**
    2110:          * Set the value of [title] column.
    2111:          *
    2112:          * @param string $v new value
    2113:          * @return DocumentI18n The current object (for fluent API support)
    2114:          */
    2115:         public function setTitle($v)
    2116:         {    $this->getCurrentTranslation()->setTitle($v);
    2117:
    2118:         return $this;
    2119:     }
    2120:
    2121:
    2122:         /**
    2123:          * Get the [description] column value.
    2124:          *
    2125:          * @return string
    2126:          */
    2127:         public function getDescription()
    2128:         {
    2129:         return $this->getCurrentTranslation()->getDescription();
    2130:     }
    2131:
    2132:
    2133:         /**
    2134:          * Set the value of [description] column.
    2135:          *
    2136:          * @param string $v new value
    2137:          * @return DocumentI18n The current object (for fluent API support)
    2138:          */
    2139:         public function setDescription($v)
    2140:         {    $this->getCurrentTranslation()->setDescription($v);
    2141:
    2142:         return $this;
    2143:     }
    2144:
    2145:
    2146:         /**
    2147:          * Get the [chapo] column value.
    2148:          *
    2149:          * @return string
    2150:          */
    2151:         public function getChapo()
    2152:         {
    2153:         return $this->getCurrentTranslation()->getChapo();
    2154:     }
    2155:
    2156:
    2157:         /**
    2158:          * Set the value of [chapo] column.
    2159:          *
    2160:          * @param string $v new value
    2161:          * @return DocumentI18n The current object (for fluent API support)
    2162:          */
    2163:         public function setChapo($v)
    2164:         {    $this->getCurrentTranslation()->setChapo($v);
    2165:
    2166:         return $this;
    2167:     }
    2168:
    2169:
    2170:         /**
    2171:          * Get the [postscriptum] column value.
    2172:          *
    2173:          * @return string
    2174:          */
    2175:         public function getPostscriptum()
    2176:         {
    2177:         return $this->getCurrentTranslation()->getPostscriptum();
    2178:     }
    2179:
    2180:
    2181:         /**
    2182:          * Set the value of [postscriptum] column.
    2183:          *
    2184:          * @param string $v new value
    2185:          * @return DocumentI18n The current object (for fluent API support)
    2186:          */
    2187:         public function setPostscriptum($v)
    2188:         {    $this->getCurrentTranslation()->setPostscriptum($v);
    2189:
    2190:         return $this;
    2191:     }
    2192:
    2193: }
    2194: