"text", "name" => "author", "value" => $author])
);
}
public function sidebar_options(string $mode, ?int $artistID = null, bool $is_admin = false): void
{
global $page, $user;
$html = "";
if ($mode == "neutral") {
$html = make_form(make_link("artist/new_artist"))."
";
}
if ($mode == "editor") {
$html = make_form(make_link("artist/new_artist"))."
".make_form(make_link("artist/edit_artist"))."
";
if ($is_admin) {
$html .= make_form(make_link("artist/nuke_artist"))."
";
}
$html .= make_form(make_link("artist/add_alias"))."
".make_form(make_link("artist/add_member"))."
".make_form(make_link("artist/add_url"))."
";
}
if ($html) {
$page->add_block(new Block("Manage Artists", $html, "left", 10));
}
}
/**
* @param ArtistArtist $artist
* @param ArtistAlias[] $aliases
* @param ArtistMember[] $members
* @param ArtistUrl[] $urls
*/
public function show_artist_editor(array $artist, array $aliases, array $members, array $urls): void
{
global $user;
$artistName = $artist['name'];
$artistNotes = $artist['notes'];
$artistID = $artist['id'];
// aliases
$aliasesString = "";
$aliasesIDsString = "";
foreach ($aliases as $alias) {
$aliasesString .= $alias["alias_name"]." ";
$aliasesIDsString .= $alias["alias_id"]." ";
}
$aliasesString = rtrim($aliasesString);
$aliasesIDsString = rtrim($aliasesIDsString);
// members
$membersString = "";
$membersIDsString = "";
foreach ($members as $member) {
$membersString .= $member["name"]." ";
$membersIDsString .= $member["id"]." ";
}
$membersString = rtrim($membersString);
$membersIDsString = rtrim($membersIDsString);
// urls
$urlsString = "";
$urlsIDsString = "";
foreach ($urls as $url) {
$urlsString .= $url["url"]."\n";
$urlsIDsString .= $url["id"]." ";
}
$urlsString = substr($urlsString, 0, strlen($urlsString) - 1);
$urlsIDsString = rtrim($urlsIDsString);
$html = make_form(make_link("artist/edited/".$artist['id'])).'
';
global $page;
$page->add_block(new Block("Edit artist", $html, "main", 10));
}
public function new_artist_composer(): void
{
global $page, $user;
$html = make_form(make_link("artist/create"))."
";
$page->set_title("Artists");
$page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10));
}
/**
* @param ArtistArtist[] $artists
*/
public function list_artists(array $artists, int $pageNumber, int $totalPages): void
{
global $user, $page;
$html = "".
"".
"Name ".
"Type ".
"Last updater ".
"Posts ";
if (!$user->is_anonymous()) {
$html .= "Action ";
} // space for edit link
$html .= " ";
$deletionLinkActionArray = [
'artist' => 'artist/nuke/',
'alias' => 'artist/alias/delete/',
'member' => 'artist/member/delete/',
];
$editionLinkActionArray = [
'artist' => 'artist/edit/',
'alias' => 'artist/alias/edit/',
'member' => 'artist/member/edit/',
];
$typeTextArray = [
'artist' => 'Artist',
'alias' => 'Alias',
'member' => 'Member',
];
foreach ($artists as $artist) {
if ($artist['type'] != 'artist') {
$artist['name'] = str_replace("_", " ", $artist['name']);
}
$elementLink = "".str_replace("_", " ", $artist['name'])." ";
//$artist_link = "".str_replace("_", " ", $artist['artist_name'])." ";
$user_link = "".$artist['user_name']." ";
$edit_link = "Edit ";
$del_link = "Delete ";
$html .= "".
"".$elementLink;
//if ($artist['type'] == 'member')
// $html .= " (member of ".$artist_link.")";
//if ($artist['type'] == 'alias')
// $html .= " (alias for ".$artist_link.")";
$html .= " ".
"".$typeTextArray[$artist['type']]." ".
"".$user_link." ".
"".$artist['posts']." ";
if (!$user->is_anonymous()) {
$html .= "".$edit_link." ";
}
if ($user->can(Permissions::ARTISTS_ADMIN)) {
$html .= "".$del_link." ";
}
$html .= " ";
}
$html .= "
";
$page->set_title("Artists");
$page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10));
$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages);
}
public function show_new_alias_composer(int $artistID): void
{
global $user;
$html = make_form(make_link("artist/alias/add")).'
';
global $page;
$page->add_block(new Block("Artist Aliases", $html, "main", 20));
}
public function show_new_member_composer(int $artistID): void
{
global $user;
$html = make_form(make_link("artist/member/add")).'
';
global $page;
$page->add_block(new Block("Artist members", $html, "main", 30));
}
public function show_new_url_composer(int $artistID): void
{
global $user;
$html = make_form(make_link("artist/url/add")).'
';
global $page;
$page->add_block(new Block("Artist URLs", $html, "main", 40));
}
/**
* @param ArtistAlias $alias
*/
public function show_alias_editor(array $alias): void
{
global $user;
$html = make_form(make_link("artist/alias/edited/".$alias['id'])).'
Alias:
';
global $page;
$page->add_block(new Block("Edit Alias", $html, "main", 10));
}
/**
* @param ArtistUrl $url
*/
public function show_url_editor(array $url): void
{
global $user;
$html = make_form(make_link("artist/url/edited/".$url['id'])).'
URL:
';
global $page;
$page->add_block(new Block("Edit URL", $html, "main", 10));
}
/**
* @param ArtistMember $member
*/
public function show_member_editor(array $member): void
{
global $user;
$html = make_form(make_link("artist/member/edited/".$member['id'])).'
Member name:
';
global $page;
$page->add_block(new Block("Edit Member", $html, "main", 10));
}
/**
* @param ArtistArtist $artist
* @param ArtistAlias[] $aliases
* @param ArtistMember[] $members
* @param ArtistUrl[] $urls
* @param Image[] $images
*/
public function show_artist(array $artist, array $aliases, array $members, array $urls, array $images, bool $userIsLogged, bool $userIsAdmin): void
{
global $page;
$artist_link = "".str_replace("_", " ", $artist['name'])." ";
$html = "
";
if ($userIsLogged) {
$html .= " ";
}
if ($userIsAdmin) {
$html .= " ";
}
$html .= "
Name:
".$artist_link." ";
if ($userIsLogged) {
$html .= " ";
}
if ($userIsAdmin) {
$html .= " ";
}
$html .= " ";
$html .= $this->render_aliases($aliases, $userIsLogged, $userIsAdmin);
$html .= $this->render_members($members, $userIsLogged, $userIsAdmin);
$html .= $this->render_urls($urls, $userIsLogged, $userIsAdmin);
$html .= "
Notes:
".$artist["notes"]." ";
if ($userIsLogged) {
$html .= " ";
}
if ($userIsAdmin) {
$html .= " ";
}
//TODO how will notes be edited? On edit artist? (should there be an editartist?) or on a editnotes?
//same question for deletion
$html .= "
";
$page->set_title("Artist");
$page->set_heading("Artist");
$page->add_block(new Block("Artist", $html, "main", 10));
//we show the images for the artist
$artist_images = "";
foreach ($images as $image) {
$thumb_html = $this->build_thumb_html($image);
$artist_images .= ''.
''.$thumb_html.' '.
' ';
}
$page->add_block(new Block("Artist Posts", $artist_images, "main", 20));
}
/**
* @param ArtistAlias[] $aliases
*/
private function render_aliases(array $aliases, bool $userIsLogged, bool $userIsAdmin): string
{
$html = "";
if (count($aliases) > 0) {
$aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore
$aliasEditLink = "Edit ";
$aliasDeleteLink = "Delete ";
$html .= "
Aliases:
" . $aliasViewLink . " ";
if ($userIsLogged) {
$html .= "" . $aliasEditLink . " ";
}
if ($userIsAdmin) {
$html .= "" . $aliasDeleteLink . " ";
}
$html .= " ";
if (count($aliases) > 1) {
$ac = count($aliases);
for ($i = 1; $i < $ac; $i++) {
$aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore
$aliasEditLink = "Edit ";
$aliasDeleteLink = "Delete ";
$html .= "
" . $aliasViewLink . " ";
if ($userIsLogged) {
$html .= "" . $aliasEditLink . " ";
}
if ($userIsAdmin) {
$html .= "" . $aliasDeleteLink . " ";
}
$html .= " ";
}
}
}
return $html;
}
/**
* @param ArtistMember[] $members
*/
private function render_members(array $members, bool $userIsLogged, bool $userIsAdmin): string
{
$html = "";
if (count($members) > 0) {
$memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore
$memberEditLink = "Edit ";
$memberDeleteLink = "Delete ";
$html .= "
Members:
" . $memberViewLink . " ";
if ($userIsLogged) {
$html .= "" . $memberEditLink . " ";
}
if ($userIsAdmin) {
$html .= "" . $memberDeleteLink . " ";
}
$html .= " ";
if (count($members) > 1) {
$mc = count($members);
for ($i = 1; $i < $mc; $i++) {
$memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore
$memberEditLink = "Edit ";
$memberDeleteLink = "Delete ";
$html .= "
" . $memberViewLink . " ";
if ($userIsLogged) {
$html .= "" . $memberEditLink . " ";
}
if ($userIsAdmin) {
$html .= "" . $memberDeleteLink . " ";
}
$html .= " ";
}
}
}
return $html;
}
/**
* @param ArtistUrl[] $urls
*/
private function render_urls(array $urls, bool $userIsLogged, bool $userIsAdmin): string
{
$html = "";
if (count($urls) > 0) {
$urlViewLink = "" . str_replace("_", " ", $urls[0]['url']) . " ";
$urlEditLink = "Edit ";
$urlDeleteLink = "Delete ";
$html .= "
URLs:
" . $urlViewLink . " ";
if ($userIsLogged) {
$html .= "" . $urlEditLink . " ";
}
if ($userIsAdmin) {
$html .= "" . $urlDeleteLink . " ";
}
$html .= " ";
if (count($urls) > 1) {
$uc = count($urls);
for ($i = 1; $i < $uc; $i++) {
$urlViewLink = "" . str_replace("_", " ", $urls[$i]['url']) . " ";
$urlEditLink = "Edit ";
$urlDeleteLink = "Delete ";
$html .= "
" . $urlViewLink . " ";
if ($userIsLogged) {
$html .= "" . $urlEditLink . " ";
}
if ($userIsAdmin) {
$html .= "" . $urlDeleteLink . " ";
}
$html .= " ";
}
return $html;
}
}
return $html;
}
public function get_help_html(): HTMLElement
{
return emptyHTML(
P("Search for posts with a particular artist."),
SHM_COMMAND_EXAMPLE("artist=leonardo", "Returns posts with the artist \"leonardo\".")
);
}
}