Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Grid.php
Go to the documentation of this file.
1 <?php
7 
15 class Grid extends \Magento\Backend\Block\Widget\Grid
16 {
20  protected $_options;
21 
25  protected $_registryManager;
26 
30  protected $jsonHelper;
31 
40  public function __construct(
41  \Magento\Backend\Block\Template\Context $context,
42  \Magento\Backend\Helper\Data $backendHelper,
43  \Magento\AdvancedSearch\Model\Adminhtml\Search\Grid\Options $options,
44  \Magento\Framework\Registry $registry,
45  \Magento\Framework\Json\Helper\Data $jsonHelper,
46  array $data = []
47  ) {
48  $this->jsonHelper = $jsonHelper;
49  parent::__construct($context, $backendHelper, $data);
50  $this->_options = $options;
51  $this->_registryManager = $registry;
52  $this->setDefaultFilter(['query_id_selected' => 1]);
53  }
54 
60  public function getQuery()
61  {
62  return $this->_registryManager->registry('current_catalog_search');
63  }
64 
71  protected function _addColumnFilterToCollection($column)
72  {
73  // Set custom filter for query selected flag
74  if ($column->getId() == 'query_id_selected' && $this->getQuery()->getId()) {
75  $selectedIds = $this->getSelectedQueries();
76  if (empty($selectedIds)) {
77  $selectedIds = 0;
78  }
79  if ($column->getFilter()->getValue()) {
80  $this->getCollection()->addFieldToFilter('query_id', ['in' => $selectedIds]);
81  } elseif (!empty($selectedIds)) {
82  $this->getCollection()->addFieldToFilter('query_id', ['nin' => $selectedIds]);
83  }
84  } else {
85  parent::_addColumnFilterToCollection($column);
86  }
87  return $this;
88  }
89 
95  public function getSelectedQueries()
96  {
97  return $this->_options->toOptionArray();
98  }
99 
105  public function getQueriesJson()
106  {
107  $queries = array_flip($this->getSelectedQueries());
108  if (!empty($queries)) {
109  return $this->jsonHelper->jsonEncode($queries);
110  }
111  return '{}';
112  }
113 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\AdvancedSearch\Model\Adminhtml\Search\Grid\Options $options, \Magento\Framework\Registry $registry, \Magento\Framework\Json\Helper\Data $jsonHelper, array $data=[])
Definition: Grid.php:40