Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
taskentity.php
1<?php
2
4
7
8final class TaskEntity extends Entity
9{
10 public const ENTITY_TYPE = 'tk';
11 const MODULE_ID = 'tasks';
12 public const XML_ID_PREFIX = 'TASK_';
13
14 private $taskPostData;
15 private $hasAccess;
16
17 protected static $permissions = array();
18
23 public function canRead($userId)
24 {
25 // you are not allowed to view the task, so you can not read messages
26 if(!$this->checkHasAccess($userId))
27 {
28 return false;
29 }
30
31 return true;
32 }
37 public function canAdd($userId)
38 {
39 // you are not allowed to view the task, so you can not add new messages
40 if(!$this->checkHasAccess($userId))
41 {
42 return false;
43 }
44
45 return true;
46 }
47
52 public function canEditOwn($userId)
53 {
55 // in case of canEdit($userId) returns FALSE, canEditOwn($userId) may override this
56
57 // if you are not an admin, you must obey "tasks" module settings
58 if(!static::checkEditOptionIsOn())
59 {
60 return false;
61 }
62
63 // if you are not an admin AND you are not allowed to view the task, you cant edit even your own comments
64 if(!$this->checkHasAccess($userId))
65 {
66 return false;
67 }
68
69 return true;
70 }
71
76 public function canEdit($userId)
77 {
78 // admin is always able to edit\remove comments
79 if (
80 Loader::includeModule("tasks")
81 && (
82 \CTasksTools::isAdmin($userId)
83 || \CTasksTools::isPortalB24Admin($userId)
84 )
85 )
86 {
87 return true;
88 }
89
90 return false;
91 }
92
96 public function dropCache()
97 {
98 $this->taskPostData = null;
99 $this->hasAccess = null;
100 return $this;
101 }
102
107 private function checkHasAccess($userId)
108 {
109 if($this->hasAccess === null)
110 {
111 try
112 {
113 if (Loader::includeModule("tasks"))
114 {
115 $task = new \CTaskItem($this->getId(), $userId);
116 $this->hasAccess = $task->checkCanRead();
117 }
118 else
119 {
120 return false;
121 }
122
123 }
124 catch(\TasksException | \CTaskAssertException $e)
125 {
126 return false;
127 }
128 }
129
130 return $this->hasAccess;
131 }
132
133 private static function checkEditOptionIsOn()
134 {
135 $value = Option::get("tasks", "task_comment_allow_edit");
136
137 return $value == 'Y' || $value == '1';
138 }
139
147 public static function onMessageIsIndexed($id, array $message, array &$index)
148 {
149 if ($message["PARAM1"] == mb_strtoupper(self::ENTITY_TYPE))
150 {
151 return false;
152 }
153
154 if (
155 preg_match("/".self::getXmlIdPrefix()."(\\d+)/", $message["XML_ID"], $matches) &&
156 ($taskId = intval($matches[1])) &&
157 $taskId > 0 &&
158 !array_key_exists($taskId, self::$permissions)
159 )
160 {
161 self::$permissions[$taskId] = [];
162 if ($task = \CTasks::GetList(array(), array("ID" => $taskId))->fetch())
163 {
164 self::$permissions[$taskId] = \CTasks::__GetSearchPermissions($task);
165 }
166 }
167
168 $index["PERMISSIONS"] = self::$permissions[$taskId];
169 return sizeof(self::$permissions[$taskId]) > 0;
170 }
171}
static onMessageIsIndexed($id, array $message, array &$index)