Advertisement
toorr2p

Untitled

Apr 18th, 2024
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <?php
  2. namespace Itscript\Question;
  3.  
  4. use Bitrix\Main\UserTable;
  5. use Bitrix\Main\Type\Date;
  6. use Bitrix\Main\Type\DateTime;
  7. use Bitrix\Main\Localization\Loc;
  8. use Bitrix\Main\ORM\Fields\StringField;
  9. use Bitrix\Main\ORM\Fields\IntegerField;
  10. use Bitrix\Main\ORM\Fields\BooleanField;
  11. use Bitrix\Main\ORM\Fields\DateField;
  12. use Bitrix\Main\Entity\Validator\Length;
  13. use Bitrix\Main\ORM\Fields\Relations\Reference;
  14. use Bitrix\Main\ORM\Data\DataManager;
  15. use Bitrix\Main\ORM\Query\Join;
  16.  
  17. class QuestionTable extends DataManager
  18. {
  19.     public static function getMap()
  20.     {
  21.         return [
  22.             new IntegerField('ID', [
  23.                 'title' => 'ID',
  24.                 'primary' => true,
  25.                 'autocomplete' => true
  26.             ]),
  27.  
  28.             new IntegerField('USER_ID', [
  29.                 'title' => Loc::getMessage('QUESTION_TABLE_TITLE_USER_ID'),
  30.                 'required' => true,
  31.                 'format' => '/^[0-9]{1,}$/',
  32.             ]),
  33.  
  34.             (new Reference(
  35.                     'USER',
  36.                     UserTable::class,
  37.                     Join::on('this.USER_ID', 'ref.ID')
  38.             ))->configureJoinType('inner'),
  39.  
  40.             new IntegerField('ENTITY_ID', [
  41.                 'title' => Loc::getMessage('QUESTION_TABLE_TITLE_ENTITY_ID'),
  42.                 'required' => true,
  43.                 'format' => '/^[0-9]{1,}$/',
  44.             ]),
  45.  
  46.             new BooleanField('ACTIVE', [
  47.                 'title' => Loc::getMessage('QUESTION_TABLE_TITLE_ACTIVE'),
  48.                 'values' => array('N', 'Y')
  49.             ]),
  50.  
  51.             new StringField('URL', [
  52.                 'title' => Loc::getMessage('QUESTION_TABLE_TITLE_URL'),
  53.                 'required' => true,
  54.                 'size' => 1000,
  55.                 'validation' => function () {
  56.                     return [
  57.                         new Length(null, 1000),
  58.                     ];
  59.                 },
  60.             ]),
  61.  
  62.             new StringField('QUESTION', [
  63.                 'title' => Loc::getMessage('QUESTION_TABLE_TITLE_QUESTION'),
  64.                 'required' => true,
  65.                 'size' => 8000,
  66.                 'validation' => function () {
  67.                     return [
  68.                         new Length(null, 8000),
  69.                     ];
  70.                 },
  71.             ]),
  72.  
  73.             new DateField('PUBLISH_DATE', [
  74.                 'title' => Loc::getMessage('QUESTION_TABLE_TITLE_PUBLISH_DATE'),
  75.                 'default_value' => new DateTime
  76.             ])
  77.         ];
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement