Usability: Turn CRLF/CR/LF into BR

This commit is contained in:
Miguel N 2021-01-29 16:56:29 +00:00
parent 3a56d2bfb2
commit 0f5e812e03
1 changed files with 16 additions and 1 deletions

View File

@ -35,6 +35,21 @@ use Illuminate\Support\Facades\Log;
class ApplicationController extends Controller class ApplicationController extends Controller
{ {
private function processOSLinebreaks(array $structuredResponses)
{
$processedResponses = $structuredResponses;
foreach ($structuredResponses as $responseKey => $response)
{
// We can't use nl2br because it preserves the line breaks and doesn't include all line breaks used by other operating systems
$originalResponse = $response['response'];
$processedResponses[$responseKey]['response'] = str_replace(["\r\n", "\r", "\n"], "<br/>", $originalResponse);
}
return $processedResponses;
}
private function canVote($votes): bool private function canVote($votes): bool
{ {
$allvotes = collect([]); $allvotes = collect([]);
@ -64,7 +79,7 @@ class ApplicationController extends Controller
[ [
'application' => $application, 'application' => $application,
'comments' => $application->comments, 'comments' => $application->comments,
'structuredResponses' => json_decode($application->response->responseData, true), 'structuredResponses' => %this->processOSLinebreaks(json_decode($application->response->responseData, true)),
'formStructure' => $application->response->form, 'formStructure' => $application->response->form,
'vacancy' => $application->response->vacancy, 'vacancy' => $application->response->vacancy,
'canVote' => $this->canVote($application->votes), 'canVote' => $this->canVote($application->votes),