Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/User/Entitlements.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\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Console\Command; | |||||
class UserEntitlements extends Command | class Entitlements 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}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = "List a user's entitlements."; | protected $description = "List a user's entitlements."; | ||||
/** | /** | ||||
* Create a new command instance. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function __construct() | |||||
{ | |||||
parent::__construct(); | |||||
} | |||||
/** | |||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = User::where('email', $this->argument('userid'))->first(); | $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 = Sku::find($id); | $sku = Sku::find($id); | ||||
$this->info("SKU: {$sku->title} ({$qty})"); | $this->info("SKU: {$sku->title} ({$qty})"); | ||||
} | } | ||||
} | } | ||||
} | } |