Skip to content

Commit

Permalink
Merge pull request #9 from niksamokhvalov/master
Browse files Browse the repository at this point in the history
Admin helper 2.0.0
  • Loading branch information
niksamokhvalov committed Dec 14, 2015
2 parents dcfdce2 + 531a6f7 commit 2bedb43
Show file tree
Hide file tree
Showing 39 changed files with 6,605 additions and 2,690 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright © 2015 DigitalWand (http://digitalwand.ru/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
215 changes: 136 additions & 79 deletions admin/route.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,136 @@
<?php
use Bitrix\Main\Loader;
use DigitalWand\AdminHelper\Helper\AdminBaseHelper;
use DigitalWand\AdminHelper\Helper\AdminListHelper;
use DigitalWand\AdminHelper\Helper\AdminEditHelper;

require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php");

function getRequestParams($param)
{
if (!isset($_REQUEST[$param])) {
return false;
} else {
return htmlspecialcharsbx($_REQUEST[$param]);
}
}

/*Очищаем переменные сессии, чтобы сортировка восстанавливалась с учетом $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 */
$adminHelper = new $helper($fields, $isPopup);
$adminHelper->getData(array($by => $order));

} else {
include $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/admin/404.php';
exit();
}

if ($isPopup) {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_popup_admin.php");
} else {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php");
}

if ($helperType == 'list') {
$adminHelper->createFilterForm();
}
$adminHelper->show();

if ($isPopup) {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_popup_admin.php");
} else {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php");
}

<?php

use Bitrix\Main\Loader;
use DigitalWand\AdminHelper\Helper\AdminBaseHelper;
use DigitalWand\AdminHelper\Helper\AdminListHelper;
use DigitalWand\AdminHelper\Helper\AdminEditHelper;
use DigitalWand\AdminHelper\Helper\AdminInterface;

require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_admin_before.php');

Loader::includeModule('digitalwand.admin_helper');

function getRequestParams($param)
{
if (!isset($_REQUEST[$param])) {
return false;
}
else {
return htmlspecialcharsbx($_REQUEST[$param]);
}
}

/**
* Очищаем переменные сессии, чтобы сортировка восстанавливалась с учетом $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';
}

// Собираем имя класса админского интерфейса
$moduleNameParts = explode('.', $module);
$entityNameParts = explode('_', $entity);
$interfaceNameParts = array_merge($moduleNameParts, $entityNameParts);
$interfaceNameClass = null;
$viewParts = explode('_', $view);

$count = count($viewParts);
for ($i = 0; $i < $count; $i++) {
$interfaceName = implode('', array_map('ucfirst', $viewParts));
$parts = $interfaceNameParts;
$parts[] = $interfaceName . 'AdminInterface';
$class = array_map('ucfirst', $parts);
$interfaceNameClass = implode('\\', $class);

if (class_exists($interfaceNameClass)) {
break;
}
else {
$className = array_pop($parts);
$parts[] = 'AdminInterface';
$parts[] = $className;
$class = array_map('ucfirst', $parts);
$interfaceNameClass = implode('\\', $class);
if (class_exists($interfaceNameClass)) {
break;
}
}
array_pop($viewParts);
}

/**
* @var AdminInterface $interfaceNameClass
*/

if ($interfaceNameClass && class_exists($interfaceNameClass)) {
$interfaceNameClass::register();
}

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);
}
elseif (is_subclass_of($helper, 'DigitalWand\AdminHelper\Helper\AdminListHelper')) {
$helperType = 'list';
/**
* @var AdminListHelper $adminHelper
*/
$adminHelper = new $helper($fields, $isPopup);
$adminHelper->buildList(array($by => $order));
}
elseif (is_subclass_of($helper, 'DigitalWand\AdminHelper\Helper\AdminBaseHelper')) {
$adminHelper = new $helper($fields, $tabs);
}
else {
include $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/admin/404.php';
exit();
}

if ($isPopup) {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_popup_admin.php");
}
else {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php");
}

if ($helperType == 'list') {
$adminHelper->createFilterForm();
}

$adminHelper->show();

