|
| 1 | +<?php |
| 2 | +namespace Learning; |
| 3 | +use Bitrix\Main\Entity; |
| 4 | + |
| 5 | +class QuestionTable extends Entity\DataManager |
| 6 | +{ |
| 7 | + /** |
| 8 | + * Returns DB table name for entity. |
| 9 | + * |
| 10 | + * @return string |
| 11 | + */ |
| 12 | + public static function getTableName() |
| 13 | + { |
| 14 | + return 'b_learn_question'; |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * Returns User Fields ID. |
| 19 | + * |
| 20 | + * @return array |
| 21 | + */ |
| 22 | + public static function getUfId() |
| 23 | + { |
| 24 | + return 'LEARNING_QUESTIONS'; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Returns entity map definition. |
| 29 | + * |
| 30 | + * @return array |
| 31 | + * @throws \Bitrix\Main\ArgumentException |
| 32 | + * @throws \Bitrix\Main\ObjectException |
| 33 | + */ |
| 34 | + public static function getMap() |
| 35 | + { |
| 36 | + return array( |
| 37 | + new Entity\IntegerField('ID', array( |
| 38 | + 'primary' => true, |
| 39 | + 'autocomplete' => true |
| 40 | + )), |
| 41 | + new Entity\BooleanField('ACTIVE', array( |
| 42 | + 'values' => array('N', 'Y') |
| 43 | + )), |
| 44 | + new Entity\DatetimeField('TIMESTAMP_X', array( |
| 45 | + 'default_value' => new \Bitrix\Main\Type\DateTime(), |
| 46 | + 'title' => 'timestamp', |
| 47 | + )), |
| 48 | + new Entity\IntegerField('LESSON_ID'), |
| 49 | + new Entity\ReferenceField( |
| 50 | + 'LESSON', |
| 51 | + '\Learning\LessonTable', |
| 52 | + array('=this.LESSON_ID' => 'ref.ID'), |
| 53 | + array('join_type' => 'LEFT') |
| 54 | + ), |
| 55 | + new Entity\StringField('QUESTION_TYPE', array( |
| 56 | + 'required' => true, |
| 57 | + 'validation' => array(__CLASS__, 'validateQuestionType'), |
| 58 | + )), |
| 59 | + new Entity\StringField('NAME', array( |
| 60 | + 'required' => true, |
| 61 | + 'validation' => array(__CLASS__, 'validateName'), |
| 62 | + )), |
| 63 | + new Entity\IntegerField('SORT'), |
| 64 | + new Entity\IntegerField('DESCRIPTION'), |
| 65 | + new Entity\TextField('DESCRIPTION_TYPE'), |
| 66 | + new Entity\BooleanField('SELF', array( |
| 67 | + 'values' => array('text', 'html') |
| 68 | + )), |
| 69 | + new Entity\TextField('COMMENT_TEXT'), |
| 70 | + new Entity\IntegerField('FILE_ID'), |
| 71 | + new Entity\BooleanField('SELF', array( |
| 72 | + 'values' => array('N', 'Y') |
| 73 | + )), |
| 74 | + new Entity\IntegerField('POINT'), |
| 75 | + new Entity\StringField('DIRECTION', array( |
| 76 | + 'required' => true, |
| 77 | + 'validation' => array(__CLASS__, 'validateDirection'), |
| 78 | + )), |
| 79 | + new Entity\BooleanField('CORRECT_REQUIRED', array( |
| 80 | + 'values' => array('N', 'Y') |
| 81 | + )), |
| 82 | + new Entity\BooleanField('EMAIL_ANSWER', array( |
| 83 | + 'values' => array('N', 'Y') |
| 84 | + )), |
| 85 | + new Entity\TextField('INCORRECT_MESSAGE'), |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Returns validators for QUESTION_TYPE field. |
| 91 | + * |
| 92 | + * @return array |
| 93 | + */ |
| 94 | + public static function validateQuestionType() |
| 95 | + { |
| 96 | + return array( |
| 97 | + new Main\Entity\Validator\Length(null, 1), |
| 98 | + ); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Returns validators for NAME field. |
| 103 | + * |
| 104 | + * @return array |
| 105 | + */ |
| 106 | + public static function validateName() |
| 107 | + { |
| 108 | + return array( |
| 109 | + new Main\Entity\Validator\Length(null, 255), |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Returns validators for DIRECTION field. |
| 115 | + * |
| 116 | + * @return array |
| 117 | + */ |
| 118 | + public static function validateDirection() |
| 119 | + { |
| 120 | + return array( |
| 121 | + new Main\Entity\Validator\Length(null, 1), |
| 122 | + ); |
| 123 | + } |
| 124 | +} |
0 commit comments