ShowTag
extends Crud
in package
uses
Tag
Render the tag cloud.
Table of Contents
Properties
- $db : PDO
Methods
- __construct() : mixed
- Open the shared database connection, once.
- tagCloud() : string|false
- Build the tag-cloud text for the current list: its most-used tags with their counts, alphabetically. With `$tags` (the list's active filter), each link adds its tag to that filter, drilling further down.
- tagSearch() : array{tags: string|false, 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 (like the cloud) and result links drill down into it.
- 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.
- links() : string|false
- Render tag rows as linked `name (count)` pairs.
-
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).
Properties
$db
protected
static PDO
$db
Shared PDO connection, created once on first construction.
Methods
__construct()
Open the shared database connection, once.
public
final __construct() : mixed
The first instantiation builds it from the DB_* constants and the rest
reuse it; 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.
tagCloud()
Build the tag-cloud text for the current list: its most-used tags with their counts, alphabetically. With `$tags` (the list's active filter), each link adds its tag to that filter, drilling further down.
public
final tagCloud([int|null $viewer = null ][, array<int, string> $tags = [] ][, string|null $username = null ]) : string|false
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
string|false —Comma-separated name (count) pairs, or false if there
are no tags.
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 (like the cloud) and result links drill down into it.
public
final tagSearch(int|null $viewer, string $term[, int $page = 1 ][, array<int, string> $tags = [] ][, string|null $username = null ]) : array{tags: string|false, 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: string|false, pages: int} —The rendered links (false if nothing matches) and the total number of pages (at least 1).
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.
links()
Render tag rows as linked `name (count)` pairs.
private
links(array<int, array{id: int, name: string, value: int}> $table[, array<int, string> $base = [] ]) : string|false
Parameters
- $table : array<int, array{id: int, name: string, value: int}>
-
Tag rows.
- $base : array<int, string> = []
-
Tag names each link keeps (the active filter).
Return values
string|false —The links, or false if there are no rows.
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: listsearchTags()
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_SIZEtags 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.