Skip to content

Commit d20c2a6

Browse files
authored
Merge pull request #3211 from codeeu/dev
Dev
2 parents d5c7462 + d34bf90 commit d20c2a6

3 files changed

Lines changed: 96 additions & 87 deletions

File tree

‎app/Http/Controllers/MatchMakingToolController.php‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Http\Request;
99
use Illuminate\View\View;
1010
use App\Filters\MatchmakingProfileFilters;
11+
use Symfony\Component\HttpFoundation\StreamedResponse;
1112

1213
class MatchMakingToolController extends Controller
1314
{
@@ -94,4 +95,94 @@ public function searchPOST(MatchmakingProfileFilters $filters, Request $request)
9495
->orderByDesc('start_time')
9596
->paginate(12);
9697
}
98+
99+
public function downloadTemplate()
100+
{
101+
$csvHeaders = [
102+
'Email',
103+
'Name',
104+
'Organisation name',
105+
'Organisation website',
106+
'Organisation type',
107+
'Main email address',
108+
'Country/Region/Areas of operation:',
109+
'Want to tell us more about your organisation?',
110+
'Do you give your consent to use your logo and display it in the matchmaking directory?',
111+
'What kind of activities or support can you offer to schools and educators? (Select all that apply):',
112+
'Are you interested in collaborating with schools to bring real-world expertise into the classroom?',
113+
'What types of schools are you most interested in working with?',
114+
'What areas of digital expertise does your organisation or you specialise in?',
115+
'Would you like to be part of the wider EU Code Week community and receive updates about future activities and events?',
116+
'Do you have any additional information or comments that could help us better match you with schools and educators?',
117+
'By registering as a Digital Volunteer, you agree to being contacted later to share feedback about your experience.',
118+
'Start time',
119+
'Completion time',
120+
];
121+
122+
// Example row with helpful values
123+
$exampleRow = [
124+
'example@example.com',
125+
'John Doe',
126+
'Example Organisation',
127+
'www.example.org',
128+
'Non-Governmental Organisation (NGO)',
129+
'contact@example.org',
130+
'Belgium',
131+
'Our mission is to promote coding education.',
132+
'Yes',
133+
'Delivering workshops or training;Providing learning resources or curricula;',
134+
'Yes',
135+
'Primary Schools;Secondary Schools;',
136+
'Coding and programming;Cybersecurity;',
137+
'Yes',
138+
'Additional information about our organisation.',
139+
'Yes',
140+
'2025-01-01 10:00:00',
141+
'2025-01-01 10:30:00',
142+
];
143+
144+
// Get valid options for reference
145+
$validOrgTypes = implode('; ', MatchmakingProfile::getValidOrganizationTypeOptions());
146+
$validCollaboration = implode('; ', MatchmakingProfile::getValidCollaborationOptions());
147+
$validFormats = implode('; ', MatchmakingProfile::getValidFormats());
148+
149+
$filename = 'matchmaking-template.csv';
150+
151+
$headers = [
152+
'Content-Type' => 'text/csv; charset=UTF-8',
153+
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
154+
'Pragma' => 'no-cache',
155+
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
156+
'Expires' => '0',
157+
];
158+
159+
$callback = function () use ($csvHeaders, $exampleRow, $validOrgTypes, $validCollaboration, $validFormats) {
160+
$stream = fopen('php://output', 'w');
161+
162+
// Add BOM for Excel compatibility
163+
fprintf($stream, chr(0xEF).chr(0xBB).chr(0xBF));
164+
165+
// Write headers
166+
fputcsv($stream, $csvHeaders);
167+
168+
// Write example row
169+
fputcsv($stream, $exampleRow);
170+
171+
// Write a comment row with valid options
172+
fputcsv($stream, ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
173+
fputcsv($stream, ['VALID OPTIONS:', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
174+
fputcsv($stream, ['Organisation type options:', $validOrgTypes, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
175+
fputcsv($stream, ['Collaboration options:', $validCollaboration, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
176+
fputcsv($stream, ['Format options:', $validFormats, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
177+
fputcsv($stream, ['NOTES:', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
178+
fputcsv($stream, ['- Multiple values should be separated by semicolons (;)', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
179+
fputcsv($stream, ['- Boolean fields: Yes/No', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
180+
fputcsv($stream, ['- Dates should be in format: YYYY-MM-DD HH:MM:SS', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
181+
fputcsv($stream, ['- Country should be the full country name (e.g., "Belgium", "United States")', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
182+
183+
fclose($stream);
184+
};
185+
186+
return new StreamedResponse($callback, 200, $headers);
187+
}
97188
}

‎app/Nova/Actions/DownloadMatchmakingTemplate.php‎

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Laravel\Nova\Actions\Action;
1111
use Laravel\Nova\Fields\ActionFields;
1212
use Laravel\Nova\Http\Requests\NovaRequest;
13-
use Symfony\Component\HttpFoundation\StreamedResponse;
1413

1514
class DownloadMatchmakingTemplate extends Action
1615
{
@@ -32,92 +31,8 @@ class DownloadMatchmakingTemplate extends Action
3231
*/
3332
public function handle(ActionFields $fields, Collection $models)
3433
{
35-
$csvHeaders = [
36-
'Email',
37-
'Name',
38-
'Organisation name',
39-
'Organisation website',
40-
'Organisation type',
41-
'Main email address',
42-
'Country/Region/Areas of operation:',
43-
'Want to tell us more about your organisation?',
44-
'Do you give your consent to use your logo and display it in the matchmaking directory?',
45-
'What kind of activities or support can you offer to schools and educators? (Select all that apply):',
46-
'Are you interested in collaborating with schools to bring real-world expertise into the classroom?',
47-
'What types of schools are you most interested in working with?',
48-
'What areas of digital expertise does your organisation or you specialise in?',
49-
'Would you like to be part of the wider EU Code Week community and receive updates about future activities and events?',
50-
'Do you have any additional information or comments that could help us better match you with schools and educators?',
51-
'By registering as a Digital Volunteer, you agree to being contacted later to share feedback about your experience.',
52-
'Start time',
53-
'Completion time',
54-
];
55-
56-
// Example row with helpful values
57-
$exampleRow = [
58-
'example@example.com',
59-
'John Doe',
60-
'Example Organisation',
61-
'www.example.org',
62-
'Non-Governmental Organisation (NGO)',
63-
'contact@example.org',
64-
'Belgium',
65-
'Our mission is to promote coding education.',
66-
'Yes',
67-
'Delivering workshops or training;Providing learning resources or curricula;',
68-
'Yes',
69-
'Primary Schools;Secondary Schools;',
70-
'Coding and programming;Cybersecurity;',
71-
'Yes',
72-
'Additional information about our organisation.',
73-
'Yes',
74-
'2025-01-01 10:00:00',
75-
'2025-01-01 10:30:00',
76-
];
77-
78-
// Get valid options for reference
79-
$validOrgTypes = implode('; ', MatchmakingProfile::getValidOrganizationTypeOptions());
80-
$validCollaboration = implode('; ', MatchmakingProfile::getValidCollaborationOptions());
81-
$validFormats = implode('; ', MatchmakingProfile::getValidFormats());
82-
83-
$filename = 'matchmaking-template.csv';
84-
85-
$httpHeaders = [
86-
'Content-Type' => 'text/csv; charset=UTF-8',
87-
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
88-
'Pragma' => 'no-cache',
89-
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
90-
'Expires' => '0',
91-
];
92-
93-
$callback = function () use ($csvHeaders, $exampleRow, $validOrgTypes, $validCollaboration, $validFormats) {
94-
$stream = fopen('php://output', 'w');
95-
96-
// Add BOM for Excel compatibility
97-
fprintf($stream, chr(0xEF).chr(0xBB).chr(0xBF));
98-
99-
// Write headers
100-
fputcsv($stream, $csvHeaders);
101-
102-
// Write example row
103-
fputcsv($stream, $exampleRow);
104-
105-
// Write a comment row with valid options
106-
fputcsv($stream, ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
107-
fputcsv($stream, ['VALID OPTIONS:', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
108-
fputcsv($stream, ['Organisation type options:', $validOrgTypes, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
109-
fputcsv($stream, ['Collaboration options:', $validCollaboration, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
110-
fputcsv($stream, ['Format options:', $validFormats, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
111-
fputcsv($stream, ['NOTES:', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
112-
fputcsv($stream, ['- Multiple values should be separated by semicolons (;)', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
113-
fputcsv($stream, ['- Boolean fields: Yes/No', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
114-
fputcsv($stream, ['- Dates should be in format: YYYY-MM-DD HH:MM:SS', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
115-
fputcsv($stream, ['- Country should be the full country name (e.g., "Belgium", "United States")', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
116-
117-
fclose($stream);
118-
};
119-
120-
return new StreamedResponse($callback, 200, $httpHeaders);
34+
// Redirect to the download route
35+
return Action::redirect(route('matchmaking_template_download'));
12136
}
12237

12338
/**

‎routes/web.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@
415415
Route::get('/matchmaking-tool/{slug}', [MatchMakingToolController::class, 'show'])->name(
416416
'matchmaking_tool_detail'
417417
);
418+
Route::get('/matchmaking-tool/download/template', [MatchMakingToolController::class, 'downloadTemplate'])
419+
->middleware('auth')
420+
->name('matchmaking_template_download');
418421
//Route::get('/resources/suggest', 'SuggestResourcesController@get')->name('suggest_resources')->middleware('auth');
419422
//Route::post('/resources/suggest', 'SuggestResourcesController@store')->name('store_suggest_resources')->middleware('auth');
420423

0 commit comments

Comments
 (0)