1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ConditionRepository.php
См. документацию.
1<?php
2
4
12
14{
15 private readonly ValidationService $validation;
16
17 public function __construct()
18 {
19 $this->validation = ServiceLocator::getInstance()->get('main.validation.service');
20 }
21
22 public function add(ConditionDto $conditionDto): ConditionCreateResult
23 {
24 $result = $this->validation->validate($conditionDto);
25 if (!$result->isSuccess())
26 {
27 return (new ConditionCreateResult())->addErrors($result->getErrors());
28 }
29
31 ->setGroupId($conditionDto->groupId)
32 ->setModule($conditionDto->module)
33 ->setEvent($conditionDto->event)
34 ->setUserId($conditionDto->userId)
35 ->save()
36 ;
37
38 if ($result->isSuccess())
39 {
40 return new ConditionCreateResult($result->getId());
41 }
42
44 }
45
46 public function deleteByGroupId(int $groupId): void
47 {
48 NotifyGroupConditionTable::deleteByFilter([
49 NotifyGroupConditionTable::FIELD_GROUP_ID => $groupId,
50 ]);
51
52 $this->deleteGroupIfEmpty($groupId);
53 }
54
55 public function deleteByDto(ConditionDto $conditionDto): void
56 {
57 NotifyGroupConditionTable::deleteByFilter([
58 NotifyGroupConditionTable::FIELD_GROUP_ID => $conditionDto->groupId,
59 NotifyGroupConditionTable::FIELD_MODULE => $conditionDto->module,
60 NotifyGroupConditionTable::FIELD_EVENT => $conditionDto->event,
61 NotifyGroupConditionTable::FIELD_USER_ID => $conditionDto->userId,
62 ]);
63
64 $this->deleteGroupIfEmpty($conditionDto->groupId);
65 }
66
67 private function deleteGroupIfEmpty(int $groupId): void
68 {
69 if (!$this->isExistsByGroupId($groupId))
70 {
71 (new GroupRepository())->deleteById($groupId, false);
72 }
73 }
74
75 private function isExistsByGroupId(int $groupId): bool
76 {
77 $row = NotifyGroupConditionTable::query()
78 ->where(NotifyGroupConditionTable::FIELD_GROUP_ID, $groupId)
79 ->setSelect([NotifyGroupConditionTable::FIELD_ID])
80 ->setLimit(1)
81 ->fetch()
82 ;
83
84 return !empty($row);
85 }
86}
$result
Определения get_property_values.php:14