Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
3
4use \Bitrix\Landing\Manager;
5
7{
8 public static $internalClass = null;
9
14 private static function getCallingClass()
15 {
16 if (static::$internalClass === null)
17 {
18 throw new \Bitrix\Main\SystemException(
19 'Variable static::$internalClass must be declarated in external class.'
20 );
21 }
22 return '\\' . __NAMESPACE__ . '\\' . static::$internalClass;
23 }
24
29 public static function getMap()
30 {
32 $class = self::getCallingClass();
33 return $class::getMap();
34 }
35
41 public static function add($fields)
42 {
43 $uid = Manager::getUserId();
44 $uid = $uid ? $uid : 1;
45 $date = new \Bitrix\Main\Type\DateTime;
46
47 $charValue = array(
48 'ACTIVE', 'PUBLIC', 'SITEMAP', 'FOLDER'
49 );
50 foreach ($charValue as $code)
51 {
52 if (isset($fields[$code]) && $fields[$code] != 'Y')
53 {
54 $fields[$code] = 'N';
55 }
56 }
57 if (!isset($fields['CREATED_BY_ID']))
58 {
59 $fields['CREATED_BY_ID'] = $uid;
60 }
61 if (!isset($fields['MODIFIED_BY_ID']))
62 {
63 $fields['MODIFIED_BY_ID'] = $uid;
64 }
65 if (!isset($fields['DATE_CREATE']))
66 {
67 $fields['DATE_CREATE'] = $date;
68 }
69 if (!isset($fields['DATE_MODIFY']))
70 {
71 $fields['DATE_MODIFY'] = $date;
72 }
73
75 $class = self::getCallingClass();
76 return $class::add($fields);
77 }
78
85 public static function update($id, $fields = array())
86 {
87 $uid = Manager::getUserId();
88 $date = new \Bitrix\Main\Type\DateTime;
89
90 $charValue = array(
91 'ACTIVE', 'PUBLIC', 'SITEMAP', 'FOLDER'
92 );
93 foreach ($charValue as $code)
94 {
95 if (isset($fields[$code]) && $fields[$code] != 'Y')
96 {
97 $fields[$code] = 'N';
98 }
99 }
100
101 if (isset($fields['ID']))
102 {
103 unset($fields['ID']);
104 }
105 if (!isset($fields['MODIFIED_BY_ID']))
106 {
107 $fields['MODIFIED_BY_ID'] = $uid;
108 }
109 else if (!$fields['MODIFIED_BY_ID'])
110 {
111 unset($fields['MODIFIED_BY_ID']);
112 }
113 if (!isset($fields['DATE_MODIFY']))
114 {
115 $fields['DATE_MODIFY'] = $date;
116 }
117 if (!$fields['DATE_MODIFY'])
118 {
119 unset($fields['DATE_MODIFY']);
120 }
121
123 $class = self::getCallingClass();
124 return $class::update($id, $fields);
125 }
126
132 public static function delete($id)
133 {
135 $class = self::getCallingClass();
136 \Bitrix\Landing\Debug::log(
137 $class,
138 'id: ' . $id . '@' . print_r(\Bitrix\Main\Diag\Helper::getBackTrace(5), true),
139 'LANDING_ENTITY_DELETE'
140 );
141 return $class::delete($id);
142 }
143
149 public static function getList($params = array())
150 {
151 $class = self::getCallingClass();
152
153 if (method_exists($class, 'setAccessFilter'))
154 {
155 $params = $class::setAccessFilter($params);
156 }
157
159 return $class::getList($params);
160 }
161
168 public static function callback($code, $callback)
169 {
170 $class = self::getCallingClass();
171 if (mb_substr(mb_strtolower($class), -5) == 'table')
172 {
173 $class = mb_substr($class, 0, -5);
174 if ($class)
175 {
176 $eventManager = \Bitrix\Main\EventManager::getInstance();
177 $eventManager->addEventHandler(
178 'landing',
179 $class . '::' . $code,
180 $callback
181 );
182 }
183 }
184 }
185}
static callback($code, $callback)
Definition base.php:168