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.

221 lines
7.8 KiB

  1. <?php
  2. /**
  3. * This is the abstract Panel class for the List All functionality
  4. * of the Address class. This code-generated class
  5. * contains a datagrid to display an HTML page that can
  6. * list a collection of Address objects. It includes
  7. * functionality to perform pagination and sorting on columns.
  8. *
  9. * To take advantage of some (or all) of these control objects, you
  10. * must create a new QPanel which extends this AddressListPanelBase
  11. * class.
  12. *
  13. * Any and all changes to this file will be overwritten with any subsequent re-
  14. * code generation.
  15. *
  16. * @package Quinta
  17. * @subpackage AdminUI
  18. *
  19. */
  20. class AddressListPanel extends QPanel
  21. {
  22. protected $strNameToFind;
  23. protected $objAccount = null;
  24. // Callback Method Names
  25. protected $strSetEditPanelMethod;
  26. protected $strCloseEditPanelMethod;
  27. // Local instance of the Meta DataGrid to list Addresses
  28. public $dtgAddresses;
  29. public $lblMessage;
  30. public $txtNameSearch;
  31. public $txtNumberSearch;
  32. // Other public QControls in this panel
  33. public $btnCreateNew;
  34. public $pxyEdit;
  35. public function __construct($objParentObject, $strSetEditPanelMethod, $strCloseEditPanelMethod, $strControlId = null) {
  36. // Call the Parent
  37. try {
  38. parent::__construct($objParentObject, $strControlId);
  39. } catch (QCallerException $objExc) {
  40. $objExc->IncrementOffset();
  41. throw $objExc;
  42. }
  43. // Record Method Callbacks
  44. $this->strSetEditPanelMethod = $strSetEditPanelMethod;
  45. $this->strCloseEditPanelMethod = $strCloseEditPanelMethod;
  46. // Setup the Template
  47. $this->Template = 'AddressListPanel.tpl.php';
  48. //messages (eg. Name not found ..)
  49. $this->lblMessage = new QLabel($this);
  50. // a search field for Address by name ..
  51. $this->txtNameSearch = new QTextBox($this);
  52. $this->txtNameSearch->AddAction(new QEnterKeyEvent(), new QServerControlAction($this, 'txtNameSearch_Click'));
  53. $this->txtNameSearch->Name = 'Search by Name:';
  54. // a search field for Address by account number ..
  55. $this->txtNumberSearch = new QIntegerTextBox($this);
  56. $this->txtNumberSearch->AddAction(new QEnterKeyEvent(), new QServerControlAction($this, 'txtNumberSearch_Click'));
  57. $this->txtNumberSearch->Name = 'Search by Number:';
  58. $this->txtNumberSearch->CausesValidation = $this->txtNumberSearch;
  59. // Instantiate the Meta DataGrid
  60. $this->dtgAddresses = new AddressDataGrid($this);
  61. // Style the DataGrid (if desired)
  62. $this->dtgAddresses->CssClass = 'datagrid';
  63. $this->dtgAddresses->AlternateRowStyle->CssClass = 'alternate';
  64. $this->dtgAddresses->SetDataBinder('AddressDataBinder', $this);
  65. // Add Pagination (if desired)
  66. $this->dtgAddresses->Paginator = new QPaginator($this->dtgAddresses);
  67. $this->dtgAddresses->ItemsPerPage = 8;
  68. // Use the MetaDataGrid functionality to add Columns for this datagrid
  69. // Create an Edit Column
  70. $this->pxyEdit = new QControlProxy($this);
  71. $this->pxyEdit->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyEdit_Click'));
  72. $this->dtgAddresses->MetaAddEditProxyColumn($this->pxyEdit, 'Edit', 'Edit');
  73. // Create the Other Columns (note that you can use strings for address's properties, or you
  74. // can traverse down QQN::address() to display fields that are down the hierarchy)
  75. $this->dtgAddresses->MetaAddColumn('Id');
  76. $this->dtgAddresses->MetaAddColumn('Title');
  77. $this->dtgAddresses->MetaAddColumn(QQN::Address()->Person);
  78. $this->dtgAddresses->MetaAddColumn('Street1');
  79. $this->dtgAddresses->MetaAddColumn('Street2');
  80. $this->dtgAddresses->MetaAddColumn('Suburb');
  81. $this->dtgAddresses->MetaAddColumn('City');
  82. $this->dtgAddresses->MetaAddColumn('County');
  83. $this->dtgAddresses->MetaAddTypeColumn('ZoneId', 'ZoneType');
  84. $this->dtgAddresses->MetaAddTypeColumn('CountryId', 'CountryType');
  85. $this->dtgAddresses->MetaAddColumn('PostalCode');
  86. $this->dtgAddresses->MetaAddColumn('IsCurrent');
  87. $this->dtgAddresses->MetaAddTypeColumn('TypeId', 'AddressType');
  88. $this->dtgAddresses->MetaAddColumn('CreationDate');
  89. $this->dtgAddresses->MetaAddColumn('LastModification');
  90. // Setup the Create New button
  91. $this->btnCreateNew = new QButton($this);
  92. $this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('Address');
  93. $this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
  94. }
  95. public function txtNumberSearch_Click($strFormId, $strControlId, $strParameter)
  96. {
  97. $intAccountId = $this->txtNumberSearch->Text;
  98. if( $this->objAccount = Account::Load($intAccountId) )
  99. {
  100. $this->lblMessage->Text = '';
  101. $this->dtgAddresses->Refresh();
  102. }
  103. else
  104. $this->lblMessage->Text = 'Account ' . $intAccountId . ' not found.';
  105. }
  106. public function txtNameSearch_Click($strFormId, $strControlId, $strParameter)
  107. {
  108. $this->lblMessage->Text = '';
  109. $this->strNameToFind =$this->txtNameSearch->Text;
  110. $this->dtgAddresses->Refresh();
  111. }
  112. public function AddressDataBinder()
  113. {
  114. $aryClauses = array();
  115. $aryConditions = array();
  116. $aryPersonIds = array();
  117. $objCondition = null;
  118. if ($objClause = $this->dtgAddresses->OrderByClause)
  119. array_push($aryClauses, $objClause);
  120. if ($objClause = $this->dtgAddresses->LimitClause)
  121. array_push($aryClauses, $objClause);
  122. if($this->strNameToFind)
  123. {
  124. $aryNamesToFind = explode(' ', $this->txtNameSearch->Text);
  125. $aryPersons = array();
  126. if(sizeof($aryNamesToFind) > 1 )
  127. {
  128. $aryPersons = Person::QueryArray(
  129. QQ::AndCondition(
  130. QQ::Like(QQN::Person()->FirstName, $aryNamesToFind[0]),
  131. QQ::Like(QQN::Person()->LastName, $aryNamesToFind[1])
  132. )
  133. );
  134. }
  135. elseif(sizeof($aryNamesToFind) == 1 )
  136. {
  137. $aryPersons = Person::QueryArray(
  138. QQ::OrCondition(
  139. QQ::Like(QQN::Person()->FirstName, $this->txtNameSearch->Text),
  140. QQ::Like(QQN::Person()->LastName, $this->txtNameSearch->Text)
  141. )
  142. );
  143. }
  144. foreach( $aryPersons as $objPerson )
  145. $aryPersonIds[] = $objPerson->Id;
  146. }
  147. /* if($this->intAddressStatusId )
  148. {
  149. $this->dtgAddresses->TotalItemCount = Address::QueryCount(QQ::Equal(QQN::Address()->StatusId, $this->intAddressStatusId));
  150. $aryAddresses = Address::QueryArray(QQ::Equal( QQN::Address()->StatusId, $this->intAddressStatusId), $aryClauses );
  151. }*/
  152. if($this->objAccount )
  153. {
  154. $aryPersons = array();
  155. $aryPersons = Person::QueryArray(
  156. QQ::OrCondition(
  157. QQ::Equal(QQN::Person()->Id, $this->objAccount->Person->Id),
  158. QQ::Equal(QQN::Person()->OwnerPersonId, $this->objAccount->Person->Id)
  159. )
  160. );
  161. foreach( $aryPersons as $objPerson )
  162. $aryPersonIds[] = $objPerson->Id;
  163. }
  164. if( count( $aryPersonIds) )
  165. $aryConditions[] = QQ::In( QQN::Address()->PersonId, $aryPersonIds);
  166. if(count($aryConditions) > 1)
  167. $objCondition = QQ::AndCondition($aryConditions);
  168. elseif(count($aryConditions) == 1)
  169. $objCondition = $aryConditions[0];
  170. else
  171. $objCondition = QQ::All();
  172. $this->dtgAddresses->TotalItemCount = Address::QueryCount($objCondition);
  173. $aryAddresses = Address::QueryArray($objCondition, $aryClauses );
  174. $this->dtgAddresses->DataSource = $aryAddresses;
  175. }
  176. public function pxyEdit_Click($strFormId, $strControlId, $strParameter) {
  177. $strParameterArray = explode(',', $strParameter);
  178. $objEditPanel = new AddressEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0]);
  179. $strMethodName = $this->strSetEditPanelMethod;
  180. $this->objForm->$strMethodName($objEditPanel);
  181. }
  182. public function btnCreateNew_Click($strFormId, $strControlId, $strParameter) {
  183. $objEditPanel = new AddressEditPanel($this, $this->strCloseEditPanelMethod, null);
  184. $strMethodName = $this->strSetEditPanelMethod;
  185. $this->objForm->$strMethodName($objEditPanel);
  186. }
  187. }
  188. ?>