# File core/lib/Thelia/Model/om/BaseAttribute.php | thelia

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