Overview

Namespaces

  • Thelia
    • Action
    • Config
    • Controller
    • Core
      • Bundle
      • DependencyInjection
        • Compiler
        • Loader
      • Event
      • EventListener
      • Template
        • BaseParam
    • Exception
    • Log
      • Destination
    • Model
      • map
      • om
    • Routing
      • Matcher
    • Tools
    • Tpex
      • BaseParam
      • Element
        • Loop
        • TestLoop
      • Event
      • Exception
      • Filter
      • Tokenizer

Classes

  • BaseAccessory
  • BaseAccessoryPeer
  • BaseAccessoryQuery
  • BaseAddress
  • BaseAddressPeer
  • BaseAddressQuery
  • BaseAdmin
  • BaseAdminGroup
  • BaseAdminGroupPeer
  • BaseAdminGroupQuery
  • BaseAdminLog
  • BaseAdminLogPeer
  • BaseAdminLogQuery
  • BaseAdminPeer
  • BaseAdminQuery
  • BaseArea
  • BaseAreaPeer
  • BaseAreaQuery
  • BaseAttribute
  • BaseAttributeAv
  • BaseAttributeAvI18n
  • BaseAttributeAvI18nPeer
  • BaseAttributeAvI18nQuery
  • BaseAttributeAvPeer
  • BaseAttributeAvQuery
  • BaseAttributeCategory
  • BaseAttributeCategoryPeer
  • BaseAttributeCategoryQuery
  • BaseAttributeCombination
  • BaseAttributeCombinationPeer
  • BaseAttributeCombinationQuery
  • BaseAttributeI18n
  • BaseAttributeI18nPeer
  • BaseAttributeI18nQuery
  • BaseAttributePeer
  • BaseAttributeQuery
  • BaseCategory
  • BaseCategoryI18n
  • BaseCategoryI18nPeer
  • BaseCategoryI18nQuery
  • BaseCategoryPeer
  • BaseCategoryQuery
  • BaseCategoryVersion
  • BaseCategoryVersionPeer
  • BaseCategoryVersionQuery
  • BaseCombination
  • BaseCombinationPeer
  • BaseCombinationQuery
  • BaseConfig
  • BaseConfigI18n
  • BaseConfigI18nPeer
  • BaseConfigI18nQuery
  • BaseConfigPeer
  • BaseConfigQuery
  • BaseContent
  • BaseContentAssoc
  • BaseContentAssocPeer
  • BaseContentAssocQuery
  • BaseContentFolder
  • BaseContentFolderPeer
  • BaseContentFolderQuery
  • BaseContentI18n
  • BaseContentI18nPeer
  • BaseContentI18nQuery
  • BaseContentPeer
  • BaseContentQuery
  • BaseContentVersion
  • BaseContentVersionPeer
  • BaseContentVersionQuery
  • BaseCountry
  • BaseCountryI18n
  • BaseCountryI18nPeer
  • BaseCountryI18nQuery
  • BaseCountryPeer
  • BaseCountryQuery
  • BaseCoupon
  • BaseCouponOrder
  • BaseCouponOrderPeer
  • BaseCouponOrderQuery
  • BaseCouponPeer
  • BaseCouponQuery
  • BaseCouponRule
  • BaseCouponRulePeer
  • BaseCouponRuleQuery
  • BaseCurrency
  • BaseCurrencyPeer
  • BaseCurrencyQuery
  • BaseCustomer
  • BaseCustomerPeer
  • BaseCustomerQuery
  • BaseCustomerTitle
  • BaseCustomerTitleI18n
  • BaseCustomerTitleI18nPeer
  • BaseCustomerTitleI18nQuery
  • BaseCustomerTitlePeer
  • BaseCustomerTitleQuery
  • BaseDelivzone
  • BaseDelivzonePeer
  • BaseDelivzoneQuery
  • BaseDocument
  • BaseDocumentI18n
  • BaseDocumentI18nPeer
  • BaseDocumentI18nQuery
  • BaseDocumentPeer
  • BaseDocumentQuery
  • BaseFeature
  • BaseFeatureAv
  • BaseFeatureAvI18n
  • BaseFeatureAvI18nPeer
  • BaseFeatureAvI18nQuery
  • BaseFeatureAvPeer
  • BaseFeatureAvQuery
  • BaseFeatureCategory
  • BaseFeatureCategoryPeer
  • BaseFeatureCategoryQuery
  • BaseFeatureI18n
  • BaseFeatureI18nPeer
  • BaseFeatureI18nQuery
  • BaseFeaturePeer
  • BaseFeatureProd
  • BaseFeatureProdPeer
  • BaseFeatureProdQuery
  • BaseFeatureQuery
  • BaseFolder
  • BaseFolderI18n
  • BaseFolderI18nPeer
  • BaseFolderI18nQuery
  • BaseFolderPeer
  • BaseFolderQuery
  • BaseFolderVersion
  • BaseFolderVersionPeer
  • BaseFolderVersionQuery
  • BaseGroup
  • BaseGroupI18n
  • BaseGroupI18nPeer
  • BaseGroupI18nQuery
  • BaseGroupModule
  • BaseGroupModulePeer
  • BaseGroupModuleQuery
  • BaseGroupPeer
  • BaseGroupQuery
  • BaseGroupResource
  • BaseGroupResourcePeer
  • BaseGroupResourceQuery
  • BaseImage
  • BaseImageI18n
  • BaseImageI18nPeer
  • BaseImageI18nQuery
  • BaseImagePeer
  • BaseImageQuery
  • BaseLang
  • BaseLangPeer
  • BaseLangQuery
  • BaseMessage
  • BaseMessageI18n
  • BaseMessageI18nPeer
  • BaseMessageI18nQuery
  • BaseMessagePeer
  • BaseMessageQuery
  • BaseMessageVersion
  • BaseMessageVersionPeer
  • BaseMessageVersionQuery
  • BaseModule
  • BaseModuleI18n
  • BaseModuleI18nPeer
  • BaseModuleI18nQuery
  • BaseModulePeer
  • BaseModuleQuery
  • BaseOrder
  • BaseOrderAddress
  • BaseOrderAddressPeer
  • BaseOrderAddressQuery
  • BaseOrderFeature
  • BaseOrderFeaturePeer
  • BaseOrderFeatureQuery
  • BaseOrderPeer
  • BaseOrderProduct
  • BaseOrderProductPeer
  • BaseOrderProductQuery
  • BaseOrderQuery
  • BaseOrderStatus
  • BaseOrderStatusI18n
  • BaseOrderStatusI18nPeer
  • BaseOrderStatusI18nQuery
  • BaseOrderStatusPeer
  • BaseOrderStatusQuery
  • BaseProduct
  • BaseProductCategory
  • BaseProductCategoryPeer
  • BaseProductCategoryQuery
  • BaseProductI18n
  • BaseProductI18nPeer
  • BaseProductI18nQuery
  • BaseProductPeer
  • BaseProductQuery
  • BaseProductVersion
  • BaseProductVersionPeer
  • BaseProductVersionQuery
  • BaseResource
  • BaseResourceI18n
  • BaseResourceI18nPeer
  • BaseResourceI18nQuery
  • BaseResourcePeer
  • BaseResourceQuery
  • BaseRewriting
  • BaseRewritingPeer
  • BaseRewritingQuery
  • BaseStock
  • BaseStockPeer
  • BaseStockQuery
  • BaseTax
  • BaseTaxI18n
  • BaseTaxI18nPeer
  • BaseTaxI18nQuery
  • BaseTaxPeer
  • BaseTaxQuery
  • BaseTaxRule
  • BaseTaxRuleCountry
  • BaseTaxRuleCountryPeer
  • BaseTaxRuleCountryQuery
  • BaseTaxRuleI18n
  • BaseTaxRuleI18nPeer
  • BaseTaxRuleI18nQuery
  • BaseTaxRulePeer
  • BaseTaxRuleQuery
  • Overview
  • Namespace
  • Class
  • Tree
   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 \PropelDateTime;
  14: use \PropelException;
  15: use \PropelPDO;
  16: use Thelia\Model\Combination;
  17: use Thelia\Model\CombinationQuery;
  18: use Thelia\Model\Product;
  19: use Thelia\Model\ProductQuery;
  20: use Thelia\Model\Stock;
  21: use Thelia\Model\StockPeer;
  22: use Thelia\Model\StockQuery;
  23: 
  24: /**
  25:  * Base class that represents a row from the 'stock' table.
  26:  *
  27:  *
  28:  *
  29:  * @package    propel.generator.Thelia.Model.om
  30:  */
  31: abstract class BaseStock extends BaseObject implements Persistent
  32: {
  33:     /**
  34:      * Peer class name
  35:      */
  36:     const PEER = 'Thelia\\Model\\StockPeer';
  37: 
  38:     /**
  39:      * The Peer class.
  40:      * Instance provides a convenient way of calling static methods on a class
  41:      * that calling code may not be able to identify.
  42:      * @var        StockPeer
  43:      */
  44:     protected static $peer;
  45: 
  46:     /**
  47:      * The flag var to prevent infinit loop in deep copy
  48:      * @var       boolean
  49:      */
  50:     protected $startCopy = false;
  51: 
  52:     /**
  53:      * The value for the id field.
  54:      * @var        int
  55:      */
  56:     protected $id;
  57: 
  58:     /**
  59:      * The value for the combination_id field.
  60:      * @var        int
  61:      */
  62:     protected $combination_id;
  63: 
  64:     /**
  65:      * The value for the product_id field.
  66:      * @var        int
  67:      */
  68:     protected $product_id;
  69: 
  70:     /**
  71:      * The value for the increase field.
  72:      * @var        double
  73:      */
  74:     protected $increase;
  75: 
  76:     /**
  77:      * The value for the value field.
  78:      * @var        double
  79:      */
  80:     protected $value;
  81: 
  82:     /**
  83:      * The value for the created_at field.
  84:      * @var        string
  85:      */
  86:     protected $created_at;
  87: 
  88:     /**
  89:      * The value for the updated_at field.
  90:      * @var        string
  91:      */
  92:     protected $updated_at;
  93: 
  94:     /**
  95:      * @var        Combination
  96:      */
  97:     protected $aCombination;
  98: 
  99:     /**
 100:      * @var        Product
 101:      */
 102:     protected $aProduct;
 103: 
 104:     /**
 105:      * Flag to prevent endless save loop, if this object is referenced
 106:      * by another object which falls in this transaction.
 107:      * @var        boolean
 108:      */
 109:     protected $alreadyInSave = false;
 110: 
 111:     /**
 112:      * Flag to prevent endless validation loop, if this object is referenced
 113:      * by another object which falls in this transaction.
 114:      * @var        boolean
 115:      */
 116:     protected $alreadyInValidation = false;
 117: 
 118:     /**
 119:      * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
 120:      * @var        boolean
 121:      */
 122:     protected $alreadyInClearAllReferencesDeep = false;
 123: 
 124:     /**
 125:      * Get the [id] column value.
 126:      *
 127:      * @return int
 128:      */
 129:     public function getId()
 130:     {
 131:         return $this->id;
 132:     }
 133: 
 134:     /**
 135:      * Get the [combination_id] column value.
 136:      *
 137:      * @return int
 138:      */
 139:     public function getCombinationId()
 140:     {
 141:         return $this->combination_id;
 142:     }
 143: 
 144:     /**
 145:      * Get the [product_id] column value.
 146:      *
 147:      * @return int
 148:      */
 149:     public function getProductId()
 150:     {
 151:         return $this->product_id;
 152:     }
 153: 
 154:     /**
 155:      * Get the [increase] column value.
 156:      *
 157:      * @return double
 158:      */
 159:     public function getIncrease()
 160:     {
 161:         return $this->increase;
 162:     }
 163: 
 164:     /**
 165:      * Get the [value] column value.
 166:      *
 167:      * @return double
 168:      */
 169:     public function getValue()
 170:     {
 171:         return $this->value;
 172:     }
 173: 
 174:     /**
 175:      * Get the [optionally formatted] temporal [created_at] column value.
 176:      *
 177:      *
 178:      * @param string $format The date/time format string (either date()-style or strftime()-style).
 179:      *               If format is null, then the raw DateTime object will be returned.
 180:      * @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
 181:      * @throws PropelException - if unable to parse/validate the date/time value.
 182:      */
 183:     public function getCreatedAt($format = 'Y-m-d H:i:s')
 184:     {
 185:         if ($this->created_at === null) {
 186:             return null;
 187:         }
 188: 
 189:         if ($this->created_at === '0000-00-00 00:00:00') {
 190:             // while technically this is not a default value of null,
 191:             // this seems to be closest in meaning.
 192:             return null;
 193:         }
 194: 
 195:         try {
 196:             $dt = new DateTime($this->created_at);
 197:         } catch (Exception $x) {
 198:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
 199:         }
 200: 
 201:         if ($format === null) {
 202:             // Because propel.useDateTimeClass is true, we return a DateTime object.
 203:             return $dt;
 204:         }
 205: 
 206:         if (strpos($format, '%') !== false) {
 207:             return strftime($format, $dt->format('U'));
 208:         }
 209: 
 210:         return $dt->format($format);
 211: 
 212:     }
 213: 
 214:     /**
 215:      * Get the [optionally formatted] temporal [updated_at] column value.
 216:      *
 217:      *
 218:      * @param string $format The date/time format string (either date()-style or strftime()-style).
 219:      *               If format is null, then the raw DateTime object will be returned.
 220:      * @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
 221:      * @throws PropelException - if unable to parse/validate the date/time value.
 222:      */
 223:     public function getUpdatedAt($format = 'Y-m-d H:i:s')
 224:     {
 225:         if ($this->updated_at === null) {
 226:             return null;
 227:         }
 228: 
 229:         if ($this->updated_at === '0000-00-00 00:00:00') {
 230:             // while technically this is not a default value of null,
 231:             // this seems to be closest in meaning.
 232:             return null;
 233:         }
 234: 
 235:         try {
 236:             $dt = new DateTime($this->updated_at);
 237:         } catch (Exception $x) {
 238:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
 239:         }
 240: 
 241:         if ($format === null) {
 242:             // Because propel.useDateTimeClass is true, we return a DateTime object.
 243:             return $dt;
 244:         }
 245: 
 246:         if (strpos($format, '%') !== false) {
 247:             return strftime($format, $dt->format('U'));
 248:         }
 249: 
 250:         return $dt->format($format);
 251: 
 252:     }
 253: 
 254:     /**
 255:      * Set the value of [id] column.
 256:      *
 257:      * @param int $v new value
 258:      * @return Stock The current object (for fluent API support)
 259:      */
 260:     public function setId($v)
 261:     {
 262:         if ($v !== null && is_numeric($v)) {
 263:             $v = (int) $v;
 264:         }
 265: 
 266:         if ($this->id !== $v) {
 267:             $this->id = $v;
 268:             $this->modifiedColumns[] = StockPeer::ID;
 269:         }
 270: 
 271: 
 272:         return $this;
 273:     } // setId()
 274: 
 275:     /**
 276:      * Set the value of [combination_id] column.
 277:      *
 278:      * @param int $v new value
 279:      * @return Stock The current object (for fluent API support)
 280:      */
 281:     public function setCombinationId($v)
 282:     {
 283:         if ($v !== null && is_numeric($v)) {
 284:             $v = (int) $v;
 285:         }
 286: 
 287:         if ($this->combination_id !== $v) {
 288:             $this->combination_id = $v;
 289:             $this->modifiedColumns[] = StockPeer::COMBINATION_ID;
 290:         }
 291: 
 292:         if ($this->aCombination !== null && $this->aCombination->getId() !== $v) {
 293:             $this->aCombination = null;
 294:         }
 295: 
 296: 
 297:         return $this;
 298:     } // setCombinationId()
 299: 
 300:     /**
 301:      * Set the value of [product_id] column.
 302:      *
 303:      * @param int $v new value
 304:      * @return Stock The current object (for fluent API support)
 305:      */
 306:     public function setProductId($v)
 307:     {
 308:         if ($v !== null && is_numeric($v)) {
 309:             $v = (int) $v;
 310:         }
 311: 
 312:         if ($this->product_id !== $v) {
 313:             $this->product_id = $v;
 314:             $this->modifiedColumns[] = StockPeer::PRODUCT_ID;
 315:         }
 316: 
 317:         if ($this->aProduct !== null && $this->aProduct->getId() !== $v) {
 318:             $this->aProduct = null;
 319:         }
 320: 
 321: 
 322:         return $this;
 323:     } // setProductId()
 324: 
 325:     /**
 326:      * Set the value of [increase] column.
 327:      *
 328:      * @param double $v new value
 329:      * @return Stock The current object (for fluent API support)
 330:      */
 331:     public function setIncrease($v)
 332:     {
 333:         if ($v !== null && is_numeric($v)) {
 334:             $v = (double) $v;
 335:         }
 336: 
 337:         if ($this->increase !== $v) {
 338:             $this->increase = $v;
 339:             $this->modifiedColumns[] = StockPeer::INCREASE;
 340:         }
 341: 
 342: 
 343:         return $this;
 344:     } // setIncrease()
 345: 
 346:     /**
 347:      * Set the value of [value] column.
 348:      *
 349:      * @param double $v new value
 350:      * @return Stock The current object (for fluent API support)
 351:      */
 352:     public function setValue($v)
 353:     {
 354:         if ($v !== null && is_numeric($v)) {
 355:             $v = (double) $v;
 356:         }
 357: 
 358:         if ($this->value !== $v) {
 359:             $this->value = $v;
 360:             $this->modifiedColumns[] = StockPeer::VALUE;
 361:         }
 362: 
 363: 
 364:         return $this;
 365:     } // setValue()
 366: 
 367:     /**
 368:      * Sets the value of [created_at] column to a normalized version of the date/time value specified.
 369:      *
 370:      * @param mixed $v string, integer (timestamp), or DateTime value.
 371:      *               Empty strings are treated as null.
 372:      * @return Stock The current object (for fluent API support)
 373:      */
 374:     public function setCreatedAt($v)
 375:     {
 376:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
 377:         if ($this->created_at !== null || $dt !== null) {
 378:             $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
 379:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
 380:             if ($currentDateAsString !== $newDateAsString) {
 381:                 $this->created_at = $newDateAsString;
 382:                 $this->modifiedColumns[] = StockPeer::CREATED_AT;
 383:             }
 384:         } // if either are not null
 385: 
 386: 
 387:         return $this;
 388:     } // setCreatedAt()
 389: 
 390:     /**
 391:      * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
 392:      *
 393:      * @param mixed $v string, integer (timestamp), or DateTime value.
 394:      *               Empty strings are treated as null.
 395:      * @return Stock The current object (for fluent API support)
 396:      */
 397:     public function setUpdatedAt($v)
 398:     {
 399:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
 400:         if ($this->updated_at !== null || $dt !== null) {
 401:             $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
 402:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
 403:             if ($currentDateAsString !== $newDateAsString) {
 404:                 $this->updated_at = $newDateAsString;
 405:                 $this->modifiedColumns[] = StockPeer::UPDATED_AT;
 406:             }
 407:         } // if either are not null
 408: 
 409: 
 410:         return $this;
 411:     } // setUpdatedAt()
 412: 
 413:     /**
 414:      * Indicates whether the columns in this object are only set to default values.
 415:      *
 416:      * This method can be used in conjunction with isModified() to indicate whether an object is both
 417:      * modified _and_ has some values set which are non-default.
 418:      *
 419:      * @return boolean Whether the columns in this object are only been set with default values.
 420:      */
 421:     public function hasOnlyDefaultValues()
 422:     {
 423:         // otherwise, everything was equal, so return true
 424:         return true;
 425:     } // hasOnlyDefaultValues()
 426: 
 427:     /**
 428:      * Hydrates (populates) the object variables with values from the database resultset.
 429:      *
 430:      * An offset (0-based "start column") is specified so that objects can be hydrated
 431:      * with a subset of the columns in the resultset rows.  This is needed, for example,
 432:      * for results of JOIN queries where the resultset row includes columns from two or
 433:      * more tables.
 434:      *
 435:      * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
 436:      * @param int $startcol 0-based offset column which indicates which restultset column to start with.
 437:      * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
 438:      * @return int             next starting column
 439:      * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
 440:      */
 441:     public function hydrate($row, $startcol = 0, $rehydrate = false)
 442:     {
 443:         try {
 444: 
 445:             $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
 446:             $this->combination_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
 447:             $this->product_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
 448:             $this->increase = ($row[$startcol + 3] !== null) ? (double) $row[$startcol + 3] : null;
 449:             $this->value = ($row[$startcol + 4] !== null) ? (double) $row[$startcol + 4] : null;
 450:             $this->created_at = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
 451:             $this->updated_at = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
 452:             $this->resetModified();
 453: 
 454:             $this->setNew(false);
 455: 
 456:             if ($rehydrate) {
 457:                 $this->ensureConsistency();
 458:             }
 459:             $this->postHydrate($row, $startcol, $rehydrate);
 460:             return $startcol + 7; // 7 = StockPeer::NUM_HYDRATE_COLUMNS.
 461: 
 462:         } catch (Exception $e) {
 463:             throw new PropelException("Error populating Stock object", $e);
 464:         }
 465:     }
 466: 
 467:     /**
 468:      * Checks and repairs the internal consistency of the object.
 469:      *
 470:      * This method is executed after an already-instantiated object is re-hydrated
 471:      * from the database.  It exists to check any foreign keys to make sure that
 472:      * the objects related to the current object are correct based on foreign key.
 473:      *
 474:      * You can override this method in the stub class, but you should always invoke
 475:      * the base method from the overridden method (i.e. parent::ensureConsistency()),
 476:      * in case your model changes.
 477:      *
 478:      * @throws PropelException
 479:      */
 480:     public function ensureConsistency()
 481:     {
 482: 
 483:         if ($this->aCombination !== null && $this->combination_id !== $this->aCombination->getId()) {
 484:             $this->aCombination = null;
 485:         }
 486:         if ($this->aProduct !== null && $this->product_id !== $this->aProduct->getId()) {
 487:             $this->aProduct = null;
 488:         }
 489:     } // ensureConsistency
 490: 
 491:     /**
 492:      * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
 493:      *
 494:      * This will only work if the object has been saved and has a valid primary key set.
 495:      *
 496:      * @param boolean $deep (optional) Whether to also de-associated any related objects.
 497:      * @param PropelPDO $con (optional) The PropelPDO connection to use.
 498:      * @return void
 499:      * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
 500:      */
 501:     public function reload($deep = false, PropelPDO $con = null)
 502:     {
 503:         if ($this->isDeleted()) {
 504:             throw new PropelException("Cannot reload a deleted object.");
 505:         }
 506: 
 507:         if ($this->isNew()) {
 508:             throw new PropelException("Cannot reload an unsaved object.");
 509:         }
 510: 
 511:         if ($con === null) {
 512:             $con = Propel::getConnection(StockPeer::DATABASE_NAME, Propel::CONNECTION_READ);
 513:         }
 514: 
 515:         // We don't need to alter the object instance pool; we're just modifying this instance
 516:         // already in the pool.
 517: 
 518:         $stmt = StockPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
 519:         $row = $stmt->fetch(PDO::FETCH_NUM);
 520:         $stmt->closeCursor();
 521:         if (!$row) {
 522:             throw new PropelException('Cannot find matching row in the database to reload object values.');
 523:         }
 524:         $this->hydrate($row, 0, true); // rehydrate
 525: 
 526:         if ($deep) {  // also de-associate any related objects?
 527: 
 528:             $this->aCombination = null;
 529:             $this->aProduct = null;
 530:         } // if (deep)
 531:     }
 532: 
 533:     /**
 534:      * Removes this object from datastore and sets delete attribute.
 535:      *
 536:      * @param PropelPDO $con
 537:      * @return void
 538:      * @throws PropelException
 539:      * @throws Exception
 540:      * @see        BaseObject::setDeleted()
 541:      * @see        BaseObject::isDeleted()
 542:      */
 543:     public function delete(PropelPDO $con = null)
 544:     {
 545:         if ($this->isDeleted()) {
 546:             throw new PropelException("This object has already been deleted.");
 547:         }
 548: 
 549:         if ($con === null) {
 550:             $con = Propel::getConnection(StockPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
 551:         }
 552: 
 553:         $con->beginTransaction();
 554:         try {
 555:             $deleteQuery = StockQuery::create()
 556:                 ->filterByPrimaryKey($this->getPrimaryKey());
 557:             $ret = $this->preDelete($con);
 558:             if ($ret) {
 559:                 $deleteQuery->delete($con);
 560:                 $this->postDelete($con);
 561:                 $con->commit();
 562:                 $this->setDeleted(true);
 563:             } else {
 564:                 $con->commit();
 565:             }
 566:         } catch (Exception $e) {
 567:             $con->rollBack();
 568:             throw $e;
 569:         }
 570:     }
 571: 
 572:     /**
 573:      * Persists this object to the database.
 574:      *
 575:      * If the object is new, it inserts it; otherwise an update is performed.
 576:      * All modified related objects will also be persisted in the doSave()
 577:      * method.  This method wraps all precipitate database operations in a
 578:      * single transaction.
 579:      *
 580:      * @param PropelPDO $con
 581:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
 582:      * @throws PropelException
 583:      * @throws Exception
 584:      * @see        doSave()
 585:      */
 586:     public function save(PropelPDO $con = null)
 587:     {
 588:         if ($this->isDeleted()) {
 589:             throw new PropelException("You cannot save an object that has been deleted.");
 590:         }
 591: 
 592:         if ($con === null) {
 593:             $con = Propel::getConnection(StockPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
 594:         }
 595: 
 596:         $con->beginTransaction();
 597:         $isInsert = $this->isNew();
 598:         try {
 599:             $ret = $this->preSave($con);
 600:             if ($isInsert) {
 601:                 $ret = $ret && $this->preInsert($con);
 602:                 // timestampable behavior
 603:                 if (!$this->isColumnModified(StockPeer::CREATED_AT)) {
 604:                     $this->setCreatedAt(time());
 605:                 }
 606:                 if (!$this->isColumnModified(StockPeer::UPDATED_AT)) {
 607:                     $this->setUpdatedAt(time());
 608:                 }
 609:             } else {
 610:                 $ret = $ret && $this->preUpdate($con);
 611:                 // timestampable behavior
 612:                 if ($this->isModified() && !$this->isColumnModified(StockPeer::UPDATED_AT)) {
 613:                     $this->setUpdatedAt(time());
 614:                 }
 615:             }
 616:             if ($ret) {
 617:                 $affectedRows = $this->doSave($con);
 618:                 if ($isInsert) {
 619:                     $this->postInsert($con);
 620:                 } else {
 621:                     $this->postUpdate($con);
 622:                 }
 623:                 $this->postSave($con);
 624:                 StockPeer::addInstanceToPool($this);
 625:             } else {
 626:                 $affectedRows = 0;
 627:             }
 628:             $con->commit();
 629: 
 630:             return $affectedRows;
 631:         } catch (Exception $e) {
 632:             $con->rollBack();
 633:             throw $e;
 634:         }
 635:     }
 636: 
 637:     /**
 638:      * Performs the work of inserting or updating the row in the database.
 639:      *
 640:      * If the object is new, it inserts it; otherwise an update is performed.
 641:      * All related objects are also updated in this method.
 642:      *
 643:      * @param PropelPDO $con
 644:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
 645:      * @throws PropelException
 646:      * @see        save()
 647:      */
 648:     protected function doSave(PropelPDO $con)
 649:     {
 650:         $affectedRows = 0; // initialize var to track total num of affected rows
 651:         if (!$this->alreadyInSave) {
 652:             $this->alreadyInSave = true;
 653: 
 654:             // We call the save method on the following object(s) if they
 655:             // were passed to this object by their coresponding set
 656:             // method.  This object relates to these object(s) by a
 657:             // foreign key reference.
 658: 
 659:             if ($this->aCombination !== null) {
 660:                 if ($this->aCombination->isModified() || $this->aCombination->isNew()) {
 661:                     $affectedRows += $this->aCombination->save($con);
 662:                 }
 663:                 $this->setCombination($this->aCombination);
 664:             }
 665: 
 666:             if ($this->aProduct !== null) {
 667:                 if ($this->aProduct->isModified() || $this->aProduct->isNew()) {
 668:                     $affectedRows += $this->aProduct->save($con);
 669:                 }
 670:                 $this->setProduct($this->aProduct);
 671:             }
 672: 
 673:             if ($this->isNew() || $this->isModified()) {
 674:                 // persist changes
 675:                 if ($this->isNew()) {
 676:                     $this->doInsert($con);
 677:                 } else {
 678:                     $this->doUpdate($con);
 679:                 }
 680:                 $affectedRows += 1;
 681:                 $this->resetModified();
 682:             }
 683: 
 684:             $this->alreadyInSave = false;
 685: 
 686:         }
 687: 
 688:         return $affectedRows;
 689:     } // doSave()
 690: 
 691:     /**
 692:      * Insert the row in the database.
 693:      *
 694:      * @param PropelPDO $con
 695:      *
 696:      * @throws PropelException
 697:      * @see        doSave()
 698:      */
 699:     protected function doInsert(PropelPDO $con)
 700:     {
 701:         $modifiedColumns = array();
 702:         $index = 0;
 703: 
 704:         $this->modifiedColumns[] = StockPeer::ID;
 705:         if (null !== $this->id) {
 706:             throw new PropelException('Cannot insert a value for auto-increment primary key (' . StockPeer::ID . ')');
 707:         }
 708: 
 709:          // check the columns in natural order for more readable SQL queries
 710:         if ($this->isColumnModified(StockPeer::ID)) {
 711:             $modifiedColumns[':p' . $index++]  = '`id`';
 712:         }
 713:         if ($this->isColumnModified(StockPeer::COMBINATION_ID)) {
 714:             $modifiedColumns[':p' . $index++]  = '`combination_id`';
 715:         }
 716:         if ($this->isColumnModified(StockPeer::PRODUCT_ID)) {
 717:             $modifiedColumns[':p' . $index++]  = '`product_id`';
 718:         }
 719:         if ($this->isColumnModified(StockPeer::INCREASE)) {
 720:             $modifiedColumns[':p' . $index++]  = '`increase`';
 721:         }
 722:         if ($this->isColumnModified(StockPeer::VALUE)) {
 723:             $modifiedColumns[':p' . $index++]  = '`value`';
 724:         }
 725:         if ($this->isColumnModified(StockPeer::CREATED_AT)) {
 726:             $modifiedColumns[':p' . $index++]  = '`created_at`';
 727:         }
 728:         if ($this->isColumnModified(StockPeer::UPDATED_AT)) {
 729:             $modifiedColumns[':p' . $index++]  = '`updated_at`';
 730:         }
 731: 
 732:         $sql = sprintf(
 733:             'INSERT INTO `stock` (%s) VALUES (%s)',
 734:             implode(', ', $modifiedColumns),
 735:             implode(', ', array_keys($modifiedColumns))
 736:         );
 737: 
 738:         try {
 739:             $stmt = $con->prepare($sql);
 740:             foreach ($modifiedColumns as $identifier => $columnName) {
 741:                 switch ($columnName) {
 742:                     case '`id`':
 743:                         $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
 744:                         break;
 745:                     case '`combination_id`':
 746:                         $stmt->bindValue($identifier, $this->combination_id, PDO::PARAM_INT);
 747:                         break;
 748:                     case '`product_id`':
 749:                         $stmt->bindValue($identifier, $this->product_id, PDO::PARAM_INT);
 750:                         break;
 751:                     case '`increase`':
 752:                         $stmt->bindValue($identifier, $this->increase, PDO::PARAM_STR);
 753:                         break;
 754:                     case '`value`':
 755:                         $stmt->bindValue($identifier, $this->value, PDO::PARAM_STR);
 756:                         break;
 757:                     case '`created_at`':
 758:                         $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
 759:                         break;
 760:                     case '`updated_at`':
 761:                         $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
 762:                         break;
 763:                 }
 764:             }
 765:             $stmt->execute();
 766:         } catch (Exception $e) {
 767:             Propel::log($e->getMessage(), Propel::LOG_ERR);
 768:             throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
 769:         }
 770: 
 771:         try {
 772:             $pk = $con->lastInsertId();
 773:         } catch (Exception $e) {
 774:             throw new PropelException('Unable to get autoincrement id.', $e);
 775:         }
 776:         $this->setId($pk);
 777: 
 778:         $this->setNew(false);
 779:     }
 780: 
 781:     /**
 782:      * Update the row in the database.
 783:      *
 784:      * @param PropelPDO $con
 785:      *
 786:      * @see        doSave()
 787:      */
 788:     protected function doUpdate(PropelPDO $con)
 789:     {
 790:         $selectCriteria = $this->buildPkeyCriteria();
 791:         $valuesCriteria = $this->buildCriteria();
 792:         BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
 793:     }
 794: 
 795:     /**
 796:      * Array of ValidationFailed objects.
 797:      * @var        array ValidationFailed[]
 798:      */
 799:     protected $validationFailures = array();
 800: 
 801:     /**
 802:      * Gets any ValidationFailed objects that resulted from last call to validate().
 803:      *
 804:      *
 805:      * @return array ValidationFailed[]
 806:      * @see        validate()
 807:      */
 808:     public function getValidationFailures()
 809:     {
 810:         return $this->validationFailures;
 811:     }
 812: 
 813:     /**
 814:      * Validates the objects modified field values and all objects related to this table.
 815:      *
 816:      * If $columns is either a column name or an array of column names
 817:      * only those columns are validated.
 818:      *
 819:      * @param mixed $columns Column name or an array of column names.
 820:      * @return boolean Whether all columns pass validation.
 821:      * @see        doValidate()
 822:      * @see        getValidationFailures()
 823:      */
 824:     public function validate($columns = null)
 825:     {
 826:         $res = $this->doValidate($columns);
 827:         if ($res === true) {
 828:             $this->validationFailures = array();
 829: 
 830:             return true;
 831:         }
 832: 
 833:         $this->validationFailures = $res;
 834: 
 835:         return false;
 836:     }
 837: 
 838:     /**
 839:      * This function performs the validation work for complex object models.
 840:      *
 841:      * In addition to checking the current object, all related objects will
 842:      * also be validated.  If all pass then <code>true</code> is returned; otherwise
 843:      * an aggreagated array of ValidationFailed objects will be returned.
 844:      *
 845:      * @param array $columns Array of column names to validate.
 846:      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
 847:      */
 848:     protected function doValidate($columns = null)
 849:     {
 850:         if (!$this->alreadyInValidation) {
 851:             $this->alreadyInValidation = true;
 852:             $retval = null;
 853: 
 854:             $failureMap = array();
 855: 
 856: 
 857:             // We call the validate method on the following object(s) if they
 858:             // were passed to this object by their coresponding set
 859:             // method.  This object relates to these object(s) by a
 860:             // foreign key reference.
 861: 
 862:             if ($this->aCombination !== null) {
 863:                 if (!$this->aCombination->validate($columns)) {
 864:                     $failureMap = array_merge($failureMap, $this->aCombination->getValidationFailures());
 865:                 }
 866:             }
 867: 
 868:             if ($this->aProduct !== null) {
 869:                 if (!$this->aProduct->validate($columns)) {
 870:                     $failureMap = array_merge($failureMap, $this->aProduct->getValidationFailures());
 871:                 }
 872:             }
 873: 
 874: 
 875:             if (($retval = StockPeer::doValidate($this, $columns)) !== true) {
 876:                 $failureMap = array_merge($failureMap, $retval);
 877:             }
 878: 
 879: 
 880: 
 881:             $this->alreadyInValidation = false;
 882:         }
 883: 
 884:         return (!empty($failureMap) ? $failureMap : true);
 885:     }
 886: 
 887:     /**
 888:      * Retrieves a field from the object by name passed in as a string.
 889:      *
 890:      * @param string $name name
 891:      * @param string $type The type of fieldname the $name is of:
 892:      *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
 893:      *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
 894:      *               Defaults to BasePeer::TYPE_PHPNAME
 895:      * @return mixed Value of field.
 896:      */
 897:     public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
 898:     {
 899:         $pos = StockPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
 900:         $field = $this->getByPosition($pos);
 901: 
 902:         return $field;
 903:     }
 904: 
 905:     /**
 906:      * Retrieves a field from the object by Position as specified in the xml schema.
 907:      * Zero-based.
 908:      *
 909:      * @param int $pos position in xml schema
 910:      * @return mixed Value of field at $pos
 911:      */
 912:     public function getByPosition($pos)
 913:     {
 914:         switch ($pos) {
 915:             case 0:
 916:                 return $this->getId();
 917:                 break;
 918:             case 1:
 919:                 return $this->getCombinationId();
 920:                 break;
 921:             case 2:
 922:                 return $this->getProductId();
 923:                 break;
 924:             case 3:
 925:                 return $this->getIncrease();
 926:                 break;
 927:             case 4:
 928:                 return $this->getValue();
 929:                 break;
 930:             case 5:
 931:                 return $this->getCreatedAt();
 932:                 break;
 933:             case 6:
 934:                 return $this->getUpdatedAt();
 935:                 break;
 936:             default:
 937:                 return null;
 938:                 break;
 939:         } // switch()
 940:     }
 941: 
 942:     /**
 943:      * Exports the object as an array.
 944:      *
 945:      * You can specify the key type of the array by passing one of the class
 946:      * type constants.
 947:      *
 948:      * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
 949:      *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
 950:      *                    Defaults to BasePeer::TYPE_PHPNAME.
 951:      * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
 952:      * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
 953:      * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
 954:      *
 955:      * @return array an associative array containing the field names (as keys) and field values
 956:      */
 957:     public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 958:     {
 959:         if (isset($alreadyDumpedObjects['Stock'][$this->getPrimaryKey()])) {
 960:             return '*RECURSION*';
 961:         }
 962:         $alreadyDumpedObjects['Stock'][$this->getPrimaryKey()] = true;
 963:         $keys = StockPeer::getFieldNames($keyType);
 964:         $result = array(
 965:             $keys[0] => $this->getId(),
 966:             $keys[1] => $this->getCombinationId(),
 967:             $keys[2] => $this->getProductId(),
 968:             $keys[3] => $this->getIncrease(),
 969:             $keys[4] => $this->getValue(),
 970:             $keys[5] => $this->getCreatedAt(),
 971:             $keys[6] => $this->getUpdatedAt(),
 972:         );
 973:         if ($includeForeignObjects) {
 974:             if (null !== $this->aCombination) {
 975:                 $result['Combination'] = $this->aCombination->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
 976:             }
 977:             if (null !== $this->aProduct) {
 978:                 $result['Product'] = $this->aProduct->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
 979:             }
 980:         }
 981: 
 982:         return $result;
 983:     }
 984: 
 985:     /**
 986:      * Sets a field from the object by name passed in as a string.
 987:      *
 988:      * @param string $name peer name
 989:      * @param mixed $value field value
 990:      * @param string $type The type of fieldname the $name is of:
 991:      *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
 992:      *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
 993:      *                     Defaults to BasePeer::TYPE_PHPNAME
 994:      * @return void
 995:      */
 996:     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
 997:     {
 998:         $pos = StockPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
 999: 
1000:         $this->setByPosition($pos, $value);
1001:     }
1002: 
1003:     /**
1004:      * Sets a field from the object by Position as specified in the xml schema.
1005:      * Zero-based.
1006:      *
1007:      * @param int $pos position in xml schema
1008:      * @param mixed $value field value
1009:      * @return void
1010:      */
1011:     public function setByPosition($pos, $value)
1012:     {
1013:         switch ($pos) {
1014:             case 0:
1015:                 $this->setId($value);
1016:                 break;
1017:             case 1:
1018:                 $this->setCombinationId($value);
1019:                 break;
1020:             case 2:
1021:                 $this->setProductId($value);
1022:                 break;
1023:             case 3:
1024:                 $this->setIncrease($value);
1025:                 break;
1026:             case 4:
1027:                 $this->setValue($value);
1028:                 break;
1029:             case 5:
1030:                 $this->setCreatedAt($value);
1031:                 break;
1032:             case 6:
1033:                 $this->setUpdatedAt($value);
1034:                 break;
1035:         } // switch()
1036:     }
1037: 
1038:     /**
1039:      * Populates the object using an array.
1040:      *
1041:      * This is particularly useful when populating an object from one of the
1042:      * request arrays (e.g. $_POST).  This method goes through the column
1043:      * names, checking to see whether a matching key exists in populated
1044:      * array. If so the setByName() method is called for that column.
1045:      *
1046:      * You can specify the key type of the array by additionally passing one
1047:      * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
1048:      * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
1049:      * The default key type is the column's BasePeer::TYPE_PHPNAME
1050:      *
1051:      * @param array  $arr     An array to populate the object from.
1052:      * @param string $keyType The type of keys the array uses.
1053:      * @return void
1054:      */
1055:     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
1056:     {
1057:         $keys = StockPeer::getFieldNames($keyType);
1058: 
1059:         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
1060:         if (array_key_exists($keys[1], $arr)) $this->setCombinationId($arr[$keys[1]]);
1061:         if (array_key_exists($keys[2], $arr)) $this->setProductId($arr[$keys[2]]);
1062:         if (array_key_exists($keys[3], $arr)) $this->setIncrease($arr[$keys[3]]);
1063:         if (array_key_exists($keys[4], $arr)) $this->setValue($arr[$keys[4]]);
1064:         if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]);
1065:         if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]);
1066:     }
1067: 
1068:     /**
1069:      * Build a Criteria object containing the values of all modified columns in this object.
1070:      *
1071:      * @return Criteria The Criteria object containing all modified values.
1072:      */
1073:     public function buildCriteria()
1074:     {
1075:         $criteria = new Criteria(StockPeer::DATABASE_NAME);
1076: 
1077:         if ($this->isColumnModified(StockPeer::ID)) $criteria->add(StockPeer::ID, $this->id);
1078:         if ($this->isColumnModified(StockPeer::COMBINATION_ID)) $criteria->add(StockPeer::COMBINATION_ID, $this->combination_id);
1079:         if ($this->isColumnModified(StockPeer::PRODUCT_ID)) $criteria->add(StockPeer::PRODUCT_ID, $this->product_id);
1080:         if ($this->isColumnModified(StockPeer::INCREASE)) $criteria->add(StockPeer::INCREASE, $this->increase);
1081:         if ($this->isColumnModified(StockPeer::VALUE)) $criteria->add(StockPeer::VALUE, $this->value);
1082:         if ($this->isColumnModified(StockPeer::CREATED_AT)) $criteria->add(StockPeer::CREATED_AT, $this->created_at);
1083:         if ($this->isColumnModified(StockPeer::UPDATED_AT)) $criteria->add(StockPeer::UPDATED_AT, $this->updated_at);
1084: 
1085:         return $criteria;
1086:     }
1087: 
1088:     /**
1089:      * Builds a Criteria object containing the primary key for this object.
1090:      *
1091:      * Unlike buildCriteria() this method includes the primary key values regardless
1092:      * of whether or not they have been modified.
1093:      *
1094:      * @return Criteria The Criteria object containing value(s) for primary key(s).
1095:      */
1096:     public function buildPkeyCriteria()
1097:     {
1098:         $criteria = new Criteria(StockPeer::DATABASE_NAME);
1099:         $criteria->add(StockPeer::ID, $this->id);
1100: 
1101:         return $criteria;
1102:     }
1103: 
1104:     /**
1105:      * Returns the primary key for this object (row).
1106:      * @return int
1107:      */
1108:     public function getPrimaryKey()
1109:     {
1110:         return $this->getId();
1111:     }
1112: 
1113:     /**
1114:      * Generic method to set the primary key (id column).
1115:      *
1116:      * @param  int $key Primary key.
1117:      * @return void
1118:      */
1119:     public function setPrimaryKey($key)
1120:     {
1121:         $this->setId($key);
1122:     }
1123: 
1124:     /**
1125:      * Returns true if the primary key for this object is null.
1126:      * @return boolean
1127:      */
1128:     public function isPrimaryKeyNull()
1129:     {
1130: 
1131:         return null === $this->getId();
1132:     }
1133: 
1134:     /**
1135:      * Sets contents of passed object to values from current object.
1136:      *
1137:      * If desired, this method can also make copies of all associated (fkey referrers)
1138:      * objects.
1139:      *
1140:      * @param object $copyObj An object of Stock (or compatible) type.
1141:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1142:      * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1143:      * @throws PropelException
1144:      */
1145:     public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1146:     {
1147:         $copyObj->setCombinationId($this->getCombinationId());
1148:         $copyObj->setProductId($this->getProductId());
1149:         $copyObj->setIncrease($this->getIncrease());
1150:         $copyObj->setValue($this->getValue());
1151:         $copyObj->setCreatedAt($this->getCreatedAt());
1152:         $copyObj->setUpdatedAt($this->getUpdatedAt());
1153: 
1154:         if ($deepCopy && !$this->startCopy) {
1155:             // important: temporarily setNew(false) because this affects the behavior of
1156:             // the getter/setter methods for fkey referrer objects.
1157:             $copyObj->setNew(false);
1158:             // store object hash to prevent cycle
1159:             $this->startCopy = true;
1160: 
1161:             //unflag object copy
1162:             $this->startCopy = false;
1163:         } // if ($deepCopy)
1164: 
1165:         if ($makeNew) {
1166:             $copyObj->setNew(true);
1167:             $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1168:         }
1169:     }
1170: 
1171:     /**
1172:      * Makes a copy of this object that will be inserted as a new row in table when saved.
1173:      * It creates a new object filling in the simple attributes, but skipping any primary
1174:      * keys that are defined for the table.
1175:      *
1176:      * If desired, this method can also make copies of all associated (fkey referrers)
1177:      * objects.
1178:      *
1179:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1180:      * @return Stock Clone of current object.
1181:      * @throws PropelException
1182:      */
1183:     public function copy($deepCopy = false)
1184:     {
1185:         // we use get_class(), because this might be a subclass
1186:         $clazz = get_class($this);
1187:         $copyObj = new $clazz();
1188:         $this->copyInto($copyObj, $deepCopy);
1189: 
1190:         return $copyObj;
1191:     }
1192: 
1193:     /**
1194:      * Returns a peer instance associated with this om.
1195:      *
1196:      * Since Peer classes are not to have any instance attributes, this method returns the
1197:      * same instance for all member of this class. The method could therefore
1198:      * be static, but this would prevent one from overriding the behavior.
1199:      *
1200:      * @return StockPeer
1201:      */
1202:     public function getPeer()
1203:     {
1204:         if (self::$peer === null) {
1205:             self::$peer = new StockPeer();
1206:         }
1207: 
1208:         return self::$peer;
1209:     }
1210: 
1211:     /**
1212:      * Declares an association between this object and a Combination object.
1213:      *
1214:      * @param             Combination $v
1215:      * @return Stock The current object (for fluent API support)
1216:      * @throws PropelException
1217:      */
1218:     public function setCombination(Combination $v = null)
1219:     {
1220:         if ($v === null) {
1221:             $this->setCombinationId(NULL);
1222:         } else {
1223:             $this->setCombinationId($v->getId());
1224:         }
1225: 
1226:         $this->aCombination = $v;
1227: 
1228:         // Add binding for other direction of this n:n relationship.
1229:         // If this object has already been added to the Combination object, it will not be re-added.
1230:         if ($v !== null) {
1231:             $v->addStock($this);
1232:         }
1233: 
1234: 
1235:         return $this;
1236:     }
1237: 
1238: 
1239:     /**
1240:      * Get the associated Combination object
1241:      *
1242:      * @param PropelPDO $con Optional Connection object.
1243:      * @param $doQuery Executes a query to get the object if required
1244:      * @return Combination The associated Combination object.
1245:      * @throws PropelException
1246:      */
1247:     public function getCombination(PropelPDO $con = null, $doQuery = true)
1248:     {
1249:         if ($this->aCombination === null && ($this->combination_id !== null) && $doQuery) {
1250:             $this->aCombination = CombinationQuery::create()->findPk($this->combination_id, $con);
1251:             /* The following can be used additionally to
1252:                 guarantee the related object contains a reference
1253:                 to this object.  This level of coupling may, however, be
1254:                 undesirable since it could result in an only partially populated collection
1255:                 in the referenced object.
1256:                 $this->aCombination->addStocks($this);
1257:              */
1258:         }
1259: 
1260:         return $this->aCombination;
1261:     }
1262: 
1263:     /**
1264:      * Declares an association between this object and a Product object.
1265:      *
1266:      * @param             Product $v
1267:      * @return Stock The current object (for fluent API support)
1268:      * @throws PropelException
1269:      */
1270:     public function setProduct(Product $v = null)
1271:     {
1272:         if ($v === null) {
1273:             $this->setProductId(NULL);
1274:         } else {
1275:             $this->setProductId($v->getId());
1276:         }
1277: 
1278:         $this->aProduct = $v;
1279: 
1280:         // Add binding for other direction of this n:n relationship.
1281:         // If this object has already been added to the Product object, it will not be re-added.
1282:         if ($v !== null) {
1283:             $v->addStock($this);
1284:         }
1285: 
1286: 
1287:         return $this;
1288:     }
1289: 
1290: 
1291:     /**
1292:      * Get the associated Product object
1293:      *
1294:      * @param PropelPDO $con Optional Connection object.
1295:      * @param $doQuery Executes a query to get the object if required
1296:      * @return Product The associated Product object.
1297:      * @throws PropelException
1298:      */
1299:     public function getProduct(PropelPDO $con = null, $doQuery = true)
1300:     {
1301:         if ($this->aProduct === null && ($this->product_id !== null) && $doQuery) {
1302:             $this->aProduct = ProductQuery::create()->findPk($this->product_id, $con);
1303:             /* The following can be used additionally to
1304:                 guarantee the related object contains a reference
1305:                 to this object.  This level of coupling may, however, be
1306:                 undesirable since it could result in an only partially populated collection
1307:                 in the referenced object.
1308:                 $this->aProduct->addStocks($this);
1309:              */
1310:         }
1311: 
1312:         return $this->aProduct;
1313:     }
1314: 
1315:     /**
1316:      * Clears the current object and sets all attributes to their default values
1317:      */
1318:     public function clear()
1319:     {
1320:         $this->id = null;
1321:         $this->combination_id = null;
1322:         $this->product_id = null;
1323:         $this->increase = null;
1324:         $this->value = null;
1325:         $this->created_at = null;
1326:         $this->updated_at = null;
1327:         $this->alreadyInSave = false;
1328:         $this->alreadyInValidation = false;
1329:         $this->alreadyInClearAllReferencesDeep = false;
1330:         $this->clearAllReferences();
1331:         $this->resetModified();
1332:         $this->setNew(true);
1333:         $this->setDeleted(false);
1334:     }
1335: 
1336:     /**
1337:      * Resets all references to other model objects or collections of model objects.
1338:      *
1339:      * This method is a user-space workaround for PHP's inability to garbage collect
1340:      * objects with circular references (even in PHP 5.3). This is currently necessary
1341:      * when using Propel in certain daemon or large-volumne/high-memory operations.
1342:      *
1343:      * @param boolean $deep Whether to also clear the references on all referrer objects.
1344:      */
1345:     public function clearAllReferences($deep = false)
1346:     {
1347:         if ($deep && !$this->alreadyInClearAllReferencesDeep) {
1348:             $this->alreadyInClearAllReferencesDeep = true;
1349:             if ($this->aCombination instanceof Persistent) {
1350:               $this->aCombination->clearAllReferences($deep);
1351:             }
1352:             if ($this->aProduct instanceof Persistent) {
1353:               $this->aProduct->clearAllReferences($deep);
1354:             }
1355: 
1356:             $this->alreadyInClearAllReferencesDeep = false;
1357:         } // if ($deep)
1358: 
1359:         $this->aCombination = null;
1360:         $this->aProduct = null;
1361:     }
1362: 
1363:     /**
1364:      * return the string representation of this object
1365:      *
1366:      * @return string
1367:      */
1368:     public function __toString()
1369:     {
1370:         return (string) $this->exportTo(StockPeer::DEFAULT_STRING_FORMAT);
1371:     }
1372: 
1373:     /**
1374:      * return true is the object is in saving state
1375:      *
1376:      * @return boolean
1377:      */
1378:     public function isAlreadyInSave()
1379:     {
1380:         return $this->alreadyInSave;
1381:     }
1382: 
1383:     // timestampable behavior
1384: 
1385:     /**
1386:      * Mark the current object so that the update date doesn't get updated during next save
1387:      *
1388:      * @return     Stock The current object (for fluent API support)
1389:      */
1390:     public function keepUpdateDateUnchanged()
1391:     {
1392:         $this->modifiedColumns[] = StockPeer::UPDATED_AT;
1393: 
1394:         return $this;
1395:     }
1396: 
1397: }
1398: 
thelia API documentation generated by ApiGen 2.8.0