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.

244 lines
11 KiB

13 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("ACCOUNTADDRESSLISTPANEL.CLASS.PHP")) {
  4. define("ACCOUNTADDRESSLISTPANEL.CLASS.PHP",1);
  5. /**
  6. * This class provides a panel in which to list addresses from within a user account.
  7. * Each address item contains an "Edit" link with which to access a specific address.
  8. * Additionally, this class creates the individual AddressEditPanel for editting as well
  9. * as another panel (PersonEditPanel) for changing or adding Persons. The Person
  10. * can be associated with the Address via a drop down list of persons.
  11. *
  12. * $Id: AccountAddressListPanel.class.php 286 2008-10-10 23:33:36Z erikwinn $
  13. *@version 0.1
  14. *
  15. *@copyright (C) 2008 by Erik Winn
  16. *@license GPL v.2
  17. This program is free software; you can redistribute it and/or modify
  18. it under the terms of the GNU General Public License as published by
  19. the Free Software Foundation; either version 2 of the License, or
  20. (at your option) any later version.
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. GNU General Public License for more details.
  25. You should have received a copy of the GNU General Public License
  26. along with this program; if not, write to the Free Software
  27. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  28. * @package Quasi
  29. * @subpackage Classes
  30. *
  31. */
  32. class AccountAddressListPanel extends QPanel
  33. {
  34. /**
  35. *@var array aryAddresses - an array of Addresses belonging to the Account
  36. */
  37. protected $aryAddresses;
  38. /**
  39. *@var array aryPersons - an array of Persons belonging to the Person of this Account
  40. */
  41. protected $aryPersons;
  42. /**
  43. *@var ContentBlock objControlBlock - the content block containing the callbacks for panel hide/show
  44. */
  45. protected $objControlBlock;
  46. /**
  47. *@var string strShowEditPanelMethod - Callback Method Names
  48. */
  49. protected $strShowEditPanelMethod;
  50. protected $strCloseEditPanelMethod;
  51. /**
  52. *@var AccountAddressEditPanel pnlAddressEditPanel - panel to edit/create an address
  53. */
  54. public $pnlAddressEditPanel=null;
  55. /**
  56. *@var AccountPersonEditPanel pnlPersonEditPanel - panel to edit/create a Person
  57. */
  58. public $pnlPersonEditPanel=null;
  59. // Meta DataGrid to list Addresses
  60. /**
  61. *@var QDataGrid dtgAddresses - Address Meta DataGrid to list Addresses
  62. */
  63. public $dtgAddresses;
  64. /**
  65. *@var QPaginator objPaginator - data page control for datagrid
  66. */
  67. public $objPaginator;
  68. /**
  69. *@var QButton btnCreateNew - button to create a new Address, shows address edit panel
  70. */
  71. public $btnCreateNew;
  72. /**
  73. *@var QControlProxy pxyEdit - action link in datagrid to edit a specific address, shows edit panel
  74. */
  75. public $pxyEdit;
  76. public function __construct( $objParentObject,
  77. $objControlBlock,
  78. $strShowEditPanelMethod,
  79. $strCloseEditPanelMethod,
  80. $strControlId = null )
  81. {
  82. try {
  83. parent::__construct($objParentObject, $strControlId);
  84. } catch (QCallerException $objExc) {
  85. $objExc->IncrementOffset();
  86. throw $objExc;
  87. }
  88. $this->objControlBlock =& $objControlBlock;
  89. $this->strShowEditPanelMethod = $strShowEditPanelMethod;
  90. $this->strCloseEditPanelMethod = $strCloseEditPanelMethod;
  91. $this->Template = __QUASI_CORE_TEMPLATES__ . '/AccountAddressListPanel.tpl.php';
  92. $this->dtgAddresses = new AddressDataGrid($this);
  93. $this->dtgAddresses->SetDataBinder('AccountAddressDataBinder', $this);
  94. $this->dtgAddresses->CssClass = 'datagrid';
  95. $this->dtgAddresses->AlternateRowStyle->CssClass = 'alternate';
  96. $this->objPaginator = new QPaginator($this->dtgAddresses);
  97. $this->dtgAddresses->Paginator = $this->objPaginator;
  98. $this->dtgAddresses->ItemsPerPage = 10;
  99. // Create an Edit Column
  100. $this->pxyEdit = new QControlProxy($this);
  101. if(IndexPage::$blnAjaxOk)
  102. $this->pxyEdit->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyEdit_Click'));
  103. else
  104. $this->pxyEdit->AddAction(new QClickEvent(), new QServerControlAction($this, 'pxyEdit_Click'));
  105. $this->dtgAddresses->MetaAddEditProxyColumn($this->pxyEdit, 'Edit', 'Edit');
  106. $this->dtgAddresses->MetaAddColumn(QQN::Address()->Person);
  107. $this->dtgAddresses->MetaAddColumn('Street1');
  108. $this->dtgAddresses->MetaAddColumn('City');
  109. $this->dtgAddresses->MetaAddTypeColumn('ZoneId', 'ZoneType');
  110. // $this->dtgAddresses->MetaAddColumn('ZoneId');
  111. $this->dtgAddresses->MetaAddColumn('PostalCode');
  112. // $this->dtgAddresses->MetaAddTypeColumn('TypeId', 'AddressType');
  113. $this->btnCreateNew = new QButton($this);
  114. $this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('Address');
  115. if(IndexPage::$blnAjaxOk)
  116. $this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
  117. else
  118. $this->btnCreateNew->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCreateNew_Click'));
  119. }
  120. public function pxyEdit_Click($strFormId, $strControlId, $strParameter)
  121. {
  122. $strParameterArray = explode(',', $strParameter);
  123. $this->pnlAddressEditPanel = new AccountAddressEditPanel($this,
  124. $this->objControlBlock,
  125. $this->strCloseEditPanelMethod,
  126. $strParameterArray[0]);
  127. $strMethodName = $this->strShowEditPanelMethod;
  128. $this->objControlBlock->$strMethodName($this->pnlAddressEditPanel);
  129. }
  130. public function btnCreateNew_Click($strFormId, $strControlId, $strParameter)
  131. {
  132. if($this->pnlPersonEditPanel)
  133. {
  134. $this->pnlPersonEditPanel->RemoveChildControls(true);
  135. $this->pnlPersonEditPanel->Visible = false;
  136. }
  137. if($this->pnlAddressEditPanel)
  138. $this->pnlAddressEditPanel->RemoveChildControls(true);
  139. $this->pnlAddressEditPanel = new AccountAddressEditPanel($this,
  140. $this->objControlBlock,
  141. $this->strCloseEditPanelMethod,
  142. null);
  143. $this->pnlAddressEditPanel->Visible = true;
  144. $strMethodName = $this->strShowEditPanelMethod;
  145. $this->objControlBlock->$strMethodName($this->pnlAddressEditPanel);
  146. }
  147. //Callbacks ..
  148. public function btnAddPerson_Click($strFormId, $strControlId, $strParameter)
  149. {
  150. $this->pnlAddressEditPanel->RemoveChildControls(true);
  151. $this->pnlAddressEditPanel->Visible = false;
  152. $this->pnlPersonEditPanel = new AccountPersonEditPanel($this, $this, 'ClosePersonEditPanel');
  153. $strMethodName = $this->strShowEditPanelMethod;
  154. $this->objControlBlock->$strMethodName($this->pnlPersonEditPanel);
  155. }
  156. public function ClosePersonEditPanel($blnChangesMade)
  157. {
  158. $this->pnlPersonEditPanel->RemoveChildControls(true);
  159. $this->pnlPersonEditPanel->Visible = false;
  160. $this->pnlAddressEditPanel = new AccountAddressEditPanel($this,
  161. $this->objControlBlock,
  162. $this->strCloseEditPanelMethod,
  163. null);
  164. $strMethodName = $this->strShowEditPanelMethod;
  165. $this->objControlBlock->$strMethodName($this->pnlAddressEditPanel);
  166. }
  167. /**
  168. * This binds the Datagrid data retrieval to this Person, the addresses listed in the Datagrid will be those
  169. * associated with this user in the database. The addresses loaded will be not only the addresses
  170. * specific to the user, but also those of others added by this user (eg. addresses of friends and/or
  171. * family to whom they may wish to have orders shipped.) via the Address management panel
  172. *
  173. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  174. * It will also perform any sorting requested in by clicking on the columns in the Datagrid.
  175. */
  176. public function AccountAddressDataBinder()
  177. {
  178. $this->aryPersons = array();
  179. $this->aryAddresses = array();
  180. $aryClauses = array();
  181. $aryPersonIds = array();
  182. // add extra people that may be in address book .. slightly inefficient but it works for now.
  183. $this->aryPersons = Person::QueryArray(
  184. QQ::OrCondition(
  185. QQ::Equal( QQN::Person()->Id, $this->objControlBlock->Account->PersonId),
  186. QQ::Equal( QQN::Person()->OwnerPersonId, $this->objControlBlock->Account->PersonId)
  187. )
  188. );
  189. foreach( $this->aryPersons as $objPerson )
  190. $aryPersonIds[] = $objPerson->Id;
  191. // If a column is selected to be sorted, and if that column has an OrderByClause
  192. // set on it, then let's add the OrderByClause to the $aryClauses array
  193. if ($objClause = $this->dtgAddresses->OrderByClause)
  194. array_push($aryClauses, $objClause);
  195. // Add the LimitClause information as well
  196. if ($objClause = $this->dtgAddresses->LimitClause)
  197. array_push($aryClauses, $objClause);
  198. $this->aryAddresses = Address::QueryArray(
  199. QQ::In( QQN::Address()->PersonId, $aryPersonIds),
  200. $aryClauses
  201. );
  202. if ($this->objPaginator)
  203. $this->dtgAddresses->TotalItemCount = count($this->aryAddresses);
  204. // Set the DataSource to be a Query result from Address, given the clauses above
  205. $this->dtgAddresses->DataSource = $this->aryAddresses;
  206. }
  207. }
  208. }
  209. ?>