Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
hierarchytable.php
1
<?php
2
namespace
Bitrix\Location\Model
;
3
4
use
Bitrix\Main
,
5
Bitrix\Main\ORM\Fields
;
6
use
Bitrix\Main\Application
;
7
use
Bitrix\Main\ORM\Fields\Relations\Reference
;
8
use
Bitrix\Main\ORM\Query\Join
;
9
10
37
class
HierarchyTable
extends
Main\Entity\DataManager
38
{
44
public
static
function
getTableName
()
45
{
46
return
'b_location_hierarchy'
;
47
}
48
54
public
static
function
getMap
()
55
{
56
return
array(
57
58
(
new
Fields\
IntegerField
(
'ANCESTOR_ID'
))
59
->configurePrimary(
true
),
60
61
(
new
Fields\
IntegerField
(
'DESCENDANT_ID'
))
62
->configurePrimary(
true
),
63
64
(
new
Fields\
IntegerField
(
'LEVEL'
))
65
->configureRequired(
true
),
66
67
// References
68
69
(
new
Reference
(
'ANCESTOR'
, LocationTable::class,
70
Join::on(
'this.ANCESTOR_ID'
,
'ref.ID'
)))
71
->configureJoinType(
'inner'
),
72
73
(
new
Reference
(
'DESCENDANT'
, LocationTable::class,
74
Join::on(
'this.DESCENDANT_ID'
,
'ref.ID'
)))
75
->configureJoinType(
'inner'
)
76
);
77
}
78
84
public
static
function
insertBatch
(array $data)
85
{
86
$values = [];
87
88
foreach
($data as $row)
89
{
90
if
((
int
)$row[
'ANCESTOR_ID'
] <= 0 || (
int
)$row[
'DESCENDANT_ID'
] <= 0)
91
{
92
continue
;
93
}
94
95
$values[] = (int)$row[
'ANCESTOR_ID'
].
', '
.(
int
)$row[
'DESCENDANT_ID'
].
', '
.(int)$row[
'LEVEL'
];
96
}
97
98
if
(!empty($values))
99
{
100
$values =
'('
. implode(
'), ('
, $values) .
')'
;
101
$sql =
"INSERT IGNORE INTO "
. static::getTableName() .
" (ANCESTOR_ID, DESCENDANT_ID, LEVEL) VALUES "
. $values;
102
Application::getConnection
()->queryExecute($sql);
103
}
104
}
105
110
public
static
function
deleteByLocationId
(
int
$locationId)
111
{
112
$locationId = (int)$locationId;
113
114
Application::getConnection
()->queryExecute(
"
115
DELETE
116
FROM "
.self::getTableName().
"
117
WHERE ANCESTOR_ID="
.$locationId.
"
118
OR DESCENDANT_ID = "
.$locationId
119
);
120
}
121
}
Bitrix\Location\Model\HierarchyTable
Definition
hierarchytable.php:38
Bitrix\Location\Model\HierarchyTable\getMap
static getMap()
Definition
hierarchytable.php:54
Bitrix\Location\Model\HierarchyTable\deleteByLocationId
static deleteByLocationId(int $locationId)
Definition
hierarchytable.php:110
Bitrix\Location\Model\HierarchyTable\insertBatch
static insertBatch(array $data)
Definition
hierarchytable.php:84
Bitrix\Location\Model\HierarchyTable\getTableName
static getTableName()
Definition
hierarchytable.php:44
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\ORM\Fields\IntegerField
Definition
integerfield.php:20
Bitrix\Main\ORM\Fields\Relations\Reference
Definition
reference.php:26
Bitrix\Main\ORM\Query\Join
Definition
join.php:19
Bitrix\Location\Model
Definition
addressfieldtable.php:3
Bitrix\Main\ORM\Fields
Definition
arrayfield.php:9
Bitrix\Main
modules
location
lib
model
hierarchytable.php
Создано системой
1.10.0