26 #####################################
28 #####################################
43 return self::getMap($page);
53 $flds = static::readMap(self::getEntityRoadCode(), $page);
58 #####################################
60 #####################################
65 $columns = static::getColumns(
'list');
66 foreach($columns as &$col)
67 $col[
'DEFAULT'] =
true;
75 $columns = static::getColumns(
'list');
76 foreach($columns as &$col)
77 $col[
'DEFAULT'] =
true;
85 return static::getColumns(
'list');
91 $columns = self::getMap(
'list');
93 $parameters = array();
97 if(is_array($proxed[
'FILTER']) && !empty($proxed[
'FILTER']))
99 foreach($columns as $code => $fld)
101 if($fld[
'data_type'] ==
'integer' || $fld[
'data_type'] ==
'float')
105 if(is_array($proxed[
'FILTER'][$code]))
107 if(mb_strlen($proxed[
'FILTER'][$code][
'FROM']) && mb_strlen($proxed[
'FILTER'][$code][
'TO']))
109 $filter[
'><'.$code] = array($proxed[
'FILTER'][$code][
'FROM'], $proxed[
'FILTER'][$code][
'TO']);
111 elseif(mb_strlen($proxed[
'FILTER'][$code][
'FROM']))
113 $filter[
'>='.$code] = $proxed[
'FILTER'][$code][
'FROM'];
115 elseif(mb_strlen($proxed[
'FILTER'][$code][
'TO']))
117 $filter[
'<='.$code] = $proxed[
'FILTER'][$code][
'TO'];
120 elseif(mb_strlen($proxed[
'FILTER'][$code]))
122 $filter[
'='.$code] = (string)$proxed[
'FILTER'][$code];
127 if($proxed[
'FILTER'][$code] <>
'')
129 $filter[static::getFilterModifier($fld[
'data_type']).$code] = $proxed[
'FILTER'][$code];
136 $parameters[
'filter'] = $filter;
139 foreach($columns as $code => $col)
140 $parameters[
'select'][] = $code;
143 if(is_array($proxed[
'ORDER']) && !empty($proxed[
'ORDER']))
144 $parameters[
'order'] = $proxed[
'ORDER'];
147 if(($page = intval($proxed[
'NAV'][
'PAGE_NUM'])) && ($lop = intval($proxed[
'NAV'][
'LOP'])))
149 $roadMap = static::getEntityRoadMap();
150 $road = $roadMap[self::getEntityRoadCode()][
'name'];
151 $class = $road.
'Table';
153 $count = $class::getList(array(
154 'filter' => is_array($parameters[
'filter']) ? $parameters[
'filter'] : array(),
155 'select' => array(
'CNT'),
158 'data_type' =>
'integer',
159 'expression' => array(
167 $bounds = Main\DB\Paginator::calculateQueryLimits($count[
'CNT'], $page, $lop);
168 $parameters[
'offset'] = $bounds[0];
169 $parameters[
'limit'] = $bounds[1];
187 if(is_array($parameters[
'ID']) && !empty($parameters[
'ID']))
189 $parameters[
'ID'] = array_unique($parameters[
'ID']);
190 foreach($parameters[
'ID'] as $id)
192 $res = static::delete($id);
195 $result[
'success'] =
false;
196 $result[
'errors'] = array_merge($result[
'errors'], $res[
'errors']);
200 else if(is_array($parameters[
'FILTER']))
202 $entityClass = static::getEntityClass();
203 $parameters = Helper::getParametersForList($parameters);
205 $glParams = array(
'select' => array(
'ID'));
207 if(is_array($parameters[
'filter']) && !empty($parameters[
'filter']))
208 $glParams[
'filter'] = $parameters[
'filter'];
210 $resItems = $entityClass::getList($glParams);
212 while ($item = $resItems->fetch())
219 if(!$entityClass::getById($item[
'ID'])->fetch())
223 $res = static::delete($item[
'ID']);
226 $result[
'success'] =
false;
227 $result[
'errors'] = array_merge($result[
'errors'], $res[
'errors']);
238 $parameters = static::proxyListRequest(
'detail');
239 $parameters[
'filter'][
'='.static::getPrimaryFieldName()] = $id;
241 $formData = static::getList($parameters)->fetch();
243 if(!is_array($formData) || empty($formData))
251 $columns = static::getColumns(
'');
253 $value = (string)$value;
254 if(!empty($columns[$code]))
256 if ($value ===
'' && isset($columns[$code][
'default']))
258 $value = (string)$columns[$code][
'default'];
261 switch($columns[$code][
'data_type'])
264 $value = (int)$value;
267 $value = (float)$value;
270 $value = htmlspecialcharsbx($value);
274 $value = htmlspecialcharsbx($value);
279 ##############################################
280 ##############################################
281 ##############################################
294 $columns = static::getColumns(
'list');
296 foreach($columns as $code => $void)
298 if(isset($data[$code]))
299 $proxed[$code] = $data[$code];
312 $columns = self::getMap($page);
314 $parameters = array(
'filter' => array());
316 foreach($columns as $code => $col)
317 $parameters[
'select'][] = $code;
320 if(self::checkUseFilter())
322 foreach($columns as $code => $fld)
324 $from =
'find_'.$code.
'_1';
325 $to =
'find_'.$code.
'_2';
327 if ($fld[
'data_type'] ===
'integer' && (isset(
$GLOBALS[$from]) || isset(
$GLOBALS[$to])))
331 $valueFrom = trim((
string)(
$GLOBALS[$from] ??
''));
332 $valueTo = trim((
string)(
$GLOBALS[$to] ??
''));
334 if ($valueFrom !==
'' && $valueTo !==
'')
336 $filter[
'><'.$code] = [(int)$valueFrom, (
int)$valueTo];
338 elseif ($valueFrom !==
'')
340 $filter[
'>='.$code] = (int)$valueFrom;
342 elseif ($valueTo !==
'')
344 $filter[
'<='.$code] = (int)$valueTo;
349 $value = trim((
string)(
$GLOBALS[
'find_'.$code] ??
''));
352 $filter[static::getFilterModifier($fld[
'data_type']).$code] = $value;
359 $parameters[
'filter'] = $filter;
362 $columns = static::getColumns($page);
364 if(isset($columns[$by]))
366 $parameters[
'order'] = array($by => isset($order)? $order :
'asc');
374 public static function add($data)
378 $entityClass = static::getEntityClass();
380 $data = static::convertToArray($data);
382 $data = static::proxyUpdateRequest($data);
383 $errors = static::validateUpdateRequest($data);
387 $res = $entityClass::add($data);
388 if(!$res->isSuccess())
391 $errors = $res->getErrorMessages();
400 'success' => $success,
407 public static function update($primary, $data)
410 $entityClass = static::getEntityClass();
412 $data = static::convertToArray($data);
413 $data = static::proxyUpdateRequest($data);
414 $errors = static::validateUpdateRequest($data);
418 $res = $entityClass::update($primary, $data);
419 if(!$res->isSuccess())
422 $errors = $res->getErrorMessages();
429 'success' => $success,
435 public static function delete($primary)
439 $entityClass = static::getEntityClass();
441 $res = $entityClass::delete($primary);
442 if(!$res->isSuccess())
445 $errors = $res->getErrorMessages();
449 'success' => $success,
456 public static function getList($parameters = array(), $tableId =
false, $navigation = 20, $params = array())
458 $entityClass = static::getEntityClass();
459 $navNum = (
$GLOBALS[
'NavNum'] ?? 0) + 1;
460 $unique = md5(
$GLOBALS[
'APPLICATION']->GetCurPage());
461 $showAll = ($_SESSION[$unique.
'SESS_ALL_'.$navNum] ??
null) || ($GET[
'SHOWALL_'.$navNum] ??
null);
462 $isAdminSection = defined(
'ADMIN_SECTION') && ADMIN_SECTION ===
true;
463 $tableId = trim((
string)$tableId);
465 if (($params[
"uiMode"] ??
null))
467 $result = new \CSaleProxyAdminUiResult($parameters, $entityClass, $tableId);
469 elseif($isAdminSection && $tableId !==
'')
471 $result = new \CSaleProxyAdminResult($parameters, $entityClass, $tableId);
475 $result = new \CSaleProxyResult($parameters, $entityClass);
478 if(!$showAll && $navigation !==
false)
480 if($navigation ===
true)
486 $result->NavStart($navigation);
495 $result->bShowAll =
false;
504 $converted = array();
505 foreach($data as $key => $value)
506 $converted[$key] = $value;
511 foreach($data as &$value)
513 if(is_string($value))
514 $value = trim($value);
524 $entityClass = static::getEntityClass();
526 $res = $entityClass::getList(array(
527 'select' => array(
'ID'),
528 'filter' => is_array($listFilter) ? $listFilter : array()
530 while($item = $res->fetch())
532 $ids[] = intval($item[
'ID']);
540 $map = static::getEntityRoadMap();
542 return (
string)($map[
'main'][
'primaryFieldName'] ??
'') !==
'' ? $map[
'main'][
'primaryFieldName'] :
'ID';
548 if(!($id = intval($id)))
551 $entityClass = static::getEntityClass(
'main');
553 $item = $entityClass::getById($id)->fetch();
554 return $item[
'CODE'];
559 return self::getUrl(static::LIST_PAGE_URL, $parameters);
564 return self::getUrl(static::EDIT_PAGE_URL, $parameters);
569 return self::getUrl(static::IMPORT_PAGE_URL, array());
574 return self::getUrl(static::REINDEX_PAGE_URL, array());
579 return self::getUrl(static::MIGRATION_PAGE_URL, array());
582 public static function getUrl($page, $parameters = array())
584 if(!is_array($parameters))
585 $parameters = array();
587 $parameters[
'lang'] = LANGUAGE_ID;
589 $selfFolderUrl = (defined(
"SELF_FOLDER_URL") ? SELF_FOLDER_URL :
"/bitrix/admin/");
591 $packed = self::packUrlParameters($parameters);
592 return $selfFolderUrl.$page.($packed <>
''?
'?'.$packed :
'');
595 #####################################
596 #### Utilily methods for CRUD
597 #####################################
605 public static function readMap($entityRoadCode, $page =
'list')
607 $roads = static::getEntityRoadMap();
608 $road = $roads[$entityRoadCode];
617 $class = $road[
'name'].
'Table';
618 $excluded = $road[
'pages'][$page][
'excludedColumns'] ??
null;
619 $included = $road[
'pages'][$page][
'includedColumns'] ??
null;
621 $map = $class::getMap();
622 if (!empty($road[
'additional']) && is_array($road[
'additional']))
624 $map = array_merge($map, $road[
'additional']);
627 foreach ($map as $fldCode => $fldDesc)
629 if (is_array($excluded) && in_array($fldCode, $excluded))
634 if (is_array($included) && !in_array($fldCode, $included))
642 (isset($fldDesc[
'title']) && mb_strlen($fldDesc[
'title']))
643 || (isset($fldDesc[
'required']) && $fldDesc[
'required'])
644 || (isset($fldDesc[
'primary']) && $fldDesc[
'primary'])
649 $title = trim((
string)($fldDesc[
'title'] ??
''));
650 $fldDesc[
'title'] = $title !==
''? htmlspecialcharsbx($title) : $fldCode;
651 $fldDesc[
'ownerEntity'] = $road[
'name'];
652 $flds[$fldCode] = $fldDesc;
661 return $type ==
'string' ?
'?' :
'=';
667 foreach($parameters as $param => $value)
671 if(mb_strpos($param,
'=') === 0)
674 $param = mb_substr($param, 1);
678 $value = urlencode($value);
681 $params[] = urlencode($param).
'='.$value;
685 return implode(
'&', $params);
690 $entityRoad = static::getEntityRoadMap();
691 $entityName = $entityRoad[$code <>
''? $code : self::getEntityRoadCode()][
'name'];
696 return $entityName.
'Table';
701 $appearance = Config\Option::get(
"sale",
"sale_location_selector_appearance");
703 if(!mb_strlen($appearance) || !in_array($appearance, array(
'search',
'steps')))
711 $list = array_unique(array_values($list));
712 foreach($list as $i => $id)
716 if(intval($id) != $id)
719 $list[$i] = intval($id);
736 $useIds = !$connectorClass::getUseCodes();
737 $useGroups = $connectorClass::getUseGroups();
738 $l = $connectorClass::DB_LOCATION_FLAG;
739 $g = $connectorClass::DB_GROUP_FLAG;
741 if(isset($links[$l]))
743 if(is_string($links[$l]))
744 $links[$l] = explode(
':', $links[$l]);
747 $links[$l] = array();
749 $links[$l] = self::normalizeList($links[$l], $useIds);
755 if(isset($links[$g]))
757 if(is_string($links[$g]))
758 $links[$g] = explode(
':', $links[$g]);
761 $links[$g] = array();
763 $links[$g] = self::normalizeList($links[$g], $useIds);
773 if(is_array($locations) && !empty($locations))
775 foreach($locations as $loc)
777 if($loc[
'LOCATION_TYPE'] ==
'L')
778 $locList[Location\Connector::DB_LOCATION_FLAG][] = $loc[
'LOCATION_ID'];
779 elseif($loc[
'LOCATION_TYPE'] ==
'G')
780 $locList[Location\Connector::DB_GROUP_FLAG][] = $loc[
'LOCATION_ID'];
784 $entityClass = $entityName.
'Table';
788 if(!empty($locList) && !$expectCodes)
790 $locList[Location\Connector::DB_LOCATION_FLAG] = $entityClass::normalizeLocationList($locList[
Location\Connector::DB_LOCATION_FLAG]);
792 $gf = Location\Connector::DB_GROUP_FLAG;
793 if(!empty($locList[$gf]))
795 $groupCodes = array();
796 $locList[$gf] = array_flip($locList[$gf]);
798 $res = Location\GroupTable::getList(array(
'select' => array(
'ID',
'CODE')));
799 while($item = $res->fetch())
801 if(isset($locList[$gf][$item[
'ID']]))
802 $groupCodes[$item[
'CODE']] = 1;
805 $locList[$gf] = array_keys($groupCodes);
809 $entityClass::resetMultipleForOwner($entityId, $locList);
static getMessage($code, $replace=null, $language=null)
static getNameToDisplay($id)
static normalizeList($list, $expectNumeric=true)
static getEditUrl($parameters=array())
static prepareLinksForSaving($connectorClass, $links)
static getEntityClass($code='')
static getListUrl($parameters=array())
static getList($parameters=array(), $tableId=false, $navigation=20, $params=array())
static readMap($entityRoadCode, $page='list')
static getFilterModifier($type)
static getEntityRoadMap()
static proxyUpdateRequest($data)
static makeSafeDisplay(&$value, $code)
static convertToArray($data)
static getUrl($page, $parameters=array())
static getPrimaryFieldName()
static getFilterColumns()
const LOCATION_LINK_DATA_CACHE_TAG
static getDetailPageRows()
static performGridOperations($parameters)
static update($primary, $data)
static resetLocationsForEntity($entityId, $locations, $entityName, $expectCodes=false)
static getWidgetAppearance()
static getIdsByFilter($listFilter)
static getListGridColumns()
static getParametersForList($proxed)
static getEntityRoadCode()
static validateUpdateRequest($data)
static packUrlParameters($parameters=array())
static proxyListRequest($page)
$GLOBALS['____1444769544']