-
Notifications
You must be signed in to change notification settings - Fork 2
/
addUfFieldEnumeration.php
96 lines (89 loc) · 2.54 KB
/
addUfFieldEnumeration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
class migration
{
private function getAddEnum()
{
$arAddEnum['n0'] = array(
'XML_ID' => "BBBB",
'VALUE' => "BBBB",
'DEF' => 'N',
'SORT' => 100
);
$arAddEnum['n1'] = array(
'XML_ID' => "VVVV",
'VALUE' => "VVVV",
'DEF' => 'N',
'SORT' => 200
);
return $arAddEnum;
}
private $arFields =
[
'ENTITY_ID' => 'CRM_CONTACT',
'FIELD_NAME' => 'UF_TYPE_PAT',
'USER_TYPE_ID' => 'enumeration',
'XML_ID' => 'UF_TYPE_PAT',
'SORT' => '100',
'MULTIPLE' => null,
'MANDATORY' => null,
'SHOW_FILTER' => 'N',
'SHOW_IN_LIST' => null,
'EDIT_IN_LIST' => null,
'IS_SEARCHABLE' => null,
'SETTINGS' => array(
'DEFAULT_VALUE' => ''
),
'EDIT_FORM_LABEL' => array(
'ru' => 'Тип',
),
'LIST_COLUMN_LABEL' => array(
'ru' => 'Тип',
),
'LIST_FILTER_LABEL' => array(
'ru' => 'Тип',
),
'ERROR_MESSAGE' => array(
'ru' => 'Тип',
),
'HELP_MESSAGE' => array(
'ru' => 'Тип',
),
];
private function getFieldId()
{
$arFields = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields("CRM_CONTACT");
if(array_key_exists( 'UF_TYPE_PAT', $arFields))
{
$fieldId = $arFields['UF_TYPE_PAT']["ID"];
}
return $fieldId;
}
/**
* Write action by apply scenario. Use method `setData` for save need rollback data
**/
public function commit()
{
$obEnum = new \CUserFieldEnum();
$obUserField = new \CUserTypeEntity;
$obUserField->Add($this->arFields);
$obEnum->SetEnumValues(
$this->getFieldId(),
$this->getAddEnum()
);
}
/**
* Write action by rollback scenario. Use method `getData` for getting commit saved data
**/
public function rollback()
{
$rsData = \CUserTypeEntity::GetList(
array($by => $order),
array('FIELD_NAME' => $this->arFields['FIELD_NAME'], 'ENTITY_ID' => $this->arFields['ENTITY_ID'])
);
if ($arRes = $rsData->Fetch())
{
$obCUserTypeEntity = new \CUserTypeEntity;
$obCUserTypeEntity->Delete($arRes['ID']);
}
}
}