Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
config.php
1
<?php
2
namespace
Bitrix\MobileApp\Designer
;
3
4
use
Bitrix\Main\Entity
;
5
use Bitrix\Main\Entity\Event;
6
use Bitrix\Main\Entity\FieldError;
7
use Bitrix\Main\Entity\Result;
8
use Bitrix\Main\Entity\ScalarField;
9
use
Bitrix\Main\Localization\Loc
;
10
use
Bitrix\Main
;
11
12
Loc::loadMessages
(__FILE__);
13
41
class
ConfigTable
extends
Entity\DataManager
42
{
43
public
static
function
getFilePath
()
44
{
45
return
__FILE__;
46
}
47
48
public
static
function
getTableName
()
49
{
50
return
'b_mobileapp_config'
;
51
}
52
53
public
static
function
getMap
()
54
{
55
return
array(
56
new
Entity
\
StringField
(
'APP_CODE'
,array(
57
'primary'
=>
true
,
58
'validation'
=> array(__CLASS__,
'validateAppCode'
),
59
'title'
=>
Loc::getMessage
(
'CONFIG_ENTITY_APP_CODE_FIELD'
),
60
)),
61
new
Entity
\
StringField
(
'PLATFORM'
,array(
62
'primary'
=>
true
,
63
'validation'
=> array(__CLASS__,
'validatePlatform'
),
64
'title'
=>
Loc::getMessage
(
'CONFIG_ENTITY_PLATFORM_FIELD'
),
65
)),
66
new
Entity
\
TextField
(
'PARAMS'
, array(
67
'serialized'
=>
true
,
68
'title'
=>
Loc::getMessage
(
'CONFIG_ENTITY_PARAMS_FIELD'
),
69
)),
70
71
new
Entity
\
DatetimeField
(
'DATE_CREATE'
,array(
72
'default_value'
=>
new
\
Bitrix
\Main\
Type
\
DateTime
,
73
'title'
=>
Loc::getMessage
(
'CONFIG_ENTITY_DATE_CREATE_FIELD'
),
74
)),
75
new
Entity
\ReferenceField(
76
'APP'
,
77
'Bitrix\MobileApp\AppTable'
,
78
array(
'=this.APP_CODE'
=>
'ref.CODE'
)
79
)
80
);
81
}
82
83
public
static
function
validateAppCode
()
84
{
85
return
array(
86
new
Entity
\Validator\Length(
null
, 255),
87
);
88
}
89
90
91
public
static
function
validatePlatform
()
92
{
93
return
array(
94
new
Entity
\Validator\Length(
null
, 255),
95
);
96
}
97
98
99
public
static
function
getSupportedPlatforms
()
100
{
101
$platforms =
AppTable::getSupportedPlatforms
();
102
$platforms[] =
"global"
;
103
return
$platforms;
104
}
105
106
public
static
function
checkFields
(
Result
$result, $primary, array $data)
107
{
108
parent::checkFields($result, $primary, $data);
109
$availablePlatforms =
self::getSupportedPlatforms
();
110
111
if
( $result instanceof
Entity
\
AddResult
)
112
{
113
$entity = self::getEntity();
114
if
(!$data[
"APP_CODE"
])
115
{
116
$result->
addError
(
new
Entity
\
FieldError
($entity->getField(
"APP_CODE"
),
"Can not be empty!"
, 1));
117
}
118
else
if
(!$data[
"PLATFORM"
])
119
{
120
$result->
addError
(
new
Entity
\
FieldError
($entity->getField(
"PLATFORM"
),
"Can not be empty!"
, 1));
121
}
122
elseif(!in_array($data[
"PLATFORM"
], $availablePlatforms))
123
{
124
$result->
addError
(
new
Entity
\
FieldError
($entity->getField(
"PLATFORM"
),
"The passed value in not available!"
, 1));
125
}
126
127
$selectResult = self::getList(array(
128
"filter"
=>array(
129
"APP_CODE"
=>$data[
"APP_CODE"
],
130
"PLATFORM"
=>$data[
"PLATFORM"
]
131
)
132
));
133
134
if
($selectResult->getSelectedRowsCount() > 0)
135
{
136
$result->
addError
(
new
Entity
\
EntityError
(
"Such configuration is already exists!"
, 1000));
137
}
138
}
139
}
140
141
public
static
function
isExists
($appCode, $platform)
142
{
143
//this is not such heavy operation as it might be expected
144
$config = self::getRowById(Array(
"APP_CODE"
=> $appCode,
"PLATFORM"
=> $platform));
145
return
(is_array($config) && count($config) > 0);
146
}
147
}
148
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\AddResult
Definition
addresult.php:12
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\ORM\EntityError
Definition
entityerror.php:12
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\ORM\Fields\DatetimeField
Definition
datetimefield.php:22
Bitrix\Main\ORM\Fields\FieldError
Definition
fielderror.php:14
Bitrix\Main\ORM\Fields\StringField
Definition
stringfield.php:20
Bitrix\Main\ORM\Fields\TextField
Definition
textfield.php:20
Bitrix\Main\Result\addError
addError(Error $error)
Definition
result.php:50
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\MobileApp\AppTable\getSupportedPlatforms
static getSupportedPlatforms()
Definition
app.php:177
Bitrix\MobileApp\Designer\ConfigTable
Definition
config.php:42
Bitrix\MobileApp\Designer\ConfigTable\getMap
static getMap()
Definition
config.php:53
Bitrix\MobileApp\Designer\ConfigTable\validateAppCode
static validateAppCode()
Definition
config.php:83
Bitrix\MobileApp\Designer\ConfigTable\getFilePath
static getFilePath()
Definition
config.php:43
Bitrix\MobileApp\Designer\ConfigTable\validatePlatform
static validatePlatform()
Definition
config.php:91
Bitrix\MobileApp\Designer\ConfigTable\isExists
static isExists($appCode, $platform)
Definition
config.php:141
Bitrix\MobileApp\Designer\ConfigTable\checkFields
static checkFields(Result $result, $primary, array $data)
Definition
config.php:106
Bitrix\MobileApp\Designer\ConfigTable\getSupportedPlatforms
static getSupportedPlatforms()
Definition
config.php:99
Bitrix\MobileApp\Designer\ConfigTable\getTableName
static getTableName()
Definition
config.php:48
Bitrix\Main\Type
Definition
collection.php:2
Bitrix\Main
Bitrix\MobileApp\Designer
Definition
app.php:2
Bitrix
modules
mobileapp
lib
designer
config.php
Создано системой
1.10.0