Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
TasksToBeDelegated.php
1<?php
2
4
8
10{
11 private array $taskIds;
12 private int $fromUserId;
13 private int $toUserId;
14 private int $currentUserId;
15
16 private function __construct(
17 array $taskIds,
18 int $fromUserId,
19 int $toUserId,
20 int $currentUserId
21 )
22 {
23 $this->taskIds = $taskIds;
24 $this->fromUserId = $fromUserId;
25 $this->toUserId = $toUserId;
26 $this->currentUserId = $currentUserId;
27 }
28
33 public static function createFromRequest(DelegateTasksRequest $request): self
34 {
35 $taskIds = self::validateTaskIds($request->taskIds);
36 if (!$taskIds)
37 {
38 throw new ArgumentException('taskIds');
39 }
40
41 $fromUserId = self::validateUserId($request->fromUserId);
42 if (!$fromUserId)
43 {
44 throw new ArgumentOutOfRangeException('fromUserId', 1, null);
45 }
46
47 $toUserId = self::validateUserId($request->toUserId);
48 if (!$toUserId)
49 {
50 throw new ArgumentOutOfRangeException('toUserId', 1, null);
51 }
52
53 $currentUserId = self::validateUserId($request->currentUserId);
54
55 return new self($taskIds, $fromUserId, $toUserId, $currentUserId);
56 }
57
62 private static function validateTaskIds(array $taskIds): array
63 {
64 $ids = [];
65 foreach ($taskIds as $taskId)
66 {
67 if (is_numeric($taskId))
68 {
69 $taskId = (int)$taskId;
70 $ids[$taskId] = $taskId;
71 }
72 }
73
74 return $ids ? array_keys($ids) : [];
75 }
76
81 private static function validateUserId(int $userId): int
82 {
83 return max($userId, 0);
84 }
85
89 public function getTaskIds(): array
90 {
91 return $this->taskIds;
92 }
93
97 public function getFromUserId(): int
98 {
99 return $this->fromUserId;
100 }
101
105 public function getToUserId(): int
106 {
107 return $this->toUserId;
108 }
109
113 public function getCurrentUserId(): int
114 {
115 return $this->currentUserId;
116 }
117}
static createFromRequest(DelegateTasksRequest $request)