Skip to content

Instantly share code, notes, and snippets.

@unnamed777
Last active March 22, 2019 19:48
Show Gist options
  • Save unnamed777/cf6e7619e72bda1d4fc75cc1235a72ed to your computer and use it in GitHub Desktop.
Save unnamed777/cf6e7619e72bda1d4fc75cc1235a72ed to your computer and use it in GitHub Desktop.
AdminHelper example
<?php
namespace project\AdminInterface\SightCategory;
class FormView extends \nav\AdminHelper\AdminEditHelper
{
protected static $model = '\project\Internals\SightCategoryTable';
protected static $entity = 'sightCategory';
protected static $localeEntityName = 'Категория';
public static function getModule()
{
return 'sightCategory';
}
}
<?php
namespace project\AdminInterface\SightCategory;
class ListView extends \nav\AdminHelper\AdminListHelper
{
protected static $model = '\project\Internals\SightCategoryTable';
protected static $entity = 'sightCategory';
protected static $localeListEntityName = 'Категории';
static protected $useSections = true;
public static function getModule()
{
return 'sightCategory';
}
}
<?php
namespace project\AdminInterface\SightCategory;
use Bitrix\Main\Localization\Loc;
use DigitalWand\AdminHelper\Helper\AdminInterface;
use DigitalWand\AdminHelper\Widget;
Loc::loadMessages(__FILE__);
class Model extends AdminInterface
{
protected static $entity = 'sightCategory';
public function fields()
{
return array(
'MAIN' => array(
'NAME' => 'Основное',
'FIELDS' => array(
'ID' => array(
'WIDGET' => new Widget\NumberWidget(),
'READONLY' => true,
'FILTER' => true,
'HIDE_WHEN_CREATE' => true,
'EDIT_LINK' => true
),
'NAME' => array(
'WIDGET' => new Widget\StringWidget(),
'SIZE' => '80',
'FILTER' => '%',
'REQUIRED' => true,
'TITLE' => 'Название'
),
'PARENT_ID' => array(
'WIDGET' => new Widget\OrmElementWidget([
'HELPER' => \project\AdminInterface\SightCategory\SectionListView::class,
'TITLE_FIELD_NAME' => 'NAME',
'TEMPLATE' => 'select'
]),
'SIZE' => '80',
'REQUIRED' => true,
'TITLE' => 'Родитель'
),
'SORT' => array(
'WIDGET' => new Widget\NumberWidget(),
'SIZE' => '10',
'TITLE' => 'Сортировка',
'DEFAULT' => 500,
),
)
)
);
}
/**
* {@inheritdoc}
*/
public function helpers()
{
return [
__NAMESPACE__ . '\ListView',
__NAMESPACE__ . '\FormView'
];
}
public function dependencies()
{
return [
__NAMESPACE__ . '\Section',
];
}
}
<?php
namespace project\AdminInterface\SightCategory;
use Bitrix\Main\Localization\Loc;
use DigitalWand\AdminHelper\Helper\AdminInterface;
use DigitalWand\AdminHelper\Widget;
Loc::loadMessages(__FILE__);
class Section extends AdminInterface
{
protected static $entity = 'sightCategory';
public function fields()
{
return array(
'MAIN' => array(
'NAME' => 'Основное',
'FIELDS' => array(
'ID' => array(
'WIDGET' => new Widget\NumberWidget(),
'READONLY' => true,
'FILTER' => true,
'HIDE_WHEN_CREATE' => true,
'TITLE' => 'ID',
),
'NAME' => array(
'WIDGET' => new Widget\StringWidget(),
'SIZE' => '80',
'FILTER' => '%',
'REQUIRED' => true,
'TITLE' => 'Название',
'SECTION_LINK' => 'Y',
),
'PARENT_ID' => array(
'WIDGET' => new Widget\StringWidget(),
'SIZE' => '80',
'FILTER' => '%',
'REQUIRED' => true,
'TITLE' => 'Родитель'
),
'SORT' => array(
'WIDGET' => new Widget\NumberWidget(),
'SIZE' => '5',
'DEFAULT' => 500,
'TITLE' => 'Сортировка'
),
)
)
);
}
/**
* {@inheritdoc}
*/
public function helpers()
{
return [
__NAMESPACE__ . '\SectionListView',
__NAMESPACE__ . '\SectionFormView',
__NAMESPACE__ . '\ListView',
__NAMESPACE__ . '\FormView'
];
}
public function dependencies()
{
return [
__NAMESPACE__ . '\Model',
];
}
}
<?php
namespace project\AdminInterface\SightCategory;
class SectionFormView extends \nav\AdminHelper\AdminSectionEditHelper
{
protected static $model = '\project\Internals\SightCategorySectionTable';
protected static $entity = 'sightCategory';
protected static $localeEntityName = 'Раздел категории';
static protected $useSections = true;
public static function getModule()
{
return 'sightCategory';
}
}
<?php
namespace project\AdminInterface\SightCategory;
class SectionListView extends \nav\AdminHelper\AdminSectionListHelper
{
protected static $model = '\project\Internals\SightCategorySectionTable';
protected static $entity = 'sightCategory';
protected static $localeListEntityName = 'Разделы';
static protected $useSections = true;
public static function getModule()
{
return 'sightCategory';
}
}
<?php
namespace project\Internals;
use Bitrix\Main\Entity\ReferenceField;
class SightCategorySectionTable extends \Bitrix\Main\Entity\DataManager
{
/**
* @return string
*/
public static function getTableName()
{
return 'tb_sight_category_section';
}
/**
* @return array
*/
public static function getMap()
{
return array(
'ID' => array(
'data_type' => 'integer',
'primary' => true,
'autocomplete' => true,
),
'PARENT_ID' => array(
'data_type' => 'integer',
),
'PARENT' => new ReferenceField(
'PARENT',
'\project\Internals\SightCategorySection',
['=this.PARENT_ID' => 'ref.ID']
),
'NAME' => array(
'data_type' => 'integer',
),
'SORT' => array(
'data_type' => 'integer',
),
);
}
}
<?php
namespace project\Internals;
use Bitrix\Main\Entity\ReferenceField;
class SightCategoryTable extends \Bitrix\Main\Entity\DataManager
{
/**
* @return string
*/
public static function getTableName()
{
return 'tb_sight_category';
}
/**
* @return array
*/
public static function getMap()
{
return array(
'ID' => array(
'data_type' => 'integer',
'primary' => true,
'autocomplete' => true,
),
'PARENT_ID' => array(
'data_type' => 'integer',
),
'PARENT' => new ReferenceField(
'PARENT',
'\project\Internals\SightCategorySection',
['=this.PARENT_ID' => 'ref.ID']
),
'NAME' => array(
'data_type' => 'integer',
),
'SORT' => array(
'data_type' => 'integer',
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment