44 $list = Entity\Segment::getList(array(
45 'select' => array(
'ID'),
53 return ($list->fetch()) ? true :
false;
64 Loader::includeModule(
'crm');
65 foreach ($this->getSegments() as $data)
67 if ($this->getInstalledSegment($data[
'CODE']))
72 $data[
'IS_SYSTEM'] =
'Y';
77 $segment->mergeData($data)->save();
100 $segments = Entity\Segment::getList(array(
101 'select' => array(
'ID'),
103 '=IS_SYSTEM' =>
true,
107 foreach ($segments as $segment)
120 private function getSegments()
122 $endpointsAll = array();
128 if (empty($data[
'sender_segment_name']))
133 $segmentCode = $code;
134 if (!empty($data[
'sender_segment_business_case']))
136 $segmentCode =
"case_" . $segmentCode;
139 $fields = $data[
'fields'];
140 $fields[
'BX_PRESET_ID'] = $code;
143 'CODE' => $segmentCode,
144 'NAME' => $data[
'sender_segment_name'],
146 'ENDPOINTS' => array(
148 'MODULE_ID' =>
'sender',
150 'FIELDS' => self::convertPresetFields($fields)
156 if ($item[
'CODE'] ===
'crm_lead_all')
158 $endpointsAll = array_merge($endpointsAll, $item[
'ENDPOINTS']);
166 if (empty($data[
'sender_segment_name']))
171 $segmentCode = $code;
172 if (!empty($data[
'sender_segment_business_case']))
174 $segmentCode =
"case_" . $segmentCode;
177 $fields = $data[
'fields'];
178 $fields[
'BX_PRESET_ID'] = $code;
181 'CODE' => $segmentCode,
182 'NAME' => $data[
'sender_segment_name'],
184 'ENDPOINTS' => array(
186 'MODULE_ID' =>
'sender',
188 'FIELDS' => self::convertPresetFields($fields)
194 if ($item[
'CODE'] ===
'crm_client_all')
196 $endpointsAll = array_merge($endpointsAll, $item[
'ENDPOINTS']);
200 if (count($endpointsAll) > 1)
204 'NAME' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_PRESET_SEGMENT_ALL'),
206 'ENDPOINTS' => $endpointsAll
213 private static function convertPresetFields($fields)
215 if (!is_array($fields))
220 $codes = [
'allow_year',
'datesel',
'from',
'to',
'days'];
222 foreach ($fields as $key => $value)
225 foreach ($codes as $code)
228 if (mb_substr($key, -mb_strlen($code)) == $code)
230 $baseKey = mb_substr($key, 0, -mb_strlen($code));
237 if (empty($result[$baseKey]))
239 $result[$baseKey] = [];
242 $result[$baseKey][$key] = $value;
246 $result[$key] = $value;
253 private function getInstalledSegment($code =
null)
256 '=IS_SYSTEM' =>
true,
260 $filter[
'=CODE'] = $code;
264 $filter[
'CODE'] =
'crm_%';
267 $list = Entity\Segment::getList(array(
268 'select' => array(
'ID'),
272 if ($segment = $list->fetch())
274 return $segment[
'ID'];
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)