Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
app.php
1<?php
2
4
6use Bitrix\Main\Entity\Event;
7use Bitrix\Main\Entity\FieldError;
8use Bitrix\Main\Entity\Result;
10use Bitrix\Main;
11
12Loc::loadMessages(__FILE__);
13
44class AppTable extends Entity\DataManager
45{
46 public static function getFilePath()
47 {
48 return __FILE__;
49 }
50
51 public static function getTableName()
52 {
53 return 'b_mobileapp_app';
54 }
55
56
57 public static function getMap()
58 {
59 return array(
60 new Entity\StringField('CODE', array(
61 'primary' => true,
62 'validation' => array(__CLASS__, 'validateCode'),
63 'title' => Loc::getMessage('APP_ENTITY_CODE_FIELD'),
64 )),
65 new Entity\StringField('SHORT_NAME', array(
66 'validation' => array(__CLASS__, 'validateShortName'),
67 'title' => Loc::getMessage('APP_ENTITY_SHORT_NAME_FIELD'),
68 'default_value' => "AppName"
69 )),
70 new Entity\StringField('NAME', array(
71 'validation' => array(__CLASS__, 'validateName'),
72 "require" => true,
73 'title' => Loc::getMessage('APP_ENTITY_NAME_FIELD'),
74 )),
75 new Entity\TextField('DESCRIPTION', array(
76 'default_value' => "App description placeholder",
77 'title' => Loc::getMessage('APP_ENTITY_DESCRIPTION_FIELD'),
78 )),
79 new Entity\TextField('FILES', array(
80 'serialized' => true,
81 'default_value' => array(),
82 'title' => Loc::getMessage('APP_ENTITY_FILES_FIELD'),
83 )),
84 new Entity\TextField('LAUNCH_ICONS', array(
85 'serialized' => true,
86 'default_value' => array(),
87 'title' => Loc::getMessage('APP_ENTITY_LAUNCH_ICONS_FIELD'),
88 )),
89 new Entity\TextField('LAUNCH_SCREENS', array(
90 'serialized' => true,
91 'default_value' => array(),
92 'title' => Loc::getMessage('APP_ENTITY_LAUNCH_SCREENS_FIELD'),
93 )),
94 new Entity\StringField('FOLDER', array(
95 'validation' => array(__CLASS__, 'validateFolder'),
96 'require' => true,
97 'title' => Loc::getMessage('APP_ENTITY_FOLDER_FIELD'),
98 )),
99 new Entity\DatetimeField('DATE_CREATE', array(
100 'default_value' => new \Bitrix\Main\Type\Date,
101 'title' => Loc::getMessage('APP_ENTITY_DATE_CREATE_FIELD'),
102 )),
103 new Entity\ReferenceField(
104 'CONFIG',
105 'Bitrix\MobileApp\Designer\ConfigTable',
106 array('=this.CODE' => 'ref.APP_CODE')
107 )
108 );
109 }
110
111 public static function validateCode()
112 {
113 return array(
114 new Entity\Validator\Unique(null, 255),
115 );
116 }
117
118 public static function validateShortName()
119 {
120 return array(
121 new Entity\Validator\Length(null, 20),
122 );
123 }
124
125 public static function validateName()
126 {
127 return array(
128 new Entity\Validator\Length(null, 255),
129 );
130 }
131
132 public static function validateFolder()
133 {
134 return array(
135 new Entity\Validator\Length(null, 255),
136 );
137 }
138
139 public static function isAppExists($code)
140 {
141 $result = self::getById($code);
142
143 return ($result->getSelectedRowsCount() ? true : false);
144 }
145
146 public static function onAfterDelete(Event $event)
147 {
148 $parameters = $event->getParameter("id");
149 $code = $parameters["CODE"];
150 Designer\ConfigTable::delete(array("APP_CODE" => $code));
151 parent::onAfterDelete($event);
152 }
153
154 public static function checkFields(Result $result, $primary, array $data)
155 {
156 parent::checkFields($result, $primary, $data);
157
158 if ($result instanceof Entity\AddResult)
159 {
160 $entity = self::getEntity();
161 if (!$data["CODE"])
162 {
163 $result->addError(new Entity\FieldError($entity->getField("CODE"), "Can not be empty!", FieldError::EMPTY_REQUIRED));
164 }
165 elseif (!$data["FOLDER"])
166 {
167 $result->addError(new Entity\FieldError($entity->getField("FOLDER"), "Can not be empty!", FieldError::EMPTY_REQUIRED));
168 }
169 elseif (!$data["NAME"])
170 {
171 $result->addError(new Entity\FieldError($entity->getField("NAME"), "Can not be empty!", FieldError::EMPTY_REQUIRED));
172 }
173
174 }
175 }
176
177 public static function getSupportedPlatforms()
178 {
179 return array(
180 "android",
181 "ios",
182 );
183 }
184
185
186}
getParameter($key)
Definition event.php:80
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
addError(Error $error)
Definition result.php:50
static validateShortName()
Definition app.php:118
static isAppExists($code)
Definition app.php:139
static checkFields(Result $result, $primary, array $data)
Definition app.php:154
static onAfterDelete(Event $event)
Definition app.php:146
static validateFolder()
Definition app.php:132
static getSupportedPlatforms()
Definition app.php:177
static getTableName()
Definition app.php:51