Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
geonametable.php
1<?php
2
11
15
33{
34 use Data\Internal\MergeTrait;
35
36 public static function getTableName()
37 {
38 return 'b_geoname';
39 }
40
41 public static function getMap()
42 {
43 return [
44 (new Fields\IntegerField('ID'))
45 ->configurePrimary(),
46 (new Fields\StringField('LANGUAGE_CODE'))
47 ->configurePrimary(),
48 (new Fields\StringField('NAME')),
49 ];
50 }
51
52 public static function save(array $data): void
53 {
54 $existing = static::get(array_keys($data), false);
55
56 foreach ($data as $geoid => $names)
57 {
58 if (is_array($names))
59 {
60 foreach ($names as $lang => $name)
61 {
62 if (!isset($existing[$geoid][$lang]) || $existing[$geoid][$lang] != $name)
63 {
64 $insert = [
65 'ID' => $geoid,
66 'LANGUAGE_CODE' => $lang,
67 'NAME' => $name,
68 ];
69 $update = [
70 'NAME' => $name,
71 ];
72 static::merge($insert, $update);
73 }
74 }
75 }
76 }
77 }
78
79 public static function get(array $ids, bool $decode = true): array
80 {
81 $existing = [];
82
83 if (!empty($ids))
84 {
85 $query = static::query()
86 ->setSelect(['*'])
87 ->whereIn('ID', $ids)
88 ->exec()
89 ;
90
91 $converter = ($decode? new UtfConverter(): null);
92
93 while ($record = $query->fetch($converter))
94 {
95 $existing[$record['ID']][$record['LANGUAGE_CODE']] = $record['NAME'];
96 }
97 }
98
99 return $existing;
100 }
101}