Skip to content

Commit

Permalink
Added in the time to the s3 images for discuss it text
Browse files Browse the repository at this point in the history
  • Loading branch information
kreut committed Oct 10, 2024
1 parent bc7e0b9 commit eb20725
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/Http/Controllers/QuestionMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Question;
use App\QuestionMediaUpload;
use Carbon\Carbon;
use DOMDocument;
use Exception;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
Expand Down Expand Up @@ -156,13 +157,13 @@ public function getByQuestion(Assignment $assignment,
->where('question_id', $question->id)
->orderBy('order')
->get();

$domDocument = new DOMDocument();
foreach ($question_media_uploads as $key => $value) {
if (pathinfo($value->s3_key, PATHINFO_EXTENSION) != 'html') {
$question_media_uploads[$key]['temporary_url'] = Storage::disk('s3')->temporaryUrl("{$questionMediaUpload->getDir()}/$value->s3_key", Carbon::now()->addDays(7));
}
if (pathinfo($value->s3_key, PATHINFO_EXTENSION) === 'html') {
$question_media_uploads[$key]['text'] = $value->getText();
$question_media_uploads[$key]['text'] = $value->getText($question, $domDocument);

}

Expand Down
6 changes: 4 additions & 2 deletions app/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ function formatQtiJson(string $json_type, string $qti_json, $seed, bool $show_so
case('discuss_it'):
$qti_array['media_uploads'] = QuestionMediaUpload::where('question_id', $this->id)->get();
foreach ($qti_array['media_uploads'] as $key => $question_media_upload) {
$qti_array['media_uploads'][$key]['text'] = $question_media_upload->getText();
$qti_array['media_uploads'][$key]['text'] = $question_media_upload->getText($this, $domDocument);
}
break;
case('submit_molecule'):
Expand Down Expand Up @@ -3142,8 +3142,10 @@ function formatQuestionToEdit(Request $request, $question_to_edit, int $question
$question_to_edit['media_uploads'] = $questionMediaUpload->where('question_id', $this->id)
->get();
if ($question_to_edit['media_uploads']) {
$domDocument = new DOMDocument();
$question = new Question();
foreach ($question_to_edit['media_uploads'] as $key => $media_upload) {
$question_to_edit['media_uploads'][$key]->text = $media_upload->getText();
$question_to_edit['media_uploads'][$key]->text = $media_upload->getText($question, $domDocument);
if (!$question_to_edit['media_uploads'][$key]->text) {
if ($media_upload->transcript) {
$question_to_edit['media_uploads'][$key]->transcript = $questionMediaUpload->parseVtt($media_upload->transcript);
Expand Down
6 changes: 5 additions & 1 deletion app/QuestionMediaUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Exceptions\Handler;
use App\Helpers\Helper;
use DOMDocument;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
Expand All @@ -16,9 +17,11 @@ class QuestionMediaUpload extends Model
protected $guarded = [];

/**
* @param Question $question
* @param DOMDocument $domDocument
* @return string
*/
public function getText(): string
public function getText(Question $question, DOMDocument $domDocument): string
{
if (strpos($this->s3_key, '.html') !== false) {
try {
Expand All @@ -28,6 +31,7 @@ public function getText(): string
$this->save();
$text = $this->text;
}
$text = $question->addTimeToS3Images($text, new DOMDocument(), false);
} catch (Exception $e) {
$text = "Unable to retrieve the text for this discuss it question.";
}
Expand Down

0 comments on commit eb20725

Please sign in to comment.