Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workflowentity.php
1<?php
2
4
6
7final class WorkflowEntity extends Entity
8{
9 const ENTITY_TYPE = 'wf';
10 const MODULE_ID = 'lists';
11 const XML_ID_PREFIX = 'WF_';
12
13 private $hasAccess;
14
15 protected static $permissions = array();
16
21 public function canRead($userId)
22 {
23 // you are not allowed to view the task, so you can not read messages
24 if(!$this->checkHasAccess($userId))
25 {
26 return false;
27 }
28
29 return true;
30 }
35 public function canAdd($userId)
36 {
37 // you are not allowed to view the task, so you can not add new messages
38 if(!$this->checkHasAccess($userId))
39 {
40 return false;
41 }
42
43 return true;
44 }
45
50 public function canEdit($userId)
51 {
52 global $USER;
53 if(
54 $USER->isAdmin()
55 || $USER->canDoOperation('bitrix24_config')
56 )
57 {
58 return true;
59 }
60
61 return false;
62 }
63
68 private function checkHasAccess($userId)
69 {
70 global $USER;
71
72 if($this->hasAccess === null)
73 {
74 if (Loader::includeModule("bizproc"))
75 {
76 if(
77 $USER->isAdmin()
78 || $USER->canDoOperation('bitrix24_config')
79 )
80 {
81 $this->hasAccess = true;
82 }
83 else
84 {
85 $workflowId = false;
86 $workflowIntegerId = intval($this->getId());
87 if ($workflowIntegerId > 0)
88 {
89 $workflowId = \CBPStateService::getWorkflowByIntegerId($workflowIntegerId);
90 }
91
92 if ($workflowId)
93 {
94 $currentUserId = (int) $USER->getId();
95 $participants = \CBPTaskService::getWorkflowParticipants($workflowId);
96 if (in_array($currentUserId, $participants))
97 {
98 $this->hasAccess = true;
99 }
100 else
101 {
102 $state = \CBPStateService::getWorkflowStateInfo($workflowId);
103 $this->hasAccess = (
104 $state
105 && $currentUserId === (int) $state['STARTED_BY']
106 );
107 }
108 }
109 else
110 {
111 $this->hasAccess = false;
112 }
113
114 if (!$this->hasAccess && Loader::includeModule("iblock"))
115 {
116 $documentId = \CBPStateService::GetStateDocumentId($workflowId);
117 $elementQuery = \CIBlockElement::getList(
118 array(), array("ID" => $documentId[2]), false, false, array("IBLOCK_ID"));
119 $element = $elementQuery->fetch();
120 if ($element['IBLOCK_ID'])
121 {
122 $this->hasAccess = \CIBlockElementRights::userHasRightTo(
123 $element["IBLOCK_ID"], $documentId[2], "element_read");
124 }
125 }
126 }
127 }
128 else
129 {
130 $this->hasAccess = false;
131 }
132 }
133
134 return $this->hasAccess;
135 }
136}