Overview

Namespaces

  • PHP
  • Thelia
    • Action
    • Controller
    • Core
      • Bundle
      • Event
      • EventListener
      • Template
    • Exception
    • Log
      • Destination
    • Model
      • map
      • om
    • Routing
      • Matcher
    • Tools

Classes

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