-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
141 lines (126 loc) · 4.5 KB
/
report.php
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
<?php
require '/home/ivan/dev/app/jira/report/vendor/autoload.php';
use JiraRestApi\JiraException;
use JiraRestApi\Group\GroupService;
use JiraRestApi\Issue\IssueService;
use JiraRestApi\Project\ProjectService;
function getProgrammers()
{
try {
$programmer = array();
$queryParam = [
'groupname' => 'jira-software-users',
'includeInactiveUsers' => true, // default false
'startAt' => 0,
'maxResults' => 50
];
$gs = new GroupService();
$ret = $gs->getMembers($queryParam);
foreach ($ret->values as $user)
array_push($programmer, array(
'Programer' => $user->displayName,
'key' => $user->key
));
return json_encode($programmer);
} catch (JiraException $e) {
print("Error Occured! " . $e->getMessage());
}
}
function getProjects()
{
$project = array();
$proj = new ProjectService();
$prjs = $proj->getAllProjects();
foreach ($prjs as $p)
array_push($project, array(
'Project' => $p->name,
'key' => $p->key
));
return json_encode($project);
}
function getReport($startdt, $enddt, $projekt, $programer=null)
{
$report = array();
$startDate = new DateTime($startdt);
$endDate = new DateTime($enddt);
$weekStart = $startDate->format("W");
$weekEnd = $endDate->format("W");
$sprints = null;
for ($i = $weekEnd; $i >= $weekStart; $i --)
$sprints .= '"' . $startDate->format("Y") . '/Week ' . $i . '",';
$jql = 'project="' . $projekt . '" and sprint in(' . rtrim($sprints, ',') . ') and assignee ='.$programer.'';
if($projekt)
$filter .='and project="' . $projekt . '"';
/* if($programer)
$filter.='and assignee ='.$programer.'';
*/
$jql ='updatedDate >= "'.$startDate->format("Y/m/d").' 00:00" and updatedDate <="'.$endDate->format("Y/m/d").' 23:59"'.$filter;
$issueService = new IssueService();
$ret1 = $issueService->search($jql, 0, 100, array(
'key',
'name',
'worklog',
'project',
'summary',
'components'
));
$ret2 = $issueService->search($jql, 100, 200, array(
'key',
'name',
'worklog',
'project',
'summary',
'components'
));
$ret3 = $issueService->search($jql, 200, 300, array(
'key',
'name',
'worklog',
'project',
'summary',
'components'
));
$issues=array_merge($ret1->issues,$ret2->issues,$ret3->issues);
foreach ($issues as $issue) {
// if ($issue->key !='T2HRAKT-201') continue;
if (is_object($issue->fields->worklog))
foreach ($issue->fields->worklog as $val) {
$time = 0;
if (! is_array($val))
continue;
foreach ($val as $log) {
if (new DateTime($log->created) > $startDate) {
$time = $log->timeSpentSeconds;
$week = new DateTime($log->created);
$programerdata = $log->author->displayName;
$date = $week->format("d.m.Y");
$sprint = $week->format("Y") . '/Week ' . $week->format("W");
$data .= $programerdata . ',' . '"' . $issue->fields->project->name . '","' . $sprint . '",' . $issue->key . ',"' . $issue->fields->summary . '"' . ',' . round(ceil($time) / (60 * 60)) . ',' . $date . $components . PHP_EOL;
$total += $time;
if ($log->author->key ==$programer and $programer!=null)
array_push($report, array(
'Programer' => $programerdata,
'Sati' => round(ceil($time) / (60 * 60)),
'Datum'=>$date,
'Task'=> $issue->key ,
'Projekt'=>$issue->fields->project->name ,
'Opis'=>$issue->fields->summary
));
}
}
}
}
return json_encode($report);
}
switch ($_GET['action']) {
case 'programmer':
echo getProgrammers();
break;
case 'project':
echo getProjects();
break;
case 'report':
$data = $_GET['filter'];
echo getReport($data['startdt'], $data['enddt'], $data['projekt'], $data['programer']);
break;
}