1: <?php
2:
3: namespace Thelia\Model\om;
4:
5: use \BaseObject;
6: use \BasePeer;
7: use \Criteria;
8: use \DateTime;
9: use \Exception;
10: use \PDO;
11: use \Persistent;
12: use \Propel;
13: use \PropelCollection;
14: use \PropelDateTime;
15: use \PropelException;
16: use \PropelObjectCollection;
17: use \PropelPDO;
18: use Thelia\Model\Address;
19: use Thelia\Model\AddressQuery;
20: use Thelia\Model\Customer;
21: use Thelia\Model\CustomerQuery;
22: use Thelia\Model\CustomerTitle;
23: use Thelia\Model\CustomerTitleI18n;
24: use Thelia\Model\CustomerTitleI18nQuery;
25: use Thelia\Model\CustomerTitlePeer;
26: use Thelia\Model\CustomerTitleQuery;
27:
28: /**
29: * Base class that represents a row from the 'customer_title' table.
30: *
31: *
32: *
33: * @package propel.generator.Thelia.Model.om
34: */
35: abstract class BaseCustomerTitle extends BaseObject implements Persistent
36: {
37: /**
38: * Peer class name
39: */
40: const PEER = 'Thelia\\Model\\CustomerTitlePeer';
41:
42: /**
43: * The Peer class.
44: * Instance provides a convenient way of calling static methods on a class
45: * that calling code may not be able to identify.
46: * @var CustomerTitlePeer
47: */
48: protected static $peer;
49:
50: /**
51: * The flag var to prevent infinit loop in deep copy
52: * @var boolean
53: */
54: protected $startCopy = false;
55:
56: /**
57: * The value for the id field.
58: * @var int
59: */
60: protected $id;
61:
62: /**
63: * The value for the by_default field.
64: * Note: this column has a database default value of: 0
65: * @var int
66: */
67: protected $by_default;
68:
69: /**
70: * The value for the position field.
71: * @var string
72: */
73: protected $position;
74:
75: /**
76: * The value for the created_at field.
77: * @var string
78: */
79: protected $created_at;
80:
81: /**
82: * The value for the updated_at field.
83: * @var string
84: */
85: protected $updated_at;
86:
87: /**
88: * @var PropelObjectCollection|Customer[] Collection to store aggregation of Customer objects.
89: */
90: protected $collCustomers;
91: protected $collCustomersPartial;
92:
93: /**
94: * @var PropelObjectCollection|Address[] Collection to store aggregation of Address objects.
95: */
96: protected $collAddresss;
97: protected $collAddresssPartial;
98:
99: /**
100: * @var PropelObjectCollection|CustomerTitleI18n[] Collection to store aggregation of CustomerTitleI18n objects.
101: */
102: protected $collCustomerTitleI18ns;
103: protected $collCustomerTitleI18nsPartial;
104:
105: /**
106: * Flag to prevent endless save loop, if this object is referenced
107: * by another object which falls in this transaction.
108: * @var boolean
109: */
110: protected $alreadyInSave = false;
111:
112: /**
113: * Flag to prevent endless validation loop, if this object is referenced
114: * by another object which falls in this transaction.
115: * @var boolean
116: */
117: protected $alreadyInValidation = false;
118:
119: // i18n behavior
120:
121: /**
122: * Current locale
123: * @var string
124: */
125: protected $currentLocale = 'en_EN';
126:
127: /**
128: * Current translation objects
129: * @var array[CustomerTitleI18n]
130: */
131: protected $currentTranslations;
132:
133: /**
134: * An array of objects scheduled for deletion.
135: * @var PropelObjectCollection
136: */
137: protected $customersScheduledForDeletion = null;
138:
139: /**
140: * An array of objects scheduled for deletion.
141: * @var PropelObjectCollection
142: */
143: protected $addresssScheduledForDeletion = null;
144:
145: /**
146: * An array of objects scheduled for deletion.
147: * @var PropelObjectCollection
148: */
149: protected $customerTitleI18nsScheduledForDeletion = null;
150:
151: /**
152: * Applies default values to this object.
153: * This method should be called from the object's constructor (or
154: * equivalent initialization method).
155: * @see __construct()
156: */
157: public function applyDefaultValues()
158: {
159: $this->by_default = 0;
160: }
161:
162: /**
163: * Initializes internal state of BaseCustomerTitle object.
164: * @see applyDefaults()
165: */
166: public function __construct()
167: {
168: parent::__construct();
169: $this->applyDefaultValues();
170: }
171:
172: /**
173: * Get the [id] column value.
174: *
175: * @return int
176: */
177: public function getId()
178: {
179: return $this->id;
180: }
181:
182: /**
183: * Get the [by_default] column value.
184: *
185: * @return int
186: */
187: public function getByDefault()
188: {
189: return $this->by_default;
190: }
191:
192: /**
193: * Get the [position] column value.
194: *
195: * @return string
196: */
197: public function getPosition()
198: {
199: return $this->position;
200: }
201:
202: /**
203: * Get the [optionally formatted] temporal [created_at] column value.
204: *
205: *
206: * @param string $format The date/time format string (either date()-style or strftime()-style).
207: * If format is null, then the raw DateTime object will be returned.
208: * @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
209: * @throws PropelException - if unable to parse/validate the date/time value.
210: */
211: public function getCreatedAt($format = 'Y-m-d H:i:s')
212: {
213: if ($this->created_at === null) {
214: return null;
215: }
216:
217: if ($this->created_at === '0000-00-00 00:00:00') {
218: // while technically this is not a default value of null,
219: // this seems to be closest in meaning.
220: return null;
221: } else {
222: try {
223: $dt = new DateTime($this->created_at);
224: } catch (Exception $x) {
225: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
226: }
227: }
228:
229: if ($format === null) {
230: // Because propel.useDateTimeClass is true, we return a DateTime object.
231: return $dt;
232: } elseif (strpos($format, '%') !== false) {
233: return strftime($format, $dt->format('U'));
234: } else {
235: return $dt->format($format);
236: }
237: }
238:
239: /**
240: * Get the [optionally formatted] temporal [updated_at] column value.
241: *
242: *
243: * @param string $format The date/time format string (either date()-style or strftime()-style).
244: * If format is null, then the raw DateTime object will be returned.
245: * @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
246: * @throws PropelException - if unable to parse/validate the date/time value.
247: */
248: public function getUpdatedAt($format = 'Y-m-d H:i:s')
249: {
250: if ($this->updated_at === null) {
251: return null;
252: }
253:
254: if ($this->updated_at === '0000-00-00 00:00:00') {
255: // while technically this is not a default value of null,
256: // this seems to be closest in meaning.
257: return null;
258: } else {
259: try {
260: $dt = new DateTime($this->updated_at);
261: } catch (Exception $x) {
262: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
263: }
264: }
265:
266: if ($format === null) {
267: // Because propel.useDateTimeClass is true, we return a DateTime object.
268: return $dt;
269: } elseif (strpos($format, '%') !== false) {
270: return strftime($format, $dt->format('U'));
271: } else {
272: return $dt->format($format);
273: }
274: }
275:
276: /**
277: * Set the value of [id] column.
278: *
279: * @param int $v new value
280: * @return CustomerTitle The current object (for fluent API support)
281: */
282: public function setId($v)
283: {
284: if ($v !== null) {
285: $v = (int) $v;
286: }
287:
288: if ($this->id !== $v) {
289: $this->id = $v;
290: $this->modifiedColumns[] = CustomerTitlePeer::ID;
291: }
292:
293:
294: return $this;
295: } // setId()
296:
297: /**
298: * Set the value of [by_default] column.
299: *
300: * @param int $v new value
301: * @return CustomerTitle The current object (for fluent API support)
302: */
303: public function setByDefault($v)
304: {
305: if ($v !== null) {
306: $v = (int) $v;
307: }
308:
309: if ($this->by_default !== $v) {
310: $this->by_default = $v;
311: $this->modifiedColumns[] = CustomerTitlePeer::BY_DEFAULT;
312: }
313:
314:
315: return $this;
316: } // setByDefault()
317:
318: /**
319: * Set the value of [position] column.
320: *
321: * @param string $v new value
322: * @return CustomerTitle The current object (for fluent API support)
323: */
324: public function setPosition($v)
325: {
326: if ($v !== null) {
327: $v = (string) $v;
328: }
329:
330: if ($this->position !== $v) {
331: $this->position = $v;
332: $this->modifiedColumns[] = CustomerTitlePeer::POSITION;
333: }
334:
335:
336: return $this;
337: } // setPosition()
338:
339: /**
340: * Sets the value of [created_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 CustomerTitle The current object (for fluent API support)
345: */
346: public function setCreatedAt($v)
347: {
348: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
349: if ($this->created_at !== null || $dt !== null) {
350: $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_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->created_at = $newDateAsString;
354: $this->modifiedColumns[] = CustomerTitlePeer::CREATED_AT;
355: }
356: } // if either are not null
357:
358:
359: return $this;
360: } // setCreatedAt()
361:
362: /**
363: * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
364: *
365: * @param mixed $v string, integer (timestamp), or DateTime value.
366: * Empty strings are treated as null.
367: * @return CustomerTitle The current object (for fluent API support)
368: */
369: public function setUpdatedAt($v)
370: {
371: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
372: if ($this->updated_at !== null || $dt !== null) {
373: $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
374: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
375: if ($currentDateAsString !== $newDateAsString) {
376: $this->updated_at = $newDateAsString;
377: $this->modifiedColumns[] = CustomerTitlePeer::UPDATED_AT;
378: }
379: } // if either are not null
380:
381:
382: return $this;
383: } // setUpdatedAt()
384:
385: /**
386: * Indicates whether the columns in this object are only set to default values.
387: *
388: * This method can be used in conjunction with isModified() to indicate whether an object is both
389: * modified _and_ has some values set which are non-default.
390: *
391: * @return boolean Whether the columns in this object are only been set with default values.
392: */
393: public function hasOnlyDefaultValues()
394: {
395: if ($this->by_default !== 0) {
396: return false;
397: }
398:
399: // otherwise, everything was equal, so return true
400: return true;
401: } // hasOnlyDefaultValues()
402:
403: /**
404: * Hydrates (populates) the object variables with values from the database resultset.
405: *
406: * An offset (0-based "start column") is specified so that objects can be hydrated
407: * with a subset of the columns in the resultset rows. This is needed, for example,
408: * for results of JOIN queries where the resultset row includes columns from two or
409: * more tables.
410: *
411: * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
412: * @param int $startcol 0-based offset column which indicates which restultset column to start with.
413: * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
414: * @return int next starting column
415: * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
416: */
417: public function hydrate($row, $startcol = 0, $rehydrate = false)
418: {
419: try {
420:
421: $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
422: $this->by_default = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
423: $this->position = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
424: $this->created_at = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
425: $this->updated_at = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
426: $this->resetModified();
427:
428: $this->setNew(false);
429:
430: if ($rehydrate) {
431: $this->ensureConsistency();
432: }
433:
434: return $startcol + 5; // 5 = CustomerTitlePeer::NUM_HYDRATE_COLUMNS.
435:
436: } catch (Exception $e) {
437: throw new PropelException("Error populating CustomerTitle object", $e);
438: }
439: }
440:
441: /**
442: * Checks and repairs the internal consistency of the object.
443: *
444: * This method is executed after an already-instantiated object is re-hydrated
445: * from the database. It exists to check any foreign keys to make sure that
446: * the objects related to the current object are correct based on foreign key.
447: *
448: * You can override this method in the stub class, but you should always invoke
449: * the base method from the overridden method (i.e. parent::ensureConsistency()),
450: * in case your model changes.
451: *
452: * @throws PropelException
453: */
454: public function ensureConsistency()
455: {
456:
457: } // ensureConsistency
458:
459: /**
460: * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
461: *
462: * This will only work if the object has been saved and has a valid primary key set.
463: *
464: * @param boolean $deep (optional) Whether to also de-associated any related objects.
465: * @param PropelPDO $con (optional) The PropelPDO connection to use.
466: * @return void
467: * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
468: */
469: public function reload($deep = false, PropelPDO $con = null)
470: {
471: if ($this->isDeleted()) {
472: throw new PropelException("Cannot reload a deleted object.");
473: }
474:
475: if ($this->isNew()) {
476: throw new PropelException("Cannot reload an unsaved object.");
477: }
478:
479: if ($con === null) {
480: $con = Propel::getConnection(CustomerTitlePeer::DATABASE_NAME, Propel::CONNECTION_READ);
481: }
482:
483: // We don't need to alter the object instance pool; we're just modifying this instance
484: // already in the pool.
485:
486: $stmt = CustomerTitlePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
487: $row = $stmt->fetch(PDO::FETCH_NUM);
488: $stmt->closeCursor();
489: if (!$row) {
490: throw new PropelException('Cannot find matching row in the database to reload object values.');
491: }
492: $this->hydrate($row, 0, true); // rehydrate
493:
494: if ($deep) { // also de-associate any related objects?
495:
496: $this->collCustomers = null;
497:
498: $this->collAddresss = null;
499:
500: $this->collCustomerTitleI18ns = null;
501:
502: } // if (deep)
503: }
504:
505: /**
506: * Removes this object from datastore and sets delete attribute.
507: *
508: * @param PropelPDO $con
509: * @return void
510: * @throws PropelException
511: * @throws Exception
512: * @see BaseObject::setDeleted()
513: * @see BaseObject::isDeleted()
514: */
515: public function delete(PropelPDO $con = null)
516: {
517: if ($this->isDeleted()) {
518: throw new PropelException("This object has already been deleted.");
519: }
520:
521: if ($con === null) {
522: $con = Propel::getConnection(CustomerTitlePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
523: }
524:
525: $con->beginTransaction();
526: try {
527: $deleteQuery = CustomerTitleQuery::create()
528: ->filterByPrimaryKey($this->getPrimaryKey());
529: $ret = $this->preDelete($con);
530: if ($ret) {
531: $deleteQuery->delete($con);
532: $this->postDelete($con);
533: $con->commit();
534: $this->setDeleted(true);
535: } else {
536: $con->commit();
537: }
538: } catch (Exception $e) {
539: $con->rollBack();
540: throw $e;
541: }
542: }
543:
544: /**
545: * Persists this object to the database.
546: *
547: * If the object is new, it inserts it; otherwise an update is performed.
548: * All modified related objects will also be persisted in the doSave()
549: * method. This method wraps all precipitate database operations in a
550: * single transaction.
551: *
552: * @param PropelPDO $con
553: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
554: * @throws PropelException
555: * @throws Exception
556: * @see doSave()
557: */
558: public function save(PropelPDO $con = null)
559: {
560: if ($this->isDeleted()) {
561: throw new PropelException("You cannot save an object that has been deleted.");
562: }
563:
564: if ($con === null) {
565: $con = Propel::getConnection(CustomerTitlePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
566: }
567:
568: $con->beginTransaction();
569: $isInsert = $this->isNew();
570: try {
571: $ret = $this->preSave($con);
572: if ($isInsert) {
573: $ret = $ret && $this->preInsert($con);
574: // timestampable behavior
575: if (!$this->isColumnModified(CustomerTitlePeer::CREATED_AT)) {
576: $this->setCreatedAt(time());
577: }
578: if (!$this->isColumnModified(CustomerTitlePeer::UPDATED_AT)) {
579: $this->setUpdatedAt(time());
580: }
581: } else {
582: $ret = $ret && $this->preUpdate($con);
583: // timestampable behavior
584: if ($this->isModified() && !$this->isColumnModified(CustomerTitlePeer::UPDATED_AT)) {
585: $this->setUpdatedAt(time());
586: }
587: }
588: if ($ret) {
589: $affectedRows = $this->doSave($con);
590: if ($isInsert) {
591: $this->postInsert($con);
592: } else {
593: $this->postUpdate($con);
594: }
595: $this->postSave($con);
596: CustomerTitlePeer::addInstanceToPool($this);
597: } else {
598: $affectedRows = 0;
599: }
600: $con->commit();
601:
602: return $affectedRows;
603: } catch (Exception $e) {
604: $con->rollBack();
605: throw $e;
606: }
607: }
608:
609: /**
610: * Performs the work of inserting or updating the row in the database.
611: *
612: * If the object is new, it inserts it; otherwise an update is performed.
613: * All related objects are also updated in this method.
614: *
615: * @param PropelPDO $con
616: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
617: * @throws PropelException
618: * @see save()
619: */
620: protected function doSave(PropelPDO $con)
621: {
622: $affectedRows = 0; // initialize var to track total num of affected rows
623: if (!$this->alreadyInSave) {
624: $this->alreadyInSave = true;
625:
626: if ($this->isNew() || $this->isModified()) {
627: // persist changes
628: if ($this->isNew()) {
629: $this->doInsert($con);
630: } else {
631: $this->doUpdate($con);
632: }
633: $affectedRows += 1;
634: $this->resetModified();
635: }
636:
637: if ($this->customersScheduledForDeletion !== null) {
638: if (!$this->customersScheduledForDeletion->isEmpty()) {
639: foreach ($this->customersScheduledForDeletion as $customer) {
640: // need to save related object because we set the relation to null
641: $customer->save($con);
642: }
643: $this->customersScheduledForDeletion = null;
644: }
645: }
646:
647: if ($this->collCustomers !== null) {
648: foreach ($this->collCustomers as $referrerFK) {
649: if (!$referrerFK->isDeleted()) {
650: $affectedRows += $referrerFK->save($con);
651: }
652: }
653: }
654:
655: if ($this->addresssScheduledForDeletion !== null) {
656: if (!$this->addresssScheduledForDeletion->isEmpty()) {
657: foreach ($this->addresssScheduledForDeletion as $address) {
658: // need to save related object because we set the relation to null
659: $address->save($con);
660: }
661: $this->addresssScheduledForDeletion = null;
662: }
663: }
664:
665: if ($this->collAddresss !== null) {
666: foreach ($this->collAddresss as $referrerFK) {
667: if (!$referrerFK->isDeleted()) {
668: $affectedRows += $referrerFK->save($con);
669: }
670: }
671: }
672:
673: if ($this->customerTitleI18nsScheduledForDeletion !== null) {
674: if (!$this->customerTitleI18nsScheduledForDeletion->isEmpty()) {
675: CustomerTitleI18nQuery::create()
676: ->filterByPrimaryKeys($this->customerTitleI18nsScheduledForDeletion->getPrimaryKeys(false))
677: ->delete($con);
678: $this->customerTitleI18nsScheduledForDeletion = null;
679: }
680: }
681:
682: if ($this->collCustomerTitleI18ns !== null) {
683: foreach ($this->collCustomerTitleI18ns as $referrerFK) {
684: if (!$referrerFK->isDeleted()) {
685: $affectedRows += $referrerFK->save($con);
686: }
687: }
688: }
689:
690: $this->alreadyInSave = false;
691:
692: }
693:
694: return $affectedRows;
695: } // doSave()
696:
697: /**
698: * Insert the row in the database.
699: *
700: * @param PropelPDO $con
701: *
702: * @throws PropelException
703: * @see doSave()
704: */
705: protected function doInsert(PropelPDO $con)
706: {
707: $modifiedColumns = array();
708: $index = 0;
709:
710: $this->modifiedColumns[] = CustomerTitlePeer::ID;
711: if (null !== $this->id) {
712: throw new PropelException('Cannot insert a value for auto-increment primary key (' . CustomerTitlePeer::ID . ')');
713: }
714:
715: // check the columns in natural order for more readable SQL queries
716: if ($this->isColumnModified(CustomerTitlePeer::ID)) {
717: $modifiedColumns[':p' . $index++] = '`ID`';
718: }
719: if ($this->isColumnModified(CustomerTitlePeer::BY_DEFAULT)) {
720: $modifiedColumns[':p' . $index++] = '`BY_DEFAULT`';
721: }
722: if ($this->isColumnModified(CustomerTitlePeer::POSITION)) {
723: $modifiedColumns[':p' . $index++] = '`POSITION`';
724: }
725: if ($this->isColumnModified(CustomerTitlePeer::CREATED_AT)) {
726: $modifiedColumns[':p' . $index++] = '`CREATED_AT`';
727: }
728: if ($this->isColumnModified(CustomerTitlePeer::UPDATED_AT)) {
729: $modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
730: }
731:
732: $sql = sprintf(
733: 'INSERT INTO `customer_title` (%s) VALUES (%s)',
734: implode(', ', $modifiedColumns),
735: implode(', ', array_keys($modifiedColumns))
736: );
737:
738: try {
739: $stmt = $con->prepare($sql);
740: foreach ($modifiedColumns as $identifier => $columnName) {
741: switch ($columnName) {
742: case '`ID`':
743: $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
744: break;
745: case '`BY_DEFAULT`':
746: $stmt->bindValue($identifier, $this->by_default, PDO::PARAM_INT);
747: break;
748: case '`POSITION`':
749: $stmt->bindValue($identifier, $this->position, PDO::PARAM_STR);
750: break;
751: case '`CREATED_AT`':
752: $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
753: break;
754: case '`UPDATED_AT`':
755: $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
756: break;
757: }
758: }
759: $stmt->execute();
760: } catch (Exception $e) {
761: Propel::log($e->getMessage(), Propel::LOG_ERR);
762: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
763: }
764:
765: try {
766: $pk = $con->lastInsertId();
767: } catch (Exception $e) {
768: throw new PropelException('Unable to get autoincrement id.', $e);
769: }
770: $this->setId($pk);
771:
772: $this->setNew(false);
773: }
774:
775: /**
776: * Update the row in the database.
777: *
778: * @param PropelPDO $con
779: *
780: * @see doSave()
781: */
782: protected function doUpdate(PropelPDO $con)
783: {
784: $selectCriteria = $this->buildPkeyCriteria();
785: $valuesCriteria = $this->buildCriteria();
786: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
787: }
788:
789: /**
790: * Array of ValidationFailed objects.
791: * @var array ValidationFailed[]
792: */
793: protected $validationFailures = array();
794:
795: /**
796: * Gets any ValidationFailed objects that resulted from last call to validate().
797: *
798: *
799: * @return array ValidationFailed[]
800: * @see validate()
801: */
802: public function getValidationFailures()
803: {
804: return $this->validationFailures;
805: }
806:
807: /**
808: * Validates the objects modified field values and all objects related to this table.
809: *
810: * If $columns is either a column name or an array of column names
811: * only those columns are validated.
812: *
813: * @param mixed $columns Column name or an array of column names.
814: * @return boolean Whether all columns pass validation.
815: * @see doValidate()
816: * @see getValidationFailures()
817: */
818: public function validate($columns = null)
819: {
820: $res = $this->doValidate($columns);
821: if ($res === true) {
822: $this->validationFailures = array();
823:
824: return true;
825: } else {
826: $this->validationFailures = $res;
827:
828: return false;
829: }
830: }
831:
832: /**
833: * This function performs the validation work for complex object models.
834: *
835: * In addition to checking the current object, all related objects will
836: * also be validated. If all pass then <code>true</code> is returned; otherwise
837: * an aggreagated array of ValidationFailed objects will be returned.
838: *
839: * @param array $columns Array of column names to validate.
840: * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
841: */
842: protected function doValidate($columns = null)
843: {
844: if (!$this->alreadyInValidation) {
845: $this->alreadyInValidation = true;
846: $retval = null;
847:
848: $failureMap = array();
849:
850:
851: if (($retval = CustomerTitlePeer::doValidate($this, $columns)) !== true) {
852: $failureMap = array_merge($failureMap, $retval);
853: }
854:
855:
856: if ($this->collCustomers !== null) {
857: foreach ($this->collCustomers as $referrerFK) {
858: if (!$referrerFK->validate($columns)) {
859: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
860: }
861: }
862: }
863:
864: if ($this->collAddresss !== null) {
865: foreach ($this->collAddresss as $referrerFK) {
866: if (!$referrerFK->validate($columns)) {
867: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
868: }
869: }
870: }
871:
872: if ($this->collCustomerTitleI18ns !== null) {
873: foreach ($this->collCustomerTitleI18ns as $referrerFK) {
874: if (!$referrerFK->validate($columns)) {
875: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
876: }
877: }
878: }
879:
880:
881: $this->alreadyInValidation = false;
882: }
883:
884: return (!empty($failureMap) ? $failureMap : true);
885: }
886:
887: /**
888: * Retrieves a field from the object by name passed in as a string.
889: *
890: * @param string $name name
891: * @param string $type The type of fieldname the $name is of:
892: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
893: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
894: * Defaults to BasePeer::TYPE_PHPNAME
895: * @return mixed Value of field.
896: */
897: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
898: {
899: $pos = CustomerTitlePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
900: $field = $this->getByPosition($pos);
901:
902: return $field;
903: }
904:
905: /**
906: * Retrieves a field from the object by Position as specified in the xml schema.
907: * Zero-based.
908: *
909: * @param int $pos position in xml schema
910: * @return mixed Value of field at $pos
911: */
912: public function getByPosition($pos)
913: {
914: switch ($pos) {
915: case 0:
916: return $this->getId();
917: break;
918: case 1:
919: return $this->getByDefault();
920: break;
921: case 2:
922: return $this->getPosition();
923: break;
924: case 3:
925: return $this->getCreatedAt();
926: break;
927: case 4:
928: return $this->getUpdatedAt();
929: break;
930: default:
931: return null;
932: break;
933: } // switch()
934: }
935:
936: /**
937: * Exports the object as an array.
938: *
939: * You can specify the key type of the array by passing one of the class
940: * type constants.
941: *
942: * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
943: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
944: * Defaults to BasePeer::TYPE_PHPNAME.
945: * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
946: * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
947: * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
948: *
949: * @return array an associative array containing the field names (as keys) and field values
950: */
951: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
952: {
953: if (isset($alreadyDumpedObjects['CustomerTitle'][$this->getPrimaryKey()])) {
954: return '*RECURSION*';
955: }
956: $alreadyDumpedObjects['CustomerTitle'][$this->getPrimaryKey()] = true;
957: $keys = CustomerTitlePeer::getFieldNames($keyType);
958: $result = array(
959: $keys[0] => $this->getId(),
960: $keys[1] => $this->getByDefault(),
961: $keys[2] => $this->getPosition(),
962: $keys[3] => $this->getCreatedAt(),
963: $keys[4] => $this->getUpdatedAt(),
964: );
965: if ($includeForeignObjects) {
966: if (null !== $this->collCustomers) {
967: $result['Customers'] = $this->collCustomers->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
968: }
969: if (null !== $this->collAddresss) {
970: $result['Addresss'] = $this->collAddresss->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
971: }
972: if (null !== $this->collCustomerTitleI18ns) {
973: $result['CustomerTitleI18ns'] = $this->collCustomerTitleI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
974: }
975: }
976:
977: return $result;
978: }
979:
980: /**
981: * Sets a field from the object by name passed in as a string.
982: *
983: * @param string $name peer name
984: * @param mixed $value field value
985: * @param string $type The type of fieldname the $name is of:
986: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
987: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
988: * Defaults to BasePeer::TYPE_PHPNAME
989: * @return void
990: */
991: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
992: {
993: $pos = CustomerTitlePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
994:
995: $this->setByPosition($pos, $value);
996: }
997:
998: /**
999: * Sets a field from the object by Position as specified in the xml schema.
1000: * Zero-based.
1001: *
1002: * @param int $pos position in xml schema
1003: * @param mixed $value field value
1004: * @return void
1005: */
1006: public function setByPosition($pos, $value)
1007: {
1008: switch ($pos) {
1009: case 0:
1010: $this->setId($value);
1011: break;
1012: case 1:
1013: $this->setByDefault($value);
1014: break;
1015: case 2:
1016: $this->setPosition($value);
1017: break;
1018: case 3:
1019: $this->setCreatedAt($value);
1020: break;
1021: case 4:
1022: $this->setUpdatedAt($value);
1023: break;
1024: } // switch()
1025: }
1026:
1027: /**
1028: * Populates the object using an array.
1029: *
1030: * This is particularly useful when populating an object from one of the
1031: * request arrays (e.g. $_POST). This method goes through the column
1032: * names, checking to see whether a matching key exists in populated
1033: * array. If so the setByName() method is called for that column.
1034: *
1035: * You can specify the key type of the array by additionally passing one
1036: * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
1037: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
1038: * The default key type is the column's BasePeer::TYPE_PHPNAME
1039: *
1040: * @param array $arr An array to populate the object from.
1041: * @param string $keyType The type of keys the array uses.
1042: * @return void
1043: */
1044: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
1045: {
1046: $keys = CustomerTitlePeer::getFieldNames($keyType);
1047:
1048: if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
1049: if (array_key_exists($keys[1], $arr)) $this->setByDefault($arr[$keys[1]]);
1050: if (array_key_exists($keys[2], $arr)) $this->setPosition($arr[$keys[2]]);
1051: if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]);
1052: if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]);
1053: }
1054:
1055: /**
1056: * Build a Criteria object containing the values of all modified columns in this object.
1057: *
1058: * @return Criteria The Criteria object containing all modified values.
1059: */
1060: public function buildCriteria()
1061: {
1062: $criteria = new Criteria(CustomerTitlePeer::DATABASE_NAME);
1063:
1064: if ($this->isColumnModified(CustomerTitlePeer::ID)) $criteria->add(CustomerTitlePeer::ID, $this->id);
1065: if ($this->isColumnModified(CustomerTitlePeer::BY_DEFAULT)) $criteria->add(CustomerTitlePeer::BY_DEFAULT, $this->by_default);
1066: if ($this->isColumnModified(CustomerTitlePeer::POSITION)) $criteria->add(CustomerTitlePeer::POSITION, $this->position);
1067: if ($this->isColumnModified(CustomerTitlePeer::CREATED_AT)) $criteria->add(CustomerTitlePeer::CREATED_AT, $this->created_at);
1068: if ($this->isColumnModified(CustomerTitlePeer::UPDATED_AT)) $criteria->add(CustomerTitlePeer::UPDATED_AT, $this->updated_at);
1069:
1070: return $criteria;
1071: }
1072:
1073: /**
1074: * Builds a Criteria object containing the primary key for this object.
1075: *
1076: * Unlike buildCriteria() this method includes the primary key values regardless
1077: * of whether or not they have been modified.
1078: *
1079: * @return Criteria The Criteria object containing value(s) for primary key(s).
1080: */
1081: public function buildPkeyCriteria()
1082: {
1083: $criteria = new Criteria(CustomerTitlePeer::DATABASE_NAME);
1084: $criteria->add(CustomerTitlePeer::ID, $this->id);
1085:
1086: return $criteria;
1087: }
1088:
1089: /**
1090: * Returns the primary key for this object (row).
1091: * @return int
1092: */
1093: public function getPrimaryKey()
1094: {
1095: return $this->getId();
1096: }
1097:
1098: /**
1099: * Generic method to set the primary key (id column).
1100: *
1101: * @param int $key Primary key.
1102: * @return void
1103: */
1104: public function setPrimaryKey($key)
1105: {
1106: $this->setId($key);
1107: }
1108:
1109: /**
1110: * Returns true if the primary key for this object is null.
1111: * @return boolean
1112: */
1113: public function isPrimaryKeyNull()
1114: {
1115:
1116: return null === $this->getId();
1117: }
1118:
1119: /**
1120: * Sets contents of passed object to values from current object.
1121: *
1122: * If desired, this method can also make copies of all associated (fkey referrers)
1123: * objects.
1124: *
1125: * @param object $copyObj An object of CustomerTitle (or compatible) type.
1126: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1127: * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1128: * @throws PropelException
1129: */
1130: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1131: {
1132: $copyObj->setByDefault($this->getByDefault());
1133: $copyObj->setPosition($this->getPosition());
1134: $copyObj->setCreatedAt($this->getCreatedAt());
1135: $copyObj->setUpdatedAt($this->getUpdatedAt());
1136:
1137: if ($deepCopy && !$this->startCopy) {
1138: // important: temporarily setNew(false) because this affects the behavior of
1139: // the getter/setter methods for fkey referrer objects.
1140: $copyObj->setNew(false);
1141: // store object hash to prevent cycle
1142: $this->startCopy = true;
1143:
1144: foreach ($this->getCustomers() as $relObj) {
1145: if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
1146: $copyObj->addCustomer($relObj->copy($deepCopy));
1147: }
1148: }
1149:
1150: foreach ($this->getAddresss() as $relObj) {
1151: if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
1152: $copyObj->addAddress($relObj->copy($deepCopy));
1153: }
1154: }
1155:
1156: foreach ($this->getCustomerTitleI18ns() as $relObj) {
1157: if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
1158: $copyObj->addCustomerTitleI18n($relObj->copy($deepCopy));
1159: }
1160: }
1161:
1162: //unflag object copy
1163: $this->startCopy = false;
1164: } // if ($deepCopy)
1165:
1166: if ($makeNew) {
1167: $copyObj->setNew(true);
1168: $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1169: }
1170: }
1171:
1172: /**
1173: * Makes a copy of this object that will be inserted as a new row in table when saved.
1174: * It creates a new object filling in the simple attributes, but skipping any primary
1175: * keys that are defined for the table.
1176: *
1177: * If desired, this method can also make copies of all associated (fkey referrers)
1178: * objects.
1179: *
1180: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1181: * @return CustomerTitle Clone of current object.
1182: * @throws PropelException
1183: */
1184: public function copy($deepCopy = false)
1185: {
1186: // we use get_class(), because this might be a subclass
1187: $clazz = get_class($this);
1188: $copyObj = new $clazz();
1189: $this->copyInto($copyObj, $deepCopy);
1190:
1191: return $copyObj;
1192: }
1193:
1194: /**
1195: * Returns a peer instance associated with this om.
1196: *
1197: * Since Peer classes are not to have any instance attributes, this method returns the
1198: * same instance for all member of this class. The method could therefore
1199: * be static, but this would prevent one from overriding the behavior.
1200: *
1201: * @return CustomerTitlePeer
1202: */
1203: public function getPeer()
1204: {
1205: if (self::$peer === null) {
1206: self::$peer = new CustomerTitlePeer();
1207: }
1208:
1209: return self::$peer;
1210: }
1211:
1212:
1213: /**
1214: * Initializes a collection based on the name of a relation.
1215: * Avoids crafting an 'init[$relationName]s' method name
1216: * that wouldn't work when StandardEnglishPluralizer is used.
1217: *
1218: * @param string $relationName The name of the relation to initialize
1219: * @return void
1220: */
1221: public function initRelation($relationName)
1222: {
1223: if ('Customer' == $relationName) {
1224: $this->initCustomers();
1225: }
1226: if ('Address' == $relationName) {
1227: $this->initAddresss();
1228: }
1229: if ('CustomerTitleI18n' == $relationName) {
1230: $this->initCustomerTitleI18ns();
1231: }
1232: }
1233:
1234: /**
1235: * Clears out the collCustomers collection
1236: *
1237: * This does not modify the database; however, it will remove any associated objects, causing
1238: * them to be refetched by subsequent calls to accessor method.
1239: *
1240: * @return void
1241: * @see addCustomers()
1242: */
1243: public function clearCustomers()
1244: {
1245: $this->collCustomers = null; // important to set this to null since that means it is uninitialized
1246: $this->collCustomersPartial = null;
1247: }
1248:
1249: /**
1250: * reset is the collCustomers collection loaded partially
1251: *
1252: * @return void
1253: */
1254: public function resetPartialCustomers($v = true)
1255: {
1256: $this->collCustomersPartial = $v;
1257: }
1258:
1259: /**
1260: * Initializes the collCustomers collection.
1261: *
1262: * By default this just sets the collCustomers collection to an empty array (like clearcollCustomers());
1263: * however, you may wish to override this method in your stub class to provide setting appropriate
1264: * to your application -- for example, setting the initial array to the values stored in database.
1265: *
1266: * @param boolean $overrideExisting If set to true, the method call initializes
1267: * the collection even if it is not empty
1268: *
1269: * @return void
1270: */
1271: public function initCustomers($overrideExisting = true)
1272: {
1273: if (null !== $this->collCustomers && !$overrideExisting) {
1274: return;
1275: }
1276: $this->collCustomers = new PropelObjectCollection();
1277: $this->collCustomers->setModel('Customer');
1278: }
1279:
1280: /**
1281: * Gets an array of Customer objects which contain a foreign key that references this object.
1282: *
1283: * If the $criteria is not null, it is used to always fetch the results from the database.
1284: * Otherwise the results are fetched from the database the first time, then cached.
1285: * Next time the same method is called without $criteria, the cached collection is returned.
1286: * If this CustomerTitle is new, it will return
1287: * an empty collection or the current collection; the criteria is ignored on a new object.
1288: *
1289: * @param Criteria $criteria optional Criteria object to narrow the query
1290: * @param PropelPDO $con optional connection object
1291: * @return PropelObjectCollection|Customer[] List of Customer objects
1292: * @throws PropelException
1293: */
1294: public function getCustomers($criteria = null, PropelPDO $con = null)
1295: {
1296: $partial = $this->collCustomersPartial && !$this->isNew();
1297: if (null === $this->collCustomers || null !== $criteria || $partial) {
1298: if ($this->isNew() && null === $this->collCustomers) {
1299: // return empty collection
1300: $this->initCustomers();
1301: } else {
1302: $collCustomers = CustomerQuery::create(null, $criteria)
1303: ->filterByCustomerTitle($this)
1304: ->find($con);
1305: if (null !== $criteria) {
1306: if (false !== $this->collCustomersPartial && count($collCustomers)) {
1307: $this->initCustomers(false);
1308:
1309: foreach($collCustomers as $obj) {
1310: if (false == $this->collCustomers->contains($obj)) {
1311: $this->collCustomers->append($obj);
1312: }
1313: }
1314:
1315: $this->collCustomersPartial = true;
1316: }
1317:
1318: return $collCustomers;
1319: }
1320:
1321: if($partial && $this->collCustomers) {
1322: foreach($this->collCustomers as $obj) {
1323: if($obj->isNew()) {
1324: $collCustomers[] = $obj;
1325: }
1326: }
1327: }
1328:
1329: $this->collCustomers = $collCustomers;
1330: $this->collCustomersPartial = false;
1331: }
1332: }
1333:
1334: return $this->collCustomers;
1335: }
1336:
1337: /**
1338: * Sets a collection of Customer objects related by a one-to-many relationship
1339: * to the current object.
1340: * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1341: * and new objects from the given Propel collection.
1342: *
1343: * @param PropelCollection $customers A Propel collection.
1344: * @param PropelPDO $con Optional connection object
1345: */
1346: public function setCustomers(PropelCollection $customers, PropelPDO $con = null)
1347: {
1348: $this->customersScheduledForDeletion = $this->getCustomers(new Criteria(), $con)->diff($customers);
1349:
1350: foreach ($this->customersScheduledForDeletion as $customerRemoved) {
1351: $customerRemoved->setCustomerTitle(null);
1352: }
1353:
1354: $this->collCustomers = null;
1355: foreach ($customers as $customer) {
1356: $this->addCustomer($customer);
1357: }
1358:
1359: $this->collCustomers = $customers;
1360: $this->collCustomersPartial = false;
1361: }
1362:
1363: /**
1364: * Returns the number of related Customer objects.
1365: *
1366: * @param Criteria $criteria
1367: * @param boolean $distinct
1368: * @param PropelPDO $con
1369: * @return int Count of related Customer objects.
1370: * @throws PropelException
1371: */
1372: public function countCustomers(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1373: {
1374: $partial = $this->collCustomersPartial && !$this->isNew();
1375: if (null === $this->collCustomers || null !== $criteria || $partial) {
1376: if ($this->isNew() && null === $this->collCustomers) {
1377: return 0;
1378: } else {
1379: if($partial && !$criteria) {
1380: return count($this->getCustomers());
1381: }
1382: $query = CustomerQuery::create(null, $criteria);
1383: if ($distinct) {
1384: $query->distinct();
1385: }
1386:
1387: return $query
1388: ->filterByCustomerTitle($this)
1389: ->count($con);
1390: }
1391: } else {
1392: return count($this->collCustomers);
1393: }
1394: }
1395:
1396: /**
1397: * Method called to associate a Customer object to this object
1398: * through the Customer foreign key attribute.
1399: *
1400: * @param Customer $l Customer
1401: * @return CustomerTitle The current object (for fluent API support)
1402: */
1403: public function addCustomer(Customer $l)
1404: {
1405: if ($this->collCustomers === null) {
1406: $this->initCustomers();
1407: $this->collCustomersPartial = true;
1408: }
1409: if (!$this->collCustomers->contains($l)) { // only add it if the **same** object is not already associated
1410: $this->doAddCustomer($l);
1411: }
1412:
1413: return $this;
1414: }
1415:
1416: /**
1417: * @param Customer $customer The customer object to add.
1418: */
1419: protected function doAddCustomer($customer)
1420: {
1421: $this->collCustomers[]= $customer;
1422: $customer->setCustomerTitle($this);
1423: }
1424:
1425: /**
1426: * @param Customer $customer The customer object to remove.
1427: */
1428: public function removeCustomer($customer)
1429: {
1430: if ($this->getCustomers()->contains($customer)) {
1431: $this->collCustomers->remove($this->collCustomers->search($customer));
1432: if (null === $this->customersScheduledForDeletion) {
1433: $this->customersScheduledForDeletion = clone $this->collCustomers;
1434: $this->customersScheduledForDeletion->clear();
1435: }
1436: $this->customersScheduledForDeletion[]= $customer;
1437: $customer->setCustomerTitle(null);
1438: }
1439: }
1440:
1441: /**
1442: * Clears out the collAddresss collection
1443: *
1444: * This does not modify the database; however, it will remove any associated objects, causing
1445: * them to be refetched by subsequent calls to accessor method.
1446: *
1447: * @return void
1448: * @see addAddresss()
1449: */
1450: public function clearAddresss()
1451: {
1452: $this->collAddresss = null; // important to set this to null since that means it is uninitialized
1453: $this->collAddresssPartial = null;
1454: }
1455:
1456: /**
1457: * reset is the collAddresss collection loaded partially
1458: *
1459: * @return void
1460: */
1461: public function resetPartialAddresss($v = true)
1462: {
1463: $this->collAddresssPartial = $v;
1464: }
1465:
1466: /**
1467: * Initializes the collAddresss collection.
1468: *
1469: * By default this just sets the collAddresss collection to an empty array (like clearcollAddresss());
1470: * however, you may wish to override this method in your stub class to provide setting appropriate
1471: * to your application -- for example, setting the initial array to the values stored in database.
1472: *
1473: * @param boolean $overrideExisting If set to true, the method call initializes
1474: * the collection even if it is not empty
1475: *
1476: * @return void
1477: */
1478: public function initAddresss($overrideExisting = true)
1479: {
1480: if (null !== $this->collAddresss && !$overrideExisting) {
1481: return;
1482: }
1483: $this->collAddresss = new PropelObjectCollection();
1484: $this->collAddresss->setModel('Address');
1485: }
1486:
1487: /**
1488: * Gets an array of Address objects which contain a foreign key that references this object.
1489: *
1490: * If the $criteria is not null, it is used to always fetch the results from the database.
1491: * Otherwise the results are fetched from the database the first time, then cached.
1492: * Next time the same method is called without $criteria, the cached collection is returned.
1493: * If this CustomerTitle is new, it will return
1494: * an empty collection or the current collection; the criteria is ignored on a new object.
1495: *
1496: * @param Criteria $criteria optional Criteria object to narrow the query
1497: * @param PropelPDO $con optional connection object
1498: * @return PropelObjectCollection|Address[] List of Address objects
1499: * @throws PropelException
1500: */
1501: public function getAddresss($criteria = null, PropelPDO $con = null)
1502: {
1503: $partial = $this->collAddresssPartial && !$this->isNew();
1504: if (null === $this->collAddresss || null !== $criteria || $partial) {
1505: if ($this->isNew() && null === $this->collAddresss) {
1506: // return empty collection
1507: $this->initAddresss();
1508: } else {
1509: $collAddresss = AddressQuery::create(null, $criteria)
1510: ->filterByCustomerTitle($this)
1511: ->find($con);
1512: if (null !== $criteria) {
1513: if (false !== $this->collAddresssPartial && count($collAddresss)) {
1514: $this->initAddresss(false);
1515:
1516: foreach($collAddresss as $obj) {
1517: if (false == $this->collAddresss->contains($obj)) {
1518: $this->collAddresss->append($obj);
1519: }
1520: }
1521:
1522: $this->collAddresssPartial = true;
1523: }
1524:
1525: return $collAddresss;
1526: }
1527:
1528: if($partial && $this->collAddresss) {
1529: foreach($this->collAddresss as $obj) {
1530: if($obj->isNew()) {
1531: $collAddresss[] = $obj;
1532: }
1533: }
1534: }
1535:
1536: $this->collAddresss = $collAddresss;
1537: $this->collAddresssPartial = false;
1538: }
1539: }
1540:
1541: return $this->collAddresss;
1542: }
1543:
1544: /**
1545: * Sets a collection of Address objects related by a one-to-many relationship
1546: * to the current object.
1547: * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1548: * and new objects from the given Propel collection.
1549: *
1550: * @param PropelCollection $addresss A Propel collection.
1551: * @param PropelPDO $con Optional connection object
1552: */
1553: public function setAddresss(PropelCollection $addresss, PropelPDO $con = null)
1554: {
1555: $this->addresssScheduledForDeletion = $this->getAddresss(new Criteria(), $con)->diff($addresss);
1556:
1557: foreach ($this->addresssScheduledForDeletion as $addressRemoved) {
1558: $addressRemoved->setCustomerTitle(null);
1559: }
1560:
1561: $this->collAddresss = null;
1562: foreach ($addresss as $address) {
1563: $this->addAddress($address);
1564: }
1565:
1566: $this->collAddresss = $addresss;
1567: $this->collAddresssPartial = false;
1568: }
1569:
1570: /**
1571: * Returns the number of related Address objects.
1572: *
1573: * @param Criteria $criteria
1574: * @param boolean $distinct
1575: * @param PropelPDO $con
1576: * @return int Count of related Address objects.
1577: * @throws PropelException
1578: */
1579: public function countAddresss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1580: {
1581: $partial = $this->collAddresssPartial && !$this->isNew();
1582: if (null === $this->collAddresss || null !== $criteria || $partial) {
1583: if ($this->isNew() && null === $this->collAddresss) {
1584: return 0;
1585: } else {
1586: if($partial && !$criteria) {
1587: return count($this->getAddresss());
1588: }
1589: $query = AddressQuery::create(null, $criteria);
1590: if ($distinct) {
1591: $query->distinct();
1592: }
1593:
1594: return $query
1595: ->filterByCustomerTitle($this)
1596: ->count($con);
1597: }
1598: } else {
1599: return count($this->collAddresss);
1600: }
1601: }
1602:
1603: /**
1604: * Method called to associate a Address object to this object
1605: * through the Address foreign key attribute.
1606: *
1607: * @param Address $l Address
1608: * @return CustomerTitle The current object (for fluent API support)
1609: */
1610: public function addAddress(Address $l)
1611: {
1612: if ($this->collAddresss === null) {
1613: $this->initAddresss();
1614: $this->collAddresssPartial = true;
1615: }
1616: if (!$this->collAddresss->contains($l)) { // only add it if the **same** object is not already associated
1617: $this->doAddAddress($l);
1618: }
1619:
1620: return $this;
1621: }
1622:
1623: /**
1624: * @param Address $address The address object to add.
1625: */
1626: protected function doAddAddress($address)
1627: {
1628: $this->collAddresss[]= $address;
1629: $address->setCustomerTitle($this);
1630: }
1631:
1632: /**
1633: * @param Address $address The address object to remove.
1634: */
1635: public function removeAddress($address)
1636: {
1637: if ($this->getAddresss()->contains($address)) {
1638: $this->collAddresss->remove($this->collAddresss->search($address));
1639: if (null === $this->addresssScheduledForDeletion) {
1640: $this->addresssScheduledForDeletion = clone $this->collAddresss;
1641: $this->addresssScheduledForDeletion->clear();
1642: }
1643: $this->addresssScheduledForDeletion[]= $address;
1644: $address->setCustomerTitle(null);
1645: }
1646: }
1647:
1648:
1649: /**
1650: * If this collection has already been initialized with
1651: * an identical criteria, it returns the collection.
1652: * Otherwise if this CustomerTitle is new, it will return
1653: * an empty collection; or if this CustomerTitle has previously
1654: * been saved, it will retrieve related Addresss from storage.
1655: *
1656: * This method is protected by default in order to keep the public
1657: * api reasonable. You can provide public methods for those you
1658: * actually need in CustomerTitle.
1659: *
1660: * @param Criteria $criteria optional Criteria object to narrow the query
1661: * @param PropelPDO $con optional connection object
1662: * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1663: * @return PropelObjectCollection|Address[] List of Address objects
1664: */
1665: public function getAddresssJoinCustomer($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
1666: {
1667: $query = AddressQuery::create(null, $criteria);
1668: $query->joinWith('Customer', $join_behavior);
1669:
1670: return $this->getAddresss($query, $con);
1671: }
1672:
1673: /**
1674: * Clears out the collCustomerTitleI18ns collection
1675: *
1676: * This does not modify the database; however, it will remove any associated objects, causing
1677: * them to be refetched by subsequent calls to accessor method.
1678: *
1679: * @return void
1680: * @see addCustomerTitleI18ns()
1681: */
1682: public function clearCustomerTitleI18ns()
1683: {
1684: $this->collCustomerTitleI18ns = null; // important to set this to null since that means it is uninitialized
1685: $this->collCustomerTitleI18nsPartial = null;
1686: }
1687:
1688: /**
1689: * reset is the collCustomerTitleI18ns collection loaded partially
1690: *
1691: * @return void
1692: */
1693: public function resetPartialCustomerTitleI18ns($v = true)
1694: {
1695: $this->collCustomerTitleI18nsPartial = $v;
1696: }
1697:
1698: /**
1699: * Initializes the collCustomerTitleI18ns collection.
1700: *
1701: * By default this just sets the collCustomerTitleI18ns collection to an empty array (like clearcollCustomerTitleI18ns());
1702: * however, you may wish to override this method in your stub class to provide setting appropriate
1703: * to your application -- for example, setting the initial array to the values stored in database.
1704: *
1705: * @param boolean $overrideExisting If set to true, the method call initializes
1706: * the collection even if it is not empty
1707: *
1708: * @return void
1709: */
1710: public function initCustomerTitleI18ns($overrideExisting = true)
1711: {
1712: if (null !== $this->collCustomerTitleI18ns && !$overrideExisting) {
1713: return;
1714: }
1715: $this->collCustomerTitleI18ns = new PropelObjectCollection();
1716: $this->collCustomerTitleI18ns->setModel('CustomerTitleI18n');
1717: }
1718:
1719: /**
1720: * Gets an array of CustomerTitleI18n objects which contain a foreign key that references this object.
1721: *
1722: * If the $criteria is not null, it is used to always fetch the results from the database.
1723: * Otherwise the results are fetched from the database the first time, then cached.
1724: * Next time the same method is called without $criteria, the cached collection is returned.
1725: * If this CustomerTitle is new, it will return
1726: * an empty collection or the current collection; the criteria is ignored on a new object.
1727: *
1728: * @param Criteria $criteria optional Criteria object to narrow the query
1729: * @param PropelPDO $con optional connection object
1730: * @return PropelObjectCollection|CustomerTitleI18n[] List of CustomerTitleI18n objects
1731: * @throws PropelException
1732: */
1733: public function getCustomerTitleI18ns($criteria = null, PropelPDO $con = null)
1734: {
1735: $partial = $this->collCustomerTitleI18nsPartial && !$this->isNew();
1736: if (null === $this->collCustomerTitleI18ns || null !== $criteria || $partial) {
1737: if ($this->isNew() && null === $this->collCustomerTitleI18ns) {
1738: // return empty collection
1739: $this->initCustomerTitleI18ns();
1740: } else {
1741: $collCustomerTitleI18ns = CustomerTitleI18nQuery::create(null, $criteria)
1742: ->filterByCustomerTitle($this)
1743: ->find($con);
1744: if (null !== $criteria) {
1745: if (false !== $this->collCustomerTitleI18nsPartial && count($collCustomerTitleI18ns)) {
1746: $this->initCustomerTitleI18ns(false);
1747:
1748: foreach($collCustomerTitleI18ns as $obj) {
1749: if (false == $this->collCustomerTitleI18ns->contains($obj)) {
1750: $this->collCustomerTitleI18ns->append($obj);
1751: }
1752: }
1753:
1754: $this->collCustomerTitleI18nsPartial = true;
1755: }
1756:
1757: return $collCustomerTitleI18ns;
1758: }
1759:
1760: if($partial && $this->collCustomerTitleI18ns) {
1761: foreach($this->collCustomerTitleI18ns as $obj) {
1762: if($obj->isNew()) {
1763: $collCustomerTitleI18ns[] = $obj;
1764: }
1765: }
1766: }
1767:
1768: $this->collCustomerTitleI18ns = $collCustomerTitleI18ns;
1769: $this->collCustomerTitleI18nsPartial = false;
1770: }
1771: }
1772:
1773: return $this->collCustomerTitleI18ns;
1774: }
1775:
1776: /**
1777: * Sets a collection of CustomerTitleI18n objects related by a one-to-many relationship
1778: * to the current object.
1779: * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1780: * and new objects from the given Propel collection.
1781: *
1782: * @param PropelCollection $customerTitleI18ns A Propel collection.
1783: * @param PropelPDO $con Optional connection object
1784: */
1785: public function setCustomerTitleI18ns(PropelCollection $customerTitleI18ns, PropelPDO $con = null)
1786: {
1787: $this->customerTitleI18nsScheduledForDeletion = $this->getCustomerTitleI18ns(new Criteria(), $con)->diff($customerTitleI18ns);
1788:
1789: foreach ($this->customerTitleI18nsScheduledForDeletion as $customerTitleI18nRemoved) {
1790: $customerTitleI18nRemoved->setCustomerTitle(null);
1791: }
1792:
1793: $this->collCustomerTitleI18ns = null;
1794: foreach ($customerTitleI18ns as $customerTitleI18n) {
1795: $this->addCustomerTitleI18n($customerTitleI18n);
1796: }
1797:
1798: $this->collCustomerTitleI18ns = $customerTitleI18ns;
1799: $this->collCustomerTitleI18nsPartial = false;
1800: }
1801:
1802: /**
1803: * Returns the number of related CustomerTitleI18n objects.
1804: *
1805: * @param Criteria $criteria
1806: * @param boolean $distinct
1807: * @param PropelPDO $con
1808: * @return int Count of related CustomerTitleI18n objects.
1809: * @throws PropelException
1810: */
1811: public function countCustomerTitleI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1812: {
1813: $partial = $this->collCustomerTitleI18nsPartial && !$this->isNew();
1814: if (null === $this->collCustomerTitleI18ns || null !== $criteria || $partial) {
1815: if ($this->isNew() && null === $this->collCustomerTitleI18ns) {
1816: return 0;
1817: } else {
1818: if($partial && !$criteria) {
1819: return count($this->getCustomerTitleI18ns());
1820: }
1821: $query = CustomerTitleI18nQuery::create(null, $criteria);
1822: if ($distinct) {
1823: $query->distinct();
1824: }
1825:
1826: return $query
1827: ->filterByCustomerTitle($this)
1828: ->count($con);
1829: }
1830: } else {
1831: return count($this->collCustomerTitleI18ns);
1832: }
1833: }
1834:
1835: /**
1836: * Method called to associate a CustomerTitleI18n object to this object
1837: * through the CustomerTitleI18n foreign key attribute.
1838: *
1839: * @param CustomerTitleI18n $l CustomerTitleI18n
1840: * @return CustomerTitle The current object (for fluent API support)
1841: */
1842: public function addCustomerTitleI18n(CustomerTitleI18n $l)
1843: {
1844: if ($l && $locale = $l->getLocale()) {
1845: $this->setLocale($locale);
1846: $this->currentTranslations[$locale] = $l;
1847: }
1848: if ($this->collCustomerTitleI18ns === null) {
1849: $this->initCustomerTitleI18ns();
1850: $this->collCustomerTitleI18nsPartial = true;
1851: }
1852: if (!$this->collCustomerTitleI18ns->contains($l)) { // only add it if the **same** object is not already associated
1853: $this->doAddCustomerTitleI18n($l);
1854: }
1855:
1856: return $this;
1857: }
1858:
1859: /**
1860: * @param CustomerTitleI18n $customerTitleI18n The customerTitleI18n object to add.
1861: */
1862: protected function doAddCustomerTitleI18n($customerTitleI18n)
1863: {
1864: $this->collCustomerTitleI18ns[]= $customerTitleI18n;
1865: $customerTitleI18n->setCustomerTitle($this);
1866: }
1867:
1868: /**
1869: * @param CustomerTitleI18n $customerTitleI18n The customerTitleI18n object to remove.
1870: */
1871: public function removeCustomerTitleI18n($customerTitleI18n)
1872: {
1873: if ($this->getCustomerTitleI18ns()->contains($customerTitleI18n)) {
1874: $this->collCustomerTitleI18ns->remove($this->collCustomerTitleI18ns->search($customerTitleI18n));
1875: if (null === $this->customerTitleI18nsScheduledForDeletion) {
1876: $this->customerTitleI18nsScheduledForDeletion = clone $this->collCustomerTitleI18ns;
1877: $this->customerTitleI18nsScheduledForDeletion->clear();
1878: }
1879: $this->customerTitleI18nsScheduledForDeletion[]= $customerTitleI18n;
1880: $customerTitleI18n->setCustomerTitle(null);
1881: }
1882: }
1883:
1884: /**
1885: * Clears the current object and sets all attributes to their default values
1886: */
1887: public function clear()
1888: {
1889: $this->id = null;
1890: $this->by_default = null;
1891: $this->position = null;
1892: $this->created_at = null;
1893: $this->updated_at = null;
1894: $this->alreadyInSave = false;
1895: $this->alreadyInValidation = false;
1896: $this->clearAllReferences();
1897: $this->applyDefaultValues();
1898: $this->resetModified();
1899: $this->setNew(true);
1900: $this->setDeleted(false);
1901: }
1902:
1903: /**
1904: * Resets all references to other model objects or collections of model objects.
1905: *
1906: * This method is a user-space workaround for PHP's inability to garbage collect
1907: * objects with circular references (even in PHP 5.3). This is currently necessary
1908: * when using Propel in certain daemon or large-volumne/high-memory operations.
1909: *
1910: * @param boolean $deep Whether to also clear the references on all referrer objects.
1911: */
1912: public function clearAllReferences($deep = false)
1913: {
1914: if ($deep) {
1915: if ($this->collCustomers) {
1916: foreach ($this->collCustomers as $o) {
1917: $o->clearAllReferences($deep);
1918: }
1919: }
1920: if ($this->collAddresss) {
1921: foreach ($this->collAddresss as $o) {
1922: $o->clearAllReferences($deep);
1923: }
1924: }
1925: if ($this->collCustomerTitleI18ns) {
1926: foreach ($this->collCustomerTitleI18ns as $o) {
1927: $o->clearAllReferences($deep);
1928: }
1929: }
1930: } // if ($deep)
1931:
1932: // i18n behavior
1933: $this->currentLocale = 'en_EN';
1934: $this->currentTranslations = null;
1935:
1936: if ($this->collCustomers instanceof PropelCollection) {
1937: $this->collCustomers->clearIterator();
1938: }
1939: $this->collCustomers = null;
1940: if ($this->collAddresss instanceof PropelCollection) {
1941: $this->collAddresss->clearIterator();
1942: }
1943: $this->collAddresss = null;
1944: if ($this->collCustomerTitleI18ns instanceof PropelCollection) {
1945: $this->collCustomerTitleI18ns->clearIterator();
1946: }
1947: $this->collCustomerTitleI18ns = null;
1948: }
1949:
1950: /**
1951: * return the string representation of this object
1952: *
1953: * @return string
1954: */
1955: public function __toString()
1956: {
1957: return (string) $this->exportTo(CustomerTitlePeer::DEFAULT_STRING_FORMAT);
1958: }
1959:
1960: /**
1961: * return true is the object is in saving state
1962: *
1963: * @return boolean
1964: */
1965: public function isAlreadyInSave()
1966: {
1967: return $this->alreadyInSave;
1968: }
1969:
1970: // timestampable behavior
1971:
1972: /**
1973: * Mark the current object so that the update date doesn't get updated during next save
1974: *
1975: * @return CustomerTitle The current object (for fluent API support)
1976: */
1977: public function keepUpdateDateUnchanged()
1978: {
1979: $this->modifiedColumns[] = CustomerTitlePeer::UPDATED_AT;
1980:
1981: return $this;
1982: }
1983:
1984: // i18n behavior
1985:
1986: /**
1987: * Sets the locale for translations
1988: *
1989: * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
1990: *
1991: * @return CustomerTitle The current object (for fluent API support)
1992: */
1993: public function setLocale($locale = 'en_EN')
1994: {
1995: $this->currentLocale = $locale;
1996:
1997: return $this;
1998: }
1999:
2000: /**
2001: * Gets the locale for translations
2002: *
2003: * @return string $locale Locale to use for the translation, e.g. 'fr_FR'
2004: */
2005: public function getLocale()
2006: {
2007: return $this->currentLocale;
2008: }
2009:
2010: /**
2011: * Returns the current translation for a given locale
2012: *
2013: * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
2014: * @param PropelPDO $con an optional connection object
2015: *
2016: * @return CustomerTitleI18n */
2017: public function getTranslation($locale = 'en_EN', PropelPDO $con = null)
2018: {
2019: if (!isset($this->currentTranslations[$locale])) {
2020: if (null !== $this->collCustomerTitleI18ns) {
2021: foreach ($this->collCustomerTitleI18ns as $translation) {
2022: if ($translation->getLocale() == $locale) {
2023: $this->currentTranslations[$locale] = $translation;
2024:
2025: return $translation;
2026: }
2027: }
2028: }
2029: if ($this->isNew()) {
2030: $translation = new CustomerTitleI18n();
2031: $translation->setLocale($locale);
2032: } else {
2033: $translation = CustomerTitleI18nQuery::create()
2034: ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
2035: ->findOneOrCreate($con);
2036: $this->currentTranslations[$locale] = $translation;
2037: }
2038: $this->addCustomerTitleI18n($translation);
2039: }
2040:
2041: return $this->currentTranslations[$locale];
2042: }
2043:
2044: /**
2045: * Remove the translation for a given locale
2046: *
2047: * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
2048: * @param PropelPDO $con an optional connection object
2049: *
2050: * @return CustomerTitle The current object (for fluent API support)
2051: */
2052: public function removeTranslation($locale = 'en_EN', PropelPDO $con = null)
2053: {
2054: if (!$this->isNew()) {
2055: CustomerTitleI18nQuery::create()
2056: ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
2057: ->delete($con);
2058: }
2059: if (isset($this->currentTranslations[$locale])) {
2060: unset($this->currentTranslations[$locale]);
2061: }
2062: foreach ($this->collCustomerTitleI18ns as $key => $translation) {
2063: if ($translation->getLocale() == $locale) {
2064: unset($this->collCustomerTitleI18ns[$key]);
2065: break;
2066: }
2067: }
2068:
2069: return $this;
2070: }
2071:
2072: /**
2073: * Returns the current translation
2074: *
2075: * @param PropelPDO $con an optional connection object
2076: *
2077: * @return CustomerTitleI18n */
2078: public function getCurrentTranslation(PropelPDO $con = null)
2079: {
2080: return $this->getTranslation($this->getLocale(), $con);
2081: }
2082:
2083:
2084: /**
2085: * Get the [short] column value.
2086: *
2087: * @return string
2088: */
2089: public function getShort()
2090: {
2091: return $this->getCurrentTranslation()->getShort();
2092: }
2093:
2094:
2095: /**
2096: * Set the value of [short] column.
2097: *
2098: * @param string $v new value
2099: * @return CustomerTitleI18n The current object (for fluent API support)
2100: */
2101: public function setShort($v)
2102: { $this->getCurrentTranslation()->setShort($v);
2103:
2104: return $this;
2105: }
2106:
2107:
2108: /**
2109: * Get the [long] column value.
2110: *
2111: * @return string
2112: */
2113: public function getLong()
2114: {
2115: return $this->getCurrentTranslation()->getLong();
2116: }
2117:
2118:
2119: /**
2120: * Set the value of [long] column.
2121: *
2122: * @param string $v new value
2123: * @return CustomerTitleI18n The current object (for fluent API support)
2124: */
2125: public function setLong($v)
2126: { $this->getCurrentTranslation()->setLong($v);
2127:
2128: return $this;
2129: }
2130:
2131: }
2132: