1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
DocumentTypeUserOptionTable.php
См. документацию.
1<?php
2
4
9use CBPHelper;
10
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}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static addOption(array $documentType, int $userId, int $option)
Определения DocumentTypeUserOptionTable.php:57
static deleteOption(array $documentType, int $userId, int $option)
Определения error.php:15
static getList(array $parameters=array())
Определения datamanager.php:431
static delete($primary)
Определения datamanager.php:1644
static add(array $data)
Определения datamanager.php:877
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$moduleId
$option
Определения options.php:1711