feat: Implement SentenceListeningNote creating based on Note
This commit is contained in:
parent
605d65e468
commit
9093b1a0f8
|
@ -206,14 +206,7 @@ class CreateProductionCommand extends Command
|
||||||
));
|
));
|
||||||
$theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]);
|
$theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]);
|
||||||
|
|
||||||
$fields = $theChosenNote->getFields();
|
dd(SentenceListeningNote::fromNote($theChosenNote, $theChosenTerm));
|
||||||
$fields['VocabKanji'] = $theChosenTerm->getKanji();
|
|
||||||
$fields['VocabFurigana'] = $theChosenTerm->getReading();
|
|
||||||
$fields['VocabDef'] = $theChosenTerm->toAnkiVocabDef();
|
|
||||||
$fields['SentKanji'] = strip_tags($fields['SentKanji']);
|
|
||||||
$theChosenNote->setFields($fields);
|
|
||||||
|
|
||||||
dd($theChosenTerm->toAnkiVocabDef(), $theChosenNote->getFields());
|
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
<<<FMNT
|
<<<FMNT
|
||||||
|
|
|
@ -7,13 +7,13 @@ class Note
|
||||||
const HIGHLIGHT_PATTERN = '/<span\s+([^>]*)>(.*?)<\/span>/i';
|
const HIGHLIGHT_PATTERN = '/<span\s+([^>]*)>(.*?)<\/span>/i';
|
||||||
const HIGHLIGHT_ATTR_KANJI = 'style="color: rgb(255, 78, 8);"';
|
const HIGHLIGHT_ATTR_KANJI = 'style="color: rgb(255, 78, 8);"';
|
||||||
|
|
||||||
private readonly int $id;
|
protected ?int $id;
|
||||||
private readonly int $mod;
|
protected ?int $mod;
|
||||||
private readonly string $model;
|
protected string $model;
|
||||||
private string $profile;
|
protected string $profile;
|
||||||
private array $cardIds = [];
|
protected array $cardIds = [];
|
||||||
protected array $fields = [];
|
protected array $fields = [];
|
||||||
private array $tags = [];
|
protected array $tags = [];
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------- Getters & setters ---
|
// -------------------------------------------------- Getters & setters ---
|
||||||
|
|
|
@ -15,9 +15,12 @@ class SentenceListeningNote extends Note
|
||||||
{
|
{
|
||||||
return $this->term;
|
return $this->term;
|
||||||
}
|
}
|
||||||
public function setTerm(Term $terms): static
|
public function setTerm(Term $term): static
|
||||||
{
|
{
|
||||||
$this->term = $terms;
|
$this->fields['VocabKanji'] = $term->getKanji();
|
||||||
|
$this->fields['VocabFurigana'] = $term->getReading();
|
||||||
|
$this->fields['VocabDef'] = $term->toAnkiVocabDef();
|
||||||
|
$this->term = $term;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +46,25 @@ class SentenceListeningNote extends Note
|
||||||
return $note;
|
return $note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function fromNote(Note $origNote, Term $term): static
|
||||||
|
{
|
||||||
|
$slNote = new static();
|
||||||
|
foreach (get_object_vars($origNote) as $prop => $value) {
|
||||||
|
$slNote->$prop = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Related fields are updated using the setter
|
||||||
|
$slNote->setTerm($term);
|
||||||
|
// Remove highlighting
|
||||||
|
$slNote->fields['SentKanji'] = strip_tags($slNote->fields['SentKanji']);
|
||||||
|
// Reset relations and basic data
|
||||||
|
$slNote->id = null;
|
||||||
|
$slNote->model = self::MODEL_NAME;
|
||||||
|
$slNote->cardIds = [];
|
||||||
|
|
||||||
|
return $slNote;
|
||||||
|
}
|
||||||
|
|
||||||
public function toAnki(): array
|
public function toAnki(): array
|
||||||
{
|
{
|
||||||
return $this->fields;
|
return $this->fields;
|
||||||
|
|
Loading…
Reference in New Issue