1010use Laravel \Nova \Actions \Action ;
1111use Laravel \Nova \Fields \ActionFields ;
1212use Laravel \Nova \Http \Requests \NovaRequest ;
13- use Symfony \Component \HttpFoundation \StreamedResponse ;
1413
1514class 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 /**
0 commit comments