Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Collection.php
Go to the documentation of this file.
1 <?php
7 
12  \Magento\Framework\View\Design\Theme\Label\ListInterface,
14 {
18  const DEFAULT_PAGE_SIZE = 6;
19 
23  protected $_idFieldName = 'theme_id';
24 
30  protected function _construct()
31  {
32  $this->_init(\Magento\Theme\Model\Theme::class, \Magento\Theme\Model\ResourceModel\Theme::class);
33  }
34 
40  public function addParentTitle()
41  {
42  $this->getSelect()->joinLeft(
43  ['parent' => $this->getMainTable()],
44  'main_table.parent_id = parent.theme_id',
45  ['parent_theme_title' => 'parent.theme_title']
46  );
47  return $this;
48  }
49 
56  public function addAreaFilter($area = \Magento\Framework\App\Area::AREA_FRONTEND)
57  {
58  $this->getSelect()->where('main_table.area=?', $area);
59  return $this;
60  }
61 
69  public function addTypeRelationFilter($typeParent, $typeChild)
70  {
71  $this->getSelect()->join(
72  ['parent' => $this->getMainTable()],
73  'main_table.parent_id = parent.theme_id',
74  ['parent_type' => 'parent.type']
75  )->where(
76  'parent.type = ?',
77  $typeParent
78  )->where(
79  'main_table.type = ?',
80  $typeChild
81  );
82  return $this;
83  }
84 
91  public function addTypeFilter($type)
92  {
93  $this->addFieldToFilter('main_table.type', ['in' => $type]);
94  return $this;
95  }
96 
102  public function filterVisibleThemes()
103  {
104  $this->addTypeFilter(
105  [
108  ]
109  );
110  return $this;
111  }
112 
118  public function toOptionArray()
119  {
120  return $this->_toOptionArray('theme_id', 'theme_title');
121  }
122 
128  public function toOptionHash()
129  {
130  return $this->_toOptionHash('theme_id', 'theme_title');
131  }
132 
139  public function getThemeByFullPath($fullPath)
140  {
141  $this->_reset()->clear();
142  list($area, $themePath) = explode('/', $fullPath, 2);
143  $this->addFieldToFilter('area', $area);
144  $this->addFieldToFilter('theme_path', $themePath);
145 
146  return $this->getFirstItem();
147  }
148 
155  public function setPageSize($size = self::DEFAULT_PAGE_SIZE)
156  {
157  return parent::setPageSize($size);
158  }
159 
166  public function updateChildRelations(\Magento\Framework\View\Design\ThemeInterface $themeModel)
167  {
168  $parentThemeId = $themeModel->getParentId();
169  $this->addFieldToFilter('parent_id', ['eq' => $themeModel->getId()])->load();
170 
172  foreach ($this->getItems() as $theme) {
173  $theme->setParentId($parentThemeId)->save();
174  }
175  return $this;
176  }
177 
186  public function filterPhysicalThemes(
187  $page = null,
189  ) {
190  $this->addAreaFilter(
191  \Magento\Framework\App\Area::AREA_FRONTEND
192  )->addTypeFilter(
194  );
195  if ($page) {
196  $this->setPageSize($pageSize)->setCurPage($page);
197  }
198  return $this;
199  }
200 
208  public function filterThemeCustomizations(
209  $area = \Magento\Framework\App\Area::AREA_FRONTEND,
211  ) {
212  $this->addAreaFilter($area)->addTypeFilter($type);
213  return $this;
214  }
215 
219  public function getLabels()
220  {
221  $labels = $this->loadRegisteredThemes();
222  return $labels->toOptionArray();
223  }
224 
228  public function loadRegisteredThemes()
229  {
230  $this->_reset()->clear();
231  return $this->setOrder('theme_title', \Magento\Framework\Data\Collection::SORT_ORDER_ASC)
232  ->filterVisibleThemes()->addAreaFilter(\Magento\Framework\App\Area::AREA_FRONTEND);
233  }
234 }
_toOptionArray($valueField=null, $labelField='name', $additional=[])
Definition: AbstractDb.php:641
filterThemeCustomizations( $area=\Magento\Framework\App\Area::AREA_FRONTEND, $type=\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL)
Definition: Collection.php:208
setPageSize($size=self::DEFAULT_PAGE_SIZE)
Definition: Collection.php:155
$type
Definition: item.phtml:13
$page
Definition: pages.php:8
load($printQuery=false, $logQuery=false)
Definition: AbstractDb.php:556
$theme
setOrder($field, $direction=self::SORT_ORDER_DESC)
Definition: AbstractDb.php:274
_toOptionHash($valueField=null, $labelField='name')
Definition: AbstractDb.php:656
addAreaFilter($area=\Magento\Framework\App\Area::AREA_FRONTEND)
Definition: Collection.php:56
filterPhysicalThemes( $page=null, $pageSize=\Magento\Theme\Model\ResourceModel\Theme\Collection::DEFAULT_PAGE_SIZE)
Definition: Collection.php:186