Skip to content

Commit

Permalink
Rename numberToRomanRepresentation to number_roman and style fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonjza committed May 2, 2018
1 parent 42b9605 commit 643288d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
16 changes: 12 additions & 4 deletions src/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,28 @@ function setting($name, bool $global = false)

}
}
if (! function_exists('numberToRomanRepresentation')) {
if (! function_exists('number_roman')) {
/**
* Converts an integer to a roman numberal representation.
*
* @param int $number
*
* @return string
*/
function numberToRomanRepresentation($number)
function number_roman($number)
{

$map = ['M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50,
'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1, ];
$map = [
'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50,
'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1,
];

$returnValue = '';

while ($number > 0) {

foreach ($map as $roman => $int) {

if ($number >= $int) {
$number -= $int;
$returnValue .= $roman;
Expand Down
25 changes: 18 additions & 7 deletions src/Repositories/Character/Pi.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,26 @@ public function getCharacterPlanetaryColonies(int $character_id): Collection
->get();
}

/**
* @param int $character_id
*
* @return \Illuminate\Support\Collection
*/
public function getCharacterPlanetaryExtractors(int $character_id): Collection
{

$extractors = CharacterPlanetExtractor::where('character_planet_extractors.character_id', $character_id)
->join('character_planet_pins as pin', 'pin.pin_id', '=', 'character_planet_extractors.pin_id')
->join('character_planets as planets', 'planets.planet_id', '=', 'character_planet_extractors.planet_id')
->join('mapDenormalize as system', 'system.itemID', '=', 'planets.solar_system_id')
->join('mapDenormalize as planet', 'planet.itemID', '=', 'character_planet_extractors.planet_id')
->join('invTypes as inventory', 'inventory.typeID', '=', 'character_planet_extractors.product_type_id')
$extractors = CharacterPlanetExtractor::where(
'character_planet_extractors.character_id', $character_id)
->join('character_planet_pins as pin',
'pin.pin_id', '=', 'character_planet_extractors.pin_id')
->join('character_planets as planets',
'planets.planet_id', '=', 'character_planet_extractors.planet_id')
->join('mapDenormalize as system',
'system.itemID', '=', 'planets.solar_system_id')
->join('mapDenormalize as planet',
'planet.itemID', '=', 'character_planet_extractors.planet_id')
->join('invTypes as inventory',
'inventory.typeID', '=', 'character_planet_extractors.product_type_id')
->select(
'character_planet_extractors.product_type_id', // Extractor Product Name f.e. Aqueous Liquids
'planet.celestialIndex', // arabic planet index
Expand All @@ -72,7 +83,7 @@ public function getCharacterPlanetaryExtractors(int $character_id): Collection

$extractors = $extractors->map(function ($item) {

$item->celestialIndex = numberToRomanRepresentation($item->celestialIndex);
$item->celestialIndex = number_roman($item->celestialIndex);

return $item;
});
Expand Down

0 comments on commit 643288d

Please sign in to comment.