Skip to content

Commit

Permalink
General Code Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
abrorAbdullaev committed Aug 26, 2018
1 parent 499608b commit 9b167c2
Show file tree
Hide file tree
Showing 30 changed files with 774 additions and 378 deletions.
62 changes: 41 additions & 21 deletions src/Api/Data/TestimonialInterface.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
<?php
/**
* Testimonials data interface
*
* @module Malithmcr_Testimonials
* @author Malith Priyashan
* @package Malithmcr\Testimonials\Api\Data
* @licence OSL 3.0
*/
namespace Malithmcr\Testimonials\Api\Data;


/**
* Interface TestimonialInterface
*/
interface TestimonialInterface
{
/**
* Constants for keys of data array. Identical to the name of the getter in snake case
/**
* Constants for keys of data array.
* Identical to the name of the getter in snake case
*/
const TESTIMONIAL_ID = 'testimonial_id';
const URL_KEY = 'url_key';
const TITLE = 'title';
const CONTENT = 'content';
const IMAGE = 'image';
const INFO = 'info';
const CREATION_TIME = 'creation_time';
const UPDATE_TIME = 'update_time';
const IS_ACTIVE = 'is_active';
const URL_KEY = 'url_key';
const CONTENT = 'content';
const TITLE = 'title';
const IMAGE = 'image';
const INFO = 'info';

/**
* Get ID
Expand Down Expand Up @@ -44,15 +55,15 @@ public function getTitle();
* @return string|null
*/
public function getContent();
/**

/**
* Get image
*
* @return string|null
*/
public function getImage();

/**
/**
* Get Info
*
* @return string|null
Expand Down Expand Up @@ -84,78 +95,87 @@ public function isActive();
* Set ID
*
* @param int $id
* @return \Ashsmith\Blog\Api\Data\PostInterface
*
* @return TestimonialInterface
*/
public function setId($id);

/**
* Set URL Key
*
* @param string $url_key
* @return \Ashsmith\Blog\Api\Data\PostInterface
*
* @return TestimonialInterface
*/
public function setUrlKey($url_key);

/**
* Return full URL including base url.
*
* @return mixed
* @return string
*/
public function getUrl();

/**
* Set title
*
* @param string $title
* @return \Ashsmith\Blog\Api\Data\PostInterface
*
* @return TestimonialInterface
*/
public function setTitle($title);

/**
* Set content
*
* @param string $content
* @return \Ashsmith\Blog\Api\Data\PostInterface
*
* @return TestimonialInterface
*/
public function setContent($content);

/**
* Set Image
*
* @param string $image
* @return \Malithmcr\Testimonials\Api\Data\TestimonialInterface
*
* @return TestimonialInterface
*/
public function setImage($image);

/**
* Set Info
*
* @param string $info
* @return \Malithmcr\Testimonials\Api\Data\TestimonialInterface
*
* @return TestimonialInterface
*/
public function setInfo($info);

/**
* Set creation time
*
* @param string $creationTime
* @return \Ashsmith\Blog\Api\Data\PostInterface
*
* @return TestimonialInterface
*/
public function setCreationTime($creationTime);

/**
* Set update time
*
* @param string $updateTime
* @return \Ashsmith\Blog\Api\Data\PostInterface
*
* @return TestimonialInterface
*/
public function setUpdateTime($updateTime);

/**
* Set is active
*
* @param int|bool $isActive
* @return \Ashsmith\Blog\Api\Data\PostInterface
*
* @return TestimonialInterface
*/
public function setIsActive($isActive);
}
33 changes: 31 additions & 2 deletions src/Block/Adminhtml/TestimonialsAdmin.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
<?php
/**
* Testimonials data interface
*
* @module Malithmcr_Testimonials
* @author Malith Priyashan
* @package Malithmcr\Testimonials\Block\Adminhtml
* @licence OSL 3.0
*/

namespace Malithmcr\Testimonials\Block\Adminhtml;
class TestimonialsAdmin extends \Magento\Backend\Block\Widget\Grid\Container

/**
* @TODO Remove usage of deprecated class
*/
use \Magento\Backend\Block\Widget\Grid\Container as GridContainer;

