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