AnkiDeckImportController
extends VocabularyBaseController
in package
Import a deck built in Anki as new LWT terms (issue #228).
Two steps, because LWT cannot guess any of the mapping: an .apkg carries no language, and field names in a shared deck are arbitrary.
GET /vocabulary/anki-deck/import upload form POST /vocabulary/anki-deck/import upload -> configure, or configure -> import
The uploaded file is parked in a temp path between the two steps, keyed by a token held in the session so the second request cannot be pointed at an arbitrary path.
Table of Contents
Constants
- SESSION_KEY : mixed = 'lwt_anki_deck_import'
Properties
- $bulkService : WordBulkService|null
- $contextService : WordContextService|null
- $crudService : WordCrudService|null
- Lazy-loaded services.
- $discoveryService : WordDiscoveryService|null
- $expressionService : ExpressionService|null
- $linkingService : WordLinkingService|null
- $multiWordService : MultiWordService|null
- $sentenceService : SentenceService|null
- $textStatisticsService : TextStatisticsService|null
- $uploadService : WordUploadService|null
- $viewPath : string
- View base path.
- $importService : AnkiDeckImportService|null
- $languageFacade : LanguageFacade
- $reader : ForeignApkgReader
Methods
- __construct() : mixed
- Constructor.
- index() : void
- setViewPath() : void
- Set custom view path.
- getBulkService() : WordBulkService
- Get WordBulkService (lazy loaded).
- getContextService() : WordContextService
- Get WordContextService (lazy loaded).
- getCrudService() : WordCrudService
- Get WordCrudService (lazy loaded).
- getDiscoveryService() : WordDiscoveryService
- Get WordDiscoveryService (lazy loaded).
- getExpressionService() : ExpressionService
- Get ExpressionService (lazy loaded).
- getLinkingService() : WordLinkingService
- Get WordLinkingService (lazy loaded).
- getMultiWordService() : MultiWordService
- Get MultiWordService (lazy loaded).
- getSentenceService() : SentenceService
- Get SentenceService (lazy loaded).
- getTextStatisticsService() : TextStatisticsService
- Get TextStatisticsService (lazy loaded).
- getUploadService() : WordUploadService
- Get WordUploadService (lazy loaded).
- render() : void
- Render a view.
- csrfField() : string
- esc() : string
- fieldSelect() : string
- forgetParkedFile() : void
- handleImport() : void
- Step 2: apply the chosen mapping.
- handleUpload() : void
- Step 1: accept the upload, park it, show the mapping form.
- importSvc() : AnkiDeckImportService
- optionalField() : string|null
- parkedFile() : string|null
- The parked upload for this session, if it is still there.
- rememberParkedFile() : void
- renderMappingForm() : void
- renderSummary() : void
- renderUploadForm() : void
- statusLabel() : string
Constants
SESSION_KEY
private
mixed
SESSION_KEY
= 'lwt_anki_deck_import'
Properties
$bulkService
protected
WordBulkService|null
$bulkService
= null
$contextService
protected
WordContextService|null
$contextService
= null
$crudService
Lazy-loaded services.
protected
WordCrudService|null
$crudService
= null
$discoveryService
protected
WordDiscoveryService|null
$discoveryService
= null
$expressionService
protected
ExpressionService|null
$expressionService
= null
$linkingService
protected
WordLinkingService|null
$linkingService
= null
$multiWordService
protected
MultiWordService|null
$multiWordService
= null
$sentenceService
protected
SentenceService|null
$sentenceService
= null
$textStatisticsService
protected
TextStatisticsService|null
$textStatisticsService
= null
$uploadService
protected
WordUploadService|null
$uploadService
= null
$viewPath
View base path.
protected
string
$viewPath
$importService
private
AnkiDeckImportService|null
$importService
$languageFacade
private
LanguageFacade
$languageFacade
$reader
private
ForeignApkgReader
$reader
Methods
__construct()
Constructor.
public
__construct([LanguageFacade|null $languageFacade = null ][, ForeignApkgReader|null $reader = null ][, AnkiDeckImportService|null $importService = null ]) : mixed
Parameters
- $languageFacade : LanguageFacade|null = null
- $reader : ForeignApkgReader|null = null
- $importService : AnkiDeckImportService|null = null
index()
public
index(array<string, string> $params) : void
Parameters
- $params : array<string, string>
-
Route params (unused).
setViewPath()
Set custom view path.
public
setViewPath(string $path) : void
Parameters
- $path : string
-
View path
getBulkService()
Get WordBulkService (lazy loaded).
protected
getBulkService() : WordBulkService
Return values
WordBulkServicegetContextService()
Get WordContextService (lazy loaded).
protected
getContextService() : WordContextService
Return values
WordContextServicegetCrudService()
Get WordCrudService (lazy loaded).
protected
getCrudService() : WordCrudService
Return values
WordCrudServicegetDiscoveryService()
Get WordDiscoveryService (lazy loaded).
protected
getDiscoveryService() : WordDiscoveryService
Return values
WordDiscoveryServicegetExpressionService()
Get ExpressionService (lazy loaded).
protected
getExpressionService() : ExpressionService
Return values
ExpressionServicegetLinkingService()
Get WordLinkingService (lazy loaded).
protected
getLinkingService() : WordLinkingService
Return values
WordLinkingServicegetMultiWordService()
Get MultiWordService (lazy loaded).
protected
getMultiWordService() : MultiWordService
Return values
MultiWordServicegetSentenceService()
Get SentenceService (lazy loaded).
protected
getSentenceService() : SentenceService
Return values
SentenceServicegetTextStatisticsService()
Get TextStatisticsService (lazy loaded).
protected
getTextStatisticsService() : TextStatisticsService
Return values
TextStatisticsServicegetUploadService()
Get WordUploadService (lazy loaded).
protected
getUploadService() : WordUploadService
Return values
WordUploadServicerender()
Render a view.
protected
render(string $view[, array<string|int, mixed> $data = [] ]) : void
Parameters
- $view : string
-
View name (without .php)
- $data : array<string|int, mixed> = []
-
View data
csrfField()
private
csrfField() : string
Return values
stringesc()
private
esc(string $value) : string
Parameters
- $value : string
Return values
stringfieldSelect()
private
fieldSelect(string $name, string $label, array<int, string> $fieldNames, bool $optional) : string
Parameters
- $name : string
- $label : string
- $fieldNames : array<int, string>
- $optional : bool
Return values
stringforgetParkedFile()
private
forgetParkedFile() : void
handleImport()
Step 2: apply the chosen mapping.
private
handleImport() : void
handleUpload()
Step 1: accept the upload, park it, show the mapping form.
private
handleUpload() : void
importSvc()
private
importSvc() : AnkiDeckImportService
Return values
AnkiDeckImportServiceoptionalField()
private
optionalField(string $key) : string|null
Parameters
- $key : string
Return values
string|nullparkedFile()
The parked upload for this session, if it is still there.
private
parkedFile() : string|null
Reading the path from the session rather than the request is what stops step 2 being pointed at an arbitrary file on disk.
Return values
string|nullrememberParkedFile()
private
rememberParkedFile(string $path) : void
Parameters
- $path : string
renderMappingForm()
private
renderMappingForm(array<int, ForeignNotetype> $notetypes, string|null $error) : void
Parameters
- $notetypes : array<int, ForeignNotetype>
- $error : string|null
renderSummary()
private
renderSummary(DeckImportResult $result, DeckImportSettings $settings) : void
Parameters
- $result : DeckImportResult
- $settings : DeckImportSettings
renderUploadForm()
private
renderUploadForm(string|null $error) : void
Parameters
- $error : string|null
statusLabel()
private
statusLabel(int $status) : string
Parameters
- $status : int