Skip to content

Commit

Permalink
Merge pull request #481 from NetrunnerDB/nb/stripped-text-title
Browse files Browse the repository at this point in the history
Add strippedTitle
  • Loading branch information
NoahTheDuke authored Mar 13, 2021
2 parents dd1efd7 + 4eebe6e commit d7182a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 39 deletions.
40 changes: 1 addition & 39 deletions src/AppBundle/Command/ImportStdCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,6 @@ public function __construct(EntityManagerInterface $entityManager)

private $collections = [];

private $xmlToStrip = [
"/<strong>/",
"/<\/strong>/",
"/<trace>/",
"/<\/trace>/",
"/<errata>/",
"/<\/errata>/",
"/<em>/",
"/<\/em>/",
"/<i>/",
"/<\/i>/",
];

private $iconsToStrip = [
"/\[click]/",
"/\[credit]/",
"/\+(\d)\[mu]/",
"/\[link]/",
"/\[trash]/",
"/\[interrupt]/",
"/\[recurring-credit]/",
];

private $replacementIcons = [
"click",
"credit",
'+$1 mu',
"link",
"trash",
"interrupt",
"recurring credit",
];

protected function configure()
{
$this
Expand Down Expand Up @@ -349,6 +316,7 @@ protected function importCardsJsonFile(\SplFileInfo $fileinfo)
'deck_limit',
'position',
'quantity',
'stripped_title',
'title',
'uniqueness',
], [
Expand Down Expand Up @@ -491,12 +459,6 @@ protected function copyFieldValueToEntity($entity, string $entityName, string $f
}
}
}
} elseif ($fieldName == "strippedText") {
$strippedText = ($entity->getText() ?: "");
$strippedText = preg_replace($this->xmlToStrip, "", $strippedText);
$strippedText = preg_replace($this->iconsToStrip, $this->replacementIcons, $strippedText);
$newTypedValue = $strippedText;
$newJsonValue = $strippedText;
}

$different = ($currentJsonValue !== $newJsonValue);
Expand Down
24 changes: 24 additions & 0 deletions src/AppBundle/Entity/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Card implements NormalizableInterface, TimestampableInterface
*/
private $title;

/**
* @var string
*/
private $strippedTitle;

/**
* @var string|null
*/
Expand Down Expand Up @@ -384,6 +389,25 @@ public function setTitle(string $title)
return $this;
}

/**
* @return string
*/
public function getStrippedTitle()
{
return $this->strippedTitle;
}

/**
* @param string $title
* @return $this
*/
public function setStrippedTitle(string $title)
{
$this->strippedTitle = $title;

return $this;
}

/**
* @return string|null
*/
Expand Down
4 changes: 4 additions & 0 deletions src/AppBundle/Resources/config/doctrine/Card.orm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ AppBundle\Entity\Card:
title:
type: string
length: 255
strippedTitle:
type: string
length: '1024'
nullable: true
keywords:
type: string
length: 255
Expand Down
2 changes: 2 additions & 0 deletions src/AppBundle/Service/CardsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public function get_search_rows(array $conditions, string $sortorder, string $lo
$like = implode('% ', str_split($arg));
$or[] = "(REPLACE(c.title, '-', ' ') like ?$i)";
$parameters[$i++] = "$like%";
$or[] = "(c.strippedTitle like ?$i)";
$parameters[$i++] = "$like%";
} else {
if ($arg == 'Franklin') {
$arg = 'Crick';
Expand Down

0 comments on commit d7182a9

Please sign in to comment.