diff --git a/Block/Post/Testimonial.php b/Block/Post/Testimonial.php index 2bbcd27..3d8bfdb 100644 --- a/Block/Post/Testimonial.php +++ b/Block/Post/Testimonial.php @@ -2,41 +2,58 @@ namespace Magiccart\Testimonial\Block\Post; -class Testimonial extends \Magento\Framework\View\Element\Template { +class Testimonial extends \Magento\Framework\View\Element\Template +{ + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var \Magiccart\Testimonial\Model\TestimonialFactory + */ + protected $testimonialFactory; - protected $_scopeConfig; - protected $_testimonialFactory; - protected $_customerSession; + /** + * @var \Magiccart\Testimonial\Helper\Data + */ + public $helper; /** * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magiccart\Testimonial\Model\testimonialFactory $testimonialFactory - * @param \Magento\Customer\Model\SessionFactory $customerSession [description] + * @param \Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory + * @param \Magento\Customer\Model\Session $customerSession * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, + \Magento\Customer\Model\Session $customerSession, \Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory, - \Magento\Customer\Model\SessionFactory $customerSession, + \Magiccart\Testimonial\Helper\Data $helper, + array $data = [] ) { - $this->_customerSession = $customerSession->create(); parent::__construct($context, $data); - - $this->_testimonialFactory = $testimonialFactory; - - $this->_scopeConfig = $context->getScopeConfig(); + $this->customerSession = $customerSession; + $this->testimonialFactory = $testimonialFactory; + $this->helper = $helper; $this->pageConfig->getTitle()->set(__('Submit Your Testimonial')); } - public function getCustomerSession(){ - return $this->_customerSession; + /** + * Add elements in layout + * + * @return + */ + protected function _prepareLayout() + { + return parent::_prepareLayout(); } - - public function getStoreId() + + public function getCustomerSession() { - return $this->_storeManager->getStore()->getId(); + return $this->customerSession; } /** @@ -47,51 +64,34 @@ public function getTestimonial() { $collection = $this->_testimonialFactory->create()->getCollection() ->addFieldToFilter('status', 1) ->addFieldToFilter('stores',array( array('finset' => 0), array('finset' => $store))); + $collection->setOrderByTestimonial(); + return $collection; } - - public function getConfig($config) - { - return $this->_scopeConfig->getValue('testimonial/general/'.$config, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); - } - - public function getIdStore() + + public function getStoreId() { return $this->_storeManager->getStore()->getId(); } - - /** - * @return - */ - public function getMediaFolder() { - $media_folder = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); - return $media_folder; - } - /** - * @return - */ - protected function _toHtml() { - $store = $this->_storeManager->getStore()->getId(); - if ($this->_scopeConfig->getValue('testimonial/general/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store)) { - return parent::_toHtml(); - } - return ''; + public function getConfig($config) + { + return $this->helper->getConfigModule('general/'.$config); } - + /** - * Add elements in layout - * * @return */ - protected function _prepareLayout() { - return parent::_prepareLayout(); + protected function _toHtml() + { + // if(!$this->helper->getConfigModule('general/enabled')) return; + return parent::_toHtml(); } - public function getFormAction() { return $this->getUrl('testimonial/index/post', ['_secure' => true]); } + } \ No newline at end of file diff --git a/Block/Post/TestimonialList.php b/Block/Post/TestimonialList.php index 90833ce..19598a8 100644 --- a/Block/Post/TestimonialList.php +++ b/Block/Post/TestimonialList.php @@ -1,37 +1,55 @@ _testimonialFactory = $testimonialFactory; - $this->customerSession = $customerSession; + $this->customerSession = $customerSession; + $this->testimonialFactory = $testimonialFactory; + $this->helper = $helper; + parent::__construct($context, $data); //get collection of data - $collection = $this->_testimonialFactory->create()->getCollection(); + $collection = $this->testimonialFactory->create()->getCollection(); $collection->addFieldToFilter('status',1); $collection->getSelect()->order(array('order asc', 'testimonial_id desc')); $this->setCollection($collection); @@ -67,13 +85,12 @@ public function getPagerHtml() public function getBaseUrl() { - return $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); + return $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); } public function getMediaUrl() { - - return $this->_urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]).'/testimonial/image'; + return $this->_urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]).'/testimonial/image'; } public function getMediabaseUrl() @@ -94,8 +111,9 @@ public function getDefaultImage() return $this->getViewFileUrl('Magiccart_testimonial::images/default.jpg'); } - public function getConfig($config) - { - return $this->_scopeConfig->getValue('testimonial/general/'.$config, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + public function getConfig($config) + { + return $this->helper->getConfigModule('general/'.$config); } + } diff --git a/Block/Post/View.php b/Block/Post/View.php index 2db2a57..7d8fd0c 100644 --- a/Block/Post/View.php +++ b/Block/Post/View.php @@ -4,14 +4,14 @@ * @Author: nguyen * @Date: 2020-05-31 11:59:46 * @Last Modified by: nguyen - * @Last Modified time: 2020-05-31 12:05:32 + * @Last Modified time: 2021-06-17 10:01:02 */ namespace Magiccart\Testimonial\Block\Post; class View extends \Magento\Framework\View\Element\Template { - protected $_testimonialFactory; + protected $testimonialFactory; /** * Core registry @@ -20,21 +20,14 @@ class View extends \Magento\Framework\View\Element\Template */ protected $_coreRegistry; - /** - * @var \Magento\Framework\App\ResourceConnection - */ - protected $_resource; - public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Registry $registry, \Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory, - \Magento\Framework\App\ResourceConnection $resource, array $data = [] ) { - $this->_testimonialFactory = $testimonialFactory; + $this->testimonialFactory = $testimonialFactory; $this->_coreRegistry = $registry; - $this->_resource = $resource; parent::__construct($context, $data); } diff --git a/Block/Testimonial.php b/Block/Testimonial.php index c6e15d3..0059392 100644 --- a/Block/Testimonial.php +++ b/Block/Testimonial.php @@ -1,10 +1,19 @@ _testimonialFactory = $testimonialFactory; - + + $this->testimonialFactory = $testimonialFactory; } /** @@ -22,21 +30,22 @@ public function __construct( * * @return */ - protected function _prepareLayout() { + protected function _prepareLayout() + { return parent::_prepareLayout(); } - public function getTestimonials() { - if(!$this->_testimonials){ + if(!$this->testimonials){ $store = $this->_storeManager->getStore()->getStoreId(); - $testimonials = $this->_testimonialCollectionFactory->create() + $testimonials = $this->testimonialFactory->create()->getCollection() ->addFieldToFilter('stores',array( array('finset' => 0), array('finset' => $store))) ->addFieldToFilter('status', 1); - $this->_testimonials = $testimonials; + $this->testimonials = $testimonials; } - return $this->_testimonials; + + return $this->testimonials; } } \ No newline at end of file diff --git a/Block/Widget/Testimonial.php b/Block/Widget/Testimonial.php index 2e64845..5cba1fa 100755 --- a/Block/Widget/Testimonial.php +++ b/Block/Widget/Testimonial.php @@ -15,10 +15,11 @@ class Testimonial extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface { - - public $_sysCfg; - + /** + * @var \Magento\Framework\Image\AdapterFactory + */ protected $_imageFactory; + // protected $_filesystem; // protected $_directory; @@ -28,41 +29,50 @@ class Testimonial extends \Magento\Framework\View\Element\Template implements \M protected $backendUrl; /** - * @var \Magiccart\Testimonial\Model\ResourceModel\Testimonial\CollectionFactory + * @var \Magiccart\Testimonial\Model\TestimonialFactory */ - protected $_testimonialCollectionFactory; - protected $_testimonials = null; - protected $_attribute = null; + protected $testimonialFactory; + + protected $_testimonials; + + /** + * @var \Magiccart\Testimonial\Model\Config\Source\GridSlider + */ + protected $gridSlider; + + /** + * @var \Magiccart\Testimonial\Helper\Data + */ + public $helper; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Image\AdapterFactory $imageFactory, // \Magento\Framework\Filesystem $filesystem, \Magento\Backend\Model\UrlInterface $backendUrl, - \Magiccart\Testimonial\Model\ResourceModel\Testimonial\CollectionFactory $testimonialCollectionFactory, + \Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory, + \Magiccart\Testimonial\Model\Config\Source\GridSlider $gridSlider, + \Magiccart\Testimonial\Helper\Data $helper, + array $data = [] ) { - $this->_imageFactory = $imageFactory; - // $this->_filesystem = $filesystem; - // $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); - $this->backendUrl = $backendUrl; - $this->_testimonialCollectionFactory = $testimonialCollectionFactory; - - $this->_sysCfg= (object) $context->getScopeConfig()->getValue( - 'testimonial', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + $this->_imageFactory = $imageFactory; + // $this->_filesystem = $filesystem; + // $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); + $this->backendUrl = $backendUrl; + $this->testimonialFactory = $testimonialFactory; + $this->gridSlider = $gridSlider; + $this->helper = $helper; parent::__construct($context, $data); } protected function _construct() { - - $data = $this->_sysCfg->general; + $data = $this->helper->getConfigModule('general'); if($data['slide']){ - $data['vertical-Swiping'] = $data['vertical']; + $data['vertical-swiping'] = $data['vertical']; $breakpoints = $this->getResponsiveBreakpoints(); $responsive = '['; $num = count($breakpoints); @@ -73,11 +83,12 @@ protected function _construct() if($num) $responsive .= ', '; } $responsive .= ']'; - $data['center-Mode'] = $data['center_mode']; - $data['slides-To-Show'] = $data['visible']; - $data['autoplay-Speed'] = $data['autoplay_speed']; - $data['swipe-To-Slide'] = 'true'; - $data['responsive'] = $responsive; + $data['center-mode'] = $data['center_mode']; + $data['slides-to-show'] = $data['visible']; + $data['autoplay-speed'] = $data['autoplay_speed']; + $data['adaptive-height'] = $data['adaptive_height']; + $data['swipe-to-slide'] = 'true'; + $data['responsive'] = $responsive; // if(!isset($data['rows']) || $data['rows'] == 1 ) $data['rows'] = 0; } @@ -124,12 +135,13 @@ public function getTestimonials() { if(!$this->_testimonials){ $store = $this->_storeManager->getStore()->getStoreId(); - $testimonials = $this->_testimonialCollectionFactory->create() + $testimonials = $this->testimonialFactory->create()->getCollection() ->addFieldToFilter('stores',array( array('finset' => 0), array('finset' => $store))) ->addFieldToFilter('status', 1); $testimonials->getSelect()->order(array('order asc', 'testimonial_id desc')); $this->_testimonials = $testimonials; } + return $this->_testimonials; } @@ -158,13 +170,12 @@ public function getImage($object) public function getResponsiveBreakpoints() { - return array(1921=>'visible', 1920=>'widescreen', 1480=>'desktop', 1200=>'laptop', 992=>'notebook', 768=>'tablet', 576=>'landscape', 481=>'portrait', 361=>'mobile', 1=>'mobile'); - return array(1201=>'visible', 1200=>'desktop', 992=>'notebook', 769=>'tablet', 641=>'landscape', 481=>'portrait', 361=>'mobile', 1=>'mobile'); + return $this->gridSlider->getBreakpoints(); } public function getSlideOptions() { - return array('autoplay', 'arrows', 'autoplay-Speed', 'center-Mode', 'dots', 'fade', 'infinite', 'padding', 'vertical', 'vertical-Swiping', 'responsive', 'rows', 'slides-To-Show', 'swipe-To-Slide'); + return $this->gridSlider->getSlideOptions(); } public function getFrontendCfg() diff --git a/Controller/Index/Post.php b/Controller/Index/Post.php index 58005f7..d2267b8 100644 --- a/Controller/Index/Post.php +++ b/Controller/Index/Post.php @@ -87,7 +87,7 @@ public function execute() $data['image'] = 'magiccart/testimonial/'.$result['file']; - $autoApprove = $this->_moduleHelper->getGeneralCfg('autoApprove'); + $autoApprove = $this->_moduleHelper->getConfigModule('general/autoApprove'); if(!$autoApprove) $data['status'] = 2; else diff --git a/Helper/Data.php b/Helper/Data.php index 29d5dc8..080c500 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -1,58 +1,65 @@ - * @@Create Date: 2015-12-14 20:26:27 - * @@Modify Date: 2016-03-21 15:59:53 - * @@Function: + * @Author: nguyen + * @Date: 2021-06-17 09:43:45 + * @Last Modified by: nguyen + * @Last Modified time: 2021-06-17 09:47:16 */ namespace Magiccart\Testimonial\Helper; -// use \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig; -use Magento\Framework\App\Helper\AbstractHelper; -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\App\Helper\Context; -use Magento\Framework\UrlInterface; -use Magento\Customer\Model\Session; class Data extends \Magento\Framework\App\Helper\AbstractHelper { + + /** + * @var \Magento\Customer\Model\Session + */ private $customerSession; + private $urlInterface; - const SECTIONS = 'testimonial'; // module name - const GROUPS = 'general'; // setup general - const MEDIA_PATH = 'magiccart/testimonial/'; + + /** + * @var array + */ + protected $configModule; + public function __construct( - Context $context, - Session $customerSession + \Magento\Framework\App\Helper\Context $context, + \Magento\Customer\Model\Session $customerSession ) { parent::__construct($context); $this->customerSession = $customerSession; - $this->urlInterface = $context->getUrlBuilder(); + $this->urlInterface = $context->getUrlBuilder(); + $module = strtolower(str_replace('Magiccart_', '', $this->_getModuleName())); + $this->configModule = $this->getConfig($module); } - public function getConfig($cfg=null) + public function getConfig($cfg='') { - return $this->scopeConfig->getValue( - $cfg, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + if($cfg) return $this->scopeConfig->getValue( $cfg, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); + return $this->scopeConfig; } - - public function getGeneralCfg($cfg=null) + + public function getConfigModule($cfg='', $value=null) { - $config = $this->scopeConfig->getValue( - self::SECTIONS.'/'.self::GROUPS, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + $values = $this->configModule; + if( !$cfg ) return $values; + $config = explode('/', $cfg); + $end = count($config) - 1; + foreach ($config as $key => $vl) { + if( isset($values[$vl]) ){ + if( $key == $end ) { + $value = $values[$vl]; + }else { + $values = $values[$vl]; + } + } - if(isset($config[$cfg])) return $config[$cfg]; - return $config; + } + return $value; } public function isAllowedToAddTestimonial() diff --git a/Model/Config/Source/GridSlider.php b/Model/Config/Source/GridSlider.php new file mode 100644 index 0000000..cf641c9 --- /dev/null +++ b/Model/Config/Source/GridSlider.php @@ -0,0 +1,50 @@ +'visible', + 1920 =>'widescreen', + 1480 =>'desktop', + 1200 =>'laptop', + 992 =>'notebook', + 768 =>'tablet', + 576 =>'landscape', + 481 =>'portrait', + 361 =>'mobile', + 1 =>'mobile' + ]; + } + +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 58cdc2a..0da184a 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -124,6 +124,12 @@ validate-zero-or-greater 1 + + Adaptive Height + Adaptive Height + Magiccart\Testimonial\Model\System\Config\Truefalse + 1 + Padding Padding Item Logo brand diff --git a/etc/config.xml b/etc/config.xml index 99d55ce..7eef6c1 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -26,13 +26,14 @@ true true false - true + false false true 0 300 3000 3000 + false 15 1 1 diff --git a/view/frontend/templates/form.phtml b/view/frontend/templates/form.phtml index 3c5e9fc..6ccc7a0 100755 --- a/view/frontend/templates/form.phtml +++ b/view/frontend/templates/form.phtml @@ -1,36 +1,22 @@ getConfig('customers_submit')) -{ - $customer_session = $this->getCustomerSession()->getCustomer(); - if($this->getConfig('allowGuest')) { - $show_submit = true; - }else { - if($customer_session->getName()) { - $show_submit = true; - }else { - $show_submit = true; - } - } -}else { - $show_submit = false; +if(!$this->helper->getConfigModule('general/customers_submit')) return; +$customer = $this->getCustomerSession()->getCustomer(); +if(!$this->helper->getConfigModule('allowGuest') && !$customer) { + return; } - if($show_submit==true): ?> - + value="getName() : '';?>" /> @@ -39,7 +25,7 @@ if($this->getConfig('customers_submit')) + value="getEmail() : '';?>" /> @@ -129,10 +115,7 @@ if($this->getConfig('customers_submit')) - \ No newline at end of file + \ No newline at end of file diff --git a/view/frontend/templates/post/list.phtml b/view/frontend/templates/post/list.phtml index acb27bc..34c299f 100644 --- a/view/frontend/templates/post/list.phtml +++ b/view/frontend/templates/post/list.phtml @@ -1,34 +1,30 @@ getConfig('customers_submit')) - { - if($this->getConfig('allowGuest')) +$show_submit = false; +if($this->getConfig('customers_submit')){ + if($this->getConfig('allowGuest')) + $urlsubmit = $this->getUrl('testimonial/index/post'); + else { + if($this->checklogin()) $urlsubmit = $this->getUrl('testimonial/index/post'); - else { - if($this->checklogin()) - $urlsubmit = $this->getUrl('testimonial/index/post'); - else - $urlsubmit = $this->getUrl('customer/account/login'); - } - $show_submit = true; - }else{ - $show_submit = false; + else + $urlsubmit = $this->getUrl('customer/account/login'); } + $show_submit = true; +} ?> - - - + + + getMediabaseUrl(); - $_testimonialrecords = $this->getCollection(); - if($_testimonialrecords && count($_testimonialrecords)) - { + $testimonials = $this->getCollection(); + if($testimonials && count($testimonials)) : + $mediaUrl = $this->getMediabaseUrl(); ?> - + @@ -46,9 +42,7 @@ if($this->getConfig('customers_submit')) - getData('text')); - ?> + getData('text')); ?> getData('job'))?> @@ -59,13 +53,9 @@ if($this->getConfig('customers_submit')) - + - + getPagerHtml()): ?> getPagerHtml(); ?> diff --git a/view/frontend/templates/testimonial.phtml b/view/frontend/templates/testimonial.phtml index 6a70469..691e770 100755 --- a/view/frontend/templates/testimonial.phtml +++ b/view/frontend/templates/testimonial.phtml @@ -5,10 +5,10 @@ $testimonials = $this->getTestimonials(); if(!count($testimonials)) return; $options = $this->getFrontendCfg(); $centerMode = false; -if(isset($options['center-Mode']) && $options['center-Mode']) $centerMode = true; +if(isset($options['center-mode']) && $options['center-mode']) $centerMode = true; ?> - data-='getData($opt) ?>'