Skip to content

Commit 63c41b2

Browse files
committed
continue the port to twig
1 parent da59f76 commit 63c41b2

12 files changed

+232
-274
lines changed

entities/Deadline.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public function isFinalReportActive() {
5656
return new DateTimeImmutable() <= $this->final_report;
5757
}
5858

59-
public function set_proj_proposal($time) { $this->proj_proposal = new DateTimeImmutable($time); }
60-
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); }
62-
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); }
59+
public function set_proj_proposal(DateTimeImmutable $time) { $this->proj_proposal = $time; }
60+
public function set_bug_selection(DateTimeImmutable $time) { $this->bug_selection = $time; }
61+
public function set_feature_selection(DateTimeImmutable $time) { $this->feature_selection = $time; }
62+
public function set_patch_submission(DateTimeImmutable $time) { $this->patch_submission = $time; }
63+
public function set_final_report(DateTimeImmutable $time) { $this->final_report = $time; }
6464
}

index.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
$success_message = null;
2929
$table = null;
3030
$deadline = null;
31+
$info_box = null;
3132

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

@@ -46,7 +47,7 @@
4647
}
4748

4849
function terminate($error_message = null) {
49-
global $page, $deadline, $table, $form, $select_form, $embed_file,
50+
global $page, $deadline, $table, $info_box, $form, $select_form, $embed_file,
5051
$success_message;
5152

5253
$appvar = new \ReflectionClass('\Symfony\Bridge\Twig\AppVariable');
@@ -112,6 +113,7 @@ function terminate($error_message = null) {
112113
'success_message' => $error_message ? '' : $success_message,
113114
'error_message' => $error_message,
114115
'table' => $table,
116+
'info_box' => $info_box,
115117
'deadline' => $deadline ? $deadline->format('c') : null,
116118
];
117119

pages/cron.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
auth_require_at_least(ROLE_PROF);
66

7-
html_header('Run cron jobs');
8-
97
$argv = [];
108
$max_exec_time = 9;
119
$checkpoint_start = (int)@$_GET['checkpoint'];

pages/deadlines.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
auth_require_at_least(ROLE_PROF);
66

7-
html_header("Deadlines");
8-
97
$year = get_current_year();
10-
$deadline = db_fetch_deadline($year);
8+
$obj = db_fetch_deadline($year);
119

12-
handle_form($deadline,
10+
handle_form($obj,
1311
/* hidden= */[],
1412
/* readonly= */['year']);

pages/editpatch.php

+23-40
Original file line numberDiff line numberDiff line change
@@ -2,7 +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('Patch Detail');
65
require_once 'email.php';
76

87
if (empty($_GET['id']))
@@ -22,9 +21,6 @@
2221
$readonly = array_keys(get_object_vars($patch));
2322
}
2423

25-
echo "<p>&nbsp;</p>\n";
26-
mk_box_left_begin();
27-
2824
$prev_status = $patch->getStatus();
2925

3026
$new_comment = trim($_POST['text'] ?? '');
@@ -53,6 +49,7 @@
5349

5450
echo "<table>\n";
5551
foreach ($patch->comments as $comment) {
52+
break;
5653
if ($comment->user) {
5754
$author = $comment->user->shortName() . ' (' . $comment->user->id . ')';
5855
$photo = $comment->user->getPhoto();
@@ -119,8 +116,6 @@
119116
</form>
120117
HTML;
121118

122-
mk_box_end();
123-
124119
// notify students of the patch review
125120
if ($patch->getStatus() != $prev_status) {
126121
$subject = null;
@@ -160,49 +155,37 @@
160155
}
161156
}
162157

163-
$authors = [];
164-
foreach ($patch->students as $author) {
165-
$authors[] = $author->shortName() . ' (' . $author->id . ')';
166-
}
167-
168-
mk_box_right_begin();
169158
if ($patch->isValid()) {
170-
echo "<p>Statistics:</p><ul>";
171-
echo "<li><b>Students:</b> ", implode(', ', $authors), "</li>\n";
172-
echo "<li><b>Lines added:</b> ", $patch->lines_added, "</li>\n";
173-
echo "<li><b>Lines removed:</b> ", $patch->lines_deleted, "</li>\n";
174-
echo "<li><b>Files modified:</b> ", $patch->files_modified, "</li>\n";
175-
echo '<li><a style="color: white" href="', $patch->getPatchURL(),
176-
'">Patch</a></li>';
177-
if ($pr = $patch->getPRURL()) {
178-
echo '<li><a style="color: white" href="', $pr, '">PR</a></li>';
179-
}
180-
if ($issue = $patch->getIssueURL()) {
181-
echo '<li><a style="color: white" href="', $issue, '">Issue</a></li>';
182-
}
183-
echo "<li><b>All authors:</b> ", gen_authors($patch->allAuthors()), "</li>\n";
184-
echo '</ul>';
159+
$info_box['title'] = 'Statistics';
160+
$info_box['rows'] = [
161+
'Lines added' => $patch->lines_added,
162+
'Lines removed' => $patch->lines_deleted,
163+
'Files modified' => $patch->files_modified,
164+
'All authors' => gen_authors($patch->allAuthors()),
165+
];
185166
} else {
186-
echo '<p>The patch is no longer available!</p>';
187-
echo '<p><a style="color: white" href="', $patch->getPatchURL(),
188-
'">Patch</a></p>';
189-
if ($pr = $patch->getPRURL()) {
190-
echo '<p><a style="color: white" href="', $pr, '">PR</a></p>';
191-
}
167+
$info_box['title'] = 'The patch is no longer available!';
192168
}
193-
mk_box_end();
194-
mk_box_end();
169+
$info_box['rows']['Patch'] = dolink_ext($issue, 'link');
195170

171+
if ($issue = $patch->getIssueURL()) {
172+
$info_box['rows']['Issue'] = dolink_ext($issue, 'link');
173+
}
174+
if ($pr = $patch->getPRURL()) {
175+
$info_box['rows']['PR'] = dolink_ext($pr, 'link');
176+
}
196177

197178
function gen_authors($list) {
198179
$data = [];
180+
$invalid = true;
199181
foreach ($list as $author) {
200-
$name = htmlspecialchars($author[1]);
201-
$email = htmlspecialchars($author[2]);
182+
$name = $author[1];
183+
$email = $author[2];
202184
if (!check_email($email))
203-
$email = '<span style="color: red">' . $email . '</span>';
185+
$invalid = true;
204186

205-
$data[] = "$name &lt;$email&gt;";
187+
$data[] = "$name <$email>";
206188
}
207-
return implode(', ', $data);
189+
$data = implode(', ', $data);
190+
return $invalid ? ["warn" => true, "data" => $data] : $data;
208191
}

pages/features.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
}
3232

33-
if ($user->role === ROLE_STUDENT) {
33+
if ($user->role === ROLE_STUDENT && $deadline->isFeatureSelectionActive()) {
3434
$form = $formFactory->createBuilder(FormType::class)
3535
->add('url', UrlType::class, [
3636
'label' => 'Issue URL (if applicable)',
@@ -47,10 +47,6 @@
4747
$form->handleRequest($request);
4848

4949
if ($form->isSubmitted() && $form->isValid()) {
50-
if (!$deadline->isFeatureSelectionActive()) {
51-
terminate('Deadline expired');
52-
}
53-
5450
$file = $form->get('file')->getData();
5551
if ($file instanceof UploadedFile) {
5652
if ($file->getSize() > 5 * 1024 * 1024) {
@@ -82,7 +78,7 @@
8278
$table[] = [
8379
'Group' => $group->group_number,
8480
'Issue URL' => $group->url_proposal
85-
? ['label' => 'link', 'url' => $group->url_proposal] : '',
81+
? dolink_ext($group->url_proposal, 'link') : '',
8682
'PDF' => $group->hash_proposal_file
8783
? dolink('features', 'link', ['download' => $group->id]) : '',
8884
];

pages/listprojects.php

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
$groups = get_user()->groups;
99
}
1010

11-
echo "<p>Groups:</p>\n";
1211
$table = [];
1312
foreach ($groups as $group) {
1413
$students = [];

pages/patches.php

+48-89
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,59 @@
44

55
require_once 'email.php';
66

7-
html_header("Patches");
7+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
8+
use Symfony\Component\Form\Extension\Core\Type\FormType;
9+
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
10+
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
11+
use Symfony\Component\Form\Extension\Core\Type\UrlType;
812

913
$user = get_user();
1014
$group = $user->getGroup();
1115
$deadline = db_fetch_deadline($group ? $group->year : get_current_year());
1216

13-
mk_box_left_begin();
14-
15-
$patch_accepted = false;
16-
17-
if (isset($_POST['url'])) {
18-
if ($user->role == ROLE_STUDENT &&
19-
!$deadline->isPatchSubmissionActive())
20-
die('Deadline expired');
21-
22-
if (!$group)
23-
die("Student's group not found");
24-
25-
try {
26-
$p = Patch::factory($group, $_POST['url'], $_POST['type'],
27-
$_POST['description'], $user);
28-
$group->patches->add($p);
29-
db_save($p);
30-
31-
$patch_accepted = true;
32-
$name = $user->shortName();
33-
email_ta($group, 'PIC1: New patch',
34-
"$name ($user) of group $group submitted a new patch\n\n" .
35-
link_patch($p));
36-
} catch (ValidationException $ex) {
37-
echo "<p style=\"color: red\">Failed to validate all fields: ",
38-
nl2br(htmlspecialchars($ex->getMessage())), "</p>\n";
17+
if ($user->role === ROLE_STUDENT /*&& $deadline->isPatchSubmissionActive()*/) {
18+
$form = $formFactory->createBuilder(FormType::class)
19+
->add('url', UrlType::class, ['label' => 'URL'])
20+
->add('type', ChoiceType::class, [
21+
'label' => 'Type',
22+
'choices' => ['Bug fix' => PATCH_BUGFIX, 'Feature' => PATCH_FEATURE],
23+
])
24+
->add('description', TextareaType::class, ['label' => 'Description'])
25+
->add('submit', SubmitType::class, ['label' => 'Submit'])
26+
->getForm();
27+
28+
$form->handleRequest($request);
29+
30+
if ($form->isSubmitted() && $form->isValid()) {
31+
if (!$group)
32+
die("Student's group not found");
33+
34+
try {
35+
$url = $form->get('url')->getData();
36+
$type = $form->get('type')->getData();
37+
$description = $form->get('description')->getData();
38+
$p = Patch::factory($group, $url, $type, $description, $user);
39+
$group->patches->add($p);
40+
db_save($p);
41+
42+
$success_message = 'Patch submitted successfully!';
43+
$patch_accepted = true;
44+
$name = $user->shortName();
45+
email_ta($group, 'PIC1: New patch',
46+
"$name ($user) of group $group submitted a new patch\n\n" .
47+
link_patch($p));
48+
} catch (ValidationException $ex) {
49+
terminate('Failed to validate all fields: ' . $ex->getMessage());
50+
}
3951
}
4052
}
4153

42-
4354
if (auth_at_least(ROLE_TA)) {
44-
do_start_form('patches');
45-
$selected_year = do_year_selector();
46-
$only_needs_review = do_bool_selector('Show only patches that need review',
55+
$groups = filter_by(['group', 'year', 'shift', 'own_shifts', 'repo']);
56+
/* $only_needs_review = do_bool_selector('Show only patches that need review',
4757
'needs_review');
4858
$only_open_patches = do_bool_selector('Show only non-merged patches',
49-
'open_patches');
50-
$own_shifts_only = do_bool_selector('Show only own shifts', 'own_shifts');
51-
$selected_shift = do_shift_selector($selected_year, $own_shifts_only);
52-
$selected_repo = do_repo_selector($selected_year);
53-
$groups = do_group_selector($selected_year, $selected_shift,
54-
$own_shifts_only, $selected_repo);
55-
echo "</form><p>&nbsp;</p>\n";
59+
'open_patches');*/
5660
} else {
5761
$groups = $user->groups;
5862
}
@@ -70,7 +74,7 @@
7074

7175
$authors = [];
7276
foreach ($patch->students as $author) {
73-
$authors[] = htmlspecialchars($author->shortName());
77+
$authors[] = $author->shortName();
7478
}
7579

7680
$pr = $patch->getPRURL();
@@ -82,61 +86,16 @@
8286
['id' => $group->id]),
8387
'Status' => $patch->getStatus(),
8488
'Type' => $patch->getType(),
85-
'Issue' => $issue ? '<a href="'. $issue . '">link</a>' : '',
86-
'Patch' => '<a href="'. $patch->getPatchURL() . '">link</a>',
87-
'PR' => $pr ? '<a href="'. $pr . '">link</a>' : '',
89+
'Issue' => $issue ? dolink_ext($issue, 'link') : '',
90+
'Patch' => dolink_ext($patch->getPatchURL(), 'link'),
91+
'PR' => $pr ? dolink_ext($pr, 'link') : '',
8892
'+' => $patch->lines_added,
8993
'-' => $patch->lines_deleted,
9094
'Files' => $patch->files_modified,
91-
'Submitter' => htmlspecialchars($patch->getSubmitterName()),
95+
'Submitter' => $patch->getSubmitterName(),
9296
'Authors' => implode(', ', $authors),
9397
];
9498
}
9599
}
96100

97-
print_table($table);
98-
99-
100-
if ($user->role == ROLE_STUDENT && $deadline->isPatchSubmissionActive()) {
101-
$bugfix = PATCH_BUGFIX;
102-
$feature = PATCH_FEATURE;
103-
104-
if ($patch_accepted) {
105-
$url = 'https://...';
106-
$description = $select_bugfix = $select_feature = '';
107-
} else {
108-
$url = htmlspecialchars($_POST['url'] ?? 'https://...');
109-
$description = htmlspecialchars($_POST['description'] ?? '');
110-
$type = (int)($_POST['type'] ?? -1);
111-
$select_bugfix = $type == $bugfix ? ' selected' : '';
112-
$select_feature = $type == $feature ? ' selected' : '';
113-
}
114-
115-
echo <<<EOF
116-
<p>&nbsp;</p>
117-
<p>Submit new patch:</p>
118-
<form action="index.php?page=patches" method="post">
119-
120-
<label for="url">URL:</label>
121-
<input type="text" id="url" name="url" value="$url" size="50">
122-
123-
<br>
124-
<label for="type">Type:</label>
125-
<select name="type" id="type">
126-
<option value="$bugfix"$select_bugfix>Bug fix</option>
127-
<option value="$feature"$select_feature>Feature</option>
128-
</select>
129-
130-
<br>
131-
<label for="description">Description:</label>
132-
<textarea id="description" name="description" rows="5" cols="60">$description</textarea>
133-
134-
<p><input type="submit"></p>
135-
</form>
136-
137-
EOF;
138-
}
139-
mk_box_end();
140-
141-
mk_deadline_box($deadline->patch_submission);
142-
mk_box_end();
101+
$deadline = $deadline->patch_submission;

0 commit comments

Comments
 (0)