Skip to content

Commit

Permalink
Merge pull request #269 from art-institute-of-chicago/fix/transript-o…
Browse files Browse the repository at this point in the history
…utput

Convert HTML paragraphs to new lines in transcripts [MA-167]
  • Loading branch information
nikhiltri authored Jun 10, 2024
2 parents 1d2451a + b2fcbc5 commit cfbd700
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
8 changes: 8 additions & 0 deletions app/Helpers/StringHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,12 @@ public static function summation(array $array = [])
return implode(', ', $array) . ', and ' . $last;
}
}

public static function convertHtmlParagraphsToNewlines($text)
{
$return = preg_replace('/<p[^>]*>/', '', $text);
$return = str_replace('</p>', "\r\n", $return);
$return = preg_replace('/<br[^>]*>/', "\r\n", $return);
return $return;
}
}
3 changes: 2 additions & 1 deletion app/Models/Transformers/AudioTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use A17\Twill\Models\Contracts\TwillModelContract;
use App\Repositories\Serializers\OptionalKeyArraySerializer;
use App\Helpers\StringHelpers;
use League\Fractal\TransformerAbstract;

class AudioTransformer extends TransformerAbstract
Expand All @@ -21,7 +22,7 @@ public function transform(TwillModelContract $audio)
'title' => $audio->title,
'nid' => (string) $audio->id, // Legacy from Drupal
'audio_file_url' => $audio->content,
'audio_transcript' => $audio->transcript,
'audio_transcript' => StringHelpers::convertHtmlParagraphsToNewlines($audio->transcript),
'track_title' => null, // Legacy from Drupal
])
];
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Transformers/AudioTranslationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use A17\Twill\Models\Contracts\TwillModelContract;
use League\Fractal\TransformerAbstract;
use App\Helpers\StringHelpers;

class AudioTranslationTransformer extends TransformerAbstract
{
Expand All @@ -17,7 +18,7 @@ public function transform(TwillModelContract $translation)
'audio_file_url' => $translation->content,
'audio_filemime' => null, // Legacy from Drupal
'audio_filesize' => null, // Legacy from Drupal
'audio_transcript' => $translation->transcript,
'audio_transcript' => StringHelpers::convertHtmlParagraphsToNewlines($translation->transcript),
'credits' => null, // Legacy from Drupal
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use App\Models\LoanObject;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
LoanObject::query()->update(['is_on_view' => 1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
Schema::table('loan_objects', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use Illuminate\Support\Facades\Schema;
use App\Models\Selector;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
Schema::table('selectors', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use Illuminate\Support\Facades\Schema;
use App\Models\LoanObject;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
Schema::table('loan_objects', function (Blueprint $table) {
Expand Down

0 comments on commit cfbd700

Please sign in to comment.