43 lines
960 B
PHP
43 lines
960 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
use App\Models\Project;
|
|
use App\Models\ProjectReport;
|
|
|
|
class AllMosaicsPresentRule implements Rule
|
|
{
|
|
protected $projectId;
|
|
protected $errorMessage = '';
|
|
|
|
public function __construct($projectId)
|
|
{
|
|
$this->projectId = $projectId;
|
|
}
|
|
|
|
public function passes($attribute, $value)
|
|
{
|
|
try {
|
|
$project = Project::find($this->projectId);
|
|
|
|
if (!$project) {
|
|
$this->errorMessage = 'Project not found.';
|
|
return false;
|
|
}
|
|
|
|
return $project->allMosaicsPresent(
|
|
ProjectReport::getReportDateForYearAndWeek($project, $value['year'], $value['week'])
|
|
);
|
|
} catch (\Exception $e) {
|
|
$this->errorMessage = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return $this->errorMessage;
|
|
}
|
|
}
|