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