PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/local/Magiccart/Magicinstall/Block/Adminhtml/Page/Grid.php

https://gitlab.com/blingbang2016/shop
PHP | 144 lines | 110 code | 20 blank | 14 comment | 2 complexity | 40132e07efed867a6eae6a510e5f201f MD5 | raw file
  1. <?php
  2. /**
  3. * Magiccart
  4. * @category Magiccart
  5. * @copyright Copyright (c) 2014 Magiccart (http://www.magiccart.net/)
  6. * @license http://www.magiccart.net/license-agreement.html
  7. * @Author: Magiccart<team.magiccart@gmail.com>
  8. * @@Create Date: 2014-07-25 14:51:41
  9. * @@Modify Date: 2015-02-05 17:17:35
  10. * @@Function:
  11. */
  12. ?>
  13. <?php
  14. class Magiccart_Magicinstall_Block_Adminhtml_Page_Grid extends Mage_Adminhtml_Block_Widget_Grid
  15. {
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. $this->setId('cmsPageGrid');
  20. $this->setDefaultSort('identifier');
  21. $this->setDefaultDir('ASC');
  22. $this->setSaveParametersInSession(true);
  23. }
  24. protected function _prepareCollection()
  25. {
  26. $collection = Mage::getModel('cms/page')->getCollection();
  27. /* @var $collection Mage_Cms_Model_Mysql4_Page_Collection */
  28. $collection->setFirstStoreFlag(true);
  29. $this->setCollection($collection);
  30. return parent::_prepareCollection();
  31. }
  32. protected function _prepareColumns()
  33. {
  34. $baseUrl = $this->getUrl();
  35. $this->addColumn('title', array(
  36. 'header' => Mage::helper('cms')->__('Title'),
  37. 'align' => 'left',
  38. 'index' => 'title',
  39. ));
  40. $this->addColumn('identifier', array(
  41. 'header' => Mage::helper('cms')->__('URL Key'),
  42. 'align' => 'left',
  43. 'index' => 'identifier'
  44. ));
  45. $this->addColumn('root_template', array(
  46. 'header' => Mage::helper('cms')->__('Layout'),
  47. 'index' => 'root_template',
  48. 'type' => 'options',
  49. 'options' => Mage::getSingleton('page/source_layout')->getOptions(),
  50. ));
  51. /**
  52. * Check is single store mode
  53. */
  54. if (!Mage::app()->isSingleStoreMode()) {
  55. $this->addColumn('store_id', array(
  56. 'header' => Mage::helper('cms')->__('Store View'),
  57. 'index' => 'store_id',
  58. 'type' => 'store',
  59. 'store_all' => true,
  60. 'store_view' => true,
  61. 'sortable' => false,
  62. 'filter_condition_callback'
  63. => array($this, '_filterStoreCondition'),
  64. ));
  65. }
  66. $this->addColumn('is_active', array(
  67. 'header' => Mage::helper('cms')->__('Status'),
  68. 'index' => 'is_active',
  69. 'type' => 'options',
  70. 'options' => Mage::getSingleton('cms/page')->getAvailableStatuses()
  71. ));
  72. $this->addColumn('creation_time', array(
  73. 'header' => Mage::helper('cms')->__('Date Created'),
  74. 'index' => 'creation_time',
  75. 'type' => 'datetime',
  76. ));
  77. $this->addColumn('update_time', array(
  78. 'header' => Mage::helper('cms')->__('Last Modified'),
  79. 'index' => 'update_time',
  80. 'type' => 'datetime',
  81. ));
  82. $this->addColumn('page_actions', array(
  83. 'header' => Mage::helper('cms')->__('Action'),
  84. 'width' => 10,
  85. 'sortable' => false,
  86. 'filter' => false,
  87. 'renderer' => 'adminhtml/cms_page_grid_renderer_action',
  88. ));
  89. return parent::_prepareColumns();
  90. }
  91. protected function _afterLoadCollection()
  92. {
  93. $this->getCollection()->walk('afterLoad');
  94. parent::_afterLoadCollection();
  95. }
  96. protected function _filterStoreCondition($collection, $column)
  97. {
  98. if (!$value = $column->getFilter()->getValue()) {
  99. return;
  100. }
  101. $this->getCollection()->addStoreFilter($value);
  102. }
  103. protected function _prepareMassaction()
  104. {
  105. $this->setMassactionIdField('page_id');
  106. $this->getMassactionBlock()->setFormFieldName('page_ids');
  107. $stores = Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, false);
  108. $this->getMassactionBlock()->addItem('export', array(
  109. 'label' => Mage::helper('adminhtml')->__('Export'),
  110. 'url' => $this->getUrl('*/*/exportXml'),
  111. 'additional' => array(
  112. 'visibility' => array(
  113. 'name' => 'store_id',
  114. 'type' => 'select',
  115. 'class' => 'required-entry',
  116. 'label' => Mage::helper('adminhtml')->__('Store'),
  117. 'values' => $stores
  118. )
  119. ),
  120. 'confirm' => Mage::helper('adminhtml')->__('Are you sure?')
  121. ));
  122. return $this;
  123. }
  124. }