Skip to content

Commit

Permalink
Character assets (#16)
Browse files Browse the repository at this point in the history
* Add assetContents collection for Character Assets view

displays nested character asset contents

* Model the character asset contents on corporation asset contents

fix extra whitespace
  • Loading branch information
freedenizen authored and leonjza committed Jan 12, 2017
1 parent 44c6db5 commit 0be2e39
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/Repositories/Character/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Seat\Eveapi\Models\Character\AssetListContents;

trait Assets
{
Expand Down Expand Up @@ -72,25 +73,35 @@ public function getCharacterAssets(int $character_id): Collection
}

/**
* Return the nested assets that belong to a Character.
* Return an assets contents. If no parent asset / item ids
* are specified, then all assets for the corporation is
* returned.
*
* @param int $character_id
* @param int $parent_asset_id
* @param int $parent_item_id
*
* @return \Illuminate\Support\Collection
*/
public function getCharacterAssetContents(int $character_id): Collection
public function getCharacterAssetContents(int $character_id,
int $parent_asset_id = null,
int $parent_item_id = null): Collection
{

return DB::table(DB::raw('character_asset_list_contents as a'))
->select(
DB::raw('*'),
DB::raw('SUM(a.quantity) as sumquantity'))
->leftJoin('invTypes',
'a.typeID', '=', 'invTypes.typeID')
->leftJoin('invGroups',
'invTypes.groupID', '=', 'invGroups.groupID')
->where('a.characterID', $character_id)
->groupBy(DB::raw('a.itemID, a.typeID'))
->get();
$contents = AssetListContents::join('invTypes',
'character_asset_list_contents.typeID', '=',
'invTypes.typeID')
->where('characterID', $character_id);

if (! is_null($parent_asset_id))
$contents = $contents->where('parentAssetItemID', $parent_asset_id);

if (! is_null($parent_item_id))
$contents = $contents->where('parentItemID', $parent_item_id);

// TODO: Allow the nested lookups to occur.
$contents = $contents->where('parentItemID', null);

return $contents->get();
}
}

0 comments on commit 0be2e39

Please sign in to comment.