Current Path : /var/www/axolotl/data/www/kirov.axolotls.ru/bitrix/components/bitrix/sender.abuse.list/ |
Current File : /var/www/axolotl/data/www/kirov.axolotls.ru/bitrix/components/bitrix/sender.abuse.list/class.php |
<? use Bitrix\Main\ErrorCollection; use Bitrix\Main\Grid\Options as GridOptions; use Bitrix\Main\Localization\Loc; use Bitrix\Main\UI\Filter\Options as FilterOptions; use Bitrix\Sender\Internals\Model; use Bitrix\Sender\Security; use Bitrix\Sender\UI\PageNavigation; if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die(); } if (!Bitrix\Main\Loader::includeModule('sender')) { ShowError('Module `sender` not installed'); die(); } Loc::loadMessages(__FILE__); class SenderAbuseListComponent extends \Bitrix\Sender\Internals\CommonSenderComponent { /** @var ErrorCollection $errors */ protected $errors; protected function checkRequiredParams() { return true; } protected function initParams() { $this->arParams['GRID_ID'] = isset($this->arParams['GRID_ID']) ? $this->arParams['GRID_ID'] : 'SENDER_ABUSE_GRID'; $this->arParams['FILTER_ID'] = isset($this->arParams['FILTER_ID']) ? $this->arParams['FILTER_ID'] : $this->arParams['GRID_ID'] . '_FILTER'; $this->arParams['SET_TITLE'] = isset($this->arParams['SET_TITLE']) ? $this->arParams['SET_TITLE'] == 'Y' : true; $this->arParams['CAN_EDIT'] = isset($this->arParams['CAN_EDIT']) ? $this->arParams['CAN_EDIT'] : Security\Access::getInstance()->canModifyAbuses(); } protected function preparePost() { $ids = $this->request->get('ID'); $action = $this->request->get('action_button_' . $this->arParams['GRID_ID']); switch ($action) { case 'delete': if (!is_array($ids)) { $ids = array($ids); } foreach ($ids as $id) { Model\AbuseTable::delete($id); } break; } } protected function prepareResult() { /* Set title */ if ($this->arParams['SET_TITLE']) { /**@var \CAllMain*/ $GLOBALS['APPLICATION']->SetTitle(Loc::getMessage('SENDER_ABUSE_LIST_COMP_TITLE')); } if (!Security\Access::getInstance()->canViewAbuses()) { Security\AccessChecker::addError($this->errors); return false; } $this->arResult['ERRORS'] = array(); $this->arResult['ROWS'] = array(); $this->arResult['ACTION_URI'] = $this->getPath() . '/ajax.php'; if ($this->request->isPost() && check_bitrix_sessid() && $this->arParams['CAN_EDIT']) { $this->preparePost(); } // set ui filter $this->setUiFilter(); // set ui grid columns $this->setUiGridColumns(); // create nav $nav = new PageNavigation("page-sender-abuses"); $nav->allowAllRecords(true)->setPageSize(10)->initFromUri(); // get rows $list = Model\AbuseTable::getList(array( 'select' => array( 'ID', 'TEXT', 'CONTACT_CODE', 'DATE_INSERT' ), 'filter' => $this->getDataFilter(), 'offset' => $nav->getOffset(), 'limit' => $nav->getLimit(), 'count_total' => true, 'order' => $this->getGridOrder() )); foreach ($list as $item) { $this->arResult['ROWS'][] = $item; } $this->arResult['TOTAL_ROWS_COUNT'] = $list->getCount(); // set rec count to nav $nav->setRecordCount($list->getCount()); $this->arResult['NAV_OBJECT'] = $nav; Model\AbuseTable::resetCountOfNew(); return true; } protected function getDataFilter() { $filterOptions = new FilterOptions($this->arParams['FILTER_ID']); $requestFilter = $filterOptions->getFilter($this->arResult['FILTERS']); $filter = []; if (isset($requestFilter['CONTACT_CODE']) && $requestFilter['CONTACT_CODE']) { $filter['CONTACT_CODE'] = '%' . $requestFilter['CONTACT_CODE'] . '%'; } return $filter; } protected function getGridOrder() { $defaultSort = array('ID' => 'DESC'); $gridOptions = new GridOptions($this->arParams['GRID_ID']); $sorting = $gridOptions->getSorting(array('sort' => $defaultSort)); $by = key($sorting['sort']); $order = mb_strtoupper(current($sorting['sort'])) === 'ASC' ? 'ASC' : 'DESC'; $list = array(); foreach ($this->getUiGridColumns() as $column) { if (!isset($column['sort']) || !$column['sort']) { continue; } $list[] = $column['sort']; } if (!in_array($by, $list)) { return $defaultSort; } return array($by => $order); } protected function setUiGridColumns() { $this->arResult['COLUMNS'] = $this->getUiGridColumns(); } protected function getUiGridColumns() { return array( array( "id" => "ID", "name" => "ID", "sort" => "ID", "default" => false ), array( "id" => "DATE_INSERT", "name" => Loc::getMessage('SENDER_ABUSE_LIST_COMP_UI_COLUMN_DATE_INSERT'), "sort" => "DATE_INSERT", "default" => true ), array( "id" => "CONTACT_CODE", "name" => Loc::getMessage('SENDER_ABUSE_LIST_COMP_UI_COLUMN_CONTACT_CODE'), "sort" => "CONTACT_CODE", "default" => true ), array( "id" => "TEXT", "name" => Loc::getMessage('SENDER_ABUSE_LIST_COMP_UI_COLUMN_CONTACT_TEXT'), "default" => true ), ); } protected function setUiFilter() { $this->arResult['FILTERS'] = array( array( "id" => "CONTACT_CODE", "name" => Loc::getMessage('SENDER_ABUSE_LIST_COMP_UI_COLUMN_CONTACT_CODE'), "default" => true ), ); } protected function printErrors() { foreach ($this->errors as $error) { ShowError($error); } } public function executeComponent() { parent::executeComponent(); parent::prepareResultAndTemplate(); } public function getEditAction() { return \Bitrix\Sender\Access\ActionDictionary::ACTION_MAILING_EMAIL_EDIT; } public function getViewAction() { return \Bitrix\Sender\Access\ActionDictionary::ACTION_MAILING_VIEW; } }