A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
5.1 KiB

  1. <?php
  2. require(__DATAGEN_CLASSES__ . '/AddressGen.class.php');
  3. /**
  4. * The Address class defined here contains any
  5. * customized code for the Address class in the
  6. * Object Relational Model. It represents the "address" table
  7. * in the database, and extends from the code generated abstract AddressGen
  8. * class, which contains all the basic CRUD-type functionality as well as
  9. * basic methods to handle relationships and index-based loading.
  10. *
  11. * @package Quinta
  12. * @subpackage Models
  13. *
  14. */
  15. class Address extends AddressGen {
  16. /**
  17. * Protected member variable that maps to the database column address.zone_id
  18. * @var integer intZoneId
  19. */
  20. protected $intZoneId = 13;
  21. const ZoneIdDefault = 13;
  22. /**
  23. * Protected member variable that maps to the database column address.country_id
  24. * @var integer intCountryId
  25. */
  26. protected $intCountryId = 223;
  27. const CountryIdDefault = 223;
  28. /**
  29. * Protected member variable that maps to the database column address.is_current
  30. * @var boolean blnIsCurrent
  31. */
  32. protected $blnIsCurrent = true;
  33. const IsCurrentDefault = true;
  34. /**
  35. * Protected member variable that maps to the database column address.type_id
  36. * @var integer intTypeId
  37. */
  38. protected $intTypeId =1;
  39. const TypeIdDefault = 1;
  40. /**
  41. * Default "to string" handler
  42. * Allows pages to _p()/echo()/print() this object, and to define the default
  43. * way this object would be outputted.
  44. *
  45. * Can also be called directly via $objAddress->__toString().
  46. *
  47. * @return string a nicely formatted string representation of this object
  48. */
  49. public function __toString()
  50. {
  51. if(isset($this->Title))
  52. return $this->Title;
  53. else
  54. return "Primary address";
  55. }
  56. ///gettors
  57. public function __get($strName)
  58. {
  59. switch ($strName)
  60. {
  61. case 'Country':
  62. return ($this->CountryId) ? CountryType::$NameArray[$this->CountryId] : null;
  63. case 'State':
  64. case 'Zone':
  65. return ($this->ZoneId) ? ZoneType::$NameArray[$this->ZoneId] : null;
  66. case 'Type':
  67. return ($this->TypeId) ? AddressType::$NameArray[$this->TypeId] : null;
  68. default:
  69. try {
  70. return parent::__get($strName);
  71. } catch (QCallerException $objExc) {
  72. $objExc->IncrementOffset();
  73. throw $objExc;
  74. }
  75. }
  76. }
  77. ///settors
  78. public function __set($strName, $mixValue)
  79. {
  80. switch ($strName)
  81. {
  82. //experimental - not really used ..
  83. case 'Country':
  84. if(! is_string($mixValue) )
  85. throw new QCallerException('Set Address country - value must be a string.');
  86. $intCountryId = 0;
  87. foreach( CountryType::$NameArray as $intId => $strName )
  88. if( $strName === $mixValue )
  89. $intCountryId = $intId;
  90. if( 0 == $intCountryId)
  91. throw new QCallerException('Set Address country - unknown country:' . $mixValue);
  92. try {
  93. return ($this->CountryId = QType::Cast($intCountryId, QType::String));
  94. } catch (QInvalidCastException $objExc) {
  95. $objExc->IncrementOffset();
  96. throw $objExc;
  97. }
  98. default:
  99. try {
  100. return (parent::__set($strName, $mixValue));
  101. } catch (QCallerException $objExc) {
  102. $objExc->IncrementOffset();
  103. throw $objExc;
  104. }
  105. }
  106. }
  107. // Override or Create New Load/Count methods
  108. // (For obvious reasons, these methods are commented out...
  109. // but feel free to use these as a starting point)
  110. /*
  111. public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses = null) {
  112. // This will return an array of Address objects
  113. return Address::QueryArray(
  114. QQ::AndCondition(
  115. QQ::Equal(QQN::Address()->Param1, $strParam1),
  116. QQ::GreaterThan(QQN::Address()->Param2, $intParam2)
  117. ),
  118. $objOptionalClauses
  119. );
  120. }
  121. public static function LoadBySample($strParam1, $intParam2, $objOptionalClauses = null) {
  122. // This will return a single Address object
  123. return Address::QuerySingle(
  124. QQ::AndCondition(
  125. QQ::Equal(QQN::Address()->Param1, $strParam1),
  126. QQ::GreaterThan(QQN::Address()->Param2, $intParam2)
  127. ),
  128. $objOptionalClauses
  129. );
  130. }
  131. public static function CountBySample($strParam1, $intParam2, $objOptionalClauses = null) {
  132. // This will return a count of Address objects
  133. return Address::QueryCount(
  134. QQ::AndCondition(
  135. QQ::Equal(QQN::Address()->Param1, $strParam1),
  136. QQ::Equal(QQN::Address()->Param2, $intParam2)
  137. ),
  138. $objOptionalClauses
  139. );
  140. }
  141. public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses) {
  142. // Performing the load manually (instead of using Qcodo Query)
  143. // Get the Database Object for this Class
  144. $objDatabase = Address::GetDatabase();
  145. // Properly Escape All Input Parameters using Database->SqlVariable()
  146. $strParam1 = $objDatabase->SqlVariable($strParam1);
  147. $intParam2 = $objDatabase->SqlVariable($intParam2);
  148. // Setup the SQL Query
  149. $strQuery = sprintf('
  150. SELECT
  151. `address`.*
  152. FROM
  153. `address` AS `address`
  154. WHERE
  155. param_1 = %s AND
  156. param_2 < %s',
  157. $strParam1, $intParam2);
  158. // Perform the Query and Instantiate the Result
  159. $objDbResult = $objDatabase->Query($strQuery);
  160. return Address::InstantiateDbResult($objDbResult);
  161. }
  162. */
  163. }
  164. ?>