Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
row.php
1<?php
3
8
13class Row extends Base
14{
21 public function addAction($params)
22 {
23 $dashboardForUser = DashboardHelper::getDashboardByKeyForCurrentUser($params['boardKey']);
24 if ($dashboardForUser)
25 {
26 $row = new DashboardRow();
27 $row->setLayoutMap($params['layoutMap']);
28 $row->setGId(Util::generateUserUniqueId());
29 $row->setBoardId($params['boardId']);
30 $row->setWeight(0);
31 $dashboardForUser->addRows($row);
32 $dashboardForUser->save();
33 return array('id' => $row->getGId());
34 }
35 else
36 {
37 $this->adderror(new Error('No dashboard for current user'));
38 return false;
39 }
40 }
41
49 public function adjustWeightsAction($boardKey, $rows)
50 {
51 $dashboardForUser = DashboardHelper::getDashboardByKeyForCurrentUser($boardKey);
52 if ($dashboardForUser)
53 {
54 $dashboardForUser->loadAttribute('rows');
55 $savedRows = $dashboardForUser->getRows();
56 if ($savedRows)
57 {
58 foreach ($savedRows as $row)
59 {
60 if (isset($rows[$row->getGId()]))
61 {
62 $row->setWeight($rows[$row->getGId()]['weight']);
63 }
64 }
65 }
66
67
68 $dashboardForUser->save();
69 return true;
70 }
71 else
72 {
73 $this->adderror(new Error('No dashboard for current user'));
74 return false;
75 }
76 }
77
84 public function deleteAction($params)
85 {
86 $boardKey = $params['boardId'];
87 $rowId = $params['rowId'];
88 $dashboardForUser = DashboardHelper::getDashboardByKeyForCurrentUser($boardKey);
89 if ($dashboardForUser)
90 {
91 $row = DashboardRow::getCurrentUserRowByGId($rowId);
92 if ($row)
93 {
94 return $row->delete();
95 }
96 else
97 {
98 $this->adderror(new Error('No Row with this id'));
99 return false;
100 }
101 }
102 else
103 {
104 $this->adderror(new Error('No dashboard for current user'));
105 return false;
106 }
107 }
108}