/** * Выполнение кастомных операций над объектом в процессе редактирования. * * @param string $action Название операции. * @param int|null $id ID элемента. * * @see AdminEditHelper::fillMenu() * * @api */ protected function customActions($action, $id) { if ($action == 'delete' and !is_null($id)) { $result = $this->deleteElement($id); if (!$result->isSuccess()) { $this->addErrors($result->getErrorMessages()); } $listHelper = static::getHelperClass(AdminListHelper::className()); $redirectUrl = $listHelper::getUrl(array_merge($this->additionalUrlParams, array('restore_query' => 'Y'))); LocalRedirect($redirectUrl); } }
/** * Устанавливает настройки интерфейса для текущего поля * * @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; }
/** * Генерирует HTML для поля в списке * @see AdminListHelper::addRowCell(); * @param \CAdminListRow $row * @param array $data - данные текущей строки */ public function generateRow(&$row, $data) { if ($this->getSettings('MULTIPLE')) { } else { if ($this->getSettings('EDIT_LINK') || $this->getSettings('SECTION_LINK')) { $entityClass = $this->entityName; $pk = $entityClass::getEntity()->getPrimary(); if ($this->getSettings('SECTION_LINK')) { $params = $this->helper->isPopup() ? $_GET : array(); $params['ID'] = $this->data[$pk]; $listHelper = $this->helper->getHelperClass($this->helper->isPopup() ? AdminSectionListHelper::className() : AdminListHelper::className()); $pageUrl = $listHelper::getUrl($params); $value = '<span class="adm-submenu-item-link-icon adm-list-table-icon iblock-section-icon"></span>'; } else { $editHelper = $this->helper->getHelperClass(AdminEditHelper::className()); $pageUrl = $editHelper::getUrl(array('ID' => $this->data[$pk])); } $value .= '<a href="' . $pageUrl . '">' . static::prepareToOutput($this->getValue()) . '</a>'; } else { $value = static::prepareToOutput($this->getValue()); } if ($this->getSettings('EDIT_IN_LIST') and !$this->getSettings('READONLY')) { $row->AddInputField($this->getCode(), array('style' => 'width:90%')); } $row->AddViewField($this->getCode(), $value); } }
/** * Обработчик групповых операций. По-умолчанию прописаны операции активации / деактивации и удаления. * * @param array $IDs * @param string $action * * @api */ protected function groupActions($IDs, $action) { $sectionEditHelperClass = $this->getHelperClass(AdminSectionEditHelper::className()); $listHelperClass = $this->getHelperClass(AdminListHelper::className()); if (!isset($_REQUEST['model'])) { $className = static::getModel(); } else { $className = $_REQUEST['model']; } if ($sectionEditHelperClass && !isset($_REQUEST['model-section'])) { $sectionClassName = $sectionEditHelperClass::getModel(); } else { $sectionClassName = $_REQUEST['model-section']; } if ($action == 'delete') { if ($this->hasDeleteRights()) { $params = $_GET; unset($params['action']); unset($params['action_button']); unset($params['ID']); if ($sectionEditHelperClass) { $sectionField = !isset($_REQUEST['model']) ? static::getSectionField() : $sectionEditHelperClass::getSectionField(); $element = $className::getById($IDs[0])->Fetch(); if ($element[$sectionField]) { $params['ID'] = $element[$sectionField]; } } foreach ($IDs as $id) { $entityManager = new EntityManager($className, array(), $id, $this); $result = $entityManager->delete(); $this->addNotes($entityManager->getNotes()); if (!$result->isSuccess()) { $this->addErrors($result->getErrorMessages()); break; } } LocalRedirect($listHelperClass::getUrl($params)); } else { $this->addErrors(Loc::getMessage('DIGITALWAND_ADMIN_HELPER_LIST_DELETE_FORBIDDEN')); } } if ($action == 'delete-section') { if ($this->hasDeleteRights()) { $section = $sectionClassName::getById($IDs[0])->Fetch(); $sectionField = $sectionEditHelperClass::getSectionField(); $params = $_GET; unset($params['action']); unset($params['action_button']); unset($params['ID']); if ($section[$sectionField]) { $params['ID'] = $section[$sectionField]; } foreach ($IDs as $id) { $sectionClassName::delete($id); } LocalRedirect($listHelperClass::getUrl($params)); } else { $this->addErrors(Loc::getMessage('DIGITALWAND_ADMIN_HELPER_LIST_DELETE_FORBIDDEN')); } } }