Documentation

ReviewService

Service class for managing word reviews.

Handles test SQL generation, word selection, status updates, and progress tracking for vocabulary testing.

Tags
category

Lwt

author

HugoFara hugo.farajallah@protonmail.com

license

Unlicense http://unlicense.org/

link
https://hugofara.github.io/lwt/docs/php/
since
3.0.0

Table of Contents

Properties

$sentenceService  : SentenceService
Sentence service instance
$sessionManager  : SessionStateManager
Session state manager instance

Methods

__construct()  : mixed
Constructor - initialize dependencies.
buildSelectionReviewSql()  : string|null
Build test SQL from selection.
calculateNewStatus()  : int
Calculate new status based on status change direction.
calculateStatusChange()  : int
Calculate status change direction.
clampReviewType()  : int
Clamp test type to valid range.
getBaseReviewType()  : int
Get base test type (removes word mode offset).
getEditFrameWaitingTime()  : int
Get edit frame waiting time setting.
getL2LanguageName()  : string
Get language name for test.
getLanguageIdFromReviewSql()  : int|null
Get the language ID from test SQL.
getLanguageSettings()  : array<string|int, mixed>
Get language settings for test display.
getNextWord()  : array<string|int, mixed>|null
Get the next word to test.
getReviewCounts()  : array{due: int, total: int}
Get test counts (due and total).
getReviewDataFromParams()  : array{title: string, property: string, reviewsql: string, counts: array{due: int, total: int}}|null
Get test data from request parameters.
getReviewIdentifier()  : array{0: string, 1: int|int[]|string}
Get test identifier from request parameters.
getReviewSessionData()  : array{start: int, correct: int, wrong: int, total: int}
Get review session data.
getReviewSql()  : string|null
Get SQL projection for test.
getSentenceForWord()  : array{sentence: string|null, found: bool}
Get sentence containing the word for testing.
getTableReviewSettings()  : array{edit: int, status: int, term: int, trans: int, rom: int, sentence: int}
Get table test settings.
getTableReviewWords()  : mysqli_result|bool
Get words for table test.
getTestSolution()  : string
Get test solution text.
getTomorrowReviewCount()  : int
Get tomorrow's test count.
getWaitingTime()  : int
Get waiting time setting.
getWordText()  : string|null
Get word text by ID.
initializeReviewSession()  : void
Initialize review session.
isWordMode()  : bool
Check if test type is word mode (no sentence).
updateSessionProgress()  : array{total: int, wrong: int, correct: int, remaining: int}
Update session progress after test.
updateWordStatus()  : array{oldStatus: int, newStatus: int, oldScore: int, newScore: int}
Update word status during test.
validateReviewSelection()  : array{valid: bool, langCount: int, error: string|null}
Validate test selection (check single language).

Properties

Methods

buildSelectionReviewSql()

Build test SQL from selection.

public buildSelectionReviewSql(int $selectionType, string $selectionData) : string|null
Parameters
$selectionType : int

Selection type (2=words, 3=texts)

$selectionData : string

Comma-separated IDs

Return values
string|null

SQL projection string

calculateNewStatus()

Calculate new status based on status change direction.

public calculateNewStatus(int $oldStatus, int $change) : int
Parameters
$oldStatus : int

Current status

$change : int

Change amount (+1 or -1)

Return values
int

New status (clamped to 1-5)

calculateStatusChange()

Calculate status change direction.

public calculateStatusChange(int $oldStatus, int $newStatus) : int
Parameters
$oldStatus : int

Old status

$newStatus : int

New status

Return values
int

-1, 0, or 1

clampReviewType()

Clamp test type to valid range.

public clampReviewType(int $testType) : int
Parameters
$testType : int

Raw test type

Return values
int

Test type clamped to 1-5

getBaseReviewType()

Get base test type (removes word mode offset).

public getBaseReviewType(int $testType) : int
Parameters
$testType : int

Test type

Return values
int

Base test type (1-3)

getEditFrameWaitingTime()

Get edit frame waiting time setting.

public getEditFrameWaitingTime() : int
Return values
int

Waiting time in milliseconds

getL2LanguageName()

Get language name for test.

public getL2LanguageName(int|null $lang, int|null $text[, int|null $selection = null ][, string|null $reviewsql = null ]) : string
Parameters
$lang : int|null

Language ID

$text : int|null

Text ID

$selection : int|null = null

Selection type

$reviewsql : string|null = null

Test SQL for selection

Return values
string

Language name or 'L2' as default

getLanguageIdFromReviewSql()

Get the language ID from test SQL.

public getLanguageIdFromReviewSql(string $reviewsql) : int|null
Parameters
$reviewsql : string

Test SQL projection

Return values
int|null

Language ID or null

getLanguageSettings()

Get language settings for test display.

public getLanguageSettings(int $langId) : array<string|int, mixed>
Parameters
$langId : int

Language ID

