Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/User/EntitlementsCommand.php
- This file was moved from src/app/Console/Commands/UserEntitlements.php.
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands\User; | ||||
use App\Console\Command; | use App\Console\Command; | ||||
class UserEntitlements extends Command | class EntitlementsCommand extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'user:entitlements {userid}'; | protected $signature = 'user:entitlements {userid}'; | ||||
Show All 9 Lines | class EntitlementsCommand extends Command | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = $this->getUser($this->argument('userid')); | $user = $this->getUser($this->argument('userid')); | ||||
if (!$user) { | if (!$user) { | ||||
$this->error("User not found."); | |||||
return 1; | return 1; | ||||
} | } | ||||
$this->info("Found user: {$user->id}"); | |||||
$skus_counted = []; | $skus_counted = []; | ||||
foreach ($user->entitlements as $entitlement) { | foreach ($user->entitlements as $entitlement) { | ||||
if (!array_key_exists($entitlement->sku_id, $skus_counted)) { | if (!array_key_exists($entitlement->sku_id, $skus_counted)) { | ||||
$skus_counted[$entitlement->sku_id] = 1; | $skus_counted[$entitlement->sku_id] = 1; | ||||
} else { | } else { | ||||
$skus_counted[$entitlement->sku_id] += 1; | $skus_counted[$entitlement->sku_id] += 1; | ||||
} | } | ||||
} | } | ||||
foreach ($skus_counted as $id => $qty) { | foreach ($skus_counted as $id => $qty) { | ||||
$sku = \App\Sku::find($id); | $sku = \App\Sku::find($id); | ||||
$this->info("SKU: {$sku->title} ({$qty})"); | $this->info("{$sku->title}: {$qty}"); | ||||
} | } | ||||
} | } | ||||
} | } |