Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dashboard.php
1<?php
2
4
5use Bitrix\Main\Entity\Query;
10
18class Dashboard extends Model
19{
20 protected $gId;
21 protected $boardKey;
22 protected $userId;
23
27 protected $version = '';
28
32 protected $rows;
33
37 public static function getTableClassName()
38 {
40 }
41
48 public static function getMapAttributes()
49 {
50 $attributes = parent::getMapAttributes();
51 $attributes['GID'] = 'gId';
52 $attributes['BOARD_KEY'] = 'boardKey';
53 $attributes['USER_ID'] = 'userId';
54 $attributes['VERSION'] = 'version';
55 return $attributes;
56 }
57
63 public static function getMapReferenceAttributes()
64 {
65 return array(
66 'rows' => array(
67 'type' => Common::ONE_TO_MANY,
68 'targetEntity' => DashboardRow::getClassName(),
69 'mappedBy' => 'dashboard'
70 ),
71 );
72 }
73
82 {
83 $with = array('rows', 'rows.widgets', 'rows.widgets.configurations');
84 $filter = Query::filter();
85 $filter->where('BOARD_KEY', $boardKey);
86 $filter->logic('and');
87 $filter->where('USER_ID', $userId);
88 $order = array('\Bitrix\Report\VisualConstructor\Internal\DashboardRow:DASHBOARD.WEIGHT' => 'ASC');
89 $board = static::load($filter, $with, $order);
90 return $board;
91 }
92
101 public static function getDefaultBoardWithEverythingByBoardKey($boardKey, $createIfNotExist = true)
102 {
103 $with = array('rows', 'rows.widgets', 'rows.widgets.configurations', 'rows.widgets.reports', 'rows.widgets.reports.configurations');
104 $filter = Query::filter();
105 $filter->where('BOARD_KEY', $boardKey);
106 $filter->logic('and');
107 $filter->where('USER_ID', 0);
108 $order = array('\Bitrix\Report\VisualConstructor\Internal\DashboardRow:DASHBOARD.WEIGHT' => 'ASC');
109 $board = static::load($filter, $with, $order);
110
111 if (!$board && $createIfNotExist)
112 {
113 $board = new Dashboard();
114 $board->setGId(Util::generateUserUniqueId());
115 $board->setBoardKey($boardKey);
116 $board->setUserId(0);
117 $board->save();
118 }
119
120 return $board;
121 }
122
129 public static function getDefaultBoardByBoardKey($boardKey)
130 {
131 $filter = Query::filter();
132 $filter->where('BOARD_KEY', $boardKey);
133 $filter->logic('and');
134 $filter->where('USER_ID', 0);
135 return static::load($filter);
136 }
137
144 public static function getCurrentUserBoardWithEverythingByBoardKey($boardKey)
145 {
147 global $USER;
148
149 $userId = $USER->getId();
150
151 $with = array('rows', 'rows.widgets', 'rows.widgets.configurations', 'rows.widgets.reports', 'rows.widgets.reports.configurations');
152 $filter = Query::filter();
153 $filter->where('BOARD_KEY', $boardKey);
154 $filter->logic('and');
155 $filter->where('USER_ID', $userId);
156 $order = array('\Bitrix\Report\VisualConstructor\Internal\DashboardRow:DASHBOARD.WEIGHT' => 'ASC');
157 $board = static::load($filter, $with, $order);
158 return $board;
159 }
160
166 public function getRows()
167 {
168 return $this->rows;
169 }
170
177 public function getCopyForCurrentUser()
178 {
179 global $USER;
180
181 $coreBoard = clone $this;
182 $copyBoard = new Dashboard();
183 $copyBoard->setBoardKey($coreBoard->getBoardKey());
184 $copyBoard->setUserId($USER->getID());
185 $copyBoard->setGId($coreBoard->getGId());
186 $rows = $coreBoard->getRows();
187 if (is_array($rows))
188 {
189 foreach ($rows as $row)
190 {
191 $copyBoard->addRows($row->getCopyForCurrentUser());
192 }
193 }
194
195
196 return $copyBoard;
197 }
198
202 public function getBoardKey()
203 {
204 return $this->boardKey;
205 }
206
212 public function setBoardKey($boardKey)
213 {
214 $this->boardKey = $boardKey;
215 }
216
220 public function getUserId()
221 {
222 return $this->userId;
223 }
224
231 public function setUserId($userId)
232 {
233 $this->userId = $userId;
234 }
235
244 {
245 return static::load(array(
246 '=BOARD_KEY' => $boardKey,
247 '=USER_ID' => $userId
248 ));
249 }
250
257 public static function loadByBoardKeyMultiple($boardKey)
258 {
259 $filter = Query::filter();
260 $filter->where('BOARD_KEY', $boardKey);
261 return static::getModelList(array(
262 'filter' => $filter
263 ));
264 }
265
269 public function getGId()
270 {
271 return $this->gId;
272 }
273
280 public function setGId($gId)
281 {
282 $this->gId = $gId;
283 }
284
290 public function getVersion()
291 {
292 return $this->version;
293 }
294
301 public function setVersion($version)
302 {
303 $this->version = $version;
304 }
305
306}
static loadByBoardKeyAndUserId($boardKey, $userId)
static getBoardWithRowsAndWidgetsByBoardKeyUserId($boardKey, $userId)
Definition dashboard.php:81
static getDefaultBoardWithEverythingByBoardKey($boardKey, $createIfNotExist=true)