Skip to content

Commit da59f76

Browse files
committed
port deadline box to twig
1 parent 7143b02 commit da59f76

9 files changed

+155
-230
lines changed

entities/Deadline.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@ class Deadline
1818
/** @Column */
1919
public DateTimeImmutable $bug_selection;
2020

21+
/** @Column */
22+
public DateTimeImmutable $feature_selection;
23+
2124
/** @Column */
2225
public DateTimeImmutable $patch_submission;
2326

27+
/** @Column */
28+
public DateTimeImmutable $final_report;
29+
2430
public function __construct($year) {
25-
$this->year = $year;
26-
$this->proj_proposal = new DateTimeImmutable();
27-
$this->bug_selection = new DateTimeImmutable();
28-
$this->patch_submission = new DateTimeImmutable();
31+
$this->year = $year;
32+
$this->proj_proposal = new DateTimeImmutable();
33+
$this->bug_selection = new DateTimeImmutable();
34+
$this->feature_selection = new DateTimeImmutable();
35+
$this->patch_submission = new DateTimeImmutable();
36+
$this->final_report = new DateTimeImmutable();
2937
}
3038

3139
public function isProjProposalActive() {
@@ -36,11 +44,21 @@ public function isBugSelectionActive() {
3644
return new DateTimeImmutable() <= $this->bug_selection;
3745
}
3846

47+
public function isFeatureSelectionActive() {
48+
return new DateTimeImmutable() <= $this->feature_selection;
49+
}
50+
3951
public function isPatchSubmissionActive() {
4052
return new DateTimeImmutable() <= $this->patch_submission;
4153
}
4254

55+
public function isFinalReportActive() {
56+
return new DateTimeImmutable() <= $this->final_report;
57+
}
58+
4359
public function set_proj_proposal($time) { $this->proj_proposal = new DateTimeImmutable($time); }
4460
public function set_bug_selection($time) { $this->bug_selection = new DateTimeImmutable($time); }
61+
public function set_feature_selection($time) { $this->feature_selection = new DateTimeImmutable($time); }
4562
public function set_patch_submission($time) { $this->patch_submission = new DateTimeImmutable($time); }
63+
public function set_final_report($time) { $this->final_report = new DateTimeImmutable($time); }
4664
}

index.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
$embed_file = null;
2828
$success_message = null;
2929
$table = null;
30+
$deadline = null;
3031

3132
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
3233

@@ -45,7 +46,8 @@
4546
}
4647

