Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
typehelper.php
1<?
10
12{
13 const LIST_PAGE_URL = 'sale_location_type_list.php';
14 const EDIT_PAGE_URL = 'sale_location_type_edit.php';
15
16 #####################################
17 #### Entity settings
18 #####################################
19
24 public static function getEntityRoadMap()
25 {
26 return array(
27 'main' => array(
28 'name' => 'Bitrix\Sale\Location\Type',
29 ),
30 'name' => array(
31 'name' => 'Bitrix\Sale\Location\Name\Type',
32 'pages' => array(
33 'list' => array(
34 'includedColumns' => array('NAME')
35 ),
36 'detail' => array(
37 'includedColumns' => array('NAME')
38 )
39 )
40 ),
41 );
42 }
43
44 public static function getTypeCodeIdMapCached()
45 {
46 static $types;
47
48 if($types == null)
49 {
50 $res = \Bitrix\Sale\Location\TypeTable::getList(array(
51 'select' => array(
52 'ID', 'CODE'
53 )
54 ));
55
56 $types = array();
57 while($item = $res->Fetch())
58 {
59 $types['ID2CODE'][intval($item['ID'])] = $item['CODE'];
60 $types['CODE2ID'][$item['CODE']] = intval($item['ID']);
61 }
62 }
63
64 return $types;
65 }
66
67 public static function getTypes($params = array('LANGUAGE_ID' => LANGUAGE_ID))
68 {
69 if(!is_array($params))
70 $params = array();
71
72 if(!isset($params['LANGUAGE_ID']))
73 $params['LANGUAGE_ID'] = LANGUAGE_ID;
74
75 $result = array();
76
77 $lang = mb_strtolower($params['LANGUAGE_ID']);
78 $langMapped = static::mapLanguage($lang);
79
80 $res = \Bitrix\Sale\Location\TypeTable::getList(array(
81 'select' => array(
82 '*',
83 'TNAME' => 'NAME.NAME',
84 'TLANGUAGE_ID' => 'NAME.LANGUAGE_ID'
85 ),
86 'order' => array(
87 'SORT' => 'asc',
88 'NAME.NAME' => 'asc'
89 )
90 ));
91 while($item = $res->fetch())
92 {
93 if(!isset($result[$item['CODE']]))
94 {
95 $result[$item['CODE']] = array(
96 'CODE' => $item['CODE'],
97 'ID' => $item['ID'],
98 'NAME' => array()
99 );
100 }
101
102 $result[$item['CODE']]['NAME'][$item['TLANGUAGE_ID']] = $item['TNAME'];
103 }
104
105 foreach($result as $code => &$data)
106 {
107 if((string) $data['NAME'][$lang] != '')
108 {
109 $name = $data['NAME'][$lang];
110 }
111 else
112 {
113 if((string) $data['NAME'][$langMapped] != '')
114 $name = $data['NAME'][$langMapped];
115 else
116 $name = $data['NAME']['en'];
117 }
118
119 $data['NAME_CURRENT'] = $name;
120 }
121
122 return $result;
123 }
124}
static getTypes($params=array('LANGUAGE_ID'=> LANGUAGE_ID))