Exemple #1
0
 /**
  * Return an assets contents. If no parent asset / item ids
  * are specified, then all assets for the corporation is
  * returned
  *
  * @param int $corporation_id
  * @param int $parent_asset_id
  * @param int $parent_item_id
  *
  * @return \Illuminate\Support\Collection
  */
 public function getCorporationAssetContents(int $corporation_id, int $parent_asset_id = null, int $parent_item_id = null) : Collection
 {
     $contents = AssetListContents::join('invTypes', 'corporation_asset_list_contents.typeID', '=', 'invTypes.typeID')->where('corporationID', $corporation_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();
 }
Exemple #2
0
 /**
  * Populate the assets table.
  *
  * This function is called recursively if an asset entry has
  * contents.
  *
  * @param      $assets
  * @param      $corporationID
  * @param null $parentAssetItemID
  * @param null $parentItemID
  */
 public function add_asset_content($assets, $corporationID, $parentAssetItemID = null, $parentItemID = null)
 {
     // Prepare a blank array that will be pupulated
     // for the mass insert at the end.
     $asset_contents = [];
     foreach ($assets as $asset) {
         // Check if this asset has contents, if so,
         // recursively call this function to do
         // the population work.
         //
         // The $parentItemID variable relates to the
         // item in the same table. The variable
         // $parentAssetItemID refers to the original
         // asset in the corp assets table.
         if (isset($asset->contents)) {
             $this->add_asset_content($asset->contents, $corporationID, $parentAssetItemID, $asset->itemID);
         }
         array_push($asset_contents, ['corporationID' => $corporationID, 'itemID' => $asset->itemID, 'parentAssetItemID' => $parentAssetItemID, 'parentItemID' => $parentItemID, 'typeID' => $asset->typeID, 'quantity' => $asset->quantity, 'flag' => $asset->flag, 'singleton' => $asset->singleton, 'rawQuantity' => isset($asset->rawQuantity) ? $asset->rawQuantity : 0, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]);
     }
     // Again, if there is any contents to add, do so.
     if (count($asset_contents) > 0) {
         AssetListContents::insert($asset_contents);
     }
     return;
 }