84 lines
2.3 KiB
PHP
84 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Note;
|
|
use App\Entity\SentenceNote;
|
|
use App\Entity\Term;
|
|
use App\Service\AnkiService;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
#[Route('/anki', name: 'app_anki_')]
|
|
class AnkiController extends AbstractController
|
|
{
|
|
function __construct(
|
|
private AnkiService $ankiService,
|
|
) {}
|
|
|
|
public static function tmpl(string $path): string
|
|
{
|
|
return "anki/$path.html.twig";
|
|
}
|
|
|
|
#[Route('/', name: 'main')]
|
|
public function index(): Response
|
|
{
|
|
$allIds = $this->ankiService->getAllSentenceNoteIds();
|
|
$allNotes = $this->ankiService->getNotes($allIds);
|
|
|
|
$kanjiNotes = [];
|
|
foreach ($allNotes as $note) {
|
|
if (!$note instanceof SentenceNote) throw new \Exception(sprintf(
|
|
'Expected SentenceNote, got %s',
|
|
$note::class,
|
|
));
|
|
|
|
foreach ($note->getTerms() as $term) {
|
|
assert($term instanceof Term);
|
|
|
|
if (key_exists($term->getKanji(), $kanjiNotes)) continue;
|
|
|
|
$newNote = new Note();
|
|
|
|
echo $note->getFields()['SentKanji'];
|
|
echo '<br><small>';
|
|
echo var_dump($note->getHighlightedKanji());
|
|
echo '</small><br><br>';
|
|
//echo $term->getKanji();
|
|
//echo ' | ';
|
|
|
|
$kanjiNotes[$term->getKanji()] = $newNote;
|
|
}
|
|
}
|
|
|
|
die();
|
|
}
|
|
|
|
#[Route('/nonconforming', name: 'nonconforming')]
|
|
public function nonconforming(): Response
|
|
{
|
|
$allIds = $this->ankiService->getAllNoteIds();
|
|
|
|
$allNotes = $this->ankiService->getNotes($allIds);
|
|
|
|
$lacking = array_filter($allNotes, function ($note) {
|
|
assert($note instanceof Note);
|
|
return empty($note->getTerms());
|
|
});
|
|
|
|
return $this->render(self::tmpl('nonconforming'), [
|
|
'notes' => $lacking,
|
|
]);
|
|
}
|
|
|
|
#[Route('/note/{nid}/get', name: 'get_note')]
|
|
public function get_note(int $nid)
|
|
{
|
|
$note = $this->ankiService->getNote($nid);
|
|
//$this->ankiService->updateNote($note);
|
|
dd($note);
|
|
}
|
|
}
|