/**
  * Производится инициализация переменных, обработка запросов на редактирование
  *
  * @param array $fields
  * @param array $tabs
  *
  * @see AdminBaseHelper::setInterfaceSettings()
  */
 public function __construct(array $fields, array $tabs = array())
 {
     $this->tabs = $tabs;
     if (empty($this->tabs)) {
         $this->tabs = array(array('DIV' => 'DEFAULT_TAB', 'TAB' => Loc::getMessage('DEFAULT_TAB'), "ICON" => "main_user_edit", 'TITLE' => Loc::getMessage('DEFAULT_TAB'), 'VISIBLE' => true));
     } else {
         if (!is_array(reset($this->tabs))) {
             $converted = array();
             foreach ($this->tabs as $tabCode => $tabName) {
                 $tabVisible = true;
                 if (is_array($tabName)) {
                     $tabVisible = isset($tabName['VISIBLE']) ? $tabName['VISIBLE'] : $tabVisible;
                     $tabName = $tabName['TITLE'];
                 }
                 $converted[] = array('DIV' => $tabCode, 'TAB' => $tabName, 'ICON' => '', 'TITLE' => $tabName, 'VISIBLE' => $tabVisible);
             }
             $this->tabs = $converted;
         }
     }
     parent::__construct($fields, $tabs);
     $this->tabControl = new \CAdminForm(str_replace("\\", "", get_called_class()), $this->tabs);
     if (isset($_REQUEST['apply']) or isset($_REQUEST['save'])) {
         $this->data = $_REQUEST['FIELDS'];
         if (isset($_REQUEST[$this->pk()])) {
             //Первичный ключ проставляем отдельно, чтобы не вынуждать всегда указывать его в настройках интерфейса.
             $this->data[$this->pk()] = $_REQUEST[$this->pk()];
         }
         foreach ($fields as $code => $settings) {
             if (isset($_REQUEST[$code])) {
                 $this->data[$code] = $_REQUEST[$code];
             }
         }
         if ($this->editAction()) {
             if (isset($_REQUEST['apply'])) {
                 $id = $this->data[$this->pk()];
                 $url = $this->app->GetCurPageParam($this->pk() . '=' . $id);
             } else {
                 if (isset($_REQUEST['save'])) {
                     $url = $this->getListPageURL(array_merge($this->additionalUrlParams, array('restore_query' => 'Y')));
                 }
             }
         } else {
             if (isset($this->data[$this->pk()])) {
                 $id = $this->data[$this->pk()];
                 $url = $this->app->GetCurPageParam($this->pk() . '=' . $id);
             } else {
                 unset($this->data);
                 $this->data = $_REQUEST['FIELDS'];
                 //Заполняем, чтобы в случае ошибки сохранения поля не были пустыми
             }
         }
         if (isset($url)) {
             $this->setAppException($this->app->GetException());
             LocalRedirect($url);
         }
     } else {
         $helperFields = $this->getFields();
         $select = array_keys($helperFields);
         foreach ($select as $key => $field) {
             if (isset($helperFields[$field]['VIRTUAL']) and $helperFields[$field]['VIRTUAL'] == true and (!isset($helperFields[$field]['FORCE_SELECT']) or $helperFields[$field]['FORCE_SELECT'] = false)) {
                 unset($select[$key]);
             }
         }
         $this->data = $this->loadElement($select);
         if (!$this->data) {
             //TODO: элемент не найден
         }
         if (isset($_REQUEST['action'])) {
             $this->customActions($_REQUEST['action'], $this->data[$this->pk()]);
         }
     }
     $this->setElementTitle();
 }
