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)]);
|
||||
|
||||
$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(
|
||||
<<<FMNT
|
||||
|
|
|
@ -7,13 +7,13 @@ class Note
|
|||
const HIGHLIGHT_PATTERN = '/<span\s+([^>]*)>(.*?)<\/span>/i';
|
||||
const HIGHLIGHT_ATTR_KANJI = 'style="color: rgb(255, 78, 8);"';
|
||||
|
||||
private readonly int $id;
|
||||
private readonly int $mod;
|
||||
private readonly string $model;
|
||||
private string $profile;
|
||||
private array $cardIds = [];
|
||||
protected ?int $id;
|
||||
protected ?int $mod;
|
||||
protected string $model;
|
||||
protected string $profile;
|
||||
protected array $cardIds = [];
|
||||
protected array $fields = [];
|
||||
private array $tags = [];
|
||||
protected array $tags = [];
|
||||
|
||||
|
||||
// -------------------------------------------------- Getters & setters ---
|
||||
|
|
|
@ -15,9 +15,12 @@ class SentenceListeningNote extends Note
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue