# File core/lib/Thelia/Model/om/BaseAddress.php | thelia

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