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