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