Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
event.php
1<?php
9
15
32class EventTable extends Entity\DataManager
33{
37 public static function getTableName()
38 {
39 return 'b_event';
40 }
41
45 public static function getMap()
46 {
47 return array(
48 'ID' => array(
49 'data_type' => 'integer',
50 'primary' => true,
51 'autocomplete' => true,
52 ),
53 'EVENT_NAME' => array(
54 'data_type' => 'string',
55 'required' => true,
56 ),
57 'MESSAGE_ID' => array(
58 'data_type' => 'integer',
59 ),
60 'LID' => array(
61 'data_type' => 'string',
62 'required' => true,
63 ),
64
65 (new ArrayField('C_FIELDS'))
66 ->configureSerializeCallback(function ($value){
67 return EventTable::serialize($value);
68 })
69 ->configureUnserializeCallback(function ($str) {
70 return unserialize(
72 ['allowed_classes' => false]
73 );
74 }),
75
76 'DATE_INSERT' => array(
77 'data_type' => 'datetime',
78 'default_value' => function(){return new Type\DateTime();},
79 ),
80 'DATE_EXEC' => array(
81 'data_type' => 'datetime',
82 ),
83 'SUCCESS_EXEC' => array(
84 'data_type' => 'string',
85 ),
86 'DUPLICATE' => array(
87 'data_type' => 'string',
88 ),
89 'LANGUAGE_ID' => array(
90 'data_type' => 'string',
91 ),
92 );
93 }
94
98 public static function getSaveModificatorsForFieldsField()
99 {
100 return array(
101 array(__CLASS__, "serialize")
102 );
103 }
104
108 public static function getFetchModificatorsForFieldsField()
109 {
110 return array(
111 array(__CLASS__, "getFetchModificationForFieldsField"),
112 array(new Entity\StringField('FIELDS', array()), "unserialize")
113 );
114 }
115
116 public static function serialize($fields)
117 {
118 if(!is_array($fields))
119 {
120 $fields = array();
121 }
122
123 array_walk_recursive($fields, array(__CLASS__, 'replaceValuesBeforeSerialize'));
124
125 if(!is_array($fields))
126 {
127 $fields = array();
128 }
129
130 return serialize($fields);
131 }
132
133 protected static function replaceValuesBeforeSerialize(&$item)
134 {
135 if(is_object($item))
136 {
137 if(method_exists($item, '__toString'))
138 $item = (string) $item;
139 else
140 $item = '';
141 }
142 }
143
148 protected static function isFieldSerialized($str)
149 {
150 $str = trim($str);
151
152 if ($str == 'N;')
153 return true;
154
155 if ( !preg_match( '/^([abdiOs]):/', $str, $matches ) )
156 return false;
157
158 switch($matches[1])
159 {
160 case 'b':
161 case 'i':
162 case 'd':
163 if(preg_match( "/^".$matches[1].":[0-9.E-]+;\$/", $str))
164 return true;
165 break;
166
167 case 'a':
168 case 'O':
169 case 's':
170 if(preg_match( "/^".$matches[1].":[0-9]+:.*[;}]\$/s", $str))
171 return true;
172 break;
173 }
174
175 return false;
176 }
177
182 public static function getFetchModificationForFieldsField($str)
183 {
184 if(static::isFieldSerialized($str))
185 return $str;
186
187 $ar = explode("&", $str);
188 $newar = array();
189 foreach($ar as $val)
190 {
191 $val = str_replace("%1", "&", $val);
192 $tar = explode("=", $val);
193 $key = $tar[0];
194 $val = $tar[1];
195 $key = str_replace("%3", "=", $key);
196 $val = str_replace("%3", "=", $val);
197 $key = str_replace("%2", "%", $key);
198 $val = str_replace("%2", "%", $val);
199 if($key != "")
200 $newar[$key] = $val;
201 }
202
203 $field = new Entity\StringField('FIELDS', array());
204 return $field->serialize($newar);
205 }
206}
static replaceValuesBeforeSerialize(&$item)
Definition event.php:133
static getFetchModificationForFieldsField($str)
Definition event.php:182