|
4 | 4 |
|
5 | 5 | require_once 'email.php';
|
6 | 6 |
|
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; |
8 | 12 |
|
9 | 13 | $user = get_user();
|
10 | 14 | $group = $user->getGroup();
|
11 | 15 | $deadline = db_fetch_deadline($group ? $group->year : get_current_year());
|
12 | 16 |
|
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 | + } |
39 | 51 | }
|
40 | 52 | }
|
41 | 53 |
|
42 |
| - |
43 | 54 | 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', |
47 | 57 | 'needs_review');
|
48 | 58 | $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> </p>\n"; |
| 59 | + 'open_patches');*/ |
56 | 60 | } else {
|
57 | 61 | $groups = $user->groups;
|
58 | 62 | }
|
|
70 | 74 |
|
71 | 75 | $authors = [];
|
72 | 76 | foreach ($patch->students as $author) {
|
73 |
| - $authors[] = htmlspecialchars($author->shortName()); |
| 77 | + $authors[] = $author->shortName(); |
74 | 78 | }
|
75 | 79 |
|
76 | 80 | $pr = $patch->getPRURL();
|
|
82 | 86 | ['id' => $group->id]),
|
83 | 87 | 'Status' => $patch->getStatus(),
|
84 | 88 | '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') : '', |
88 | 92 | '+' => $patch->lines_added,
|
89 | 93 | '-' => $patch->lines_deleted,
|
90 | 94 | 'Files' => $patch->files_modified,
|
91 |
| - 'Submitter' => htmlspecialchars($patch->getSubmitterName()), |
| 95 | + 'Submitter' => $patch->getSubmitterName(), |
92 | 96 | 'Authors' => implode(', ', $authors),
|
93 | 97 | ];
|
94 | 98 | }
|
95 | 99 | }
|
96 | 100 |
|
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> </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