/**
* Class TestimonialsAdmin
*/
class TestimonialsAdmin extends GridContainer
{
/**
* TestimonialsAdmin Constructor
*/
protected function _construct()
{
$this->_controller = 'adminhtml_index';
$this->_blockGroup = 'Malithmcr_Testimonials';
$this->_headerText = __('Manage Blog Posts');
parent::_construct();

if ($this->_isAllowedAction('Malithmcr_Testimonials::save')) {
$this->buttonList->update('add', 'label', __('Add New Testimonial'));
} else {
$this->buttonList->remove('add');
}

parent::_construct();
}

/**
* @param $resourceId
*
* @return bool
*/
protected function _isAllowedAction($resourceId)
{
return $this->_authorization->isAllowed($resourceId);
Expand Down
85 changes: 52 additions & 33 deletions src/Block/TestimonialsList.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,79 @@
<?php
/**
* Testimonials data interface
*
* @module Malithmcr_Testimonials
* @author Malith Priyashan
* @package Malithmcr\Testimonials\Block
* @licence OSL 3.0
*/

namespace Malithmcr\Testimonials\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Customer\Model\Session as CustomerSession;
use Malithmcr\Testimonials\Model\Testimonial;
use Malithmcr\Testimonials\Api\Data\TestimonialInterface;
use Malithmcr\Testimonials\Model\ResourceModel\Testimonial\Collection as TestimonialCollection;
use Malithmcr\Testimonials\Model\ResourceModel\Testimonial\CollectionFactory as TestimonialsCollectionFactory;

class TestimonialsList extends \Magento\Framework\View\Element\Template implements
\Magento\Framework\DataObject\IdentityInterface
/**
* Class TestimonialsList
*/
class TestimonialsList extends Template implements IdentityInterface
{
/**
* @var \Malithmcr\Testimonials\Model\ResourceModel\Testimonial\CollectionFactory
* @var TestimonialsCollectionFactory
*/
protected $testimonialCollectionFactory;

/**
* @var CustomerSession
*/
protected $_testimonialCollectionFactory;
protected $customerSession;

/**
* Construct
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Malithmcr\Testimonials\Model\ResourceModel\Testimonial\CollectionFactory $testimonialCollectionFactory,
* @param TestimonialsCollectionFactory $testimonialCollectionFactory ,
* @param CustomerSession $session
* @param Context $context
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Malithmcr\Testimonials\Model\ResourceModel\Testimonial\CollectionFactory $testimonialCollectionFactory,
TestimonialsCollectionFactory $testimonialCollectionFactory,
CustomerSession $session,
Context $context,
array $data = []
) {
$this->testimonialCollectionFactory = $testimonialCollectionFactory;
$this->customerSession = $session;

parent::__construct($context, $data);
$this->_testimonialCollectionFactory = $testimonialCollectionFactory;
}

/**
* @return \Malithmcr\Testimonials\Model\ResourceModel\Testimonial\Collection
* Gets the testimonials from database saves in local variable for caching
*
* @return TestimonialCollection
*/
public function getTestimonials()
{
// Check if Testimonials has already been defined
if (!$this->hasData('testimonials')) {
$testimonials = $this->_testimonialCollectionFactory
$testimonialsCollection = $this->testimonialCollectionFactory
->create()
->addFilter('is_active', 1)
->addOrder(
TestimonialInterface::CREATION_TIME,
TestimonialCollection::SORT_ORDER_DESC
);
$this->setData('testimonials', $testimonials);

$this->setData('testimonials', $testimonialsCollection);
}

return $this->getData('testimonials');
}

Expand All @@ -54,27 +84,16 @@ public function getTestimonials()
*/
public function getIdentities()
{
return [\Malithmcr\Testimonials\Model\Testimonial::CACHE_TAG . '_' . 'list'];
return [Testimonial::CACHE_TAG . '_' . 'list'];
}

/**
* Check if customer loggedIn
*
* @return bool
*/
public function getCustomerStatus()
{

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
return true;
}else{
return false;
}



}

/**
* Check if customer is logged in
*
* @return bool
*/
public function getCustomerStatus()
{
return $this->customerSession->isLoggedIn();
}
}
Loading

0 comments on commit 9b167c2

Please sign in to comment.