Skip to content

Commit

Permalink
Merge pull request #782 from distributive/informative-embeds
Browse files Browse the repository at this point in the history
Added descriptions for most pages
  • Loading branch information
distributive authored Dec 1, 2023
2 parents 820caad + 3897abe commit b67ea59
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<meta property="og:image" content="https://netrunnerdb.com/icon.png" />
<meta property="og:image" content="{% if pageimage is defined and pageimage %}{{ pageimage }}{% else %}https://netrunnerdb.com/icon.png{% endif %}" />
{% if pagedescription is defined %}<meta name="description" content="{{ pagedescription }}">{% endif %}

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
Expand Down
1 change: 1 addition & 0 deletions src/AppBundle/Controller/BanlistsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function getAction(Request $request, EntityManagerInterface $entityManage
'format' => $request->query->get('format'),
'restriction' => $request->query->get('restriction'),
'pagetitle' => "Ban Lists",
'pagedescription' => "View the ban lists for each format from throughout the game's history.",
]);
}
}
12 changes: 11 additions & 1 deletion src/AppBundle/Controller/DecklistsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function listAction(string $type, int $page = 1, Request $request, Entity
case 'find':
$result = $decklistManager->find($start, $limit, $request, $cardsData);
$pagetitle = "Decklist search results";
$pagedescription = "View the results of a decklist search.";
$header = $this->searchForm($request, $entityManager, $cardsData);
break;
case 'favorites':
Expand All @@ -56,6 +57,7 @@ public function listAction(string $type, int $page = 1, Request $request, Entity
$result = $decklistManager->favorites($user->getId(), $start, $limit);
}
$pagetitle = "Favorite Decklists";
$pagedescription = "View your favourited decklists.";
break;
case 'mine':
$response->setPrivate();
Expand All @@ -66,26 +68,32 @@ public function listAction(string $type, int $page = 1, Request $request, Entity
$result = $decklistManager->by_author($user->getId(), $start, $limit);
}
$pagetitle = "My Decklists";
$pagedescription = "View your own published decklists.";
break;
case 'recent':
$result = $decklistManager->recent($start, $limit);
$pagetitle = "Recent Decklists";
$pagedescription = "View recently published decklists.";
break;
case 'dotw':
$result = $decklistManager->dotw($start, $limit);
$pagetitle = "Decklist of the week";
$pagedescription = "View the decklists of the week.";
break;
case 'halloffame':
$result = $decklistManager->halloffame($start, $limit);
$pagetitle = "Hall of Fame";
$pagedescription = "View the most loved decklists from all of NetrunnerDB history.";
break;
case 'hottopics':
$result = $decklistManager->hottopics($start, $limit);
$pagetitle = "Hot Topics";
$pagedescription = "View decklists currently receiving attention.";
break;
case 'tournament':
$result = $decklistManager->tournaments($start, $limit);
$pagetitle = "Tournaments";
$pagedescription = "View decklists that placed in tournaments.";
break;
case 'trashed':
$this->denyAccessUnlessGranted('ROLE_MODERATOR');
Expand All @@ -101,6 +109,7 @@ public function listAction(string $type, int $page = 1, Request $request, Entity
default:
$result = $decklistManager->popular($start, $limit);
$pagetitle = "Popular Decklists";
$pagedescription = "View popular recently published decklists.";
break;
}

Expand Down Expand Up @@ -152,7 +161,7 @@ public function listAction(string $type, int $page = 1, Request $request, Entity

return $this->render('/Decklist/decklists.html.twig', [
'pagetitle' => $pagetitle,
'pagedescription' => "Browse the collection of thousands of premade decks.",
'pagedescription' => $pagedescription ? $pagedescription : "Browse the collection of thousands of premade decks.",
'decklists' => $decklists,
'packs' => $packs,
'factions' => $factions,
Expand Down Expand Up @@ -199,6 +208,7 @@ public function searchAction(Request $request, EntityManagerInterface $entityMan

return $this->render('/Search/search.html.twig', [
'pagetitle' => 'Decklist Search',
'pagedescription' => 'Search for published Netrunner decklists.',
'url' => $request
->getRequestUri(),
'factions' => $factions,
Expand Down
9 changes: 5 additions & 4 deletions src/AppBundle/Controller/FactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function factionAction(string $faction_code, EntityManagerInterface $enti
];
}

// Sort the identities alphabetically.
// Sort the identities alphabetically.
usort($decklists, function ($a, $b) {
return strcasecmp($a['identity']->getTitle(), $b['identity']->getTitle());
});
Expand All @@ -108,9 +108,10 @@ public function factionAction(string $faction_code, EntityManagerInterface $enti
}

return $this->render('/Faction/faction.html.twig', [
"pagetitle" => "Faction Page: $faction_name",
"results" => $result,
"banned_cards" => $banned_cards,
"pagetitle" => "Faction Page: $faction_name",
"pagedescription" => "Explore all $faction_name identities and recent decklists.",
"results" => $result,
"banned_cards" => $banned_cards,
], $response);
}
}
3 changes: 2 additions & 1 deletion src/AppBundle/Controller/FormatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class FormatsController extends Controller
public function getAction(EntityManagerInterface $entityManager)
{
return $this->render('/Formats/formats.html.twig', [
'pagetitle' => "Play Formats",
'pagetitle' => "Play Formats",
'pagedescription' => "See the official formats for Netrunner play.",
]);
}
}
3 changes: 2 additions & 1 deletion src/AppBundle/Controller/IllustratorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class IllustratorsController extends Controller
public function getAction(EntityManagerInterface $entityManager)
{
return $this->render('/Illustrators/illustrators.html.twig', [
'pagetitle' => "Illustrators",
'pagetitle' => "Illustrators",
'pagedescription' => "Credit the artists who designed the look of the game.",
]);
}
}
7 changes: 4 additions & 3 deletions src/AppBundle/Controller/RotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public function getAction(EntityManagerInterface $entityManager, CardsData $card
$r = $entityManager->createQuery("SELECT r FROM AppBundle:Rotation r ORDER BY r.dateStart DESC");

return $this->render('/Rotation/rotation.html.twig', [
'pagetitle' => "Rotation",
'rotations' => $r->getResult(),
'cycles_and_packs' => $cardsData->getCyclesAndPacks(),
'pagetitle' => "Rotation",
'pagedescription' => "Compare the different card pools from the Standard format.",
'rotations' => $r->getResult(),
'cycles_and_packs' => $cardsData->getCyclesAndPacks(),
]);
}
}
2 changes: 2 additions & 0 deletions src/AppBundle/Controller/RulingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function listAction(EntityManagerInterface $entityManager)
$list = $entityManager->getRepository('AppBundle:Card')->findAll();

$response = $this->render('/Rulings/list.html.twig', [
'pagetitle' => 'Rulings',
'pagedescription' => 'Check out the official and unofficial rulings on cards and their interactions.',
'list' => $list,
]);
$response->setPublic();
Expand Down
48 changes: 48 additions & 0 deletions src/AppBundle/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,14 @@ public function displayAction(
$pack = $entityManager->getRepository('AppBundle:Pack')->findOneBy(["code" => $conditions[0][2]]);
if ($pack instanceof Pack) {
$title = $pack->getName();
$description = "View all cards from the $title pack.";
}
}
if ($conditions[0][0] == "c") {
$cycle = $entityManager->getRepository('AppBundle:Cycle')->findOneBy(["code" => $conditions[0][2]]);
if ($cycle instanceof Cycle) {
$title = $cycle->getName();
$description = "View all cards from the $title cycle.";
}
}
}
Expand Down Expand Up @@ -614,6 +616,19 @@ public function displayAction(
if (empty($title)) {
$title = $q;
}
if (empty($description)) {
if (count($cards) == 0) {
$description = "This search query has no results.";
} else if (count($cards) > 1) {
$description = "View all " . strval(count($cards)) . " results of this card search query.";
} else {
$description = $this->formatCardForEmbed($cards[0]);
$image = "https://card-images.netrunnerdb.com/v1" . $cards[0]["medium_image_path"]; // Hardcoding the link because
}
}
if (empty($image)) {
$image = "";
}

if ($view == "zoom") {
$card = $cards[0];
Expand All @@ -633,13 +648,46 @@ public function displayAction(
"searchbar" => $searchbar,
"pagination" => $pagination,
"pagetitle" => $title,
"pagedescription" => $description,
"pageimage" => $image,
"metadescription" => $meta,
"locales" => $locales,
"currentRotationCycles" => $currentRotationCycles,
"comments_enabled" => $userVerified,
], $response);
}

