Added LBC and note reference retrieval

Convert get-reference to retrieve data from database instead of files
Fixed error with saving new note
This commit is contained in:
Ryan Prather 2024-05-26 22:43:56 -04:00
parent 435402ee41
commit a20caf1fc8

View File

@ -166,6 +166,7 @@ class AjaxController extends AbstractController
} }
ReferenceController::$emi = $emi; ReferenceController::$emi = $emi;
$user = $this->getUser();
$ret = match(strtolower($data->type)) { $ret = match(strtolower($data->type)) {
'bible' => ReferenceController::retrieveBible("{$data->book} {$search}"), 'bible' => ReferenceController::retrieveBible("{$data->book} {$search}"),
@ -175,7 +176,9 @@ class AjaxController extends AbstractController
'wcf' => ReferenceController::retrieveWCF($ref), 'wcf' => ReferenceController::retrieveWCF($ref),
'wsc' => ReferenceController::retrieveWSC($ref), 'wsc' => ReferenceController::retrieveWSC($ref),
'wlc' => ReferenceController::retrieveWLC($ref), 'wlc' => ReferenceController::retrieveWLC($ref),
'creed' => ReferenceController::retrieveCreed($data->book) 'lbc' => ReferenceController::retrieveLBC($ref),
'creed' => ReferenceController::retrieveCreed($data->book),
'note' => ReferenceController::retrieveNote($user)
}; };
if (!is_a($ret, Reference::class)) { if (!is_a($ret, Reference::class)) {
@ -195,19 +198,12 @@ class AjaxController extends AbstractController
{ {
$res = new Response(); $res = new Response();
$data = json_decode($req->getContent()); $data = json_decode($req->getContent());
$ret = match ($data->type) { $ref = $emi->getRepository(Reference::class)->find($data->file);
'creed' => '/Creeds/',
'bc' => '/Belgic/',
'hc' => '/Heidelberg/',
'cd' => '/Dort/',
'wcf' => '/Westminster/Confessions/',
'wsc' => '/Westminster/Shorter Catechism/',
'wlc' => '/Westminster/Larger Catechism/'
};
$fc = file_get_contents(dirname(dirname(__DIR__))."/references{$ret}{$data->file}"); if (!is_a($ref, Reference::class)) {
$ref = new Reference();
$res->setContent(json_encode(['text' => $fc])); }
$res->setContent(json_encode(['text' => $ref->getContent()]));
return $res; return $res;
} }
@ -274,6 +270,10 @@ class AjaxController extends AbstractController
if (is_array($note) && count($note) > 0) { if (is_array($note) && count($note) > 0) {
/** @var Note $note */ /** @var Note $note */
$note = $note[0]; $note = $note[0];
} else {
$note = new Note();
$newNote = true;
$note->setUser($this->getUser());
} }
} else { } else {
$note = new Note(); $note = new Note();
@ -293,6 +293,7 @@ class AjaxController extends AbstractController
->setSpeaker($speaker) ->setSpeaker($speaker)
->setText($data->note) ->setText($data->note)
->setPassage($data->passage) ->setPassage($data->passage)
->setRecording($data->recording)
->setRefs($refs); ->setRefs($refs);
$emi->persist($note); $emi->persist($note);