-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php
More file actions
189 lines (165 loc) · 5.47 KB
/
controller.php
File metadata and controls
189 lines (165 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
namespace Plugin\Poker;
class Controller extends \Controller {
public function index(\Base $f3) {
$user_id = $this->_requireLogin();
$filter = "";
if($f3->get("GET.group_id")) {
$group = new \Model\User\Group();
$users = $group->find(array("group_id = ?", $f3->get("GET.group_id")));
$filter_users = array();
foreach($users as $u) {
$filter_users[] = $u["user_id"];
}
$filter = "AND owner_id IN (" . implode(",", $filter_users) . ")";
}
$issue = new \Model\Issue\Detail();
$large_projects = $f3->get("db.instance")->exec("SELECT DISTINCT parent_id FROM issue WHERE parent_id IS NOT NULL AND type_id = ?", $f3->get("issue_type.project"));
$large_project_ids = array();
foreach($large_projects as $p) {
$large_project_ids[] = $p["parent_id"];
}
// Load backlog
if($large_project_ids) {
$large_project_ids = implode(",", $large_project_ids);
$projects = $issue->find(
array("deleted_date IS NULL AND sprint_id IS NULL AND type_id = ? AND status_closed = '0' AND id NOT IN ({$large_project_ids}) $filter", $f3->get("issue_type.project")),
array('order' => 'priority DESC, due_date')
);
} else {
$projects = $issue->find(
array("deleted_date IS NULL AND sprint_id IS NULL AND type_id = ? AND status_closed = '0' $filter", $f3->get("issue_type.project")),
array('order' => 'priority DESC, due_date')
);
}
if($f3->get("GET.group_id")) {
// Add sorted projects
$backlog = array();
$sortModel = new \Model\Issue\Backlog;
$sortModel->load(array("user_id = ? AND sprint_id IS NULL", $f3->get("GET.group_id")));
$sortArray = array();
if($sortModel->id) {
$sortArray = json_decode($sortModel->issues);
foreach($sortArray as $id) {
foreach($projects as $p) {
if($p->id == $id) {
$backlog[] = $p;
}
}
}
}
// Add remaining projects
foreach($projects as $p) {
if(!in_array($p->id, $sortArray)) {
$backlog[] = $p;
}
}
// Set projects to sorted result
$projects = $backlog;
}
$f3->set("projects", $projects);
// Load existing votes
$vote = new Model\Vote;
$project_ids = array();
foreach($projects as $p) {
$project_ids[] = $p->id;
}
$votes = $vote->find(array("user_id = ? AND project_id IN (" . implode(",", $project_ids) . ")", $user_id));
$vote_array = array();
foreach($votes as $v) {
$vote_array[] = array(
"project_id" => $v->project_id,
"vote" => $v->vote
);
}
$f3->set("votes", $vote_array);
$f3->set("title", "Backlog Poker");
$this->_render("poker/view/index.html");
}
public function results(\Base $f3) {
$user_id = $this->_requireLogin();
$filter = "";
if($f3->get("GET.group_id")) {
$group = new \Model\User\Group();
$users = $group->find(array("group_id = ?", $f3->get("GET.group_id")));
foreach($users as $u) {
$filter_users[] = $u["user_id"];
}
$filter = "AND owner_id IN (" . implode(",", $filter_users) . ")";
}
$issue = new \Model\Issue\Detail();
$large_projects = $f3->get("db.instance")->exec("SELECT DISTINCT parent_id FROM issue WHERE parent_id IS NOT NULL AND type_id = ?", $f3->get("issue_type.project"));
$large_project_ids = array();
foreach($large_projects as $p) {
$large_project_ids[] = $p["parent_id"];
}
// Load backlog
if($large_project_ids) {
$large_project_ids = implode(",", $large_project_ids);
$projects = $issue->find(
array("deleted_date IS NULL AND sprint_id IS NULL AND type_id = ? AND status_closed = '0' AND id NOT IN ({$large_project_ids}) $filter", $f3->get("issue_type.project")),
array('order' => 'priority DESC, due_date')
);
} else {
$projects = $issue->find(
array("deleted_date IS NULL AND sprint_id IS NULL AND type_id = ? AND status_closed = '0' $filter", $f3->get("issue_type.project")),
array('order' => 'priority DESC, due_date')
);
}
if($f3->get("GET.group_id")) {
// Add sorted projects
$backlog = array();
$sortModel = new \Model\Issue\Backlog;
$sortModel->load(array("user_id = ? AND sprint_id IS NULL", $f3->get("GET.group_id")));
$sortArray = array();
if($sortModel->id) {
$sortArray = json_decode($sortModel->issues);
foreach($sortArray as $id) {
foreach($projects as $p) {
if($p->id == $id) {
$backlog[] = $p;
}
}
}
}
// Add remaining projects
foreach($projects as $p) {
if(!in_array($p->id, $sortArray)) {
$backlog[] = $p;
}
}
// Set projects to sorted result
$projects = $backlog;
}
$f3->set("projects", $projects);
// Load all votes
$vote = new Model\Vote;
$project_ids = array();
foreach($projects as $p) {
$project_ids[] = $p->id;
}
$vote->user_name = "SELECT name FROM user WHERE user.id = poker_vote.user_id";
$votes = $vote->find(array("project_id IN (" . implode(",", $project_ids) . ")", $user_id));
$vote_array = array();
foreach($votes as $v) {
$vote_array[$v->project_id][] = array(
"user_name" => $v->user_name,
"vote" => $v->vote,
"class" => $v->vote > 10 ? "high" : "low"
);
}
$f3->set("votes", $vote_array);
$f3->set("title", "Backlog Poker Results");
$this->_render("poker/view/results.html");
}
public function post(\Base $f3) {
$user_id = $this->_requireLogin();
$vote = new Model\Vote;
$vote->load(array("user_id = ? AND project_id = ?", $user_id, $f3->get("POST.project_id")));
$vote->user_id = $user_id;
$vote->project_id = $f3->get("POST.project_id");
$vote->vote = $f3->get("POST.vote");
$vote->save();
$this->_printJson($vote->cast());
}
}