izartu API

ShowTag extends Crud
in package
uses Tag

FinalYes

Supply the tag cloud and the tag index to the view, as data for the template to render.

Table of Contents

Methods

behind()  : bool
Whether the database lacks migrations the code has.
connect()  : PDO
Open a connection to the database the `DB_*` settings name.
dsn()  : string
Build a MySQL DSN.
options()  : array<int, bool|int|string>
The PDO options of a connection.
rows()  : array<int, array{name: string, count: int, url: string}>
Tag rows as name, count and URL.
sslConflict()  : string
The `DB_SSL_*` settings another one leaves without effect, as a warning for the operator.
sslHint()  : string
What to check when a connection over TLS fails.
tagCloud()  : array<int, array{name: string, count: int, url: string}>
The tag cloud for the current list: its most-used tags with their counts, alphabetically. With `$tags` (the list's active filter), each URL adds its tag to that filter.
tagSearch()  : array{tags: list, pages: int}
Build one page of the tag index or search results: the matching tags with their visible-bookmark count, alphabetically. An empty term matches every tag. With `$tags`/`$username` the search is scoped to that list, and each URL adds its tag to the filter.
db()  : PDO
The shared database connection, opened on first use.
read()  : array<int, array<string, mixed>>
Prepare and run a read query, then return its rows.
countTags()  : int
Count the tags whose name contains the search term (see `searchTags`).
getCloud()  : array<int, array{id: int, name: string, value: int}>
Return the tag-cloud data for the current list: the `CLOUD_SIZE` most-used tags among the bookmarks the list shows, with their counts, ordered alphabetically.
listFilter()  : array{0: string, 1: string, 2: string, 3: list}
The SQL pieces every tag listing shares: the visibility condition, the `user` join and extra WHERE clauses for the list's tag/username filters (with the filtered tag names themselves excluded), and the parameters.
searchTags()  : array<int, array{id: int, name: string, value: int}>
Return one page of the tags whose name contains the search term, with their visible-bookmark count, ordered alphabetically. Same visibility and list filters as the cloud (`$tags`/`$username` scope the search to the current list). An empty term matches every tag (the tag index).

Methods

behind()

Whether the database lacks migrations the code has.

public static behind() : bool
Tags
throws
RuntimeException

When the database cannot be checked (see Migration::version()).

Return values
bool

connect()

Open a connection to the database the `DB_*` settings name.

public static connect() : PDO

The charset is utf8mb4 and the timezone is the server's.

Tags
throws
PDOException

When the database cannot be reached; when TLS may be why, the message says what to check (sslHint()).

Return values
PDO —

The connection, with options().

dsn()

Build a MySQL DSN.

public static dsn(string $host, int $port, string $name) : string
Parameters
$host : string

Host name or IP address, or the path of a Unix socket (it starts with /).

$port : int

TCP port, left out of the DSN when it is MySQL's default (3306) and ignored for a socket.

$name : string

Database name.

Return values
string —

The PDO DSN, with the utf8mb4 charset.

options()

The PDO options of a connection.

public static options(string $host, bool $ssl, bool $verify, string $ca) : array<int, bool|int|string>

Errors throw, and prepared statements are native, so integer columns come back as int. Over TCP the connection is encrypted, unless $ssl is off; over a Unix socket TLS does not work.

Parameters
$host : string

Host name or IP address, or a socket path; localhost connects over the default socket.

$ssl : bool

Whether to encrypt over TCP.

$verify : bool

Whether to verify the server's certificate, name included.

$ca : string

CA file to verify it against; '' for the CAs the system trusts.

Return values
array<int, bool|int|string> —

The options.

rows()

Tag rows as name, count and URL.

public static rows(array<int, array{id: int, name: string, value: int}> $table[, array<int, string> $base = [] ]) : array<int, array{name: string, count: int, url: string}>

The names in a URL are sorted, so one combination of tags has one address.

Parameters
$table : array<int, array{id: int, name: string, value: int}>

Tag rows.

$base : array<int, string> = []

Tag names each URL keeps (the active filter).

Return values
array<int, array{name: string, count: int, url: string}> —

One entry per row.

sslConflict()

The `DB_SSL_*` settings another one leaves without effect, as a warning for the operator.

public static sslConflict(string $host, bool $ssl, bool $verify, string $ca) : string
Parameters
$host : string

Host name or IP address, or a socket path, as for options().

$ssl : bool

Whether to encrypt over TCP.

$verify : bool

Whether to verify the server's certificate.

$ca : string

CA file to verify it against.

Return values
string —

The warning; '' when every setting takes effect.

sslHint()

What to check when a connection over TLS fails.

public static sslHint(string $error, array<int, bool|int|string> $options) : string

mysqlnd gives one message for every certificate that does not verify, readable CA or not, and reports a server without TLS as gone away.

Parameters
$error : string

The connection's error message.

$options : array<int, bool|int|string>

Its options, options()'s.

Return values
string —

The setting to check, as a sentence; '' when TLS is not why.

tagCloud()

The tag cloud for the current list: its most-used tags with their counts, alphabetically. With `$tags` (the list's active filter), each URL adds its tag to that filter.

public final tagCloud([int|null $viewer = null ][, array<int, string> $tags = [] ][, string|null $username = null ]) : array<int, array{name: string, count: int, url: string}>
Parameters
$viewer : int|null = null

The viewer's user id (Auth::id()), or null for anonymous.

$tags : array<int, string> = []

The tag names the list is filtered by; empty for none.

$username : string|null = null

The username the list is filtered by, or null.

Return values
array<int, array{name: string, count: int, url: string}> —

One entry per tag.

tagSearch()

Build one page of the tag index or search results: the matching tags with their visible-bookmark count, alphabetically. An empty term matches every tag. With `$tags`/`$username` the search is scoped to that list, and each URL adds its tag to the filter.

public final tagSearch(int|null $viewer, string $term[, int $page = 1 ][, array<int, string> $tags = [] ][, string|null $username = null ]) : array{tags: list, pages: int}
Parameters
$viewer : int|null

The viewer's user id (Auth::id()), or null for anonymous.

$term : string

The search term (matched as a substring).

$page : int = 1

1-based page number.

$tags : array<int, string> = []

The tag names the list is filtered by; empty for none.

$username : string|null = null

The username the list is filtered by, or null.

Return values
array{tags: list, pages: int} —

The matching tags and the number of pages (at least 1).

db()

The shared database connection, opened on first use.

protected final static db() : PDO

Building, validating or formatting a model therefore needs no database. With DEBUG on, statements are created as DebugStatement so every query execution is timed.

Tags
throws
DatabaseUnavailable

When the database cannot be reached.

Return values
PDO —

The shared connection, opened by connect().

read()

Prepare and run a read query, then return its rows.

protected final read(string $sql[, array<int, array{0: string, 1: mixed, 2: int, 3: int}>|false $param = false ]) : array<int, array<string, mixed>>
Parameters
$sql : string

SQL query with bind placeholders.

$param : array<int, array{0: string, 1: mixed, 2: int, 3: int}>|false = false

Bind parameters (each: [name, value, PDO type, length]), or false for none.

Return values
array<int, array<string, mixed>> —

The result rows.

countTags()

Count the tags whose name contains the search term (see `searchTags`).

private countTags(int|null $viewer, string $term[, array<int, string> $tags = [] ][, string|null $username = null ]) : int
Parameters
$viewer : int|null

The viewer's user id (Auth::id()), or null for anonymous.

$term : string

The search term, matched as a substring that ignores case and accents.

$tags : array<int, string> = []

The tag names the list is filtered by; empty for none.

$username : string|null = null

The username the list is filtered by, or null.

Return values
int —

How many visible tags match.

getCloud()

Return the tag-cloud data for the current list: the `CLOUD_SIZE` most-used tags among the bookmarks the list shows, with their counts, ordered alphabetically.

private getCloud([int|null $viewer = null ][, array<int, string> $tags = [] ][, string|null $username = null ]) : array<int, array{id: int, name: string, value: int}>

A viewer counts public bookmarks plus their own private ones; tags with no visible bookmark are not returned. With $tags, only bookmarks carrying ALL of them count, and those tags themselves are left out (they are the active filter). With $username, only that user's bookmarks count.

Parameters
$viewer : int|null = null

The viewer's user id (Auth::id()), or null for anonymous.

$tags : array<int, string> = []

The tag names the list is filtered by; empty for none.

$username : string|null = null

The username the list is filtered by, or null.

Return values
array<int, array{id: int, name: string, value: int}> —

One row per tag.

listFilter()

The SQL pieces every tag listing shares: the visibility condition, the `user` join and extra WHERE clauses for the list's tag/username filters (with the filtered tag names themselves excluded), and the parameters.

private listFilter(int|null $viewer, array<int, string> $tags, string|null $username) : array{0: string, 1: string, 2: string, 3: list}
Parameters
$viewer : int|null

The viewer's user id, or null for anonymous.

$tags : array<int, string>

The tag names the list is filtered by; empty for none.

$username : string|null

The username the list is filtered by, or null.

Return values
array{0: string, 1: string, 2: string, 3: list}

searchTags()

Return one page of the tags whose name contains the search term, with their visible-bookmark count, ordered alphabetically. Same visibility and list filters as the cloud (`$tags`/`$username` scope the search to the current list). An empty term matches every tag (the tag index).

private searchTags(int|null $viewer, string $term[, int $page = 1 ][, array<int, string> $tags = [] ][, string|null $username = null ]) : array<int, array{id: int, name: string, value: int}>
Parameters
$viewer : int|null

The viewer's user id (Auth::id()), or null for anonymous.

$term : string

The search term, matched as a substring that ignores case and accents.

$page : int = 1

1-based page number (TAGS_PAGE_SIZE tags per page).

$tags : array<int, string> = []

The tag names the list is filtered by; empty for none.

$username : string|null = null

The username the list is filtered by, or null.

Return values
array<int, array{id: int, name: string, value: int}> —

One row per tag.

On this page

Search results