예제 #2
0
/*Очищаем переменные сессии, чтобы сортировка восстанавливалась с учетом $table_id */
/** @global CMain $APPLICATION */
global $APPLICATION;
$uniq = md5($APPLICATION->GetCurPage());
if (isset($_SESSION["SESS_SORT_BY"][$uniq])) {
    unset($_SESSION["SESS_SORT_BY"][$uniq]);
}
if (isset($_SESSION["SESS_SORT_ORDER"][$uniq])) {
    unset($_SESSION["SESS_SORT_ORDER"][$uniq]);
}
$module = getRequestParams('module');
$view = getRequestParams('view');
if (!$module or !$view or !Loader::IncludeModule($module)) {
    include $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/admin/404.php';
}
list($helper, $interface) = AdminBaseHelper::getGlobalInterfaceSettings($module, $view);
if (!$helper or !$interface) {
    include $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/admin/404.php';
}
$isPopup = isset($_REQUEST['popup']) and $_REQUEST['popup'] == 'Y';
$fields = isset($interface['FIELDS']) ? $interface['FIELDS'] : array();
$tabs = isset($interface['TABS']) ? $interface['TABS'] : array();
$helperType = false;
if (is_subclass_of($helper, 'DigitalWand\\AdminHelper\\Helper\\AdminEditHelper')) {
    $helperType = 'edit';
    /** @var AdminEditHelper $adminHelper */
    $adminHelper = new $helper($fields, $tabs);
} else {
    if (is_subclass_of($helper, 'DigitalWand\\AdminHelper\\Helper\\AdminListHelper')) {
        $helperType = 'list';
        /** @var AdminListHelper $adminHelper */
 /**
  * Получаем ID HL-инфоблока по имени его класса
  * @return mixed
  */
 protected function getHLId()
 {
     static $id = false;
     if ($id === false) {
         $model = $this->getSettings('MODEL');
         $info = AdminBaseHelper::getHLEntityInfo($model);
         if ($info and isset($info['ID'])) {
             $id = $info['ID'];
         }
     }
     return $id;
 }
 /**
  * Устанавливает настройки интерфейса для текущего поля
  *
  * @see AdminBaseHelper::getInterfaceSettings();
  * @see AdminBaseHelper::setFields();
  *
  * @param string $code
  *
  * @return bool
  */
 public function loadSettings($code = null)
 {
     $interface = $this->helper->getInterfaceSettings();
     $code = is_null($code) ? $this->code : $code;
     if (!isset($interface['FIELDS'][$code])) {
         return false;
     }
     unset($interface['FIELDS'][$code]['WIDGET']);
     $this->settings = array_merge($this->settings, $interface['FIELDS'][$code]);
     $this->setDefaultValue();
     return true;
 }
 /**
  * Производится инициализация переменных, обработка запросов на редактирование
  *
  * @param array $fields
  * @param bool $isPopup
  * @throws \Bitrix\Main\ArgumentException
  */
 public function __construct(array $fields, $isPopup = false)
 {
     $this->isPopup = $isPopup;
     if ($this->isPopup) {
         $this->fieldPopupResultName = preg_replace("/[^a-zA-Z0-9_:\\[\\]]/", "", $_REQUEST['n']);
         $this->fieldPopupResultIndex = preg_replace("/[^a-zA-Z0-9_:]/", "", $_REQUEST['k']);
         $this->fieldPopupResultElTitle = $_REQUEST['eltitle'];
     }
     parent::__construct($fields);
     $this->restoreLastGetQuery();
     $this->prepareAdminVariables();
     $className = static::getModel();
     $oSort = new \CAdminSorting($this->getListTableID(), static::pk(), "desc");
     $this->list = new \CAdminList($this->getListTableID(), $oSort);
     $this->list->InitFilter($this->arFilterFields);
     if ($this->list->EditAction() and $this->hasWriteRights()) {
         global $FIELDS;
         foreach ($FIELDS as $id => $fields) {
             if (!$this->list->IsUpdated($id)) {
                 continue;
             }
             $this->editAction($id, $fields);
         }
     }
     if ($IDs = $this->list->GroupAction() and $this->hasWriteRights()) {
         if ($_REQUEST['action_target'] == 'selected') {
             $this->setContext(AdminListHelper::OP_GROUP_ACTION);
             $IDs = array();
             //Текущий фильтр должен быть модифицирован виждтами
             //для соответствия результатов фильтрации тому, что видит пользователь в интерфейсе.
             $raw = array('SELECT' => $this->pk(), 'FILTER' => $this->arFilter, 'SORT' => array());
             foreach ($this->fields as $code => $settings) {
                 $widget = $this->createWidgetForField($code);
                 $widget->changeGetListOptions($this->arFilter, $raw['SELECT'], $raw['SORT'], $raw);
             }
             $res = $className::getList(array('filter' => $this->arFilter, 'select' => array($this->pk())));
             while ($el = $res->Fetch()) {
                 $IDs[] = $el[$this->pk()];
             }
         }
         $filteredIDs = array();
         foreach ($IDs as $id) {
             if (strlen($id) <= 0) {
                 continue;
             }
             $filteredIDs[] = IntVal($id);
         }
         $this->groupActions($IDs, $_REQUEST['action']);
     }
     if (isset($_REQUEST['action']) || isset($_REQUEST['action_button']) && count($this->getErrors()) == 0) {
         $listHelperClass = $this->getHelperClass(AdminListHelper::className());
         $className = $listHelperClass::getModel();
         $id = isset($_GET['ID']) ? $_GET['ID'] : null;
         $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : $_REQUEST['action_button'];
         if ($action != 'edit' && $_REQUEST['cancel'] != 'Y') {
             $params = $_GET;
             unset($params['action']);
             unset($params['action_button']);
             $this->customActions($action, $id);
             $sectionEditHelperClass = $this->getHelperClass(AdminSectionEditHelper::className());
             if ($sectionEditHelperClass) {
                 $element = $className::getById($id)->Fetch();
                 $sectionField = $listHelperClass::getSectionField();
                 if ($element[$sectionField]) {
                     $params['ID'] = $element[$sectionField];
                 }
             }
             LocalRedirect($listHelperClass::getUrl($params));
         }
     }
     if ($this->isPopup()) {
         $this->genPopupActionJS();
     }
     // Получаем параметры навигации
     $navUniqSettings = array('sNavID' => $this->getListTableID());
     $this->navParams = array('nPageSize' => \CAdminResult::GetNavSize($navUniqSettings), 'navParams' => \CAdminResult::GetNavParams($navUniqSettings));
 }
 /**
  * Производится инициализация переменных, обработка запросов на редактирование
  *
  * @param array $fields
  * @param bool $isPopup
  * @throws \Bitrix\Main\ArgumentException
  */
 public function __construct($fields, $isPopup = false)
 {
     $this->isPopup = $isPopup;
     parent::__construct($fields);
     $this->restoreLastGetQuery();
     $this->prepareAdminVariables();
     $this->addContextMenu();
     $this->addGroupActions();
     if (isset($_REQUEST['action'])) {
         $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : null;
         $this->customActions($_REQUEST['action'], $id);
     }
     $className = static::getModel();
     $oSort = new \CAdminSorting($this->getListTableID(), static::pk(), "desc");
     $this->list = new \CAdminList($this->getListTableID(), $oSort);
     $this->list->InitFilter($this->arFilterFields);
     if ($this->list->EditAction() and $this->hasWriteRights()) {
         global $FIELDS;
         foreach ($FIELDS as $id => $fields) {
             if (!$this->list->IsUpdated($id)) {
                 continue;
             }
             $id = intval($id);
             $this->editAction($id, $fields);
         }
     }
     if ($IDs = $this->list->GroupAction() and $this->hasWriteRights()) {
         if ($_REQUEST['action_target'] == 'selected') {
             $this->setContext(AdminListHelper::OP_GROUP_ACTION);
             $IDs = array();
             //Текущий фильтр должен быть модифицирован виждтами
             //для соответствия результатов фильтрации тому, что видит пользователь в интерфейсе.
             $raw = array('SELECT' => $this->pk(), 'FILTER' => $this->arFilter, 'SORT' => array());
             foreach ($this->fields as $code => $settings) {
                 $widget = $this->createWidgetForField($code);
                 $widget->changeGetListOptions($this->arFilter, $raw['SELECT'], $raw['SORT'], $raw);
             }
             $res = $className::getList(array('filter' => $this->arFilter, 'select' => array($this->pk())));
             while ($el = $res->Fetch()) {
                 $IDs[] = $el[$this->pk()];
             }
         }
         $filteredIDs = array();
         foreach ($IDs as $id) {
             if (strlen($id) <= 0) {
                 continue;
             }
             $filteredIDs[] = IntVal($id);
         }
         $this->groupActions($IDs, $_REQUEST['action']);
     }
     if ($this->isPopup()) {
         $this->genPopupActionJS();
     }
 }