From 76f5f30a47b1433a8f1504a6cf92848a6578b938 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Mon, 8 Sep 2025 08:25:31 +0200 Subject: [PATCH] feat: Add terms automagically when creating unicode cards --- src/Entity/UnicodeNote.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Entity/UnicodeNote.php b/src/Entity/UnicodeNote.php index 7c92ab6..121260a 100644 --- a/src/Entity/UnicodeNote.php +++ b/src/Entity/UnicodeNote.php @@ -9,7 +9,9 @@ class UnicodeNote extends Note const string MODEL_NAME = 'Unicode'; const string DECK = 'unicode'; - private ?int $codepoint = null; + private ?int $codepoint = null; + /** @var Term[] */ + private array $terms = []; public static function fromCharacter(string $character): self { @@ -37,6 +39,7 @@ class UnicodeNote extends Note 'fields' => [ 'Character' => $this->getCharacter(), 'Codepoint' => $this->getHex(), + 'Examples' => implode("\n", array_map(fn(Term $t) => $t->toAnkiVocabDef(), $this->terms)), ], ]); } @@ -96,4 +99,18 @@ class UnicodeNote extends Note $this->fields['Codepoint'] = $this->getHex(); return $this; } + + /** @return Term[] */ + public function getTerms(): array + { + return $this->terms; + } + + /** @param Term[] $terms */ + public function setTerms(array $terms): static + { + $this->terms = $terms; + $this->fields['Examples'] = implode("
", array_map(fn(Term $t) => $t->toAnkiVocabDef(), $this->terms)); + return $this; + } }