diff --git a/src/Command/CreateProductionCommand.php b/src/Command/CreateProductionCommand.php index f5238a8..2bb765c 100644 --- a/src/Command/CreateProductionCommand.php +++ b/src/Command/CreateProductionCommand.php @@ -206,14 +206,7 @@ class CreateProductionCommand extends Command )); $theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]); - $fields = $theChosenNote->getFields(); - $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()); + dd(SentenceListeningNote::fromNote($theChosenNote, $theChosenTerm)); printf( <<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; } @@ -43,6 +46,25 @@ class SentenceListeningNote extends 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 { return $this->fields;