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