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