Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
config.php
1<?php
3
5use Bitrix\Main\Entity\Event;
6use Bitrix\Main\Entity\FieldError;
7use Bitrix\Main\Entity\Result;
8use Bitrix\Main\Entity\ScalarField;
10use Bitrix\Main;
11
12Loc::loadMessages(__FILE__);
13
41class 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
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 getSupportedPlatforms()
Definition app.php:177
static isExists($appCode, $platform)
Definition config.php:141
static checkFields(Result $result, $primary, array $data)
Definition config.php:106