Return values
array<string|int, mixed>

Language settings

getNextWord()

Get the next word to test.

public getNextWord(string $reviewsql) : array<string|int, mixed>|null
Parameters
$reviewsql : string

SQL projection string

Return values
array<string|int, mixed>|null

Word record or null if none available

getReviewCounts()

Get test counts (due and total).

public getReviewCounts(string $reviewsql) : array{due: int, total: int}
Parameters
$reviewsql : string

SQL projection string

Return values
array{due: int, total: int}

getReviewDataFromParams()

Get test data from request parameters.

public getReviewDataFromParams(int|null $selection, string|null $sessTestsql, int|null $langId, int|null $textId) : array{title: string, property: string, reviewsql: string, counts: array{due: int, total: int}}|null
Parameters
$selection : int|null

Selection type

$sessTestsql : string|null

Session test SQL

$langId : int|null

Language ID

$textId : int|null

Text ID

Return values
array{title: string, property: string, reviewsql: string, counts: array{due: int, total: int}}|null

getReviewIdentifier()

Get test identifier from request parameters.

public getReviewIdentifier(int|null $selection, string|null $sessTestsql, int|null $lang, int|null $text) : array{0: string, 1: int|int[]|string}
Parameters
$selection : int|null

Test is of type selection

$sessTestsql : string|null

SQL string for test

$lang : int|null

Test is of type language

$text : int|null

Testing text with ID $text

Return values
array{0: string, 1: int|int[]|string}

Selector type and selection value

getReviewSessionData()

Get review session data.

public getReviewSessionData() : array{start: int, correct: int, wrong: int, total: int}
Return values
array{start: int, correct: int, wrong: int, total: int}

getReviewSql()

Get SQL projection for test.

public getReviewSql(string $selector, int|array<string|int, int> $selection) : string|null
Parameters
$selector : string

Type of test ('words', 'texts', 'lang', 'text')

$selection : int|array<string|int, int>

Selection value

Return values
string|null

SQL projection string

getSentenceForWord()

Get sentence containing the word for testing.

public getSentenceForWord(int $wordId, string $wordlc) : array{sentence: string|null, found: bool}
Parameters
$wordId : int

Word ID

$wordlc : string

Lowercase word text

Return values
array{sentence: string|null, found: bool}

getTableReviewSettings()

Get table test settings.

public getTableReviewSettings() : array{edit: int, status: int, term: int, trans: int, rom: int, sentence: int}
Return values
array{edit: int, status: int, term: int, trans: int, rom: int, sentence: int}

getTableReviewWords()

Get words for table test.

public getTableReviewWords(string $reviewsql) : mysqli_result|bool
Parameters
$reviewsql : string

SQL projection string

Return values
mysqli_result|bool

Query result

getTestSolution()

Get test solution text.

public getTestSolution(int $testType, array<string, mixed> $wordData, bool $wordMode, string $wordText) : string
Parameters
$testType : int

Test type (1-5)

$wordData : array<string, mixed>

Word record data

$wordMode : bool

Whether in word mode (no sentence)

$wordText : string

Word text for display

Return values
string

Solution text

getTomorrowReviewCount()

Get tomorrow's test count.

public getTomorrowReviewCount(string $reviewsql) : int
Parameters
$reviewsql : string

SQL projection string

Return values
int

Number of tests due tomorrow

getWaitingTime()

Get waiting time setting.

public getWaitingTime() : int
Return values
int

Waiting time in milliseconds

getWordText()

Get word text by ID.

public getWordText(int $wordId) : string|null
Parameters
$wordId : int

Word ID

Return values
string|null

Word text or null

initializeReviewSession()

Initialize review session.

public initializeReviewSession(int $totalDue) : void
Parameters
$totalDue : int

Total words due for review

isWordMode()

Check if test type is word mode (no sentence).

public isWordMode(int $testType) : bool
Parameters
$testType : int

Test type

Return values
bool

True if word mode (type > 3)

updateSessionProgress()

Update session progress after test.

public updateSessionProgress(int $statusChange) : array{total: int, wrong: int, correct: int, remaining: int}
Parameters
$statusChange : int

Status change direction (-1, 0, or 1)

Return values
array{total: int, wrong: int, correct: int, remaining: int}

updateWordStatus()

Update word status during test.

public updateWordStatus(int $wordId, int $newStatus) : array{oldStatus: int, newStatus: int, oldScore: int, newScore: int}
Parameters
$wordId : int

Word ID

$newStatus : int

New status (1-5)

Return values
array{oldStatus: int, newStatus: int, oldScore: int, newScore: int}

validateReviewSelection()

Validate test selection (check single language).

public validateReviewSelection(string $reviewsql) : array{valid: bool, langCount: int, error: string|null}
Parameters
$reviewsql : string

SQL projection string

Return values
array{valid: bool, langCount: int, error: string|null}

        
On this page

Search results