Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
rowtype.php
1<?php
2
3namespace Bitrix\Iblock\Grid;
4
6
7class RowType
8{
9 public const ELEMENT = 'E';
10 public const SECTION = 'S';
11
17 public static function getIndex(string $type, string|int $id): string
18 {
19 return ($type === self::SECTION ? self::SECTION : self::ELEMENT) . $id;
20 }
21
27 public static function parseIndex(string $index): ?array
28 {
29 $re = '/^(E|S|)(\d+)$/';
30 if (preg_match($re, $index, $m))
31 {
32 $type = ($m[1] ?: RowType::ELEMENT);
33 $index = (int)$m[2];
34
35 return [$type, $index];
36 }
37 elseif (is_numeric($index))
38 {
39 return [RowType::ELEMENT, (int)$index];
40 }
41
42 return null;
43 }
44
52 public static function parseIndexList(array $ids): array
53 {
54 $elementIds = [];
55 $sectionIds = [];
56
57 foreach ($ids as $id)
58 {
59 $index = self::parseIndex($id);
60 if ($index === null)
61 {
62 continue;
63 }
64 [$type, $id] = $index;
65
66 if ($type === self::ELEMENT)
67 {
68 $elementIds[] = $id;
69 }
70 else
71 {
72 $sectionIds[] = $id;
73 }
74 }
75
76 return [$elementIds, $sectionIds];
77 }
78}
static parseIndexList(array $ids)
Definition rowtype.php:52
static getIndex(string $type, string|int $id)
Definition rowtype.php:17
static parseIndex(string $index)
Definition rowtype.php:27