feat: Add terms automagically when creating unicode cards
This commit is contained in:
parent
1ab67249bf
commit
76f5f30a47
|
@ -10,6 +10,8 @@ class UnicodeNote extends Note
|
||||||
const string DECK = '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
|
public static function fromCharacter(string $character): self
|
||||||
{
|
{
|
||||||
|
@ -37,6 +39,7 @@ class UnicodeNote extends Note
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'Character' => $this->getCharacter(),
|
'Character' => $this->getCharacter(),
|
||||||
'Codepoint' => $this->getHex(),
|
'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();
|
$this->fields['Codepoint'] = $this->getHex();
|
||||||
return $this;
|
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("<br/>", array_map(fn(Term $t) => $t->toAnkiVocabDef(), $this->terms));
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue