1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
workflowtemplateuseroptiontable.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Workflow\Template;
4
5use Bitrix\Main\Error;
6use Bitrix\Main\ORM;
7use Bitrix\Main\ORM\Data\DataManager;
8use Bitrix\Main\Result;
9
27{
28 public const PINNED = 1;
29
30 public static function getTableName(): string
31 {
32 return 'b_bp_workflow_template_user_option';
33 }
34
35 public static function getMap(): array
36 {
37 return [
38 (new ORM\Fields\IntegerField('ID'))
39 ->configurePrimary()
40 ->configureAutocomplete()
41 ,
42 (new ORM\Fields\IntegerField('TEMPLATE_ID'))
43 ->configureRequired()
44 ,
45 (new ORM\Fields\IntegerField('USER_ID'))
46 ->configureRequired()
47 ,
48 (new ORM\Fields\IntegerField('OPTION_CODE'))
49 ->configureRequired()
50 ,
52 'TEMPLATE',
53 Entity\WorkflowTemplateTable::class,
54 ORM\Query\Join::on('this.TEMPLATE_ID', 'ref.ID')
55 ),
56 ];
57 }
58
59 public static function isOption(int $option): bool
60 {
61 return in_array($option, [self::PINNED], true);
62 }
63
64 public static function addOption(int $templateId, int $userId, int $option): Result
65 {
66 $addResult = new Result();
67
68 if ($templateId <= 0 || $userId <= 0 || !static::isOption($option))
69 {
70 $addResult->addError(new Error('Some parameter is wrong.', 1));
71 return $addResult;
72 }
73
74 $data = [
75 'TEMPLATE_ID' => $templateId,
76 'USER_ID' => $userId,
77 'OPTION_CODE' => $option,
78 ];
79
80 $item = self::getList([
81 'select' => ['ID'],
82 'filter' => $data,
83 ])->fetch();
84
85 if (!$item)
86 {
87 $tableAddResult = self::add($data);
88 if (!$tableAddResult->isSuccess())
89 {
90 $addResult->addError(new Error('Adding to table failed.', 2));
91 return $addResult;
92 }
93
94 return $addResult;
95 }
96
97 return $addResult;
98 }
99
100 public static function deleteOption(int $templateId, int $userId, int $option): Result
101 {
102 $deleteResult = new Result();
103
104 if ($templateId <= 0 || $userId <= 0 || !static::isOption($option))
105 {
106 $deleteResult->addError(new Error('Some parameter is wrong.', 1));
107 return $deleteResult;
108 }
109
110 $item = self::getList([
111 'select' => ['ID'],
112 'filter' => [
113 'TEMPLATE_ID' => $templateId,
114 'USER_ID' => $userId,
115 'OPTION_CODE' => $option,
116 ],
117 ])->fetch();
118
119 if ($item)
120 {
121 $tableDeleteResult = self::delete($item);
122 if (!$tableDeleteResult->isSuccess())
123 {
124 $deleteResult->addError(new Error('Deleting from table failed.', 2));
125
126 return $deleteResult;
127 }
128 }
129
130 return $deleteResult;
131 }
132}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static deleteOption(int $templateId, int $userId, int $option)
static addOption(int $templateId, 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
$templateId
Определения component_props2.php:51
$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
Определения ufield.php:9
Определения chain.php:3
$option
Определения options.php:1711