1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
location_group.php
См. документацию.
1<?php
2
3require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/sale/general/location_group.php");
4
6
8{
9 public static function GetList($arOrder = Array("NAME"=>"ASC"), $arFilter=Array(), $strLang = LANGUAGE_ID)
10 {
11 global $DB;
12 $arSqlSearch = Array();
13 $arSqlSearchFrom = array();
14
15 if(!is_array($arFilter))
16 $filter_keys = Array();
17 else
18 $filter_keys = array_keys($arFilter);
19
20 $countFilterKey = count($filter_keys);
21 for($i=0; $i < $countFilterKey; $i++)
22 {
23 $val = $DB->ForSql($arFilter[$filter_keys[$i]]);
24 if ($val == '') continue;
25
26 $key = $filter_keys[$i];
27 if ($key[0]=="!")
28 {
29 $key = mb_substr($key, 1);
30 $bInvert = true;
31 }
32 else
33 $bInvert = false;
34
35 switch(mb_strtoupper($key))
36 {
37 case "ID":
38 $arSqlSearch[] = "LG.ID ".($bInvert?"<>":"=")." ".intval($val)." ";
39 break;
40 case "LOCATION":
41
43 {
44 try
45 {
46 $class = self::CONN_ENTITY_NAME.'Table';
47 $arSqlSearch[] = " LG.ID ".($bInvert ? 'not' : '')." in (".$class::getConnectedEntitiesQuery(intval($val), 'id', array('select' => array('ID'))).") ";
48 }
49 catch(Exception $e)
50 {
51 }
52 }
53 else
54 {
55 $arSqlSearch[] = "LG.ID = L2LG.LOCATION_GROUP_ID AND L2LG.LOCATION_GROUP_ID ".($bInvert?"<>":"=")." ".intval($val)." ";
56 $arSqlSearchFrom[] = ", b_sale_location2location_group L2LG ";
57 }
58
59 break;
60 }
61 }
62
63 $strSqlSearch = "";
64 $countSqlSearch = count($arSqlSearch);
65 for($i=0; $i < $countSqlSearch; $i++)
66 {
67 $strSqlSearch .= " AND ";
68 $strSqlSearch .= " (".$arSqlSearch[$i].") ";
69 }
70
71 $strSqlSearchFrom = "";
72 $countSqlSearchForm = count($arSqlSearchFrom);
73 for($i=0; $i < $countSqlSearchForm; $i++)
74 {
75 $strSqlSearchFrom .= " ".$arSqlSearchFrom[$i]." ";
76 }
77
78 $strSql =
79 "SELECT DISTINCT LG.ID, LG.SORT, LGL.NAME, LGL.LID ".
80 "FROM (b_sale_location_group LG ".
81 " ".$strSqlSearchFrom.") ".
82 " LEFT JOIN b_sale_location_group_lang LGL ON (LG.ID = LGL.LOCATION_GROUP_ID AND LGL.LID = '".$DB->ForSql($strLang, 2)."') ".
83 "WHERE 1 = 1 ".
84 " ".$strSqlSearch." ";
85
86 $arSqlOrder = Array();
87 foreach ($arOrder as $by=>$order)
88 {
89 $by = mb_strtoupper($by);
90 $order = mb_strtoupper($order);
91 if ($order!="ASC") $order = "DESC";
92
93 if ($by == "ID") $arSqlOrder[] = " LG.ID ".$order." ";
94 elseif ($by == "NAME") $arSqlOrder[] = " LGL.NAME ".$order." ";
95 else
96 {
97 $arSqlOrder[] = " LG.SORT ".$order." ";
98 $by = "SORT";
99 }
100 }
101
102 $strSqlOrder = "";
103 DelDuplicateSort($arSqlOrder);
104 $countSqlOrder = count($arSqlOrder);
105 for ($i=0; $i < $countSqlOrder; $i++)
106 {
107 if ($i==0)
108 $strSqlOrder = " ORDER BY ";
109 else
110 $strSqlOrder .= ", ";
111
112 $strSqlOrder .= $arSqlOrder[$i];
113 }
114
115 $strSql .= $strSqlOrder;
116 $db_res = $DB->Query($strSql);
117 return $db_res;
118 }
119
120 public static function GetByID($ID, $strLang = LANGUAGE_ID)
121 {
122 global $DB;
123
124 $ID = intval($ID);
125 $strSql =
126 "SELECT LG.ID, LG.SORT, LGL.NAME, LGL.LID ".
127 "FROM b_sale_location_group LG ".
128 " LEFT JOIN b_sale_location_group_lang LGL ON (LG.ID = LGL.LOCATION_GROUP_ID AND LGL.LID = '".$DB->ForSql($strLang, 2)."') ".
129 "WHERE LG.ID = ".$ID." ";
130 $db_res = $DB->Query($strSql);
131
132 if ($res = $db_res->Fetch())
133 {
134 return $res;
135 }
136 return False;
137 }
138
139 public static function Add($arFields)
140 {
141 global $DB;
142
144 return false;
145
146 // make IX_B_SALE_LOC_GROUP_CODE feel happy
147 $arFields['CODE'] = 'randstr'.rand(999, 999999);
148
149 $db_events = GetModuleEvents("sale", "OnBeforeLocationGroupAdd");
150 while ($arEvent = $db_events->Fetch())
151 if (ExecuteModuleEventEx($arEvent, array($arFields))===false)
152 return false;
153
154 $arInsert = $DB->PrepareInsert("b_sale_location_group", $arFields);
155 $strSql =
156 "INSERT INTO b_sale_location_group(".$arInsert[0].") ".
157 "VALUES(".$arInsert[1].")";
158
159 $DB->Query($strSql);
160
161 $ID = intval($DB->LastID());
162
163 // make IX_B_SALE_LOC_CODE feel happy
165
166 $countFieldLang = count($arFields["LANG"]);
167 for ($i = 0; $i < $countFieldLang; $i++)
168 {
169 $arInsert = $DB->PrepareInsert("b_sale_location_group_lang", $arFields["LANG"][$i]);
170 $strSql =
171 "INSERT INTO b_sale_location_group_lang(LOCATION_GROUP_ID, ".$arInsert[0].") ".
172 "VALUES(".$ID.", ".$arInsert[1].")";
173
174 $DB->Query($strSql);
175 }
176
178 {
179 try
180 {
181 $entityClass = self::CONN_ENTITY_NAME.'Table';
182 $entityClass::resetMultipleForOwner($ID, array(
183 Location\Connector::DB_LOCATION_FLAG => $entityClass::normalizeLocationList($arFields["LOCATION_ID"])
184 ));
185 }
186 catch(Exception $e)
187 {
188 }
189 }
190 else
191 {
192 $strSqlHead ="INSERT INTO b_sale_location2location_group (LOCATION_ID, LOCATION_GROUP_ID) VALUES ";
193 $strSqlHeadLength = mb_strlen($strSqlHead);
194
195 $res = $DB->Query('SHOW VARIABLES LIKE \'max_allowed_packet\'');
196 $maxPack = $res->Fetch();
197
198 if(isset($maxPack["Value"]))
199 $max_allowed_packet = $maxPack["Value"]-$strSqlHeadLength-100;
200 else
201 $max_allowed_packet = 0;
202
203 $tmpSql = '';
204 $strSql = '';
205 $countFieldLoc = count($arFields["LOCATION_ID"]);
206 for ($i = 0; $i < $countFieldLoc; $i++)
207 {
208 $tmpSql ="(".$arFields["LOCATION_ID"][$i].", ".$ID.")";
209 $strSqlLen = mb_strlen($strSql);
210
211 if($strSqlHeadLength + $strSqlLen + mb_strlen($tmpSql) < $max_allowed_packet || $max_allowed_packet <= 0)
212 {
213 if($strSqlLen > 0)
214 $strSql .=",";
215
216 $strSql .= $tmpSql;
217 }
218 else
219 {
220 $DB->Query($strSqlHead.$strSql);
221 $strSql = $tmpSql;
222 }
223 }
224
225 if($strSql <> '')
226 $DB->Query($strSqlHead.$strSql);
227 }
228
229 $events = GetModuleEvents("sale", "OnLocationGroupAdd");
230 while ($arEvent = $events->Fetch())
232
233 return $ID;
234 }
235}
$db_res
Определения options_user_settings.php:8
const DB_LOCATION_FLAG
Определения connector.php:25
static update($primary, array $data)
Определения group.php:76
static CheckFields($ACTION, &$arFields)
Определения location_group.php:174
static isLocationProMigrated()
Определения location.php:58
static GetByID($ID, $strLang=LANGUAGE_ID)
Определения location_group.php:120
static Add($arFields)
Определения location_group.php:139
static GetList($arOrder=Array("NAME"=>"ASC"), $arFilter=Array(), $strLang=LANGUAGE_ID)
Определения location_group.php:9
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
if($ajaxMode) $ID
Определения get_user.php:27
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
DelDuplicateSort(&$arSort)
Определения tools.php:2055
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$val
Определения options.php:1793
$arFilter
Определения user_search.php:106