-
Notifications
You must be signed in to change notification settings - Fork 38
/
smarty_tools.php
259 lines (225 loc) · 8.61 KB
/
smarty_tools.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
/*
This file is part of CoDev-Timetracking.
CoDev-Timetracking is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CoDev-Timetracking is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CoDev-Timetracking. If not, see <http://www.gnu.org/licenses/>.
*/
class SmartyTools {
/**
* @var Logger The logger
*/
private static $logger;
/**
* Initialize complex static variables
* @static
*/
public static function staticInit() {
self::$logger = Logger::getLogger(__CLASS__);
}
/**
* @param int $value
* @param bool $allowNull
* @return int $value
* @throws Exception
* @deprecated Use Tools::getSecurePOSTIntValue($key, $defaultValue)
*/
public static function checkNumericValue($value, $allowNull = FALSE) {
if ((NULL == $value) && (TRUE == $allowNull)) { return NULL; }
$formattedValue = $value; // Tools::escape_string($value);
if (!is_numeric($formattedValue)) {
echo "<span style='color:red'>ERROR: Please contact your CodevTT administrator</span>";
$e = new Exception("SECURITY ALERT: Attempt to set non_numeric value ($value)");
self::$logger->fatal("EXCEPTION: ".$e->getMessage());
self::$logger->fatal("EXCEPTION stack-trace:\n".$e->getTraceAsString());
throw $e;
}
return $formattedValue;
}
/**
* Convert an array in smarty array
* @param string[] $list
* @param int $selected
* @return mixed[]
*/
public static function getSmartyArray(array $list, $selected) {
if ($list != NULL) {
$smartyList = array();
foreach ($list as $id => $name) {
$smartyList[$id] = array(
'id' => $id,
'name' => $name,
'selected' => $id == $selected
);
}
return $smartyList;
} else {
return array();
}
}
/**
* @param int $projectid
* @param int $defaultBugid
* @param array $projList
* @return mixed[]
*/
public static function getBugs($projectid = 0, $defaultBugid = 0, array $projList = NULL) {
// Task list
if (0 != $projectid) {
$project1 = ProjectCache::getInstance()->getProject($projectid);
$issueList = $project1->getIssues();
} else {
// no project specified: show all tasks
$issueList = Project::getProjectIssues(array_keys($projList));
}
$bugs = NULL;
foreach ($issueList as $issue) {
$summary = "";
if($issue->getSummary()) {
$summary = ' : '.$issue->getSummary();
}
$bugs[$issue->getId()] = array(
'id' => $issue->getId(),
'name' => $issue->getFormattedIds().$summary,
'selected' => $issue->getId() == $defaultBugid,
'projectid' => $issue->getProjectId()
);
}
return $bugs;
}
/**
* Get the list of weeks of a specific year in Smarty comprehensible array
* @param int $weekid The selected week
* @param int $year The specific year
* @return mixed[] The result
*/
public static function getWeeks($weekid, $year) {
$weeks = array();
# In ISO-8601 specification, it says that December 28th is always in the last week of its year.
$nbWeeks=date("W", strtotime("28 December $year"));
for ($i = 1; $i <= $nbWeeks; $i++) {
$date_string = $year . 'W' . sprintf('%02d', $i);
$mondayTimestamp = strtotime($date_string);
$monday = T_('W').$i.' | '.strftime('%d %b', strtotime("Monday",$mondayTimestamp));
$friday = strftime("%d %b", strtotime("Friday",$mondayTimestamp));
/* if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$monday = utf8_encode($monday);
$friday = utf8_encode($friday);
}
*/
$weeks[] = array(
'id' => $i,
'value' => $monday." - ".$friday,
'selected' => $i == $weekid
);
}
return $weeks;
}
/**
* Get the list of years in [year-offset;year+offset] in Smarty comprehensible array
* @param int $year The actual year
* @param int $offset The offset
* @return mixed[] The years
*/
public static function getYears($year, $offset = 1) {
$years = array();
for ($y = ($year-$offset); $y <= ($year+$offset); $y++) {
$years[] = array(
'id' => $y,
'selected' => $y == $year
);
}
return $years;
}
/**
* Get the list of years in [startYear;now] in Smarty comprehensible array
* @param int $startYear The start year
* @param int $curYear The actual year
* @return mixed[] The years
*/
public static function getYearsToNow($startYear, $curYear) {
$years = array();
for ($y = $startYear; $y <= date('Y'); $y++) {
$years[] = array(
'id' => $y,
'selected' => $y == $curYear
);
}
return $years;
}
/**
* Get detailed mgr
* @param IssueSelection $issueSelection
* @return mixed[]
*/
public static function getIssueSelectionDetailedMgr(IssueSelection $issueSelection) {
//$formatedList = implode( ',', array_keys($issueSelection->getIssueList()));
$valuesMgr = $issueSelection->getDriftMgr();
$valuesDrift = $issueSelection->getDrift();
$driftMgrColor = IssueSelection::getDriftColor($valuesMgr['percent']);
$formatteddriftMgrColor = (NULL == $driftMgrColor) ? "" : "style='background-color: #".$driftMgrColor.";' ";
$driftColor = IssueSelection::getDriftColor($valuesDrift['percent']);
$formattedDriftColor = (NULL == $driftMgrColor) ? "" : "style='background-color: #".$driftColor.";' ";
$selectionDetailedMgr = array('name' => $issueSelection->name,
//'progress' => round(100 * $pv->getProgress()),
'effortEstim' => ($issueSelection->effortEstim + $issueSelection->getProvision()),
'mgrEffortEstim' => ($issueSelection->mgrEffortEstim + $issueSelection->getProvision()),
'reestimated' => $issueSelection->getReestimated(),
'elapsed' => $issueSelection->elapsed,
'backlog' => $issueSelection->duration,
'driftMgrColor' => $formatteddriftMgrColor,
'driftMgr' => round($valuesMgr['nbDays'],2),
'driftColor' => $formattedDriftColor,
'drift' => round($valuesDrift['nbDays'],2),
'progress' => round(100 * $issueSelection->getProgress(),2),
);
return $selectionDetailedMgr;
}
/**
* get issues attributes
* @param IssueSelection $issueSelection
* @return mixed[]
*/
public static function getIssueListInfo(IssueSelection $issueSelection) {
$issueArray = array();
$issues = $issueSelection->getIssueList();
foreach ($issues as $id => $issue) {
$driftMgr = $issue->getDriftMgr();
$driftMgrColor = $issue->getDriftColor($driftMgr);
$issueArray[$id] = array(
//"mantisLink" => Tools::mantisIssueURL($issue->getId(), NULL, TRUE),
"bugid" => Tools::issueInfoURL(sprintf("%07d\n", $issue->getId())),
"project" => $issue->getProjectName(),
"target" => $issue->getTargetVersion(),
//"status" => $issue->getCurrentStatusName(),
//"progress" => round(100 * $issue->getProgress()),
"effortEstim" => $issue->getMgrEffortEstim(),
"elapsed" => $issue->getElapsed(),
//"driftMgr" => $driftMgr,
//"driftMgrColor" => (NULL == $driftMgrColor) ? "" : "style='background-color: #".$driftMgrColor.";' ",
//"duration" => $issue->getDuration(),
"summary" => $issue->getSummary(),
"category" => $issue->getCategoryName()
);
}
return $issueArray;
}
public static function getIssueDescription($bugid, $extid, $summary, $tooltipAttr = NULL) {
$description = Tools::mantisIssueURL($bugid, NULL, TRUE) . ' ' . Tools::issueInfoURL($bugid, $tooltipAttr);
if($extid != NULL && strlen($extid) > 0) {
$description .= " / " . $extid;
}
if($summary != NULL && strlen($summary) > 0) {
$description .= " : " . htmlspecialchars($summary);;
}
return $description;
}
}
SmartyTools::staticInit();