1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
DocumentTypeUserOptionTable.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Bizproc\DocumentType
;
4
5
use
Bitrix\Main\Error
;
6
use
Bitrix\Main\ORM
;
7
use
Bitrix\Main\ORM\Data\DataManager
;
8
use
Bitrix\Main\Result
;
9
use CBPHelper;
10
14
class
DocumentTypeUserOptionTable
extends
DataManager
15
{
16
public
const
PINNED
= 1;
17
18
public
const
PARAMETER_ERROR
= 1;
19
public
const
ADDING_ERROR
= 2;
20
public
const
DELETING_ERROR
= 3;
21
22
public
static
function
getTableName
(): string
23
{
24
return
'b_bp_document_type_user_option'
;
25
}
26
27
public
static
function
getMap
():
array
28
{
29
return
[
30
(
new
ORM\Fields\IntegerField
(
'ID'
))
31
->configurePrimary()
32
->configureAutocomplete()
33
,
34
(
new
ORM\Fields\StringField
(
'MODULE_ID'
))
35
->configureRequired()
36
,
37
(
new
ORM\Fields\StringField
(
'ENTITY'
))
38
->configureRequired()
39
,
40
(
new
ORM\Fields\StringField
(
'DOCUMENT_TYPE'
))
41
->configureRequired()
42
,
43
(
new
ORM\Fields\IntegerField
(
'USER_ID'
))
44
->configureRequired()
45
,
46
(
new
ORM\Fields\IntegerField
(
'OPTION_CODE'
))
47
->configureRequired()
48
,
49
];
50
}
51
52
public
static
function
isOption
(
int
$option
): bool
53
{
54
return
in_array(
$option
, [self::PINNED],
true
);
55
}
56
57
public
static
function
addOption
(
array
$documentType,
int
$userId
,
int
$option
):
Result
58
{
59
$addResult =
new
Result
();
60
[
$moduleId
,
$entity
, $documentType] = CBPHelper::ParseDocumentId($documentType);
61
62
if
(empty(
$moduleId
) || empty(
$entity
) || empty($documentType) ||
$userId
<= 0 || !static::isOption(
$option
))
63
{
64
$addResult->addError(
new
Error
(
'Some parameter is wrong.'
, self::PARAMETER_ERROR));
65
return
$addResult;
66
}
67
68
$data
= [
69
'MODULE_ID'
=>
$moduleId
,
70
'ENTITY'
=>
$entity
,
71
'DOCUMENT_TYPE'
=> $documentType,
72
'USER_ID'
=>
$userId
,
73
'OPTION_CODE'
=>
$option
,
74
];
75
76
$item =
self::getList
([
77
'select'
=> [
'ID'
],
78
'filter'
=> [
79
'=MODULE_ID'
=>
$moduleId
,
80
'=ENTITY'
=>
$entity
,
81
'=DOCUMENT_TYPE'
=> $documentType,
82
'=USER_ID'
=>
$userId
,
83
'=OPTION_CODE'
=>
$option
,
84
],
85
])->fetch();
86
87
if
(!$item)
88
{
89
$tableAddResult =
self::add
(
$data
);
90
if
(!$tableAddResult->isSuccess())
91
{
92
$addResult->addError(
new
Error
(
'Adding to table failed.'
, self::ADDING_ERROR));
93
94
return
$addResult;
95
}
96
97
return
$addResult;
98
}
99
100
return
$addResult;
101
}
102
103
public
static
function
deleteOption
(
array
$documentType,
int
$userId
,
int
$option
):
Result
104
{
105
$deleteResult =
new
Result
();
106
107
[
$moduleId
,
$entity
, $documentType] = CBPHelper::ParseDocumentId($documentType);
108
109
if
(empty(
$moduleId
) || empty(
$entity
) || empty($documentType) ||
$userId
<= 0 || !static::isOption(
$option
))
110
{
111
$deleteResult->addError(
new
Error
(
'Some parameter is wrong.'
, self::PARAMETER_ERROR));
112
113
return
$deleteResult;
114
}
115
116
$item =
self::getList
([
117
'select'
=> [
'ID'
],
118
'filter'
=> [
119
'=MODULE_ID'
=>
$moduleId
,
120
'=ENTITY'
=>
$entity
,
121
'=DOCUMENT_TYPE'
=> $documentType,
122
'=USER_ID'
=>
$userId
,
123
'=OPTION_CODE'
=>
$option
,
124
],
125
])->fetch();
126
127
if
($item)
128
{
129
$tableDeleteResult =
self::delete
($item);
130
if
(!$tableDeleteResult->isSuccess())
131
{
132
$deleteResult->addError(
new
Error
(
'Deleting from table failed.'
, self::DELETING_ERROR));
133
134
return
$deleteResult;
135
}
136
}
137
138
return
$deleteResult;
139
}
140
}
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable
Определения
DocumentTypeUserOptionTable.php:15
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\getMap
static getMap()
Определения
DocumentTypeUserOptionTable.php:27
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\addOption
static addOption(array $documentType, int $userId, int $option)
Определения
DocumentTypeUserOptionTable.php:57
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\PINNED
const PINNED
Определения
DocumentTypeUserOptionTable.php:16
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\ADDING_ERROR
const ADDING_ERROR
Определения
DocumentTypeUserOptionTable.php:19
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\deleteOption
static deleteOption(array $documentType, int $userId, int $option)
Определения
DocumentTypeUserOptionTable.php:103
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\isOption
static isOption(int $option)
Определения
DocumentTypeUserOptionTable.php:52
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\DELETING_ERROR
const DELETING_ERROR
Определения
DocumentTypeUserOptionTable.php:20
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\PARAMETER_ERROR
const PARAMETER_ERROR
Определения
DocumentTypeUserOptionTable.php:18
Bitrix\Bizproc\DocumentType\DocumentTypeUserOptionTable\getTableName
static getTableName()
Определения
DocumentTypeUserOptionTable.php:22
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\ORM\Data\DataManager
Определения
datamanager.php:35
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
Bitrix\Main\ORM\Data\DataManager\$entity
static $entity
Определения
datamanager.php:47
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Определения
datamanager.php:1644
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Определения
datamanager.php:877
Bitrix\Main\ORM\Data\Result
Определения
result.php:16
Bitrix\Main\ORM\Fields\IntegerField
Определения
integerfield.php:20
Bitrix\Main\ORM\Fields\StringField
Определения
stringfield.php:20
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$moduleId
$moduleId
Определения
group_bizproc_workflow_delete.php:16
Bitrix\Bizproc\DocumentType
Определения
DocumentTypeUserOptionTable.php:3
Bitrix\Main\ORM
$option
$option
Определения
options.php:1711
bitrix
modules
bizproc
lib
DocumentType
DocumentTypeUserOptionTable.php
Создано системой
1.14.0