Created
December 22, 2016 13:54
-
-
Save anonymous/88c36e3474ba3ab7687e9fbe1fbb3219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\FreeLook; | |
use App\Models\FreeLook\FreeLook; | |
use Carbon\Carbon; | |
use Illuminate\Support\Collection; | |
trait Actionable | |
{ | |
/** | |
* @var FreeLook | |
*/ | |
protected $freeLook; | |
/** | |
* This will be the route name to the next action step. | |
* | |
* @var string | |
*/ | |
protected $route; | |
/** | |
* This will be the name of the next action step that needs to be taken. | |
* | |
* @var string | |
*/ | |
protected $name; | |
/** | |
* This will be the next action date. | |
* | |
* @var mixed null|string | |
*/ | |
protected $date = null; | |
/** | |
* How long an action will take. | |
* | |
* @var mixed string|null | |
*/ | |
protected $duration = null; | |
/** | |
* This is how much time is remaining for the next action. | |
* | |
* @var mixed null|string | |
*/ | |
protected $timeRemaining = null; | |
/** | |
* This is the output for the next action. | |
* | |
* @var Collection | |
*/ | |
protected $output; | |
/** | |
* @return bool|mixed | |
*/ | |
protected function wantsSign(): bool | |
{ | |
return $this->freeLook->wants_sign; | |
} | |
/** | |
* @return bool | |
*/ | |
protected function signJobIsComplete(): bool | |
{ | |
return $this->freeLook->signJob && $this->freeLook->signJob->isComplete(); | |
} | |
/** | |
* @return bool|mixed | |
*/ | |
protected function wantsPaint(): bool | |
{ | |
return $this->freeLook->wants_paint; | |
} | |
/** | |
* @return bool | |
*/ | |
protected function paintJobIsComplete(): bool | |
{ | |
return $this->freeLook->paintJob->isComplete(); | |
} | |
/** | |
* @return bool | |
*/ | |
protected function needsToSubmitCoOp(): bool | |
{ | |
return $this->wantsSignAndPaint() && $this->signJobIsComplete() && $this->paintJobIsComplete(); | |
} | |
/** | |
* @return bool | |
*/ | |
protected function wantsSignAndPaint(): bool | |
{ | |
return $this->freeLook->wants_paint && $this->freeLook->wants_sign; | |
} | |
/** | |
* @return bool | |
*/ | |
protected function hasNotChosenVendors(): bool | |
{ | |
return $this->wantsSignAndPaint() && $this->hasNotChosenSignVendor() && $this->hasNotChosenPaintVendor(); | |
} | |
/** | |
* @return bool | |
*/ | |
protected function hasNotChosenSignVendor(): bool | |
{ | |
return !$this->freeLook->signJob; | |
} | |
/** | |
* @return bool | |
*/ | |
protected function hasNotChosenPaintVendor(): bool | |
{ | |
return !$this->freeLook->paintJob; | |
} | |
/** | |
* @return bool | |
*/ | |
protected function isPerformingSignJob(): bool | |
{ | |
return $this->freeLook->signJob && !$this->freeLook->signJob->isComplete(); | |
} | |
/** | |
* @return bool | |
*/ | |
protected function isPerformingPaintJob(): bool | |
{ | |
return $this->freeLook->paintJob && !$this->freeLook->paintJob->isComplete(); | |
} | |
/** | |
* @return \Illuminate\Support\Collection | |
*/ | |
protected function needToChooseVendor() | |
{ | |
$this->name = 'Choose Vendor'; | |
$this->duration = $this->freeLook->status->expected_duration; | |
$this->calculateTimeRemaining(); | |
return $this->buildOutput(); | |
} | |
/** | |
* Set the time remaining in days. | |
*/ | |
protected function calculateTimeRemaining() | |
{ | |
if ($this->duration) { | |
$this->timeRemaining = Carbon::now()->diffInDays($this->date); | |
} | |
} | |
/** | |
* Wrapping our output in a collection to make it easy to use. | |
* | |
* @return \Illuminate\Support\Collection | |
*/ | |
protected function buildOutput() | |
{ | |
return collect([ | |
'name' => $this->name, | |
'date' => $this->date, | |
'timeRemaining' => $this->timeRemaining, | |
'route' => $this->route, | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment