Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
hierarchytable.php
1<?php
3
9
10
37class 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}
static deleteByLocationId(int $locationId)
static getConnection($name="")