if ($isPopup) {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_popup_admin.php");
}
else {
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php");
}
17 changes: 13 additions & 4 deletions include.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@
array(
'DigitalWand\AdminHelper\EventHandlers' => 'lib/EventHandlers.php',

'DigitalWand\AdminHelper\Helper\Exception' => 'lib/helper/Exception.php',

'DigitalWand\AdminHelper\Helper\AdminInterface' => 'lib/helper/AdminInterface.php',
'DigitalWand\AdminHelper\Helper\AdminBaseHelper' => 'lib/helper/AdminBaseHelper.php',
'DigitalWand\AdminHelper\Helper\AdminListHelper' => 'lib/helper/AdminListHelper.php',
'DigitalWand\AdminHelper\Helper\AdminSectionListHelper' => 'lib/helper/AdminSectionListHelper.php',
'DigitalWand\AdminHelper\Helper\AdminEditHelper' => 'lib/helper/AdminEditHelper.php',
'DigitalWand\AdminHelper\Helper\Exception' => 'lib/helper/Exception.php',
'DigitalWand\AdminHelper\Helper\AdminSectionEditHelper' => 'lib/helper/AdminSectionEditHelper.php',

'DigitalWand\AdminHelper\EntityManager' => 'lib/EntityManager.php',

'DigitalWand\AdminHelper\Widget\HelperWidget' => 'lib/widget/HelperWidget.php',
'DigitalWand\AdminHelper\Widget\CheckboxWidget' => 'lib/widget/CheckboxWidget.php',
'DigitalWand\AdminHelper\Widget\ComboBoxWidget' => 'lib/widget/ComboBoxWidget.php',
'DigitalWand\AdminHelper\Widget\StringWidget' => 'lib/widget/StringWidget.php',
'DigitalWand\AdminHelper\Widget\NumberWidget' => 'lib/widget/NumberWidget.php',
'DigitalWand\AdminHelper\Widget\ImageWidget' => 'lib/widget/ImageWidget.php',
'DigitalWand\AdminHelper\Widget\FileWidget' => 'lib/widget/FileWidget.php',
'DigitalWand\AdminHelper\Widget\TextAreaWidget' => 'lib/widget/TextAreaWidget.php',
'DigitalWand\AdminHelper\Widget\VisualEditorWidget' => 'lib/widget/VisualEditorWidget.php',
'DigitalWand\AdminHelper\Widget\DateTimeWidget' => 'lib/widget/DateTimeWidget.php',
'DigitalWand\AdminHelper\Widget\HLIBlockFieldWidget' => 'lib/widget/HLIBlockFieldWidget.php',
'DigitalWand\AdminHelper\Widget\DateTimeWidget' => 'lib/widget/DateTimeWidget.php',
'DigitalWand\AdminHelper\Widget\IblockElementWidget' => 'lib/widget/IblockElementWidget.php',
'DigitalWand\AdminHelper\Widget\UrlWidget' => 'lib/widget/UrlWidget.php',
'DigitalWand\AdminHelper\Widget\VisualEditorWidget' => 'lib/widget/VisualEditorWidget.php',
'DigitalWand\AdminHelper\Widget\UserWidget' => 'lib/widget/UserWidget.php',
'DigitalWand\AdminHelper\Widget\OrmElementWidget' => 'lib/widget/OrmElementWidget.php',
)
);
2 changes: 1 addition & 1 deletion install/admin/admin_helper_route.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?
require_once($_SERVER["DOCUMENT_ROOT"]."/local/modules/digitalwand.admin_helper/admin/route.php");
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/digitalwand.admin_helper/admin/route.php");
?>
3 changes: 2 additions & 1 deletion lang/ru/lib/helper/AdminBaseHelper.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php

