Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
magiccart committed Jun 17, 2021
1 parent 3cdbf59 commit 8de7241
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 210 deletions.
94 changes: 47 additions & 47 deletions Block/Post/Testimonial.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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]);
}

}
58 changes: 38 additions & 20 deletions Block/Post/TestimonialList.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
<?php

/**
* @Author: nguyen
* @Date: 2021-06-17 11:58:22
* @Last Modified by: nguyen
* @Last Modified time: 2021-06-17 12:01:51
*/

namespace Magiccart\Testimonial\Block\Post;

use Magento\Framework\UrlInterface;

/**
* Main contact form block
*/
class TestimonialList extends \Magento\Framework\View\Element\Template
{
/**
* @param Template\Context $context
* @param array $data
* @var \Magento\Customer\Model\Session
*/
protected $_testimonialFactory;
protected $customerSession;
/**
* url builder
*
* @var \Magento\Framework\UrlInterface

/**
* @var \Magiccart\Testimonial\Model\TestimonialFactory
*/
protected $testimonialFactory;

/**
* @var \Magiccart\Testimonial\Helper\Data
*/
public $helper;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory
* @param \Magiccart\Testimonial\Helper\Data $helper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory,
\Magento\Customer\Model\Session $customerSession,
\Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory,
\Magiccart\Testimonial\Helper\Data $helper,
array $data = []
)
{
$this->_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);
Expand Down Expand Up @@ -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()
Expand All @@ -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);
}

}
13 changes: 3 additions & 10 deletions Block/Post/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
29 changes: 19 additions & 10 deletions Block/Testimonial.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
<?php

/**
* @Author: nguyen
* @Date: 2021-06-17 09:57:16
* @Last Modified by: nguyen
* @Last Modified time: 2021-06-17 09:57:48
*/

namespace Magiccart\Testimonial\Block;

class Testimonial extends \Magento\Framework\View\Element\Template {

protected $_testimonialFactory;
protected $testimonials;

protected $testimonialFactory;

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magiccart\Testimonial\Model\TestimonialFactory $testimonialFactory,
array $data = []
) {
parent::__construct($context, $data);

$this->_testimonialFactory = $testimonialFactory;


$this->testimonialFactory = $testimonialFactory;
}

/**
* Add elements in layout
*
* @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;
}

}
Loading

0 comments on commit 8de7241

Please sign in to comment.