Documentation

TextController extends BaseController
in package

Controller for text management and reading interface.

Handles:

  • Text reading interface
  • Text CRUD operations
  • Text display/print modes
  • Archived texts
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

Constants

MODULE_VIEWS  = __DIR__ . '/../Views'
Module views path.

Properties

$displayService  : TextDisplayService
$languageService  : LanguageFacade
$textService  : TextFacade

Methods

__construct()  : mixed
Create a new TextController.
archive()  : RedirectResponse
Archive a text.
archived()  : RedirectResponse|null
Archived texts management (replaces text_archived.php)
archivedEdit()  : RedirectResponse|null
Edit archived text form.
check()  : void
Check text (replaces text_check.php)
delete()  : RedirectResponse
Delete a text.
deleteArchived()  : RedirectResponse
Delete an archived text.
display()  : RedirectResponse|null
Display improved text (replaces text_display.php)
edit()  : RedirectResponse|null
Edit texts list (replaces text_edit.php)
editSingle()  : RedirectResponse|null
Edit single text form.
new()  : RedirectResponse|null
Show new text form.
read()  : RedirectResponse|null
Read text interface.
setMode()  : void
Set text mode (replaces text_set_mode.php)
unarchive()  : RedirectResponse
Unarchive a text.
endRender()  : void
End page rendering with standard LWT footer.
execute()  : int
Execute an INSERT/UPDATE/DELETE query.
get()  : string
Get a string GET parameter.
getMarkedIds()  : array<string|int, int>
Get IDs from marked checkboxes.
getValue()  : mixed
Get a single value from the database.
hasParam()  : bool
Check if a parameter exists in the request.
isGet()  : bool
Check if the request is a GET request.
isPost()  : bool
Check if the request is a POST request.
json()  : JsonResponse
Return JSON response.
message()  : void
Display a message (success/error) to the user using Bulma notifications.
param()  : string
Get a string request parameter (GET, POST, or REQUEST).
paramArray()  : array<string|int, mixed>
Get an array request parameter.
paramInt()  : int|null
Get an integer request parameter.
post()  : string
Get a string POST parameter.
query()  : mysqli_result|bool
Execute a database query using the LWT query wrapper.
redirect()  : RedirectResponse
Redirect to another URL.
render()  : void
Start page rendering with standard LWT header.
requireInt()  : int
Get a required integer request parameter.
getTextIdFromRequest()  : int|null
Get text ID from request parameters.
handleArchivedMarkAction()  : string|RedirectResponse
Handle mark actions for archived texts.
handleAutoSplitImport()  : array{message: string, redirect: bool}|RedirectResponse
Handle auto-split import for long texts.
handleMarkAction()  : string|RedirectResponse
Handle mark actions for multiple texts.
handleTextOperation()  : array{message: string, redirect: bool}|RedirectResponse
Handle text save/update operations.
renderReadPage()  : RedirectResponse|null
Render the text reading page.
showEditTextForm()  : void
Show the edit text form.
showNewTextForm()  : void
Show the new text form.
showTextsList()  : void
Show the texts list.

Constants

MODULE_VIEWS

Module views path.

private mixed MODULE_VIEWS = __DIR__ . '/../Views'

Properties

Methods

archived()

Archived texts management (replaces text_archived.php)

public archived(array<string|int, mixed> $params) : RedirectResponse|null
Parameters
$params : array<string|int, mixed>

Route parameters

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

archivedEdit()

Edit archived text form.

public archivedEdit(int $id) : RedirectResponse|null

Route: GET/POST /text/archived/{id}/edit

Parameters
$id : int

Archived text ID from route parameter

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

check()

Check text (replaces text_check.php)

public check(array<string|int, mixed> $params) : void
Parameters
$params : array<string|int, mixed>

Route parameters

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

deleteArchived()

Delete an archived text.

public deleteArchived(int $id) : RedirectResponse

Route: DELETE /text/archived/{id}

Parameters
$id : int

Archived text ID from route parameter

Return values
RedirectResponse

Redirect to archived texts list

display()

Display improved text (replaces text_display.php)

public display([int|null $text = null ]) : RedirectResponse|null

