Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
magenizr committed Jul 11, 2021
0 parents commit c932a8d
Show file tree
Hide file tree
Showing 30 changed files with 1,362 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Controller/Adminhtml/Activity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Controller\Adminhtml;

/**
* Class Activity
*
* @package Magenizr\AdminUser\Controller\Adminhtml
*/
abstract class Activity extends \Magento\Backend\App\Action
{
const ADMIN_RESOURCE = 'Magenizr_AdminUser::activity';
}
47 changes: 47 additions & 0 deletions Controller/Adminhtml/Activity/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Controller\Adminhtml\Activity;

/**
* Class Index
*
* @package Magenizr\AdminUser\Controller\Adminhtml\Activity
*/
class Index extends \Magenizr\AdminUser\Controller\Adminhtml\Activity
{
/**
* @var bool|\Magento\Framework\View\Result\PageFactory
*/
private $resultPageFactory = false;

/**
* Index constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {

parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}

public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend((__('User Activity')));

return $resultPage;
}
}
66 changes: 66 additions & 0 deletions Controller/Adminhtml/Activity/MassDisable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Controller\Adminhtml\Activity;

use Magento\Framework\Controller\ResultFactory;

/**
* Class MassDisable
*
* @package Magenizr\AdminUser\Controller\Adminhtml\Activity
*/
class MassDisable extends \Magenizr\AdminUser\Controller\Adminhtml\Activity
{
/**
* @var \Magenizr\AdminUser\Model\ResourceModel\Activity
*/
private $activityModel;

/**
* MassDisable constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magenizr\AdminUser\Model\ResourceModel\Activity $activityModel
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magenizr\AdminUser\Model\ResourceModel\Activity $activityModel
) {
$this->resultPageFactory = $resultPageFactory;
$this->activityModel = $activityModel;

parent::__construct($context);
}

public function execute()
{
try {
$userIds = $this->getRequest()->getPost('selected');

if (is_array($userIds)) {
$this->activityModel->updateUserStatus($userIds, 0);

$this->messageManager->addSuccess(
__(
'Disabled <strong>%1</strong> user(s).',
count($userIds)
)
);
}
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
}

$this->_redirect('*/*/index');
}
}
66 changes: 66 additions & 0 deletions Controller/Adminhtml/Activity/MassEnable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Controller\Adminhtml\Activity;

use Magento\Framework\Controller\ResultFactory;

/**
* Class MassEnable
*
* @package Magenizr\AdminUser\Controller\Adminhtml\Activity
*/
class MassEnable extends \Magenizr\AdminUser\Controller\Adminhtml\Activity
{
/**
* @var \Magenizr\AdminUser\Model\ResourceModel\Activity
*/
private $activityModel;

/**
* MassEnable constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magenizr\AdminUser\Model\ResourceModel\Activity $activityModel
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magenizr\AdminUser\Model\ResourceModel\Activity $activityModel
) {
$this->resultPageFactory = $resultPageFactory;
$this->activityModel = $activityModel;

parent::__construct($context);
}

public function execute()
{
try {
$userIds = $this->getRequest()->getPost('selected');

if (is_array($userIds)) {
$this->activityModel->updateUserStatus($userIds, 1);

$this->messageManager->addSuccess(
__(
'Enabled <strong>%1</strong> user(s).',
count($userIds)
)
);
}
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
}

$this->_redirect('*/*/index');
}
}
68 changes: 68 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;

/**
* Class Data
*
* @package Magenizr\AdminUser\Helper
*/
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const TABLE_USER = 'admin_user';

/**
* @var string
*/
protected $tab = 'admin/magenizr_adminuser';

/**
* Get current date based on date settings.
*
* @return false|int
*/
public function getNow()
{
return $this->dateFactory->create()->gmtDate();
}

/**
* Get difference between two dates. Return the number of days.
*
* @param string $dateFrom
* @param $dateTo
* @return float
*/
public function getDateDiff($dateTo, $dateFrom = 'now')
{
if ($dateFrom == 'now') {
$dateFrom = $this->getNow();
}

return round(abs(strtotime($dateFrom) - strtotime($dateTo))/86400);
}

/**
* Get module configuration values from core_config_data
*
* @param $setting
* @return mixed
*/
public function getConfig($setting)
{
return $this->scopeConfig->getValue(
$this->tab . '/' . $setting,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
}
26 changes: 26 additions & 0 deletions Model/Activity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Model;

/**
* Class Activity
*
* @package Magenizr\AdminUser\Model
*/
class Activity extends \Magento\Framework\Model\AbstractModel
{
// @codingStandardsIgnoreStart
protected function _construct()
{
$this->_init(\Magenizr\AdminUser\Model\ResourceModel\Activity::class);
}
// @codingStandardsIgnoreEnd
}
47 changes: 47 additions & 0 deletions Model/ResourceModel/Activity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Model\ResourceModel;

use Magenizr\AdminUser\Helper\Data as Helper;

/**
* Class Style
*
* @package Magenizr\Notification\Model\ResourceModel
*/
class Activity extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
// @codingStandardsIgnoreStart
protected function _construct() {
$this->_init(Helper::TABLE_USER, 'user_id');
}
// @codingStandardsIgnoreEnd

/**
* Update the user status
*
* @param $userIds
* @param $status
* @return mixed
*/
public function updateUserStatus($userIds, $status)
{
if (!is_array($userIds)) {
$userIds = [$userIds];
}

return $this->getConnection()->update(
$this->getMainTable(),
['is_active' => $status],
$this->getIdFieldName() . ' IN (' . $this->getConnection()->quote($userIds) . ')'
);
}
}
26 changes: 26 additions & 0 deletions Model/ResourceModel/Activity/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Magenizr AdminUser
*
* @category Magenizr
* @package Magenizr_AdminUser
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminUser\Model\ResourceModel\Activity;

/**
* Class Collection
*
* @package Magenizr\Notification\Model\ResourceModel\Activity
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
// @codingStandardsIgnoreStart
protected function _construct()
{
$this->_init(\Magenizr\AdminUser\Model\Activity::class, \Magenizr\AdminUser\Model\ResourceModel\Activity::class);
}
// @codingStandardsIgnoreEnd
}
Loading

0 comments on commit c932a8d

Please sign in to comment.