107 $this->_entityFactory = $entityFactory;
120 $filter = new \Magento\Framework\DataObject();
122 $filter[
'field'] = $field;
123 $filter[
'value'] =
$value;
124 $filter[
'type'] = strtolower(
$type);
126 $this->_filters[] = $filter;
127 $this->_isFiltersRendered =
false;
172 throw new \Magento\Framework\Exception\LocalizedException(
new \
Magento\Framework\
Phrase(
'Not implemented'));
189 if (is_array($field)) {
196 foreach ($this->_filters as $filter) {
197 if (in_array($filter[
'field'], $field)) {
205 foreach ($this->_filters as $filter) {
206 if ($filter[
'field'] === $field) {
230 $this->_isCollectionLoaded = $flag;
242 if ($this->_curPage + $displacement < 1) {
247 return $this->_curPage + $displacement;
258 $collectionSize = (int)$this->
getSize();
259 if (0 === $collectionSize) {
261 }
elseif ($this->_pageSize) {
262 return ceil($collectionSize / $this->_pageSize);
286 if ($this->_totalRecords ===
null) {
289 return intval($this->_totalRecords);
301 if (
count($this->_items)) {
302 reset($this->_items);
303 return current($this->_items);
306 return $this->_entityFactory->create($this->_itemObjectClass);
318 if (
count($this->_items)) {
319 return end($this->_items);
322 return $this->_entityFactory->create($this->_itemObjectClass);
348 $col[] =
$item->getData($colName);
365 foreach ($this as
$item) {
384 foreach ($this as
$item) {
403 if ($itemId !==
null) {
404 if (isset($this->_items[$itemId])) {
405 throw new \Exception(
406 'Item (' . get_class(
$item) .
') with the same ID "' .
$item->getId() .
'" already exists.' 409 $this->_items[$itemId] =
$item;
424 $this->_items[] =
$item;
436 return $item->getId();
461 if (isset($this->_items[$key])) {
462 unset($this->_items[$key]);
500 public function walk($callback, array $args = [])
503 $useItemCallback = is_string($callback) && strpos($callback,
'::') ===
false;
506 if ($useItemCallback) {
507 $cb = [
$item, $callback];
524 public function each($objMethod, $args = [])
526 if ($objMethod instanceof \Closure) {
528 $objMethod(
$item, ...$args);
530 }
elseif (is_array($objMethod)) {
536 $item->$objMethod(...$args);
550 if (is_array($key)) {
551 foreach ($key as $k => $v) {
570 $this->_curPage =
$page;
582 $this->_pageSize = $size;
593 public function setOrder($field, $direction = self::SORT_ORDER_DESC)
595 $this->_orders[$field] = $direction;
609 throw new \InvalidArgumentException(
$className .
' does not extend \Magento\Framework\DataObject');
622 return $this->_entityFactory->create($this->_itemObjectClass);
675 public function loadData($printQuery =
false, $logQuery =
false)
687 public function load($printQuery =
false, $logQuery =
false)
689 return $this->
loadData($printQuery, $logQuery);
701 return $this->
loadData($printQuery, $logQuery);
711 $xml =
'<?xml version="1.0" encoding="UTF-8"?> 714 $this->_totalRecords .
718 foreach ($this as
$item) {
719 $xml .=
$item->toXml();
732 public function toArray($arrRequiredFields = [])
735 $arrItems[
'totalRecords'] = $this->
getSize();
737 $arrItems[
'items'] = [];
738 foreach ($this as
$item) {
739 $arrItems[
'items'][] =
$item->toArray($arrRequiredFields);
760 protected function _toOptionArray($valueField =
'id', $labelField =
'name', $additional = [])
763 $additional[
'value'] = $valueField;
764 $additional[
'label'] = $labelField;
766 foreach ($this as
$item) {
767 foreach ($additional as
$code => $field) {
804 foreach ($this as
$item) {
805 $res[
$item->getData($valueField)] =
$item->getData($labelField);
819 if (isset($this->_items[$idValue])) {
820 return $this->_items[$idValue];
833 return new \ArrayIterator($this->_items);
844 return count($this->_items);
855 return $this->_flags[$flag] ??
null;
867 $this->_flags[$flag] =
$value;
879 return array_key_exists($flag, $this->_flags);
907 $this->_entityFactory =
$objectManager->get(EntityFactoryInterface::class);
loadWithFilter($printQuery=false, $logQuery=false)
addFieldToFilter($field, $condition)
elseif(isset( $params[ 'redirect_parent']))
loadData($printQuery=false, $logQuery=false)
call_user_func($callable, $param)
toArray($arrRequiredFields=[])
setOrder($field, $direction=self::SORT_ORDER_DESC)
addFilter($field, $value, $type='and')
_getItemId(\Magento\Framework\DataObject $item)
getItemByColumnValue($column, $value)
_toOptionArray($valueField='id', $labelField='name', $additional=[])
getItemsByColumnValue($column, $value)
load($printQuery=false, $logQuery=false)
walk($callback, array $args=[])
setFlag($flag, $value=null)
each($objMethod, $args=[])
_toOptionHash($valueField='id', $labelField='name')
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
setDataToAll($key, $value=null)
__construct(EntityFactoryInterface $entityFactory)
addItem(\Magento\Framework\DataObject $item)
getCurPage($displacement=0)
getColumnValues($colName)
setItemObjectClass($className)