_slidesSollection = $slidesCollectionFactory->create(); $this->_groupSollection = $groupCollectionFactory->create(); $this->httpContext = $httpContext; $this->json = $json ?: ObjectManager::getInstance()->get( Json::class ); parent::__construct( $context, $data ); } protected function _construct() { $this->addData( [ 'cache_lifetime' => 86400, ] ); if ( !$this->hasData( 'template' ) && !$this->getTemplate() ) { $this->setTemplate( 'Olegnax_BannerSlider::bannerslider.phtml' ); } parent::_construct(); } public function getCacheKeyInfo( $newval = [] ) { return array_merge( [ 'OLEGNAX_BANNERSLIDER_WIDGET', $this->_storeManager->getStore()->getId(), $this->_design->getDesignTheme()->getId(), $this->httpContext->getValue( Context::CONTEXT_GROUP ), $this->json->serialize( $this->getRequest()->getParams() ), $this->json->serialize( $this->getData() ), ], parent::getCacheKeyInfo(), $newval ); } public function getConfig( $path, $storeCode = null ) { $value = $this->_scopeConfig->getValue( $path, ScopeInterface::SCOPE_STORE, $storeCode ); if (is_null($value)) { $value = ''; } return $value; } public function getSlides() { $group = $this->getGroup(); if ( !empty( $group ) ) { return $this->_slidesSollection ->addFieldToSelect( '*' ) ->addStoreFilter( $this->_storeManager->getStore() ) ->addFieldToFilter( 'slide_group', $group[ 'group_id' ] ) ->addFieldToFilter( 'status', 1 ) ->setOrder( 'sort_order', 'asc' ); } return []; } public function getGroup() { $group = $this->getData( 'current_group' ); if ( empty( $group ) ) { $groups = $this->_groupSollection ->addFieldToSelect( '*' ) ->addFieldToFilter( 'identifier', $this->getSlideGroup() ); if ( $groups->getSize() ) { foreach ( $groups as $group ) { $this->setData( 'current_group', $group ); break; } } } return $group; } public function getSliderId() { return 'ox_' . $this->getNameInLayout() . substr( md5( microtime() ), -5 );; } public function prepareStyle( array $style, string $separatorValue = ': ', string $separatorAttribute = ';' ) { $style = array_filter( $style ); if ( empty( $style ) ) { return ''; } foreach ( $style as $key => &$value ) { $value = $key . $separatorValue . $value; } $style = implode( $separatorAttribute, $style ); return $style; } public function getResponsive( $to_string = true ) { $width = $this->getGroup()->getSlideWidth(); $responsive = [ 0 => [ 'items' => 1, ], ]; $j = 1; for ( $i = $width + 1; $i < 3000; $i += $width ) { $j++; $responsive[ $i ] = [ 'items' => $j, ]; } if ( $to_string ) { return json_encode( $responsive ); } return $responsive; } public function getAutoScroll() { $auto_scroll = $this->getData( 'auto_scroll' ); if ( empty( $auto_scroll ) ) { $auto_scroll = 0; } return $auto_scroll; } }