Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tools.php
1<?php
3
10class Tools
11{
20 public static function checkExistKeys(array $fields, array $keyList, $checkNull = false)
21 {
22 $result = false;
23 if (empty($fields) || empty($keyList))
24 return $result;
25
26 $checkNull = ($checkNull === true);
27 if (!$checkNull)
28 $fields = array_filter($fields, '\Bitrix\Catalog\Helpers\Tools::clearNullFields');
29
30 foreach ($keyList as &$key)
31 {
32 if (array_key_exists($key, $fields))
33 {
34 $result = true;
35 break;
36 }
37 }
38 unset($key);
39
40 return $result;
41 }
42
51 public static function getMissingKeys(array $fields, array $keyList, $checkNull = false)
52 {
53 $result = array();
54 if (empty($keyList))
55 return $result;
56 if (empty($fields))
57 return $keyList;
58
59 $checkNull = ($checkNull === true);
60 if (!$checkNull)
61 $fields = array_filter($fields, '\Bitrix\Catalog\Helpers\Tools::clearNullFields');
62
63 foreach ($keyList as &$key)
64 {
65 if (!array_key_exists($key, $fields))
66 $result[] = $key;
67 }
68 unset($key);
69 return $result;
70 }
71
80 public static function prepareKeys(array $fields, array $keyList, $checkNull = false)
81 {
82 $result = array(
83 'EXIST' => array(),
84 'MISSING' => array()
85 );
86 if (empty($keyList))
87 return false;
88
89 if (empty($fields))
90 {
91 $result['MISSING'] = $keyList;
92 return $result;
93 }
94
95 $checkNull = ($checkNull === true);
96 if (!$checkNull)
97 $fields = array_filter($fields, '\Bitrix\Catalog\Helpers\Tools::clearNullFields');
98
99 foreach ($keyList as &$key)
100 {
101 if (!array_key_exists($key, $fields))
102 $result['MISSING'][] = $key;
103 else
104 $result['EXIST'][] = $key;
105 }
106 unset($key);
107 return $result;
108 }
109
116 public static function clearNullFields($value)
117 {
118 return ($value !== null);
119 }
120}
static prepareKeys(array $fields, array $keyList, $checkNull=false)
Definition tools.php:80
static checkExistKeys(array $fields, array $keyList, $checkNull=false)
Definition tools.php:20
static clearNullFields($value)
Definition tools.php:116
static getMissingKeys(array $fields, array $keyList, $checkNull=false)
Definition tools.php:51