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.

162 lines
7.2 KiB

13 years ago
  1. <?php
  2. /**
  3. * This class provides a panel in which to list orders
  4. * from within a user account owned by that user.
  5. *
  6. * $Id: AccountOrderListPanel.class.php 286 2008-10-10 23:33:36Z erikwinn $
  7. *@version 0.1
  8. *
  9. *@copyright (C) 2008 by Erik Winn
  10. *@license GPL v.2
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  22. * @package Quasi
  23. * @subpackage Classes
  24. *
  25. */
  26. class AccountOrderListPanel extends QPanel
  27. {
  28. // Local instance of the Meta DataGrid to list Orders
  29. public $dtgOrders;
  30. // A local Paginator to facilitate data binding on the DataGrid
  31. public $objPaginator;
  32. //button and the view link for the item in the grid list
  33. public $btnCreateNew;
  34. public $pxyView;
  35. protected $objControlBlock;
  36. // Callback Method Names - these are in the control block
  37. protected $strSetEditPanelMethod;
  38. protected $strCloseEditPanelMethod;
  39. public function __construct( $objParentObject,
  40. $objControlBlock,
  41. $strSetEditPanelMethod,
  42. $strCloseEditPanelMethod,
  43. $strControlId = null )
  44. {
  45. try {
  46. parent::__construct($objParentObject, $strControlId);
  47. } catch (QCallerException $objExc) {
  48. $objExc->IncrementOffset();
  49. throw $objExc;
  50. }
  51. $this->objControlBlock = $objControlBlock;
  52. $this->strSetEditPanelMethod = $strSetEditPanelMethod;
  53. $this->strCloseEditPanelMethod = $strCloseEditPanelMethod;
  54. $this->Template = __QUASI_CORE_TEMPLATES__ . '/AccountOrderListPanel.tpl.php';
  55. $this->dtgOrders = new OrderDataGrid($this);
  56. $this->dtgOrders->SetDataBinder('AccountOrderDataBinder', $this);
  57. $this->dtgOrders->CssClass = 'datagrid';
  58. $this->dtgOrders->AlternateRowStyle->CssClass = 'alternate';
  59. // Add Pagination
  60. $this->objPaginator = new QPaginator($this->dtgOrders);
  61. $this->dtgOrders->Paginator = $this->objPaginator;
  62. $this->dtgOrders->ItemsPerPage = 20;
  63. $this->pxyView = new QControlProxy($this);
  64. if(IndexPage::$blnAjaxOk)
  65. $this->pxyView->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyView_Click'));
  66. else
  67. $this->pxyView->AddAction(new QClickEvent(), new QServerControlAction($this, 'pxyView_Click'));
  68. $this->dtgOrders->MetaAddProxyColumn($this->pxyView, 'Id', '<?= $_ITEM->Id ?>', Quasi::Translate('Order'));
  69. $this->dtgOrders->MetaAddTypeColumn('StatusId', 'OrderStatusType');
  70. $this->dtgOrders->MetaAddColumn('CreationDate');
  71. $this->dtgOrders->GetColumn(2)->Name = Quasi::Translate('Ordered');
  72. $strOrderTotalParam = '<?= money_format("%n", $_ITEM->ProductTotalCharged '
  73. . ' + $_ITEM->ShippingCharged '
  74. . ' + $_ITEM->HandlingCharged '
  75. . ' + $_ITEM->Tax ) ?>';
  76. $objOrderTotalColumn = new QDataGridColumn(Quasi::Translate('Order Total'), $strOrderTotalParam );
  77. $this->dtgOrders->AddColumn($objOrderTotalColumn);
  78. // Column sizes will need to be tweaked to use these:
  79. // $this->dtgOrders->MetaAddColumn('TrackingNumber');
  80. // $this->dtgOrders->MetaAddColumn('LastModificationDate');
  81. // $this->dtgOrders->GetColumn(3)->Name = Quasi::Translate('Last Change');
  82. // $this->dtgOrders->MetaAddColumn('ShippingCity');
  83. $this->btnCreateNew = new QButton($this);
  84. $this->btnCreateNew->Text = Quasi::Translate('Create a New') . ' ' . Quasi::Translate('Order');
  85. if(IndexPage::$blnAjaxOk)
  86. $this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
  87. else
  88. $this->btnCreateNew->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnCreateNew_Click'));
  89. }
  90. public function pxyView_Click($strFormId, $strControlId, $intOrderId)
  91. {
  92. $objEditPanel = new AccountOrderViewPanel($this,
  93. $this->objControlBlock,
  94. $this->strCloseEditPanelMethod,
  95. $intOrderId);
  96. $strShowMethod = $this->strSetEditPanelMethod;
  97. $this->objControlBlock->$strShowMethod($objEditPanel);
  98. }
  99. public function btnCreateNew_Click($strFormId, $strControlId, $strParameter)
  100. {
  101. $objEditPanel = new AccountOrderViewPanel($this, $this->objControlBlock,
  102. $this->strCloseEditPanelMethod, null);
  103. $strMethodName = $this->strSetEditPanelMethod;
  104. $this->objControlBlock->$strMethodName($objEditPanel);
  105. }
  106. /**
  107. * This binds the Datagrid data retrieval to this Person, the orders listed in the Datagrid will be those
  108. * associated with this user in the database.
  109. *
  110. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  111. * It will also perform any sorting requested in by clicking on the column titles in the Datagrid.
  112. */
  113. public function AccountOrderDataBinder()
  114. {
  115. if ($this->objPaginator)
  116. $this->dtgOrders->TotalItemCount = Order::CountByAccountId($this->objControlBlock->Account->Id) ;
  117. $objClauses = array();
  118. // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
  119. // the OrderByClause to the $objClauses array - this is in the datagrid if the user clicks on column title
  120. if ($objClause = $this->dtgOrders->OrderByClause)
  121. array_push($objClauses, $objClause);
  122. // Add the LimitClause information, as well
  123. if ($objClause = $this->dtgOrders->LimitClause)
  124. array_push($objClauses, $objClause);
  125. array_push($objClauses, QQ::OrderBy(QQN::Order()->CreationDate, false) );
  126. $this->dtgOrders->DataSource = Order::LoadArrayByAccountId(
  127. $this->objControlBlock->Account->Id, $objClauses
  128. );
  129. }
  130. }
  131. ?>