From 58003e5d1808ac012bd54d8b597aadf3932c2659 Mon Sep 17 00:00:00 2001 From: Kamil Niemczycki Date: Thu, 27 Jul 2023 14:02:54 +0200 Subject: [PATCH] - show elements as table --- app/Console/Commands/CVInfo.php | 23 +++++++++++++++++------ app/Console/Commands/ListCV.php | 25 +++++++++++++++++-------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/CVInfo.php b/app/Console/Commands/CVInfo.php index 5aa674a..fd76a7a 100644 --- a/app/Console/Commands/CVInfo.php +++ b/app/Console/Commands/CVInfo.php @@ -26,19 +26,30 @@ class CVInfo extends Command $this->line('Company: '. $cv->recipient); $this->line('Phone: '. $cv->formattedPhoneNumber .', '. $cv->PhoneNumber); $this->line('Locations: '. implode(' / ', $cv->locations)); - $this->line('Views: '. $cv->views); + $this->line('Actual views: '. $cv->info()->select('id')->get()->count()); + $this->line('Registered views: '. $cv->views); $this->line('Mission: '. (is_null($mission = $cv->mission) ? 'domyślne' : $mission)); $this->line('Rodo: '. (is_null($rodo = $cv->rodo) ? 'domyślne' : $rodo)); $this->line(''); $this->line('Showed list:'); - foreach ($cv->info()->orderByDesc('id')->get() as $cvInfo) { - $this->line('ID: '. $cvInfo->id); - $this->line('IP: '. $cvInfo->ip); - $this->line('Date: '. $cvInfo->created_at->format('d-m-Y H:i:s')); - $this->line(''); + $listCVInfo = []; + foreach (($cvInfoList = $cv->info()->orderByDesc('id')->get(['id', 'ip', 'created_at'])) as $cvInfo) { + $listCVInfo[] = [ + 'id' => $cvInfo->id, + 'ip' => $cvInfo->ip, + 'created' => $cvInfo->created_at->format('d-m-Y H:i:s'), + ]; } + if ($cvInfoList->count() === 0) + $this->warn('Empty!'); + else + $this->table( + ['Id', 'IP', 'Showed'], + $listCVInfo, + ); + return Command::SUCCESS; } } diff --git a/app/Console/Commands/ListCV.php b/app/Console/Commands/ListCV.php index 01d3314..46fb684 100644 --- a/app/Console/Commands/ListCV.php +++ b/app/Console/Commands/ListCV.php @@ -17,19 +17,28 @@ class ListCV extends Command public function handle(): int { $cvList = CV::all(); + $cvListCollection = []; /** @var CV $cv */ foreach ($cvList as $cv) { - $resource = new CVResource($cv); - $this->line('ID: '. $resource->id); - $this->line('Token: '. $resource->token); - $this->line('Company: '. $resource->recipient); - $this->line('Phone: '. $resource->formattedPhoneNumber .', '. $resource->PhoneNumber); - $this->line('Locations: '. implode(' / ', $resource->locations)); - $this->line('Views: '. $resource->views); - $this->line(''); + $cvResource = (new CVResource($cv))->setAsConsole()->toArray(); + $cvListCollection[] = [ + 'id' => $cvResource['id'], + 'token' => $cvResource['token'], + 'email' => $cvResource['email'], + 'recipient' => $cvResource['recipient'], + 'locations' => implode(' / ', $cvResource['locations']), + 'phone' => $cvResource['phone']['formattedPhoneNumber'], + 'views' => $cvResource['views'] . '/' . $cvResource['registeredViews'], + ]; } + if (count($cvListCollection) > 0) + $this->table( + ['Id', 'Token', 'E-mail', 'Company', 'Locations', 'Phone', 'Views'], + $cvListCollection + ); + return Command::SUCCESS; } }