Routes:

  • GET /text/{text:int}/display (new RESTful route)
  • GET /text/display?text=[id] (legacy route)
Parameters
$text : int|null = null

Text ID (injected from route parameter)

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

edit()

Edit texts list (replaces text_edit.php)

public edit(array<string|int, mixed> $params) : RedirectResponse|null
Parameters
$params : array<string|int, mixed>

Route parameters

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

editSingle()

Edit single text form.

public editSingle(int $id) : RedirectResponse|null

Route: GET/POST /texts/{id}/edit

Parameters
$id : int

Text ID from route parameter

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

new()

Show new text form.

public new(array<string|int, mixed> $params) : RedirectResponse|null

Route: GET /texts/new

Parameters
$params : array<string|int, mixed>

Route parameters

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

read()

Read text interface.

public read([int|null $text = null ]) : RedirectResponse|null

Modern text reading interface with client-side rendering using Alpine.js.

Routes:

  • GET /text/{text:int}/read (new RESTful route)
  • GET /text/read?text=[id] (legacy route)
Parameters
$text : int|null = null

Text ID (injected from route parameter)

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

setMode()

Set text mode (replaces text_set_mode.php)

public setMode(array<string|int, mixed> $params) : void
Parameters
$params : array<string|int, mixed>

Route parameters

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

unarchive()

Unarchive a text.

public unarchive(int $id) : RedirectResponse

Route: POST /texts/{id}/unarchive

Parameters
$id : int

Text ID from route parameter

Return values
RedirectResponse

Redirect to archived texts list

endRender()

End page rendering with standard LWT footer.

protected endRender() : void

execute()

Execute an INSERT/UPDATE/DELETE query.

protected execute(string $sql) : int
Parameters
$sql : string

SQL query

Tags
psalm-suppress

PossiblyUnusedReturnValue

Return values
int

Number of affected rows

get()

Get a string GET parameter.

protected get(string $key[, string $default = '' ]) : string
Parameters
$key : string

Parameter name

$default : string = ''

Default value if not set

Return values
string

Parameter value or default

getMarkedIds()

Get IDs from marked checkboxes.

protected getMarkedIds(string|array<string|int, mixed> $marked) : array<string|int, int>
Parameters
$marked : string|array<string|int, mixed>

The 'marked' request parameter value

Tags
psalm-return

array

Return values
array<string|int, int>

Array of integer IDs

getValue()

Get a single value from the database.

protected getValue(string $sql) : mixed
Parameters
$sql : string

SQL query (should return single value as 'value')

Return values
mixed

The value or null

hasParam()

Check if a parameter exists in the request.

protected hasParam(string $key) : bool
Parameters
$key : string

Parameter name

Return values
bool

True if the parameter exists

isGet()

Check if the request is a GET request.

protected isGet() : bool
Return values
bool

isPost()

Check if the request is a POST request.

protected isPost() : bool
Return values
bool

json()

Return JSON response.

protected json(mixed $data[, int $status = 200 ]) : JsonResponse

Return this from a controller method; the router will send it.

Parameters
$data : mixed

Data to encode as JSON

$status : int = 200

HTTP status code (default: 200)

Return values
JsonResponse

message()

Display a message (success/error) to the user using Bulma notifications.

protected message(string $message[, bool $autoHide = true ]) : void
Parameters
$message : string

The message to display

$autoHide : bool = true

Whether to auto-hide the message (default: true)

param()

Get a string request parameter (GET, POST, or REQUEST).

protected param(string $key[, string $default = '' ]) : string
Parameters
$key : string

Parameter name

$default : string = ''

Default value if not set

Return values
string

Parameter value or default

paramArray()

Get an array request parameter.

protected paramArray(string $key[, array<string|int, mixed> $default = [] ]) : array<string|int, mixed>
Parameters
$key : string

Parameter name

$default : array<string|int, mixed> = []

Default value if not set

Return values
array<string|int, mixed>

Parameter value or default

paramInt()

Get an integer request parameter.

protected paramInt(string $key[, int|null $default = null ][, int|null $min = null ][, int|null $max = null ]) : int|null
Parameters
$key : string

Parameter name

$default : int|null = null

Default value if not set

$min : int|null = null

Minimum allowed value

