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