localeDate = $localeDate; $this->locale = $localeResolver->getLocale(); parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); } /** * Define model & resource model */ protected function _construct() { $this->_init(PostHistory::class, \Mageplaza\Blog\Model\ResourceModel\PostHistory::class); } /** * Add field filter to collection * * @param string|array $field * @param null|string|array $condition * * @return \Magento\Framework\Data\Collection\AbstractDb * @see self::_getConditionSql for $condition * */ public function addFieldToFilter($field, $condition = null) { if (is_array($field)) { $conditions = []; foreach ($field as $key => $value) { $conditions[] = $this->_translateCondition($value, isset($condition[$key]) ? $condition[$key] : null); } $resultCondition = '(' . implode(') ' . \Magento\Framework\DB\Select::SQL_OR . ' (', $conditions) . ')'; } else { $resultCondition = $this->_translateCondition($field, $condition); } $this->_select->where($resultCondition, null, Select::TYPE_CONDITION); return $this; } /** * @return Collection * @throws Exception */ protected function _afterLoad() { foreach ($this->getItems() as $item) { $convertedDate = $this->localeDate->date( new DateTime($item->getData('updated_at'), new DateTimeZone('UTC')), $this->locale, true ); $item->setData('updated_at', $convertedDate->format('M j, Y h:i:s A')); } return parent::_afterLoad(); } }