$max : int|null = null

Maximum allowed value

Return values
int|null

Parameter value or default

post()

Get a string POST parameter.

protected post(string $key[, string $default = '' ]) : string
Parameters
$key : string

Parameter name

$default : string = ''

Default value if not set

Return values
string

Parameter value or default

query()

Execute a database query using the LWT query wrapper.

protected query(string $sql) : mysqli_result|bool
Parameters
$sql : string

SQL query

Return values
mysqli_result|bool

Query result

redirect()

Redirect to another URL.

protected redirect(string $url[, int $statusCode = 302 ]) : RedirectResponse

Return this from a controller method; the router will send it.

Parameters
$url : string

URL to redirect to

$statusCode : int = 302

HTTP status code (default: 302)

Return values
RedirectResponse

render()

Start page rendering with standard LWT header.

protected render(string $title[, bool $showMenu = true ]) : void
Parameters
$title : string

Page title

$showMenu : bool = true

Whether to show navigation menu (default: true)

requireInt()

Get a required integer request parameter.

protected requireInt(string $key[, int|null $min = null ][, int|null $max = null ]) : int
Parameters
$key : string

Parameter name

$min : int|null = null

Minimum allowed value

$max : int|null = null

Maximum allowed value

Tags
throws
InvalidArgumentException

If parameter is missing or invalid

Return values
int

Parameter value

getTextIdFromRequest()

Get text ID from request parameters.

private getTextIdFromRequest([int|null $injectedId = null ]) : int|null
Parameters
$injectedId : int|null = null

Text ID injected from route parameter

Return values
int|null

Text ID or null

handleArchivedMarkAction()

Handle mark actions for archived texts.

private handleArchivedMarkAction(string $markAction, array<string|int, mixed> $marked, string $actionData) : string|RedirectResponse
Parameters
$markAction : string

Action to perform

$marked : array<string|int, mixed>

Array of marked text IDs

$actionData : string

Additional data for the action

Return values
string|RedirectResponse

Result message or redirect

handleAutoSplitImport()

Handle auto-split import for long texts.

private handleAutoSplitImport(int $languageId, string $title, string $text, string $audioUri, string $sourceUri, bool $openAfter) : array{message: string, redirect: bool}|RedirectResponse

Creates a book with chapters for texts that exceed 60KB.

Parameters
$languageId : int

Language ID

$title : string

Text title

$text : string

Text content

$audioUri : string

Audio URI

$sourceUri : string

Source URI

$openAfter : bool

Whether to open the first chapter after import

Return values
array{message: string, redirect: bool}|RedirectResponse

handleMarkAction()

Handle mark actions for multiple texts.

private handleMarkAction(string $markAction, array<string|int, mixed> $marked, string $actionData) : string|RedirectResponse
Parameters
$markAction : string

Action to perform

$marked : array<string|int, mixed>

Array of marked text IDs

$actionData : string

Additional data for the action

Return values
string|RedirectResponse

Result message or redirect

handleTextOperation()

Handle text save/update operations.

private handleTextOperation(string $op, bool $noPagestart, string|int $currentLang) : array{message: string, redirect: bool}|RedirectResponse
Parameters
$op : string

Operation name

$noPagestart : bool

Whether to skip page start

$currentLang : string|int

Current language ID

Return values
array{message: string, redirect: bool}|RedirectResponse

renderReadPage()

Render the text reading page.

private renderReadPage(int $textId) : RedirectResponse|null

Uses client-side rendering via Alpine.js and API.

Parameters
$textId : int

Text ID

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

Return values
RedirectResponse|null

Redirect response or null if rendered

showEditTextForm()

Show the edit text form.

private showEditTextForm(int $txid) : void
Parameters
$txid : int

Text ID

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

showNewTextForm()

Show the new text form.

private showNewTextForm(int $langId) : void
Parameters
$langId : int

Language ID

Tags
psalm-suppress

UnusedVariable Variables are used in included view files

showTextsList()

Show the texts list.

private showTextsList(string|int $currentLang, string $message) : void
Parameters
$currentLang : string|int

Current language filter

$message : string

Message to display

Tags
psalm-suppress

UnusedVariable Variables are used in included view files


        
On this page

Search results