API Index — Namespaces, Packages, Reports, Indices
Notes
in package
Data-access helpers for the notes table used by the Learn module.
Provides CRUD + search operations for per-user notes. All methods are
stateless static helpers that accept a \PDO instance so callers control
the connection lifetime. Input validation (title length, body size, per-user
note cap) is enforced here rather than at the API layer.
The per-user note cap defaults to 256 and is overridden by the
ZEALPHP_LEARN_MAX_NOTES environment variable.
Table of Contents
Methods
- create() : int|null
- Create a new note for
$userId. - delete() : bool
- Delete a note by id, scoped to
$userId. - list() : array<int, array<string, mixed>>
- List all notes for
$userId, most recently updated first. - read() : array<string, mixed>|null
- Fetch a single note by id, scoped to
$userId. - search() : array<int, array<string, mixed>>
- Full-text
LIKEsearch acrosstitleandbodyfor$userId. - update() : bool
- Update a note's title and/or body.
Methods
create()
Create a new note for $userId.
public
static create(PDO $db, int $userId, string $title, string $body) : int|null
Returns the new note's auto-increment id, or null when validation fails:
$titleis empty or exceeds 200 characters.$bodyexceeds 4096 bytes.- The user already has
ZEALPHP_LEARN_MAX_NOTES(default256) notes.
Parameters
- $db : PDO
- $userId : int
- $title : string
- $body : string
Return values
int|nulldelete()
Delete a note by id, scoped to $userId.
public
static delete(PDO $db, int $userId, int $noteId) : bool
Returns true when a row was deleted, false when no matching row existed.
Parameters
- $db : PDO
- $userId : int
- $noteId : int
Return values
boollist()
List all notes for $userId, most recently updated first.
public
static list(PDO $db, int $userId) : array<int, array<string, mixed>>
Parameters
- $db : PDO
- $userId : int
Return values
array<int, array<string, mixed>>read()
Fetch a single note by id, scoped to $userId.
public
static read(PDO $db, int $userId, int $noteId) : array<string, mixed>|null
Returns null when the note does not exist or belongs to a different user.
Parameters
- $db : PDO
- $userId : int
- $noteId : int
Return values
array<string, mixed>|nullsearch()
Full-text LIKE search across title and body for $userId.
public
static search(PDO $db, int $userId, string $query[, int $limit = 10 ]) : array<int, array<string, mixed>>
Returns up to $limit notes (default 10), ordered by updated_at DESC.
Parameters
- $db : PDO
- $userId : int
- $query : string
- $limit : int = 10
Return values
array<int, array<string, mixed>>update()
Update a note's title and/or body.
public
static update(PDO $db, int $userId, int $noteId, string|null $title, string|null $body) : bool
Pass null for either field to keep the existing value. Applies the same
validation as create() (title length, body size). Returns false when
the note does not exist, belongs to a different user, or validation fails.
Parameters
- $db : PDO
- $userId : int
- $noteId : int
- $title : string|null
- $body : string|null