A Qcodo based CMS/ecommerce framework
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.

178 lines
7.4 KiB

12 years ago
  1. <?php
  2. require(__DATAGEN_META_CONTROLS__ . '/AddressMetaControlGen.class.php');
  3. /**
  4. * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
  5. * and QControls to perform the Create, Edit, and Delete functionality of the
  6. * Address class. This code-generated class extends from
  7. * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
  8. * display an HTML form that can manipulate a single Address object.
  9. *
  10. * To take advantage of some (or all) of these control objects, you
  11. * must create a new QForm or QPanel which instantiates a AddressMetaControl
  12. * class.
  13. *
  14. * This file is intended to be modified. Subsequent code regenerations will NOT modify
  15. * or overwrite this file.
  16. *
  17. * @package Quasi
  18. * @subpackage MetaControls
  19. */
  20. class AddressMetaControl extends AddressMetaControlGen
  21. {
  22. /**
  23. * @var QListBox - a listbox with People associated with a specific person
  24. */
  25. protected $lstMyPeople;
  26. /**
  27. * @var QListBox - a listbox with Address associated with a specific Account
  28. */
  29. protected $lstMyAddresses;
  30. /**
  31. * Create and setup QListBox lstMyPeople
  32. * This creates a listbox containing only persons associated with the Person
  33. * passed as PersonId.
  34. *
  35. *@param integer intPersonId - the person for whom to create an associated listbox
  36. * @param string $strControlId optional ControlId to use
  37. * @return QListBox
  38. */
  39. public function lstMyPeople_Create($intPersonId, $strControlId = null)
  40. {
  41. $this->lstPerson = new QListBox($this->objParentObject, $strControlId);
  42. $this->lstPerson->Name = QApplication::Translate('Person');
  43. $this->lstPerson->Required = true;
  44. if (!$this->blnEditMode)
  45. $this->lstPerson->AddItem(QApplication::Translate('- Select One -'), null);
  46. $aryPersons[] = Person::LoadById($intPersonId);
  47. $aryOwnedPersons = Person::LoadArrayByOwnerPersonId($intPersonId);
  48. if($aryOwnedPersons)
  49. $aryPersons = array_merge($aryPersons, $aryOwnedPersons);
  50. if ($aryPersons)
  51. foreach ($aryPersons as $objPerson)
  52. {
  53. $objListItem = new QListItem($objPerson->__toString(), $objPerson->Id);
  54. if ($this->objAddress->PersonId == $objPerson->Id)
  55. $objListItem->Selected = true;
  56. $this->lstPerson->AddItem($objListItem);
  57. }
  58. return $this->lstPerson;
  59. }
  60. /**
  61. * Create and setup QListBox lstMyAddresses
  62. * This creates a listbox containing only addresses associated with the Account
  63. * passed as AccountId.
  64. *
  65. * @param Account objAccount - the account for which to create an associated listbox
  66. * @param string $strControlId optional ControlId to use
  67. * @return QListBox
  68. */
  69. public function lstMyAddresses_Create($objAccount, $strControlId = null)
  70. {
  71. $this->lstMyAddresses = new QListBox($this->objParentObject, $strControlId);
  72. $this->lstMyAddresses->Name = QApplication::Translate('My Addresses');
  73. $this->lstMyAddresses->Required = true;
  74. if (!$this->blnEditMode)
  75. $this->lstMyAddresses->AddItem(QApplication::Translate('- Select One -'), null);
  76. if(!$objAccount instanceof Account)
  77. return $this->lstMyAddresses;
  78. $aryPersons[] = Person::LoadById($objAccount->PersonId);
  79. $aryOwnedPersons = Person::LoadArrayByOwnerPersonId($objAccount->PersonId);
  80. if($aryOwnedPersons)
  81. $aryPersons = array_merge($aryPersons, $aryOwnedPersons);
  82. $aryPersonIds = array();
  83. foreach($aryPersons as $objPerson)
  84. $aryPersonIds[] = $objPerson->Id;
  85. $aryAddresses = Address::QueryArray( QQ::In( QQN::Address()->PersonId, $aryPersonIds ));
  86. if( is_array($aryAddresses) )
  87. foreach ($aryAddresses as $objAddress)
  88. {
  89. $objListItem = new QListItem($objAddress->__toString(), $objAddress->Id);
  90. if ($this->objAddress->Id == $objAddress->Id)
  91. $objListItem->Selected = true;
  92. $this->lstMyAddresses->AddItem($objListItem);
  93. }
  94. return $this->lstMyAddresses;
  95. }
  96. /**
  97. * Create and setup QListBox lstZone - this checks our Address for a country id and attempts
  98. * to load only those zones for the country.
  99. * @param integer intCountryId - optional country to filter zones by
  100. * @param string $strControlId optional ControlId to use
  101. * @return QListBox
  102. */
  103. public function lstZone_Create($intCountryId = null, $strControlId = null)
  104. {
  105. $this->lstZone = new QListBox($this->objParentObject, $strControlId);
  106. $this->lstZone->Name = QApplication::Translate('Zone');
  107. $this->lstZone->Required = true;
  108. if($intCountryId)
  109. $aryZones = ZoneType::GetNameArrayByCountryId($intCountryId);
  110. elseif($this->objAddress->CountryId)
  111. $aryZones = ZoneType::GetNameArrayByCountryId($this->objAddress->CountryId);
  112. else
  113. $aryZones = ZoneType::$NameArray;
  114. foreach (ZoneType::$NameArray as $intId => $strValue)
  115. $this->lstZone->AddItem(new QListItem($strValue, $intId, $this->objAddress->ZoneId == $intId));
  116. return $this->lstZone;
  117. }
  118. public function __get($strName)
  119. {
  120. switch ($strName)
  121. {
  122. case 'PersonId':
  123. if($this->objAddress instanceof Address)
  124. return $this->objAddress->PersonId;
  125. return null;
  126. default:
  127. try {
  128. return parent::__get($strName);
  129. } catch (QCallerException $objExc) {
  130. $objExc->IncrementOffset();
  131. throw $objExc;
  132. }
  133. }
  134. }
  135. public function __set($strName, $mixValue)
  136. {
  137. switch ($strName)
  138. {
  139. case 'PersonId':
  140. //set up the lstPerson control so that SaveAddress will work
  141. if( ! $this->lstPerson instanceof QListBox )
  142. $this->lstPerson_Create();
  143. try {
  144. return ($this->lstPerson->SelectedValue = QType::Cast($mixValue, QType::Integer));
  145. } catch (QInvalidCastException $objExc) {
  146. $objExc->IncrementOffset();
  147. throw $objExc;
  148. }
  149. default:
  150. try {
  151. return (parent::__set($strName, $mixValue));
  152. } catch (QCallerException $objExc) {
  153. $objExc->IncrementOffset();
  154. throw $objExc;
  155. }
  156. }
  157. }
  158. }
  159. ?>