-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddNewEnumItemForUf.php
64 lines (53 loc) · 1.55 KB
/
addNewEnumItemForUf.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
<?php
class addNewEnumItem extends AbstractMigration
{
private $userFieldXmlId = 'UF_LIST_DEAL';
private function getFieldId()
{
$arFields = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields("CRM_DEAL");
if(array_key_exists( $this->userFieldXmlId, $arFields))
{
$fieldId = $arFields[$this->userFieldXmlId]["ID"];
}
return $fieldId;
}
private function getAddEnum()
{
$i = 4;
$arAddEnum['n'.$i] = array(
'XML_ID' => "NEW_ITEM_VALUE_XML_ID",//xml_id
'VALUE' => "Новое значения в списке",//значение
'DEF' => 'N',//по умолчанию
'SORT' => 500//сортировка
);
return $arAddEnum;
}
public function commit()
{
$obEnum = new \CUserFieldEnum();
$obEnum->SetEnumValues(
$this->getFieldId(),
$this->getAddEnum()
);
}
public function rollback()
{
// удалим значение из списка
$rsEnum = \CUserFieldEnum::GetList(array(), array(
"USER_FIELD_ID"=>$this->getFieldId(),
'XML_ID' => "NEW_ITEM_VALUE_XML_ID",
));
if($arEnum = $rsEnum->Fetch())
{
$obEnum = new \CUserFieldEnum;
$obEnum->SetEnumValues(
$this->getFieldId(),
array(
$arEnum["ID"] => array(
"DEL" => "Y",
),
)
);
}
}
}