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