This repository has been archived by the owner on Feb 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proper profile endpoint and inventory items
- Loading branch information
Showing
2 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
namespace Fortnite\Model; | ||
|
||
class Items { | ||
private $items; | ||
|
||
public function __construct($items) { | ||
$this->items = $this->parseItems((array)$items); | ||
} | ||
|
||
/** | ||
* Returns item by it's item id. | ||
* @param string $id Item id | ||
* @return object The item (null if not found) | ||
*/ | ||
public function id($id) { | ||
foreach ($this->items as $item) { | ||
if ($item->itemId == $id) return $item; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Returns all owned items. | ||
* @return array The items | ||
*/ | ||
public function all() { | ||
return $this->items; | ||
} | ||
|
||
// | ||
// TODO (Tustin): maybe get all items of a certain type? Not really possible for me since I don't own more than like 5 items and they're all dances and gliders. | ||
// You would just need to parse 'templateId' for the first part to get the type. | ||
// | ||
|
||
/** | ||
* Parses a list of items and removes any non items (for some reason, quests show up in here) | ||
* @param array $items Items | ||
* @return array Actual items | ||
*/ | ||
private function parseItems($items) { | ||
$actual = []; | ||
foreach ($items as $key => $item) { | ||
if (strpos($item->templateId, "Quest:") !== false) continue; | ||
$newItem = $item; | ||
$newItem->itemId = $key; // Add the itemId as a kvp since it only exists as the object identifier initially | ||
$actual[] = $newItem; | ||
} | ||
return $actual; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters