Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hmib committed Oct 22, 2019
1 parent 00c30f6 commit 478e21e
Show file tree
Hide file tree
Showing 87 changed files with 592 additions and 236 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@
/var/package/*
!/var/package/*.xml

/.idea/*
.DS_Store
1 change: 1 addition & 0 deletions Block/Adminhtml/Category/Edit/BackButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Category\Edit;

use Magento\Backend\Block\Widget\Context;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Category/Edit/DeleteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Category\Edit;

use Magento\Backend\Block\Widget\Context;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Category/Edit/SaveAndContinueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Category\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Category/Edit/SaveButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Category\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
Expand Down
20 changes: 15 additions & 5 deletions Block/Adminhtml/Customer/AssignCustomers.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* AssignCustomers
*
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Customer;

Expand Down Expand Up @@ -99,7 +105,6 @@ public function getProductsJson()
return '{}';
}


/**
* @return array
*/
Expand All @@ -108,7 +113,7 @@ public function getUsageCustomer()
$id = $this->getRequest()->getParam('entity_id');
$customerArray = [];

if(isset($id)){
if (isset($id)) {
$collection = $this->collectionFactory->create();
foreach ($collection as $item) {
$customerArray[$item->getCustomerId()] = $item->getCustomerId();
Expand All @@ -117,10 +122,15 @@ public function getUsageCustomer()
return $customerArray;
}

public function showGrid(){
/**
* @return bool|mixed
*/
public function showGrid()
{
$customLicense = $this->request->getParam('custom_license');
if(isset($customLicense))
if (isset($customLicense)) {
return $customLicense;
}
return false;
}
}
}
70 changes: 60 additions & 10 deletions Block/Adminhtml/Customer/Tab/Customer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* Customer
*
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Customer\Tab;

Expand All @@ -20,9 +26,9 @@ class Customer extends \Magento\Backend\Block\Widget\Grid\Extended
protected $coreRegistry = null;

/**
* @var \Magento\Customer\Model\CustomerFactory
* @var \DevStone\UsageCalculator\Model\ResourceModel\Customer\CollectionFactory|\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory
*/
protected $customerFactory;
protected $customerCollectionFactory;

/**
* @var mixed
Expand All @@ -44,12 +50,13 @@ class Customer extends \Magento\Backend\Block\Widget\Grid\Extended
*/
protected $collectionFactory;

protected $resource;

/**
* Customer constructor.
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
* @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollectionFactory
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\App\RequestInterface $request
* @param \DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\CollectionFactory $collectionFactory
Expand All @@ -60,18 +67,20 @@ class Customer extends \Magento\Backend\Block\Widget\Grid\Extended
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\Customer\Model\CustomerFactory $customerFactory,
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\App\RequestInterface $request,
\DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\CollectionFactory $collectionFactory,
\DevStone\UsageCalculator\Model\ResourceModel\Customer\CollectionFactory $customerCollectionFactory,
array $data = [],
Visibility $visibility = null,
Status $status = null
) {
$this->customerFactory = $customerFactory;
$this->customerCollectionFactory = $customerCollectionFactory;
$this->coreRegistry = $coreRegistry;
$this->request = $request;
$this->collectionFactory = $collectionFactory;
$this->resource = $resource;
$this->visibility = $visibility ?: ObjectManager::getInstance()->get(Visibility::class);
$this->status = $status ?: ObjectManager::getInstance()->get(Status::class);
parent::__construct($context, $backendHelper, $data);
Expand All @@ -86,10 +95,14 @@ protected function _construct()
$this->setId('usage_calculator_customers');
$this->setDefaultSort('id');
$this->setDefaultFilter(['in_usage' => 1]);

$this->setUseAjax(true);
}

/**
* @param Grid\Column $column
* @return $this|Extended
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _addColumnFilterToCollection($column)
{
if ($column->getId() == 'in_usage') {
Expand All @@ -98,26 +111,30 @@ protected function _addColumnFilterToCollection($column)
$customerIds = 0;
}
$linkField = 'entity_id';
$filter = $column->getFilter();
$filter = $column->getFilter();
if ($filter !== false && $column->getFilter()->getValue()) {
$this->getCollection()->addFieldToFilter($linkField, ['in' => $customerIds]);
} elseif (!empty($customerIds)) {
$this->getCollection()->addFieldToFilter($linkField, ['nin' => $customerIds]);
}
} elseif ($column->getId() == 'name') {
$this->getCollection()->getSelect()->where("CONCAT(e.firstname, ' ', e.lastname) like '%" . $column->getFilter()->getValue() . "%'");
} elseif ($column->getId() == 'company') {
$this->getCollection()->getSelect()->where('company like "%' . $column->getFilter()->getValue() . '%"');
} else {
parent::_addColumnFilterToCollection($column);
}

return $this;
}


/**
* @return Extended
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareCollection()
{
$collection = $this->customerFactory->create()->getCollection()->addAttributeToSelect('*');
$collection = $this->customerCollectionFactory->create();
$storeId = (int)$this->getRequest()->getParam('store', 0);
if ($storeId > 0) {
$collection->addStoreFilter($storeId);
Expand Down Expand Up @@ -156,8 +173,39 @@ protected function _prepareColumns()
'column_css_class' => 'col-id'
]
);
$this->addColumn('email', ['header' => __('Email'), 'index' => 'email']);

// Customer Email Column
$this->addColumn(
'email',
[
'type' => 'text',
'name' => 'email',
'header' => __('Email'),
'index' => 'email'
]
);

//Customer Name Column
$this->addColumn(
'name',
[
'type' => 'text',
'name' => 'name',
'header' => __('Name'),
'index' => 'name'
]
);

//Customer Company Column
$this->addColumn(
'company',
[
'type' => 'text',
'name' => 'company',
'header' => __('Company'),
'index' => 'company'
]
);
return parent::_prepareColumns();
}

Expand Down Expand Up @@ -197,4 +245,6 @@ public function getCustomersId()
}
return $customerArray;
}


}
1 change: 1 addition & 0 deletions Block/Adminhtml/Size/Edit/BackButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Size\Edit;

use Magento\Backend\Block\Widget\Context;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Size/Edit/DeleteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Size\Edit;

use Magento\Backend\Block\Widget\Context;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Size/Edit/SaveAndContinueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Size\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Size/Edit/SaveButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Size\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Usage/Edit/BackButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Usage\Edit;

use Magento\Backend\Block\Widget\Context;
Expand Down
11 changes: 8 additions & 3 deletions Block/Adminhtml/Usage/Edit/CustomLicense.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* CustomLicense
*
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Usage\Edit;

Expand All @@ -17,9 +23,8 @@ class CustomLicense implements \Magento\Framework\View\Element\UiComponent\Contr
* CustomLicense constructor.
* @param \Magento\Framework\UrlInterface $urlBuilder
*/
public function __construct(
\Magento\Framework\UrlInterface $urlBuilder
) {
public function __construct(\Magento\Framework\UrlInterface $urlBuilder)
{
$this->urlBuilder = $urlBuilder;
}

Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Usage/Edit/DeleteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Usage\Edit;

use Magento\Backend\Block\Widget\Context;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Usage/Edit/SaveAndContinueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Usage\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Usage/Edit/SaveButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright © 2018 DevStone. All rights reserved.
* @author [email protected]
*/

namespace DevStone\UsageCalculator\Block\Adminhtml\Usage\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
Expand Down
Loading

0 comments on commit 478e21e

Please sign in to comment.