PageRenderTime 50ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/community/TBT/Rewards/Block/Manage/Customer/Points/Grid.php

https://bitbucket.org/acidel/buykoala
PHP | 192 lines | 87 code | 30 blank | 75 comment | 10 complexity | 2d31b2016cd70a32cffdc23f343e6cbd MD5 | raw file
  1. <?php
  2. /**
  3. * WDCA - Sweet Tooth
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS
  8. * License, which extends the Open Software License (OSL 3.0).
  9. * The Sweet Tooth License is available at this URL:
  10. * http://www.wdca.ca/sweet_tooth/sweet_tooth_license.txt
  11. * The Open Software License is available at this URL:
  12. * http://opensource.org/licenses/osl-3.0.php
  13. *
  14. * DISCLAIMER
  15. *
  16. * By adding to, editing, or in any way modifying this code, WDCA is
  17. * not held liable for any inconsistencies or abnormalities in the
  18. * behaviour of this code.
  19. * By adding to, editing, or in any way modifying this code, the Licensee
  20. * terminates any agreement of support offered by WDCA, outlined in the
  21. * provided Sweet Tooth License.
  22. * Upon discovery of modified code in the process of support, the Licensee
  23. * is still held accountable for any and all billable time WDCA spent
  24. * during the support process.
  25. * WDCA does not guarantee compatibility with any other framework extension.
  26. * WDCA is not responsbile for any inconsistencies or abnormalities in the
  27. * behaviour of this code if caused by other framework extension.
  28. * If you did not receive a copy of the license, please send an email to
  29. * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy
  30. * immediately.
  31. *
  32. * @category [TBT]
  33. * @package [TBT_Rewards]
  34. * @copyright Copyright (c) 2009 Web Development Canada (http://www.wdca.ca)
  35. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  36. */
  37. /**
  38. * Manage Customer Points Grid
  39. *
  40. * @category TBT
  41. * @package TBT_Rewards
  42. * @author WDCA Sweet Tooth Team <contact@wdca.ca>
  43. */
  44. class TBT_Rewards_Block_Manage_Customer_Points_Grid extends Mage_Adminhtml_Block_Widget_Grid {
  45. protected $columnsAreSet = false;
  46. public function __construct() {
  47. parent::__construct ();
  48. $this->setId ( 'customerGrid' );
  49. //$this->setUseAjax(true);
  50. $this->setDefaultSort ( 'name' );
  51. $this->setDefaultDir ( 'ASC' );
  52. }
  53. protected function _prepareCollection() {
  54. if ($this->_collection == null) {
  55. $collection = Mage::getResourceModel ( 'customer/customer_collection' );
  56. }
  57. $collection->addNameToSelect ()->addAttributeToSelect ( 'email' )->addAttributeToSelect ( 'created_at' )
  58. ->addAttributeToSelect ( 'group_id' )->joinAttribute ( 'billing_city', 'customer_address/city', 'default_billing', null, 'left' )
  59. ->joinAttribute ( 'billing_region', 'customer_address/region', 'default_billing', null, 'left' )
  60. ->joinAttribute ( 'billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left' );
  61. $this->_joinCustomerPointsIndex($collection);
  62. $this->setCollection ( $collection );
  63. return parent::_prepareCollection ();
  64. }
  65. /**
  66. * If we should be using the customer points balance index table, this will join the index table to this grid collection
  67. * @note: TODO this is a copy from the class TBT_Rewards_Block_Manage_Transfer_Edit_Tab_Customer_Grid. We should be using a decorator design pattern here.
  68. * @param unknown_type $collection
  69. */
  70. protected function _joinCustomerPointsIndex($collection=null) {
  71. if(!Mage::helper('rewards/customer_points_index')->useIndex()) {
  72. // Shouldn't be using the customer points index.
  73. return $this;
  74. }
  75. $collection = $collection == null ? $this->getCollection() : $collection;
  76. $points_index_table = Mage::getResourceModel('rewards/customer_indexer_points')->getIdxTable();
  77. $collection->getSelect()->joinLeft(
  78. array('points_index' => $points_index_table),
  79. 'e.entity_id = points_index.customer_id');
  80. return $this;
  81. }
  82. protected function _getStore() {
  83. $storeId = ( int ) $this->getRequest ()->getParam ( 'store', 0 );
  84. return Mage::app ()->getStore ( $storeId );
  85. }
  86. protected function _prepareColumns() {
  87. if ($this->columnsAreSet)
  88. return parent::_prepareColumns ();
  89. else
  90. $this->columnsAreSet = true;
  91. $this->addColumn ( 'entity_id', array ('header' => Mage::helper ( 'customer' )->__ ( 'ID' ), 'width' => '50px', 'index' => 'entity_id', 'type' => 'number' ) );
  92. /* $this->addColumn('firstname', array(
  93. 'header' => Mage::helper('customer')->__('First Name'),
  94. 'index' => 'firstname'
  95. ));
  96. $this->addColumn('lastname', array(
  97. 'header' => Mage::helper('customer')->__('Last Name'),
  98. 'index' => 'lastname'
  99. )); */
  100. $this->addColumn ( 'name', array ('header' => Mage::helper ( 'customer' )->__ ( 'Name' ), 'index' => 'name', 'renderer' => 'rewards/manage_grid_renderer_customer' ) );
  101. $this->addColumn ( 'email', array ('header' => Mage::helper ( 'customer' )->__ ( 'Email' ), 'width' => '150', 'index' => 'email' ) );
  102. $groups = Mage::getResourceModel ( 'customer/group_collection' )->addFieldToFilter ( 'customer_group_id', array ('gt' => 0 ) )->load ()->toOptionHash ();
  103. $this->addColumn ( 'group', array ('header' => Mage::helper ( 'customer' )->__ ( 'Group' ), 'width' => '100', 'index' => 'group_id', 'type' => 'options', 'options' => $groups ) );
  104. $this->addColumn ( 'billing_country_id', array ('header' => Mage::helper ( 'customer' )->__ ( 'Country' ), 'width' => '100', 'type' => 'country', 'index' => 'billing_country_id' ) );
  105. $this->addColumn ( 'billing_region', array ('header' => Mage::helper ( 'customer' )->__ ( 'State/Province' ), 'width' => '100', 'index' => 'billing_region' ) );
  106. $this->addColumn ( 'customer_since', array ('header' => Mage::helper ( 'customer' )->__ ( 'Customer Since' ), 'type' => 'datetime', 'align' => 'center', 'index' => 'created_at', 'gmtoffset' => true ) );
  107. //@nelkaake Added on Saturday July 17, 2010: To fix bug #0000359
  108. if (! Mage::app ()->isSingleStoreMode ()) {
  109. if (Mage::helper ( 'rewards' )->isBaseMageVersionAtLeast ( '1.4.0.0' )) {
  110. $this->addColumn ( 'website_id', array ('header' => Mage::helper ( 'customer' )->__ ( 'Website' ), 'align' => 'center', 'width' => '80px', 'type' => 'options', 'options' => Mage::getSingleton ( 'adminhtml/system_store' )->getWebsiteOptionHash ( true ), 'index' => 'website_id' ) );
  111. } else {
  112. $websites = Mage::getSingleton ( 'adminhtml/system_store' )->getWebsiteValuesForGridFilter ( true, true );
  113. $this->addColumn ( 'website_id', array ('header' => Mage::helper ( 'customer' )->__ ( 'Website' ), 'align' => 'center', 'width' => '80px', 'type' => 'options', 'options' => $websites, 'index' => 'website_id' ) );
  114. }
  115. }
  116. $this->addColumn ( 'action', array ('header' => Mage::helper ( 'customer' )->__ ( 'Action' ), 'width' => '120px', 'type' => 'action', 'getter' => 'getId', 'actions' => array (array ('caption' => Mage::helper ( 'rewards' )->__ ( 'Make Transfer' ), 'url' => array ('base' => '*/manage_transfer/new/controller/manage_customer_points' ), 'field' => 'customer_id' ) ), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'is_system' => true ) );
  117. $this->addColumn ( 'points', array (
  118. 'header' => Mage::helper ( 'rewards' )->__ ( 'Points' ),
  119. 'width' => '220px',
  120. 'renderer' => 'rewards/manage_grid_renderer_points',
  121. 'sortable' => false,
  122. 'filter' => false,
  123. 'index' => 'customer_points_usable'
  124. ) );
  125. $this->addExportType ( '*/*/exportCsv', Mage::helper ( 'customer' )->__ ( 'CSV' ) );
  126. $this->addExportType ( '*/*/exportXml', Mage::helper ( 'customer' )->__ ( 'XML' ) );
  127. return parent::_prepareColumns ();
  128. }
  129. protected function _prepareMassaction() {
  130. $this->setMassactionIdField ( 'entity_id' );
  131. $this->getMassactionBlock ()->setFormFieldName ( 'customer' );
  132. // $this->getMassactionBlock()->addItem('delete', array(
  133. // 'label' => Mage::helper('customer')->__('Delete'),
  134. // 'url' => $this->getUrl('*/*/massDelete'),
  135. // 'confirm' => Mage::helper('customer')->__('Are you sure?')
  136. // ));
  137. //
  138. // $this->getMassactionBlock()->addItem('newsletter_subscribe', array(
  139. // 'label' => Mage::helper('customer')->__('Subscribe to newsletter'),
  140. // 'url' => $this->getUrl('*/*/massSubscribe')
  141. // ));
  142. //
  143. // $this->getMassactionBlock()->addItem('newsletter_unsubscribe', array(
  144. // 'label' => Mage::helper('customer')->__('Unsubscribe from newsletter'),
  145. // 'url' => $this->getUrl('*/*/massUnsubscribe')
  146. // ));
  147. //
  148. $currencies = Mage::helper ( 'rewards/currency' )->getAvailCurrencyOptions ();
  149. $cids = Mage::helper ( 'rewards/currency' )->getAvailCurrencyIds ();
  150. //array_unshift($currencies, array('label'=> '', 'value'=> ''));
  151. $mass_transfer_fields = array ('points' => array ('name' => 'quantity', 'type' => 'text', 'class' => 'required-entry', 'label' => Mage::helper ( 'customer' )->__ ( 'Quantity' ) ) );
  152. if (sizeof ( $cids ) > 1) {
  153. $mass_transfer_fields ['currency'] = array ('name' => 'currency', 'type' => 'select', 'class' => 'required-entry', 'label' => Mage::helper ( 'customer' )->__ ( 'Currency' ), 'values' => $currencies );
  154. } else {
  155. $currency_id = $cids [0];
  156. $mass_transfer_fields ['currency'] = array ('name' => 'currency', 'type' => 'hidden', 'class' => 'required-entry', 'label' => Mage::helper ( 'customer' )->__ ( 'Currency' ), 'value' => $currency_id );
  157. }
  158. $this->getMassactionBlock ()->addItem ( 'mass_distribution', array ('label' => Mage::helper ( 'rewards' )->__ ( 'Give Points' ), 'url' => $this->getUrl ( '*/*/massTransferPoints', array ('is_deduction' => 0 ) ), 'additional' => $mass_transfer_fields, 'confirm' => Mage::helper ( 'customer' )->__ ( 'Are you sure you want to create the transfer for all selected customers?' ) ) );
  159. $this->getMassactionBlock ()->addItem ( 'mass_redemption', array ('label' => Mage::helper ( 'rewards' )->__ ( 'Deduct Points' ), 'url' => $this->getUrl ( '*/*/massTransferPoints', array ('is_deduction' => 1 ) ), 'additional' => array ('currency' => array ('name' => 'currency', 'type' => 'select', 'class' => 'required-entry', 'label' => Mage::helper ( 'customer' )->__ ( 'Currency' ), 'values' => $currencies ), 'points' => array ('name' => 'quantity', 'type' => 'text', 'class' => 'required-entry', 'label' => Mage::helper ( 'customer' )->__ ( 'Quantity' ) ) ), 'confirm' => Mage::helper ( 'customer' )->__ ( 'Are you sure you want to create the transfer for all selected customers?' ) ) );
  160. return $this;
  161. }
  162. }