diff --git a/src/Command/CreateProductionCommand.php b/src/Command/CreateProductionCommand.php index 2bb765c..4f6fbc4 100644 --- a/src/Command/CreateProductionCommand.php +++ b/src/Command/CreateProductionCommand.php @@ -206,7 +206,10 @@ class CreateProductionCommand extends Command )); $theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]); - dd(SentenceListeningNote::fromNote($theChosenNote, $theChosenTerm)); + $newSlNote = SentenceListeningNote::fromNote($theChosenNote, $theChosenTerm); + if (!$this->ankiService->addNote($newSlNote, 'production')) { + throw new \Exception('Failed to add note!'); + } printf( <<id; } + public function setId(int $id): static + { + $this->id = $id; + return $this; + } public function getModel(): string { return $this->model; @@ -36,6 +41,11 @@ class Note $this->fields = $fields; return $this; } + /** @return list */ + public function getTags(): array + { + return $this->tags; + } // ------------------------------------------------------- Anki-related --- diff --git a/src/Service/AnkiService.php b/src/Service/AnkiService.php index 7dd224f..9e1eaee 100644 --- a/src/Service/AnkiService.php +++ b/src/Service/AnkiService.php @@ -32,6 +32,22 @@ class AnkiService return $result; } + /** The note's id is updated on success. + * @return bool True on success + */ + public function addNote(Note &$note, string $deckName): bool + { + $note->setId($this->request('addNote', ['note' => [ + 'deckName' => $deckName, + 'modelName' => $note->getModel(), + 'fields' => $note->getFields(), + 'options' => ['allowDuplicate' => false], + 'tags' => array_merge($note->getTags(), ['anker_made']), + ]])); + + return $note->getId() !== null; + } + public function findNotesIds(string $query): array { return $this->request('findNotes', ['query' => $query]);