4748
function terminate($error_message = null) {
48-
global $page, $table, $form, $select_form, $embed_file, $success_message;
49+
global $page, $deadline, $table, $form, $select_form, $embed_file,
50+
$success_message;
4951

5052
$appvar = new \ReflectionClass('\Symfony\Bridge\Twig\AppVariable');
5153
$loader = new \Twig\Loader\FilesystemLoader([
@@ -110,6 +112,7 @@ function terminate($error_message = null) {
110112
'success_message' => $error_message ? '' : $success_message,
111113
'error_message' => $error_message,
112114
'table' => $table,
115+
'deadline' => $deadline ? $deadline->format('c') : null,
113116
];
114117

115118
if ($form)
@@ -190,6 +193,25 @@ function filter_by($filters) {
190193
'data' => $selected_group,
191194
]);
192195
}
196+
if (in_array('repo', $filters)) {
197+
$repos = [];
198+
foreach (db_fetch_groups($selected_year) as $group) {
199+
if (!has_group_permissions($group))
200+
continue;
201+
202+
if ($repo = $group->getRepositoryId())
203+
$repos[$repo] = true;
204+
}
205+
$repos = array_keys($repos);
206+
natsort($repos);
207+
208+
$repos = ['All' => 'all'] + array_combine($repos, $repos);
209+
$select_form->add('repo', ChoiceType::class, [
210+
'label' => 'Repository',
211+
'choices' => $repos,
212+
'data' => $selected_repo,
213+
]);
214+
}
193215
if (in_array('own_shifts', $filters)) {
194216
$select_form->add('own_shifts', CheckboxType::class, [
195217
'label' => 'Show only own shifts',

pages/bugs.php

+2-15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright (c) 2022-present Instituto Superior Técnico.
33
// Distributed under the MIT license that can be found in the LICENSE file.
44

5-
html_header("Bugs");
6-
75
$user = get_user();
86
$group = $user->getGroup();
97
$year = $group ? $group->year : get_current_year();
@@ -35,14 +33,7 @@
3533
mk_box_left_begin();
3634

3735
if (auth_at_least(ROLE_TA)) {
38-
do_start_form('bugs');
39-
$selected_year = do_year_selector();
40-
$own_shifts_only = do_bool_selector('Show only own shifts', 'own_shifts');
41-
$selected_shift = do_shift_selector($selected_year, $own_shifts_only);
42-
$selected_repo = do_repo_selector($selected_year);
43-
$groups = do_group_selector($selected_year, $selected_shift,
44-
$own_shifts_only, $selected_repo);
45-
echo "</form><p>&nbsp;</p>\n";
36+
$groups = filter_by(['group', 'year', 'shift', 'own_shifts', 'repo']);
4637
} else {
4738
$groups = $user->groups;
4839
}
@@ -69,7 +60,6 @@
6960
];
7061
}
7162
}
72-
print_table($table);
7363

7464
echo <<<HTML
7565
<script>
@@ -119,7 +109,4 @@ function toggleVideo(button) {
119109
EOF;
120110
}
121111

122-
mk_box_end();
123-
124-
mk_deadline_box($deadline->bug_selection);
125-
mk_box_end();
112+
$deadline = $deadline->bug_selection;

pages/features.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
$user = get_user();
1212
$group = $user->getGroup();
13+
$year = $group ? $group->year : get_current_year();
14+
$deadline = db_fetch_deadline($year);
15+
1316
if (!$group && $user->role === ROLE_STUDENT) {
1417
terminate('Student is not in a group');
1518
}
@@ -44,6 +47,10 @@
4447
$form->handleRequest($request);
4548

4649
if ($form->isSubmitted() && $form->isValid()) {
50+
if (!$deadline->isFeatureSelectionActive()) {
51+
terminate('Deadline expired');
52+
}
53+
4754
$file = $form->get('file')->getData();
4855
if ($file instanceof UploadedFile) {
4956
if ($file->getSize() > 5 * 1024 * 1024) {
@@ -77,9 +84,7 @@
7784
'Issue URL' => $group->url_proposal
7885
? ['label' => 'link', 'url' => $group->url_proposal] : '',
7986
'PDF' => $group->hash_proposal_file
80-
? ['label' => 'link',
81-
'url' => dourl('features', ['download' => $group->id], '&')]
82-
: '',
87+
? dolink('features', 'link', ['download' => $group->id]) : '',
8388
];
8489
}
8590
if (sizeof($groups) === 1) {
@@ -88,5 +93,7 @@
8893
}
8994

9095
if ($group && $group->hash_proposal_file) {
91-
$embed_file = dourl('features', ['download' => $group->id], '&');
96+
$embed_file = dourl('features', ['download' => $group->id]);
9297
}
98+
99+
$deadline = $deadline->feature_selection;

pages/listprojects.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22
// Copyright (c) 2022-present Instituto Superior Técnico.
33
// Distributed under the MIT license that can be found in the LICENSE file.
44

5-
html_header('Project List');
6-
75
if (auth_at_least(ROLE_TA)) {
8-
do_start_form('listprojects');
9-
$selected_year = do_year_selector();
10-
$own_shifts_only = do_bool_selector('Show only own shifts', 'own_shifts');
11-
$selected_shift = do_shift_selector($selected_year, $own_shifts_only);
12-
$selected_repo = do_repo_selector($selected_year);
13-
$groups = do_group_selector($selected_year, $selected_shift,
14-
$own_shifts_only, $selected_repo);
15-
echo "</form>\n";
6+
$groups = filter_by(['group', 'year', 'shift', 'own_shifts', 'repo']);
167
} else {
178
$groups = get_user()->groups;
189
}
@@ -25,7 +16,5 @@
2516
$students[] = "$s->name ($s->id)";
2617
}
2718
$group = dolink('listproject', $group->group_number, ['id' => $group->id]);
28-
$table[] = ['Group' => $group, 'Students' => $students];
19+
$table[] = ['Group' => $group, 'Students' => implode("\n", $students)];
2920
}
30-
31-
print_table($table);

templates.php

+4-133
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,12 @@
44

55
use Doctrine\Common\Annotations\AnnotationReader;
66

7-
function html_header($title) {
8-
$user = get_user();
9-
$role = get_role_string();
10-
$name = htmlspecialchars($user->name);
11-
12-
echo <<< EOF
13-
<!DOCTYPE html>
14-
<html><head>
15-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
16-
<style>
17-
table, th, td {
18-
border: 1px solid
19-
}
20-
th, td {
21-
padding: 3px
22-
}
23-
</style>
24-
<title>PIC1: $title</title>
25-
</head>
26-
<body>
27-
<p><img src="{$user->getPhoto()}" alt="Photo"></p>
28-
<p>User: $name ($user->id)<br>
29-
Email: <a href="mailto:$user->email">$user->email</a><br>
30-
Role: $role</p>
31-
EOF;
32-
}
33-
34-
function html_footer() {
35-
$pages = [
36-
['dashboard', 'Statistics', ROLE_STUDENT],
37-
['profile', 'Edit profile', ROLE_STUDENT],
38-
['listprojects', 'Projects', ROLE_STUDENT],
39-
['bugs', 'Bugs', ROLE_STUDENT],
40-
['features', 'Features', ROLE_STUDENT],
41-
['patches', 'Patches', ROLE_STUDENT],
42-
['shifts', 'Shifts', ROLE_PROF],
43-
['deadlines', 'Deadlines', ROLE_PROF],
44-
['changerole', 'Change Role', ROLE_PROF],
45-
['impersonate', 'Impersonate', ROLE_SUDO],
46-
['cron', 'Cron', ROLE_PROF],
47-
['phpinfo', 'PHP Info', ROLE_PROF],
48-
];
49-
echo '<p>&nbsp;</p><footer>';
50-
foreach ($pages as $page) {
51-
if (auth_at_least($page[2]))
52-
echo dolink($page[0], $page[1]), ' | ';
53-
}
54-
echo <<< EOF
55-
<a href="logout.php">Logout</a></footer>
56-
</body>
57-
</html>
58-
EOF;
59-
}
60-
617
function quote($str) {
628
return "'" . htmlspecialchars($str) . "'";
639
}
6410

