Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Soon/AdminLogger/Block/Adminhtml/Log/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Soon/AdminLogger/Block/Adminhtml/Log/Grid.php
<?php
/**
 * @license http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @author Hervé Guétin <[email protected]> <@herveguetin>
 * @copyright Copyright (c) 2018 Kaliop Digital Commerce (http://digitalcommerce.kaliop.com)
 */

namespace Soon\AdminLogger\Block\Adminhtml\Log;

class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
{
    /**
     * @var \Soon\AdminLogger\Model\ResourceModel\Log\CollectionFactory
     */
    private $collectionFactory;
    /**
     * @var \Magento\User\Model\ResourceModel\User\CollectionFactory
     */
    private $userCollectionFactory;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Backend\Helper\Data $backendHelper,
        \Soon\AdminLogger\Model\ResourceModel\Log\CollectionFactory $collectionFactory,
        \Magento\User\Model\ResourceModel\User\CollectionFactory $userCollectionFactory,
        array $data = []
    )
    {
        parent::__construct($context, $backendHelper, $data);
        $this->setId('soonAdminLoggerLogGrid');
        $this->setDefaultSort('created_at');
        $this->setDefaultDir('DESC');
        $this->collectionFactory = $collectionFactory;
        $this->userCollectionFactory = $userCollectionFactory;
    }

    /**
     * @return \Magento\Backend\Block\Widget\Grid\Extended
     */
    protected function _prepareCollection()
    {
        /** @var \Soon\AdminLogger\Model\ResourceModel\Log\Collection $collection */
        $collection = $this->collectionFactory->create();
        $collection->populateDb();

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn('action', array(
            'header' => __('Action'),
            'index' => 'full_action_name',
        ));

        $this->addColumn('uri', array(
            'header' => __('URi'),
            'index' => 'uri',
            'width' => '120px',
            'frame_callback' => array($this, 'truncate')
        ));

        $this->addColumn('post_data', array(
            'header' => __('Saved Data'),
            'index' => 'post_data',
            'width' => '120px',
            'frame_callback' => array($this, 'truncate')
        ));

        $this->addColumn('is_post', array(
            'header' => __('Action Type'),
            'index' => 'is_post',
            'type' => 'options',
            'options' => array(
                0 => __('View'),
                1 => __('Edit'),
            ),
            'width' => '120px',
            'frame_callback' => array($this, 'decorateIsPost')
        ));

        $this->addColumn('created_at', array(
            'header' => __('When'),
            'index' => 'created_at',
            'type' => 'datetime',
        ));

        $this->addColumn('admin_user', array(
            'header' => __('Admin User'),
            'index' => 'admin_user',
            'type' => 'options',
            'options' => $this->getAdminUsersArray(),
        ));
    }

    /**
     * Decorate status column values
     *
     * @return string
     */
    public function decorateIsPost($value, $row, $column)
    {
        /** @var \Magento\Framework\DataObject $row */
        if (!$row->getData('is_post')) {
            return $value;
        }

        $title = __('Download Posted Data');
        $html = '&nbsp;&nbsp;&nbsp;&nbsp;<a title="' . $title . '" href="' . $this->_urlBuilder->getUrl('*/*/dlPostData', ['log_id' => $row->getData('log_id')]) . '">💾</a>';

        return $value . $html;
    }

    /**
     * @param $value
     * @param $row
     * @param $column
     * @return string
     */
    public function truncate($value, $row, $column)
    {
        $value = str_replace('[]', '', $value);
        return $this->filterManager->truncate($value, ['length' => 40]);
    }

    /**
     * @return array
     */
    private function getAdminUsersArray()
    {
        /** @var \Magento\User\Model\ResourceModel\User\Collection $userCollection */
        $userCollection = $this->userCollectionFactory->create();
        $usersArray = [];
        array_map(function ($user) use (&$usersArray) {
            /** @var \Magento\User\Model\User $user */
            $usersArray[$user->getData('user_id')] = $this->getFormattedAdminUserInfo($user);
        }, $userCollection->getItems());

        return $usersArray;
    }

    /**
     * @param \Magento\User\Model\User $user
     * @return mixed
     */
    private function getFormattedAdminUserInfo($user)
    {
        return sprintf('%s (%s %s)', $user->getData('username'), $user->getData('firstname'), $user->getData('lastname'));
    }
}

Spamworldpro Mini