Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
group.php
1
<?php
8
namespace
Bitrix\Sale\Location
;
9
10
use
Bitrix\Main
;
11
use
Bitrix\Main\Entity
;
12
use
Bitrix\Main\Config
;
13
use
Bitrix\Main\Localization\Loc
;
14
15
use
Bitrix\Sale\Location\Name
;
16
use
Bitrix\Sale\Location\Util\Assert
;
17
18
Loc::loadMessages
(__FILE__);
19
36
class
GroupTable
extends
Entity\DataManager
37
{
38
const
PROJECT_USES_GROUPS_OPT
=
'project_uses_groups'
;
39
40
public
static
function
getFilePath
()
41
{
42
return
__FILE__;
43
}
44
45
public
static
function
getTableName
()
46
{
47
return
'b_sale_location_group'
;
48
}
49
50
public
static
function
add
(array $data)
51
{
52
if
(isset($data[
'NAME'
]))
53
{
54
$name = $data[
'NAME'
];
55
unset($data[
'NAME'
]);
56
}
57
58
$addResult = parent::add($data);
59
60
// add connected data
61
if
($addResult->isSuccess())
62
{
63
$primary = $addResult->getId();
64
65
// names
66
if
(isset($name))
67
Name\GroupTable::addMultipleForOwner($primary, $name);
68
69
// set flag that indicates whether project still uses groups or not
70
self::setGroupUsage();
71
}
72
73
return
$addResult;
74
}
75
76
public
static
function
update
($primary, array $data)
77
{
78
$primary = Assert::expectIntegerPositive($primary,
'$primary'
);
79
80
// first update parent, and if it succeed, do updates of the connected data
81
82
if
(isset($data[
'NAME'
]))
83
{
84
$name = $data[
'NAME'
];
85
unset($data[
'NAME'
]);
86
}
87
88
$updResult = parent::update($primary, $data);
89
90
// update connected data
91
if
($updResult->isSuccess())
92
{
93
// names
94
if
(isset($name))
95
Name\GroupTable::updateMultipleForOwner($primary, $name);
96
}
97
98
return
$updResult;
99
}
100
101
public
static
function
delete
($primary)
102
{
103
$primary = Assert::expectIntegerPositive($primary,
'$primary'
);
104
105
$delResult = parent::delete($primary);
106
107
// delete connected data
108
if
($delResult->isSuccess())
109
{
110
Name\GroupTable::deleteMultipleForOwner($primary);
111
GroupLocationTable::deleteByGroupId($primary);
112
113
// set flag that indicates whether project still uses groups or not
114
self::checkGroupUsage();
115
}
116
117
return
$delResult;
118
}
119
120
public
static
function
checkGroupUsage
()
121
{
122
$optValue = Config\Option::get(
"sale"
, self::PROJECT_USES_GROUPS_OPT,
''
,
''
);
123
if
(!$optValue)
// option is undefined, we are not sure if there are groups or not
124
return
self::getGroupUsage();
125
126
return
$optValue ==
'Y'
;
127
}
128
129
public
static
function
getGroupUsage
()
130
{
131
$isUsing = !!
GroupTable::getList
(array(
'limit'
=> 1,
'select'
=> array(
'ID'
)))->fetch();
132
Config\Option::set(
"sale"
, self::PROJECT_USES_GROUPS_OPT, $isUsing ?
'Y'
:
'N'
,
''
);
133
134
return
$isUsing;
135
}
136
137
public
static
function
setGroupUsage
()
138
{
139
Config\Option::set(
"sale"
, self::PROJECT_USES_GROUPS_OPT,
'Y'
);
140
}
141
142
public
static
function
getCodeValidators
()
143
{
144
return
array(
145
new
Entity
\Validator\Unique(),
146
);
147
}
148
149
public
static
function
getMap
()
150
{
151
return
array(
152
153
'ID'
=> array(
154
'data_type'
=>
'integer'
,
155
'primary'
=>
true
,
156
'autocomplete'
=>
true
,
157
),
158
'CODE'
=> array(
159
'data_type'
=>
'string'
,
160
'required'
=>
true
,
161
'title'
=>
Loc::getMessage
(
'SALE_LOCATION_GROUP_ENTITY_CODE_FIELD'
),
162
'validation'
=> array(__CLASS__,
'getCodeValidators'
)
163
),
164
'SORT'
=> array(
165
'data_type'
=>
'integer'
,
166
'title'
=>
Loc::getMessage
(
'SALE_LOCATION_GROUP_ENTITY_SORT_FIELD'
),
167
'default_value'
=>
'100'
168
),
169
170
// virtual
171
'NAME'
=> array(
172
'data_type'
=>
'\Bitrix\Sale\Location\Name\Group'
,
173
'reference'
=> array(
174
'=this.ID'
=>
'ref.LOCATION_GROUP_ID'
175
)
176
),
177
'LOCATION'
=> array(
178
'data_type'
=>
'\Bitrix\Sale\Location\Location'
,
179
'reference'
=> array(
180
'=this.ID'
=>
'ref.LOCATION_GROUP_ID'
181
)
182
)
183
);
184
}
185
}
Bitrix\Main\GroupTable
Definition
group.php:29
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\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Sale\Location\GroupTable\getGroupUsage
static getGroupUsage()
Definition
group.php:129
Bitrix\Sale\Location\GroupTable\PROJECT_USES_GROUPS_OPT
const PROJECT_USES_GROUPS_OPT
Definition
group.php:38
Bitrix\Sale\Location\GroupTable\getMap
static getMap()
Definition
group.php:149
Bitrix\Sale\Location\GroupTable\getCodeValidators
static getCodeValidators()
Definition
group.php:142
Bitrix\Sale\Location\GroupTable\getFilePath
static getFilePath()
Definition
group.php:40
Bitrix\Sale\Location\GroupTable\checkGroupUsage
static checkGroupUsage()
Definition
group.php:120
Bitrix\Sale\Location\GroupTable\add
static add(array $data)
Definition
group.php:50
Bitrix\Sale\Location\GroupTable\setGroupUsage
static setGroupUsage()
Definition
group.php:137
Bitrix\Sale\Location\GroupTable\update
static update($primary, array $data)
Definition
group.php:76
Bitrix\Sale\Location\GroupTable\getTableName
static getTableName()
Definition
group.php:45
Bitrix\Sale\Location\Util\Assert
Definition
assert.php:17
Bitrix\Main\Config
Definition
configuration.php:2
Bitrix\Main
Bitrix\Sale\Location\Name
Definition
group.php:8
Bitrix\Sale\Location
modules
sale
lib
location
group.php
Создано системой
1.10.0