-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrm_relations.php
82 lines (68 loc) · 2.31 KB
/
crm_relations.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
<?php
class crm_relations extends \WS\ReduceMigrations\Scenario\ScriptScenario {
static public function name() {
return "Crm relations";
}
static public function priority() {
return self::PRIORITY_HIGH;
}
static public function hash() {
return "2de829a0b13ec71e37c6ea0f4cf7c53df608c292";
}
static public function approximatelyTime() {
return 90;
}
public function commit() {
self::setRelations();
}
public function rollback() {
// my code
}
static function setRelations(){
if(\Bitrix\Main\Loader::includeModule('crm') && \Bitrix\Main\Loader::includeModule('main')){
$dbCCrmRole = \CCrmRole::GetList(
[],
[]
);
$arAllRoles = [];
while($res = $dbCCrmRole->Fetch()){
$code = str_replace(" ", "_", $res['NAME']);
$arAllRoles[$code] = $res['ID'];
}
if(count($arAllRoles) > 0){
$dbGroupTable = \Bitrix\Main\GroupTable::getList([
'filter'=>[
'STRING_ID'=>[
'ADMINISTRATORS',
]
],
'select'=>[
'ID',
'NAME',
'STRING_ID'
],
]);
$arPerms = [];
while($resGroup = $dbGroupTable->fetch()){
if($resGroup['NAME'] == 'Administrators'){
$arPerms['G'.$resGroup['ID']] = [
$arAllRoles['Full_access']
];
}
if($resGroup['NAME'] == 'AdministratorsCS'){
$arPerms['G'.$resGroup['ID']] = [
$arAllRoles['Subdepartments']
];
}
}
$CCrmRole = new \CcrmRole();
$CCrmRole->SetRelation($arPerms);
if (IsModuleInstalled("bitrix24")){
\CCrmSaleHelper::deleteAllUserFromShopGroup();
$cache = new \CPHPCache;
$cache->CleanDir("/crm/list_crm_roles/");
}
}
}
}
}