private function formatCardForEmbed($card)
{
$out = "";

// Title
$out .= "<h2>" . ($card["uniqueness"] ? "" : "") . $card["title"] . "</h2><br>";
// Type/subtype
if (empty($card["subtype"])) {
$out .= "<b>" . $card["type_name"] . "</b> ";
} else {
$out .= "<b>" . $card["type_name"] . ":</b> " . $card["subtype"] . " ";
}
// Stats
if ($card["type_code"] == "identity") {
$out .= "(" . $card["minimumdecksize"] . "/" . $card["influencelimit"] . ")<br>";
} else if ($card["type_code"] == "agenda") {
$out .= "(" . $card["advancementcost"] . "/" . $card["agendapoints"] . ")<br>";
} else {
$out .= "(" . $card["cost"] . ")<br>";
if (!empty($card["memorycost"])) {
$out .= "<b>MU cost:</b> " . $card["memorycost"] . "<br>";
} else if (!empty($card["trashcost"])) {
$out .= "<b>Trash cost:</b> " . $card["trashcost"] . "<br>";
}
}
// Text
$out .= $card["stripped_text"];

return $out;
}

public function setsAction(EntityManagerInterface $entityManager, CardsData $cardsData)
{
$response = new Response();
Expand Down
1 change: 1 addition & 0 deletions src/AppBundle/Service/CardsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ public function getCardInfo(Card $card, string $locale)
"subtype" => $card->getKeywords(),
"formatted_type" => $card->getFormattedType(),
"text" => $card->getText(),
"stripped_text" => $card->getStrippedText(),
"advancementcost" => $card->getAdvancementCost(),
"agendapoints" => $card->getAgendaPoints(),
"baselink" => $card->getBaseLink(),
Expand Down

0 comments on commit b67ea59

Please sign in to comment.