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