6511
function do_ext_link($page, $args = []) {
66-
return 'https://' . $_SERVER['HTTP_HOST'] . '/' . dourl($page, $args, '&');
12+
return 'https://' . $_SERVER['HTTP_HOST'] . '/' . dourl($page, $args);
6713
}
6814

6915
function link_patch(Patch $patch) {
@@ -74,67 +20,20 @@ function link_group(ProjGroup $group) {
7420
return do_ext_link('listproject', ['id' => $group->id]);
7521
}
7622

77-
function dourl($page, $args = [], $separator = '&amp;') {
23+
function dourl($page, $args = []) {
7824
$args['page'] = $page;
79-
$q = http_build_query($args, '', $separator);
25+
$q = http_build_query($args, '', '&');
8026
return "index.php?$q";
8127
}
8228

8329
function dolink($page, $txt, $args = []) {
84-
return '<a href="' . dourl($page, $args) . "\">$txt</a>";
30+
return ['label' => $txt, 'url' => dourl($page, $args)];
8531
}
8632

8733
function format_text($text) {
8834
return nl2br(htmlspecialchars(wordwrap($text, 80, "\n", true)));
8935
}
9036

91-
function mk_box_left_begin() {
92-
echo '<div style="display: inline-block"><div style="float: left">';
93-
}
94-
95-
function mk_box_right_begin() {
96-
echo '<div style="float: right; width: 300px; padding: 10px; margin: 10px; ',
97-
'background: blue; color: white">';
98-
}
99-
100-
function mk_box_end() {
101-
echo "</div>\n";
102-
}
103-
104-
function mk_deadline_box($deadline) {
105-
$now = new DateTimeImmutable();
106-
echo '<div style="float: right; width: 300px; padding: 10px; margin: 10px; ',
107-
'background: green; color: white">';
108-
if ($now > $deadline) {
109-
echo "<p>Deadline has expired!</p>";
110-
} else {
111-
echo "<p>Time until deadline: ",
112-
$deadline->diff($now)->format('%ad, %Hh, %Im, %Ss'), "</p>\n";
113-
}
114-
mk_box_end();
115-
}
116-
117-
function print_table($table) {
118-
if (!$table)
119-
return;
120-
121-
echo "<table><tr>\n";
122-
foreach ($table[0] as $key => $val) {
123-
echo "<th>$key</th>\n";
124-
}
125-
echo "</tr>\n";
126-
foreach ($table as $row) {
127-
echo "<tr>\n";
128-
foreach ($row as $val) {
129-
if (is_array($val))
130-
$val = implode("<br>\n", $val);
131-
echo "<td>$val</td>\n";
132-
}
133-
echo "</tr>\n";
134-
}
135-
echo "</table>\n";
136-
}
137-
13837
function handle_form(&$obj, $hide_fields, $readonly, $only_fields = null,
13938
$extra_buttons = null, $flush_db = true) {
14039
$class = new ReflectionClass($obj);
@@ -301,31 +200,3 @@ function handle_form(&$obj, $hide_fields, $readonly, $only_fields = null,
301200
}
302201
echo "</form>\n";
303202
}
304-
305-
function do_repo_selector($selected_year) {
306-
$selected_repo = $_REQUEST['repo'] ?? 'all';
307-
echo <<<HTML
308-
<label for="repo">Filter by repository:</label>
309-
<select name="repo" id="repo" onchange='this.form.submit()'>
310-
<option value="all">All</option>
311-
HTML;
312-
313-
$repos = [];
314-
foreach (db_fetch_groups($selected_year) as $group) {
315-
if (!has_group_permissions($group))
316-
continue;
317-
318-
if ($repo = $group->getRepositoryId())
319-
$repos[$repo] = true;
320-
}
321-
$repos = array_keys($repos);
322-
natsort($repos);
323-
324-
foreach ($repos as $repo) {
325-
$select = $repo == $selected_repo ? ' selected' : '';
326-
echo "<option value=\"$repo\"$select>", htmlspecialchars($repo),
327-
"</option>\n";
328-
}
329-
echo "</select>\n<br>\n";
330-
return $selected_repo;
331-
}

templates/footer.html.twig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<footer class="bg-body-secondary text-center p-2">
2+
&copy; Instituto Superior Técnico. All rights reserved.
3+
</footer>
4+
5+
</body>
6+
</html>

0 commit comments

Comments
 (0)