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

dsn()  : string
Build a MySQL DSN, for the app's connection and for the CLI scripts that open their own.
rows()  : array<int, array{name: string, count: int, url: string}>
Tag rows as name, count and URL.
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.
getTags()  : array<int, array{id: int, name: string}>
Return the tags attached to a single bookmark.
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

dsn()

Build a MySQL DSN, for the app's connection and for the CLI scripts that open their own.

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.

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.

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. The connection comes from the DB_* constants; a failure triggers E_USER_ERROR. With DEBUG on, statements are created as DebugStatement so every query execution is timed.

Prepared statements are native, so integer columns come back as int; the charset is utf8mb4 and the timezone is the server's.

Return values
PDO —

The shared connection.

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).

$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.

getTags()

Return the tags attached to a single bookmark.

private getTags(int $id) : array<int, array{id: int, name: string}>
Parameters
$id : int

Bookmark id.

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

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).

$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