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