/**
  * Render a representation of a ResourceItem object.
  *
  * @param   ResourceItem  $resource  A resource item object.
  *
  * @return  A representation of the object.
  */
 public function renderResourceItem(ResourceItem $resource)
 {
     // Initialise.
     $xml = '<resource>';
     $links = $resource->getLinks()->getLinks();
     // Does the resource have a self link?
     if (isset($links['self'])) {
         $self = $links['self'];
         $xml = '<resource rel="self" href="' . $self->getUri() . '">';
         unset($links['self']);
     }
     // Iterate through the links and add them at the top.
     if (!empty($links)) {
         $xml .= $this->render($resource->getLinks());
     }
     // Iterate through the metadata properties and add them to the top-level array.
     if (!empty($resource->getMetadata())) {
         $xml .= $this->render($resource->getMetadata());
     }
     // Iterate through the data properties and add them to the top-level array.
     if (!empty($resource->getData())) {
         $xml .= $this->render($resource->getData());
     }
     // Iterate through the embedded resources and add them to the _embedded element.
     if (!empty($resource->getEmbedded())) {
         $xml .= $this->render($resource->getEmbedded());
     }
     $xml .= '</resource>';
     return $xml;
 }
 public function Get_Item_Information($itemtypeid)
 {
     $itemtypeid = urldecode($itemtypeid);
     if (!is_numeric($itemtypeid)) {
         return Response::json(array('status' => 'error', 'error' => 'This is not a proper ItemTypeID.'));
     }
     if (strlen($itemtypeid) > 8) {
         return Response::json(array('status' => 'error', 'error' => 'This is not a proper ItemTypeID.'));
     }
     //check the cache
     if (Cache::has($this->class_name . "_" . $itemtypeid)) {
         //pull from cache
         $itemtypeid_info = Cache::get($this->class_name . "_" . $itemtypeid);
         return json_encode($itemtypeid_info);
     }
     $basic_info = hWebIcon::where(function ($query) use($itemtypeid) {
         $query->where('itemTypeId', '=', $itemtypeid);
         $query->where('version', '=', $this->version);
     })->first(array('asset_path', 'abilitymodule_id', 'backpack_id', 'basic_id', 'blueprint_id', 'chassis_id', 'consumable_id', 'craftingcomponent_id', 'craftingstation_id', 'craftingsubcomponent_id', 'framemodule_id', 'palettemodule_id', 'powerup_id', 'resourceitem_id', 'scopemodule_id', 'weapon_id', 'weaponmodule_id'));
     if (empty($basic_info)) {
         return Response::json(array('status' => 'error', 'error' => 'ItemTypeID not found in db.'));
     }
     //break up the types
     $detailed_info = array();
     $constraint_info = array();
     $weapon_info = array();
     if ($basic_info['abilitymodule_id'] != "") {
         $detailed_info = AbilityModule::where('id', '=', $basic_info['abilitymodule_id'])->first(array('type', 'abilityId', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'powerLevel', 'rarity', 'durability'));
         $constraint_info = hConstraint::where(function ($query) use($itemtypeid) {
             $query->where('itemTypeId', '=', $itemtypeid);
             $query->where('version', '=', $this->version);
         })->first(array('cpu', 'mass', 'power'));
     }
     if ($basic_info['basic_id'] != "") {
         $detailed_info = Basic::where('id', '=', $basic_info['basic_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity'));
     }
     if ($basic_info['blueprint_id'] != "") {
         //Note -> blueprint_id = recipe_id
     }
     if ($basic_info['chassis_id'] != "") {
         //Note -> links to hattributes
         $detailed_info = Chassis::where('id', '=', $basic_info['chassis_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity', 'progression_item_id', 'progression_resource_id'));
         $chassis_info = hAttributes::where(function ($query) use($itemtypeid) {
             $query->where('itemTypeId', '=', $itemtypeid);
             $query->where('version', '=', $this->version);
         })->get(array('description', 'display_name', 'value', 'stat_id'));
     }
     if ($basic_info['consumable_id'] != "") {
         $detailed_info = Consumable::where('id', '=', $basic_info['consumable_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'powerLevel', 'name', 'rarity'));
     }
     if ($basic_info['craftingcomponent_id'] != "") {
         $detailed_info = CraftingComponent::where('id', '=', $basic_info['craftingcomponent_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity'));
     }
     if ($basic_info['craftingsubcomponent_id'] != "") {
         $detailed_info = CraftingSubcomponent::where('id', '=', $basic_info['craftingsubcomponent_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity'));
     }
     if ($basic_info['framemodule_id'] != "") {
         $detailed_info = FrameModule::where('id', '=', $basic_info['framemodule_id'])->first(array('type', 'abilityId', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'powerLevel', 'rarity', 'durability'));
         $constraint_info = hConstraint::where(function ($query) use($itemtypeid) {
             $query->where('itemTypeId', '=', $itemtypeid);
             $query->where('version', '=', $this->version);
         })->first(array('cpu', 'mass', 'power'));
     }
     if ($basic_info['palletmodule_id'] != "") {
         $detailed_info = PaletteModule::where('id', '=', $basic_info['palettemodule_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity'));
     }
     if ($basic_info['powerup_id'] != "") {
         $detailed_info = Powerup::where('id', '=', $basic_info['powerup_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity'));
     }
     if ($basic_info['resourceitem_id'] != "") {
         $detailed_info = ResourceItem::where('id', '=', $basic_info['resourceitem_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity', 'resource_color'));
     }
     if ($basic_info['weapon_id'] != "") {
         //weapons have hstats also!
         $detailed_info = Weapon::where('id', '=', $basic_info['weapon_id'])->first(array('type', 'craftingTypeId', 'subTypeId', 'description', 'level', 'name', 'rarity', 'durability'));
         $constraint_info = hConstraint::where(function ($query) use($itemtypeid) {
             $query->where('itemTypeId', '=', $itemtypeid);
             $query->where('version', '=', $this->version);
         })->first(array('cpu', 'mass', 'power'));
         $weapon_info = hStat::where(function ($query) use($itemtypeid) {
             $query->where('itemTypeId', '=', $itemtypeid);
             $query->where('version', '=', $this->version);
         })->first(array('ammoPerBurst', 'clipSize', 'damagePerRound', 'damagePerSecond', 'healthPerRound', 'maxAmmo', 'range', 'reloadTime', 'roundsPerBurst', 'roundsPerMinute', 'splashRadius', 'spread'));
     }
     if (empty($detailed_info)) {
         return Response::json(array('status' => 'error', 'error' => 'error getting detailed information for this itemtypeid.'));
     }
     $detailed_info = $detailed_info->toArray();
     $detailed_info['asset_path'] = $basic_info['asset_path'];
     //add contstraint details
     if (!empty($constraint_info)) {
         $constraint_info = $constraint_info->toArray();
         $detailed_info['cpu'] = $constraint_info['cpu'];
         $detailed_info['mass'] = $constraint_info['mass'];
         $detailed_info['power'] = $constraint_info['power'];
     }
     if (!empty($weapon_info)) {
         $weapon_info = $weapon_info->toArray();
         foreach ($weapon_info as $key => $data) {
             $detailed_info[$key] = $data;
         }
     }
     if (!empty($chassis_info)) {
         $chassis_info = $chassis_info->toArray();
         foreach ($chassis_info as $key => $data) {
             $detailed_info[$key] = $data;
         }
     }
     //cache
     //Cache::forever($this->class_name . "_" . $itemtypeid,$detailed_info);
     $detailed_info['status'] = 'success';
     return json_encode($detailed_info);
 }
$resource->addData(array('state' => '1'));
// Add some metadata.  Can be anything as it's not checked against the profile.
$resource->addMetadata(array('date' => date('Y-m-d H:i:s')));
// Add some links.
$links = array('self' => new ResourceLink('/orders'), 'next' => new ResourceLink('/orders?page=2'), 'ea:find' => new ResourceLink('/orders{?id}', true), 'ea:admin' => array(new ResourceLink('/admins/2', false, 'Fred'), new ResourceLink('/admins/5', false, 'Kate')));
$resource->addLinks($links);
// Add some curies.
$curies = array(new ResourceCurie('ea', 'http://example.com/docs/rels/{rel}', true), new ResourceCurie('joomla', 'http://docs.joomla.org/rels/{rel}', true));
$resource->addCuries($curies);
// Now create a resource that will be embedded in the main resource.
$embeddedResource = new ResourceItem(new Profile('profile/order.json'));
$embeddedResource->addData(array('total' => '30.00', 'currency' => 'USD', 'status' => 'shipped'))->addLinks(array('self' => new ResourceLink('/orders/123'), 'ea:basket' => new ResourceLink('/baskets/98712'), 'ea:customer' => new ResourceLink('/customers/7809')));
// Embed the resource into the main resource.
$resource->addEmbedded(array('ea:order' => $embeddedResource));
// And create another resource that will be embedded in the main resource.
$embeddedResource = new ResourceItem(new Profile('profile/contact.json'));
$embeddedResource->addData(array('total' => '20.00', 'currency' => 'USD', 'status' => 'processing'))->addLinks(array('self' => new ResourceLink('/orders/124'), 'ea:basket' => new ResourceLink('/baskets/97213'), 'ea:customer' => new ResourceLink('/customers/12369')));
// Embed the resource into the main resource.
$resource->addEmbedded(array('ea:order' => $embeddedResource));
// Get the data back out.
print_r($resource->getInternalData());
// Generate a hal+json representation of the resource.
// Well, not really HAL, but that's the idea.
$representation = new RepresentationHalJson();
$json = $representation->render($resource);
echo 'Representation as application/hal+json' . "\n";
echo $json . "\n";
// Generate a hal+xml representation of the resource.
// Again, not really HAL, but the idea is there.
$representation = new RepresentationHalXml();
$xml = $representation->render($resource);
 /**
  * Render a representation of a ResourceItem object.
  *
  * @param   ResourceItem  $resource  A resource item object.
  *
  * @return  A representation of the object.
  */
 public function renderResourceItem(ResourceItem $resource)
 {
     $properties = array();
     // Iterate through the metadata properties and add them to the top-level array.
     if (!empty($resource->getMetadata())) {
         foreach ($this->render($resource->getMetadata()) as $name => $property) {
             $properties[$name] = $property;
         }
     }
     // Iterate through the links and add them to the _links element.
     if (!empty($resource->getLinks())) {
         foreach ($this->render($resource->getLinks()) as $rel => $link) {
             $properties['_links'][$rel] = $link;
         }
     }
     // Iterate through the data properties and add them to the top-level array.
     if (!empty($resource->getData())) {
         foreach ($this->render($resource->getData()) as $name => $property) {
             $properties[$name] = $property;
         }
     }
     // Iterate through the embedded resources and add them to the _embedded element.
     if (!empty($resource->getEmbedded())) {
         foreach ($this->render($resource->getEmbedded()) as $rel => $embedded) {
             $properties['_embedded'][$rel] = $embedded;
         }
     }
     return json_encode($properties, JSON_PRETTY_PRINT);
 }
$resource->addData(array('state' => '1'));
// Add some metadata.  Can be anything as it's not checked against the profile.
$resource->addMetadata(array('date' => date('Y-m-d H:i:s')));
// Add some links.
$links = array('self' => new ResourceLink('/orders'), 'next' => new ResourceLink('/orders?page=2'), 'ea:find' => new ResourceLink('/orders{?id}', true), 'ea:admin' => array(new ResourceLink('/admins/2', false, 'Fred'), new ResourceLink('/admins/5', false, 'Kate')));
$resource->addLinks($links);
// Add some curies.
$curies = array(new ResourceCurie('ea', 'http://example.com/docs/rels/{rel}', true), new ResourceCurie('joomla', 'http://docs.joomla.org/rels/{rel}', true));
$resource->addCuries($curies);
// Now create a resource that will be embedded in the main resource.
$embeddedResource = new ResourceItem(new Profile('profile/order.json'));
$embeddedResource->addData(array('total' => '30.00', 'currency' => 'USD', 'status' => 'shipped'))->addLinks(array('self' => new ResourceLink('/orders/123'), 'ea:basket' => new ResourceLink('/baskets/98712'), 'ea:customer' => new ResourceLink('/customers/7809')));
// Embed the resource into the main resource.
$resource->addEmbedded(array('ea:order' => $embeddedResource));
// And create another resource that will be embedded in the main resource.
$embeddedResource = new ResourceItem(new Profile('profile/order.json'));
$embeddedResource->addData(array('total' => '50.00', 'currency' => 'GBP', 'status' => 'pending'))->addLinks(array('self' => new ResourceLink('/orders/125'), 'ea:basket' => new ResourceLink('/baskets/35131'), 'ea:customer' => new ResourceLink('/customers/55646')));
// Embed the resource into the main resource.
$resource->addEmbedded(array('ea:order' => $embeddedResource));
// Get the data back out.
print_r($resource->getInternalData());
// Generate a hal+json representation of the resource.
// Well, not really HAL, but that's the idea.
$representation = new RepresentationHalJson();
$json = $representation->render($resource);
echo 'Representation as application/hal+json' . "\n";
echo $json . "\n";
// Generate a hal+xml representation of the resource.
// Again, not really HAL, but the idea is there.
$representation = new RepresentationHalXml();
$xml = $representation->render($resource);