add controllers
This commit is contained in:
parent
83d9d23a0a
commit
7114b60271
217
src/Controller/AjaxController.php
Normal file
217
src/Controller/AjaxController.php
Normal file
@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Series;
|
||||
use App\Entity\Speaker;
|
||||
use App\Entity\Template;
|
||||
use App\Entity\Notes;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class AjaxController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* A method to retrieve a template
|
||||
*
|
||||
* @param Request $req description
|
||||
* @param EntityManagerInterface $emi description
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
#[Route('/retrieve-template', name: 'app_retrieve_template')]
|
||||
public function retrieveTemplate(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$ret = new Response();
|
||||
$template_id = json_decode($req->getContent())->template;
|
||||
$template = $emi->getRepository(Template::class)->find($template_id);
|
||||
$ret->setContent($template->getValue());
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
#[Route('/save-template', name: 'app_save_template')]
|
||||
public function saveTemplate(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$ret = new Response();
|
||||
$req = json_decode($req->getContent());
|
||||
$template_value = $req->template_value;
|
||||
$template_id = $req->template_id;
|
||||
$template_name = $req->template_name;
|
||||
|
||||
if($template_id) {
|
||||
$template = $emi->getRepository(Template::class)->find($template_id);
|
||||
$template->setName($template_name);
|
||||
$template->setValue($template_value);
|
||||
$emi->persist($template);
|
||||
$emi->flush();
|
||||
$ret->setContent('updated');
|
||||
} else {
|
||||
$template = new Template();
|
||||
$template->setName($template_name);
|
||||
$template->setValue($template_value);
|
||||
$emi->persist($template);
|
||||
$emi->flush();
|
||||
$ret->setContent('added');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a speaker from the database based on the given request and entity manager.
|
||||
*
|
||||
* @param Request $req The request object
|
||||
* @param EntityManagerInterface $emi The entity manager
|
||||
* @return Response
|
||||
*/
|
||||
#[Route('/retrieve-speaker', name: 'app_retrieve_speaker')]
|
||||
public function retrieveSpeaker(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$ret = new Response();
|
||||
$speaker_id = json_decode($req->getContent())->speaker;
|
||||
$speaker = $emi->getRepository(Speaker::class)->find($speaker_id);
|
||||
$ret->setContent($speaker->getProfile());
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
#[Route('/save-speaker', name: 'app_save_speaker')]
|
||||
public function saveSpeaker(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$ret = new Response();
|
||||
$req = json_decode($req->getContent());
|
||||
$speaker_id = $req->speaker_id;
|
||||
$speaker_name = $req->speaker_name;
|
||||
|
||||
if ($speaker_id) {
|
||||
$speaker = $emi->getRepository(Speaker::class)->find($speaker_id);
|
||||
$speaker->setName($speaker_name);
|
||||
$emi->persist($speaker);
|
||||
$emi->flush();
|
||||
$ret->setContent('updated');
|
||||
} else {
|
||||
$speaker = new Speaker();
|
||||
$speaker->setName($speaker_name);
|
||||
$emi->persist($speaker);
|
||||
$emi->flush();
|
||||
$ret->setContent('added');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a series
|
||||
*
|
||||
* @param Request $req description
|
||||
* @param EntityManagerInterface $emi description
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
#[Route('/retrieve-series', name: 'app_retrieve_series')]
|
||||
public function retrieveSeries(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$ret = new Response();
|
||||
$series_id = json_decode($req->getContent())->series;
|
||||
$series = $emi->getRepository(Series::class)->find($series_id);
|
||||
$ret->setContent($series->getName());
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
#[Route('/save-series', name: 'app_save_series')]
|
||||
public function saveSeries(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$ret = new Response();
|
||||
$req = json_decode($req->getContent());
|
||||
$series_id = $req->series_id;
|
||||
$series_name = $req->series_name;
|
||||
|
||||
if ($series_id) {
|
||||
$series = $emi->getRepository(Series::class)->find($series_id);
|
||||
$series->setName($series_name);
|
||||
$emi->persist($series);
|
||||
$emi->flush();
|
||||
$ret->setContent('updated');
|
||||
} else {
|
||||
$series = new Series();
|
||||
$series->setName($series_name);
|
||||
$emi->persist($series);
|
||||
$emi->flush();
|
||||
$ret->setContent('added');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
#[Route('/autocomplete-reference', name: 'app_autocomplete_reference')]
|
||||
public function autocompleteReference(Request $req): Response
|
||||
{
|
||||
$res = new Response();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
#[Route('/retrieve-reference', name: 'app_retrive_reference')]
|
||||
public function retrieveReference(Request $req): Response
|
||||
{
|
||||
$type = null;
|
||||
$search = null;
|
||||
$passage = null;
|
||||
|
||||
$res = new Response();
|
||||
$ref = json_decode($req->getContent())->reference;
|
||||
if (count(explode(':', $ref)) > 2) {
|
||||
list($type, $search, $passage) = explode(':', $ref);
|
||||
} else {
|
||||
list($type, $search) = explode(':', $ref);
|
||||
}
|
||||
|
||||
$ret = match(strtolower($type)) {
|
||||
'bible' => ReferenceController::retrieveBible("{$search}:{$passage}"),
|
||||
'hc' => ReferenceController::retrieveHC($search),
|
||||
'bc' => ReferenceController::retrieveBC($search),
|
||||
'dc' => ReferenceController::retrieveCD($search),
|
||||
'wcf' => ReferenceController::retrieveWCF($search),
|
||||
'wsc' => ReferenceController::retrieveWSC($search),
|
||||
'wlc' => ReferenceController::retrieveWLC($search),
|
||||
'creed' => ReferenceController::retrieveCreed($search)
|
||||
};
|
||||
|
||||
$res->setContent(json_encode(['text' => $ret, 'title' => "{$search}"]));
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
#[Route('/open-note', name: 'app_open_note')]
|
||||
public function openNote(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$res = new Response();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
#[Route('/save-note', name: 'app_save_note')]
|
||||
public function saveNote(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$res = new Response();
|
||||
$note = new Notes();
|
||||
$note->setTitle($req->get('title'));
|
||||
|
||||
$series = $emi->getRepository(Series::class)->find($req->get('series'));
|
||||
$speaker = $emi->getRepository(Speaker::class)->find($req->get('speaker'));
|
||||
$note->setSeries($series);
|
||||
$note->setSpeaker($speaker);
|
||||
$note->setText($req->get('note'));
|
||||
|
||||
$res->setContent(json_encode($note));
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
45
src/Controller/DefaultController.php
Normal file
45
src/Controller/DefaultController.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Speaker;
|
||||
use App\Entity\Template;
|
||||
use App\Entity\Series;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class DefaultController extends AbstractController
|
||||
{
|
||||
#[Route('/', name: 'app_default')]
|
||||
public function index(EntityManagerInterface $emi): Response
|
||||
{
|
||||
$speakers = $emi->getRepository(Speaker::class)->findAll();
|
||||
$series = $emi->getRepository(Series::class)->findAll();
|
||||
$templates = $emi->getRepository(Template::class)->findAll();
|
||||
|
||||
return $this->render('default/index.html.twig', [
|
||||
'controller_name' => 'DefaultController',
|
||||
'speakers' => $speakers,
|
||||
'series' => $series,
|
||||
'templates' => $templates
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/template-editor', name: 'app_template_editor')]
|
||||
public function templateEditor(EntityManagerInterface $emi): Response
|
||||
{
|
||||
$templates = $emi->getRepository(Template::class)->findAll();
|
||||
return $this->render('default/template-editor.html.twig', [
|
||||
'templates' => $templates
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/reference-editor', name: 'app_reference_editor')]
|
||||
public function referenceEditor(EntityManagerInterface $emi): Response
|
||||
{
|
||||
return $this->render('default/reference-editor.html.twig', []);
|
||||
}
|
||||
}
|
105
src/Controller/ReferenceController.php
Normal file
105
src/Controller/ReferenceController.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use \Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ReferenceController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Method to retrieve a Bible reference
|
||||
*
|
||||
* @param string $ref
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function retrieveBible($ref): string
|
||||
{
|
||||
if(count(explode(' ', $ref)) > 2) {
|
||||
list($index, $book, $chapter, $passage) = preg_split("/:| /", $ref);
|
||||
$book = "{$index}{$book}";
|
||||
} else {
|
||||
list($book, $chapter, $passage) = preg_split("/:| /", $ref);
|
||||
}
|
||||
|
||||
$file = glob(dirname(dirname(__DIR__))."/references/Bible/* - {$book}/{$book}{$chapter}.md");
|
||||
$res = implode("\n", file(current($file)));
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a creed
|
||||
*
|
||||
* @param string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function retrieveCreed($ref)
|
||||
{
|
||||
$file = match($ref) {
|
||||
'apc' => "Apostle's Creed.md",
|
||||
'atc' => "Athanasian Creed.md",
|
||||
'dc' => 'Definition of Chalcedon.md',
|
||||
'fc' => 'French Confession.md',
|
||||
'nc' => 'Nicene Creed.md'
|
||||
};
|
||||
|
||||
return implode("\n", file(dirname(dirname(__DIR__))."/references/Creeds/{$file}"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a Heidelberg Catechism reference
|
||||
*
|
||||
* @param string $ref
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function retrieveHC($ref)
|
||||
{
|
||||
$ref = strtoupper($ref);
|
||||
return implode("\n", file(dirname(dirname(__DIR__))."/references/Heidelberg/{$ref}.md"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a Belgian Catechism reference
|
||||
*
|
||||
* @param string $ref
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function retrieveBC($ref)
|
||||
{
|
||||
$ref = ucfirst($ref);
|
||||
return implode("\n", file(dirname(dirname(__DIR__))."/references/Belgic/{$ref}.md"));
|
||||
}
|
||||
|
||||
public static function retrieveCD($ref)
|
||||
{
|
||||
$ref = strtoupper($ref);
|
||||
return implode("\n", file(dirname(dirname(__DIR__))."/references/Dort/{$ref}.md"));
|
||||
}
|
||||
|
||||
public static function retrieveWSC($ref)
|
||||
{
|
||||
$art = str_pad($ref, 3, '0', STR_PAD_LEFT);
|
||||
$files = glob(dirname(dirname(__DIR__))."/references/Westminster/Shorter Catechism/WSC{$art}.md");
|
||||
return implode("\n", file(current($files)));
|
||||
}
|
||||
|
||||
public static function retrieveWLC($ref)
|
||||
{
|
||||
$art = str_pad($ref, 3, '0', STR_PAD_LEFT);
|
||||
$files = glob(dirname(dirname(__DIR__))."/references/Westminster/Larger Catechism/WLC{$art}.md");
|
||||
return implode("\n", file(current($files)));
|
||||
}
|
||||
|
||||
public static function retrieveWCF($ref)
|
||||
{
|
||||
$files = glob(dirname(dirname(__DIR__))."/references/Westminster/Confessions/Chapter {$ref}.md");
|
||||
return implode("\n", file(current($files)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user