$MESS['DIGITALWAND_ADMIN_HELPER_GETMODEL_EXCEPTION'] = "Попыка обращение к несуществующему HL-инфоблоку #CLASS#";
$MESS['DIGITALWAND_ADMIN_HELPER_GETMODEL_EXCEPTION'] = 'Попыка обращение к несуществующему HL-инфоблоку #CLASS#';
$MESS['DIGITALWAND_ADMIN_HELPER_ACCESS_FORBIDDEN'] = 'Доступ запрещен';
8 changes: 7 additions & 1 deletion lang/ru/lib/helper/AdminEditHelper.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php
$MESS['DEFAULT_TAB'] = 'Элемент';
$MESS['RETURN_TO_LIST'] = 'Список';
$MESS['DIGITALWAND_ADMIN_HELPER_RETURN_TO_LIST'] = 'Список';
$MESS['DELETE'] = 'Удалить';
$MESS['VALIDATION_ERROR'] = "Не заполнены обязательные поля:\n#FIELD_LIST#";
$MESS['VALIDATION_ERROR_FIELDS'] = "Не заполнены обязательные поля:";
$MESS['DIGITALWAND_ADMIN_HELPER_NEW_ELEMENT'] = "Новый элемент";
$MESS['DIGITALWAND_ADMIN_HELPER_EDIT_TITLE'] = "Элемент #ID#";
$MESS['DIGITALWAND_ADMIN_HELPER_EDIT_DELETE_CONFIRM'] = "Удалить запись?";
$MESS['DIGITALWAND_ADMIN_HELPER_ACTIONS'] = "Действия";
$MESS['DIGITALWAND_ADMIN_HELPER_ADD_ELEMENT'] = "Добавить элемент";
$MESS['DIGITALWAND_ADMIN_HELPER_DELETE_ELEMENT'] = "Удалить элемент";
$MESS['DIGITALWAND_ADMIN_HELPER_EDIT_DELETE_FORBIDDEN'] = 'Не хватает прав доступа для удаления элемента';
$MESS['DIGITALWAND_ADMIN_HELPER_EDIT_WRITE_FORBIDDEN'] = 'Не хватает прав доступа для изменения элемента';
4 changes: 3 additions & 1 deletion lang/ru/lib/helper/AdminListHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
$MESS['DIGITALWAND_ADMIN_HELPER_LIST_CREATE_NEW_SECTION'] = 'Создать раздел';
$MESS['DIGITALWAND_ADMIN_HELPER_LIST_SECTION_UP'] = 'На раздел выше';
$MESS['DIGITALWAND_ADMIN_HELPER_LIST_SECTION_DELETE'] = 'Удалить раздел';
$MESS['DIGITALWAND_ADMIN_HELPER_LIST_SELECT'] = 'Выбрать';
$MESS['DIGITALWAND_ADMIN_HELPER_LIST_SELECT'] = 'Выбрать';
$MESS['DIGITALWAND_ADMIN_HELPER_LIST_DELETE_FORBIDDEN'] = 'Не хватает прав доступа для удаления элемента';
$MESS['DIGITALWAND_ADMIN_HELPER_LIST_WRITE_FORBIDDEN'] = 'Не хватает прав доступа для изменения элемента';
7 changes: 4 additions & 3 deletions lang/ru/lib/widget/CheckboxWidget.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?
$MESS['CHECKBOX_YES'] = 'Да';
$MESS['CHECKBOX_NO'] = 'Нет';
<?php

$MESS['DIGITALWAND_AH_CHECKBOX_YES'] = 'Да';
$MESS['DIGITALWAND_AH_CHECKBOX_NO'] = 'Нет';
2 changes: 2 additions & 0 deletions lang/ru/lib/widget/ComboBoxWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS['COMBO_BOX_LIST_EMPTY'] = 'Не выбрано';
3 changes: 3 additions & 0 deletions lang/ru/lib/widget/FileWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$MESS['DIGITALWAND_AH_FAIL_ADD_FILE'] = 'Не удалось добавить файл #FILE_NAME#';
6 changes: 4 additions & 2 deletions lang/ru/lib/widget/HelperWidget.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php
$MESS['REQUIRED_FIELD_ERROR'] = 'Обязательное поле "#FIELD#" не заполнено';
$MESS['DUPLICATE_FIELD_ERROR'] = 'Значение поля "#FIELD#" не является уникальным';

$MESS['DIGITALWAND_AH_REQUIRED_FIELD_ERROR'] = 'Обязательное поле "#FIELD#" не заполнено';
$MESS['DIGITALWAND_AH_DUPLICATE_FIELD_ERROR'] = 'Значение поля "#FIELD#" не является уникальным';
$MESS['DIGITALWAND_AH_MULTI_NOT_SUPPORT'] = 'Поле не поддерживает множественный режим';
2 changes: 2 additions & 0 deletions lang/ru/lib/widget/IblockElementWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS['IBLOCK_ELEMENT_NOT_FOUND'] = 'Элемент не найден';
3 changes: 3 additions & 0 deletions lang/ru/lib/widget/OrmElementWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$MESS['TITLE_FIELD_NAME'] = 'Элемент не найден';
2 changes: 2 additions & 0 deletions lang/ru/lib/widget/UrlWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS['PROTOCOL_REQUIRED'] = 'Укажите протокол ссылки "#FIELD#" (например http://)';
Loading

0 comments on commit 2bedb43

Please sign in to comment.