Skip to content

Commit

Permalink
option to generate certificates since a certain date
Browse files Browse the repository at this point in the history
  • Loading branch information
bpow committed Dec 1, 2023
1 parent e19f863 commit 4942833
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions app/Actions/TrainingCertificateGenerateForExisting.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
use Illuminate\Console\Command;
use Lorisleiva\Actions\Concerns\AsCommand;
use App\Actions\TrainingCertificateGenerate;
use Carbon\Carbon;

// FIXME: the options here don't make a lot of sense because of the order of filtering... limit and offset are for # of volunteers, who may have had multiple trainings

ini_set('memory_limit', '512M');
class TrainingCertificateGenerateForExisting
{
use AsCommand;

public $commandSignature = 'volunteers:training:generate-certificates-for-existing {--limit= : # of volunteers} {--offset= : Offset at which to begin } {--dry-run : Print certificate params; don\'t actually generate certificates.} {--dry-run-quiet : print count of effected volunteers; don\'t generate certs.}';

public $commandSignature = 'volunteers:training:generate-certificates-for-existing {--since= : First date (ISO-formatted like "2023-12-01") from which to include trainings} {--limit= : # of volunteers} {--offset= : Offset at which to begin } {--dry-run : Print certificate params; don\'t actually generate certificates.} {--dry-run-quiet : print count of effected volunteers; don\'t generate certs.}';

private $since = null;
private $limit = null;
private $offset = null;
private $dryRun = false;
Expand All @@ -23,7 +27,7 @@ class TrainingCertificateGenerateForExisting
public function __construct(private TrainingCertificateGenerate $certGen)
{
}


public function handle(): void
{
Expand All @@ -45,7 +49,7 @@ public function handle(): void
$query->get()
->each(function ($volunteer) {
$volunteer->userAptitudes->each(function ($userApt) use ($volunteer) {
if (!$userApt->trained_at) {
if ($userApt->trained_at < $this->since) {
return;
}
if ($this->dryRun) {
Expand All @@ -56,16 +60,23 @@ public function handle(): void
});
});
}

public function asCommand(Command $command)
{
$this->setLimit($command->option('limit'))
->setOffset($command->option('offset'))
->setDryRun($command->option('dry-run'))
->setDryRunQuiet($command->option('dry-run-quiet'))
->setSince($command->option('since'))
->handle();
}

private function setSince($since)
{
$this->since = new Carbon($since == null ? 0 : $since);
return $this;
}

private function setLimit($limit)
{
$this->limit = ($limit > 0) ? $limit : null;
Expand All @@ -75,24 +86,23 @@ private function setLimit($limit)
private function setOffset($offset)
{
$this->offset = ($offset > 0) ? $offset : null;

return $this;
}


private function setDryRun($dryRun)
{
$this->dryRun = $dryRun;
return $this;
}

private function setDryRunQuiet($dryRunQuiet)
{
$this->dryRunQuiet = $dryRunQuiet;
return $this;
}



private function generateCert($volunteer, $userApt)
{
Expand All @@ -102,7 +112,7 @@ private function generateCert($volunteer, $userApt)
type: Str::kebab($userApt->aptitude->subject->name)
);
}

private function dumpCertParams($volunteer, $userApt): void
{
dump([
Expand All @@ -111,6 +121,6 @@ private function dumpCertParams($volunteer, $userApt): void
'type' => Str::kebab($userApt->aptitude->subject->name)
]);
}


}

0 comments on commit 4942833

Please sign in to comment.