|
@@ -1,9 +1,11 @@
|
|
|
-<?php
|
|
|
|
|
|
|
+<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @var int $id
|
|
* @var int $id
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
+use Carbon\CarbonImmutable;
|
|
|
|
|
+
|
|
|
$project = Project::get($id);
|
|
$project = Project::get($id);
|
|
|
if(!$project) throw new Exception("Project not found.");
|
|
if(!$project) throw new Exception("Project not found.");
|
|
|
|
|
|
|
@@ -30,34 +32,34 @@ if($submit) {
|
|
|
try {
|
|
try {
|
|
|
Core::validateCSRFToken($submit);
|
|
Core::validateCSRFToken($submit);
|
|
|
|
|
|
|
|
- $new_location_ids = http::value("location_ids");
|
|
|
|
|
|
|
+ $new_location_ids = HTTP::value("location_ids");
|
|
|
$new_location_ids = explode(", ", $new_location_ids);
|
|
$new_location_ids = explode(", ", $new_location_ids);
|
|
|
$new_location_ids = array_filter($new_location_ids);
|
|
$new_location_ids = array_filter($new_location_ids);
|
|
|
|
|
|
|
|
$location_ids_to_add = array_diff($new_location_ids, $location_ids);
|
|
$location_ids_to_add = array_diff($new_location_ids, $location_ids);
|
|
|
$location_ids_to_delete = array_diff($location_ids, $new_location_ids);
|
|
$location_ids_to_delete = array_diff($location_ids, $new_location_ids);
|
|
|
|
|
|
|
|
- $project->template_id = http::value("template_id", "int");
|
|
|
|
|
|
|
+ $project->template_id = HTTP::value("template_id", "int");
|
|
|
$project->setTemplateKeys(HTTP::value("template_keys"));
|
|
$project->setTemplateKeys(HTTP::value("template_keys"));
|
|
|
- $project->name = http::value("name", "trim");
|
|
|
|
|
- $project->test_count = http::value("test_count", "int");
|
|
|
|
|
- $project->min_age = http::value("min_age", "int");
|
|
|
|
|
- $project->max_age = http::value("max_age", "int");
|
|
|
|
|
- $project->default_customer_fee = http::value("default_customer_fee", "float");
|
|
|
|
|
- $project->default_tester_fee = http::value("default_tester_fee", "float");
|
|
|
|
|
- $project->time_of_day = http::value("time_of_day", "trim");
|
|
|
|
|
- $project->tester_can_claim = http::value("tester_can_claim", "trim");
|
|
|
|
|
-
|
|
|
|
|
- $date_start = http::getDateFromFields("date_start");
|
|
|
|
|
- $date_deadline = http::getDateFromFields("date_deadline");
|
|
|
|
|
- $date_report = http::getDateFromFields("date_report");
|
|
|
|
|
|
|
+ $project->name = HTTP::value("name", "trim");
|
|
|
|
|
+ $project->test_count = HTTP::value("test_count", "int");
|
|
|
|
|
+ $project->min_age = HTTP::value("min_age", "int");
|
|
|
|
|
+ $project->max_age = HTTP::value("max_age", "int");
|
|
|
|
|
+ $project->default_customer_fee = HTTP::value("default_customer_fee", "float");
|
|
|
|
|
+ $project->default_tester_fee = HTTP::value("default_tester_fee", "float");
|
|
|
|
|
+ $project->time_of_day = HTTP::value("time_of_day", "trim");
|
|
|
|
|
+ $project->tester_can_claim = HTTP::value("tester_can_claim", "trim");
|
|
|
|
|
+
|
|
|
|
|
+ $date_start = HTTP::value("date_start");
|
|
|
|
|
+ $date_deadline = HTTP::value("date_deadline");
|
|
|
|
|
+ $date_report = HTTP::value("date_report");
|
|
|
|
|
|
|
|
$form_exception = new FormException;
|
|
$form_exception = new FormException;
|
|
|
|
|
|
|
|
if(empty($project->template_id)) $form_exception->addError("Template is required.");
|
|
if(empty($project->template_id)) $form_exception->addError("Template is required.");
|
|
|
else {
|
|
else {
|
|
|
$template = Template::get($project->template_id);
|
|
$template = Template::get($project->template_id);
|
|
|
- if($template->customer_id != $customer->id) $form_exception->addError("Invalid template selected.");
|
|
|
|
|
|
|
+ if((int) $template->customer_id !== (int) $customer->id) $form_exception->addError("Invalid template selected.");
|
|
|
}
|
|
}
|
|
|
if(empty($project->name)) $form_exception->addError("Name is required.");
|
|
if(empty($project->name)) $form_exception->addError("Name is required.");
|
|
|
if(empty($project->test_count)) $form_exception->addError("Test count is required.");
|
|
if(empty($project->test_count)) $form_exception->addError("Test count is required.");
|
|
@@ -71,29 +73,34 @@ if($submit) {
|
|
|
if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
|
|
if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
|
|
|
if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
|
|
if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
|
|
|
|
|
|
|
|
- $unix_start = strtotime($date_start . " 00:00:00");
|
|
|
|
|
- $unix_deadline = strtotime($date_deadline . " 23:59:59");
|
|
|
|
|
- $unix_report = null;
|
|
|
|
|
- if(!empty($date_report)) {
|
|
|
|
|
- $unix_report = strtotime($date_report . " 12:00:00");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $dt_start = CarbonImmutable::createFromFormat("Y-m-d", $date_start, "UTC");
|
|
|
|
|
+ if(!$dt_start) $form_exception->addError("Start Date is invalid.");
|
|
|
|
|
|
|
|
- $project->dts_start = Util::getDateTime($unix_start);
|
|
|
|
|
- $project->dts_deadline = Util::getDateTime($unix_deadline);
|
|
|
|
|
- $project->dts_report = is_null($unix_report) ? null : Util::getDateTime($unix_report);
|
|
|
|
|
|
|
+ $dt_deadline = CarbonImmutable::createFromFormat("Y-m-d", $date_deadline, "UTC");
|
|
|
|
|
+ if(!$dt_deadline) $form_exception->addError("Deadline is invalid.");
|
|
|
|
|
|
|
|
- if($unix_start > $unix_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
|
|
|
|
|
|
|
+ $dt_report = null;
|
|
|
|
|
+ if($date_report) {
|
|
|
|
|
+ $dt_report = CarbonImmutable::createFromFormat("Y-m-d", $date_report, "UTC");
|
|
|
|
|
+ if(!$dt_report) $form_exception->addError("Report Month is invalid.");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($dt_start && $dt_deadline && $dt_start > $dt_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
|
|
|
|
|
|
|
|
// Verify location IDs
|
|
// Verify location IDs
|
|
|
Location::load($location_ids_to_add);
|
|
Location::load($location_ids_to_add);
|
|
|
foreach($location_ids_to_add as $location_id) {
|
|
foreach($location_ids_to_add as $location_id) {
|
|
|
$location = Location::get($location_id);
|
|
$location = Location::get($location_id);
|
|
|
if(!$location) $form_exception->addError("An invalid location was picked.");
|
|
if(!$location) $form_exception->addError("An invalid location was picked.");
|
|
|
- if($location->customer_id != $customer->id) $form_exception->addError("An invalid location was picked.");
|
|
|
|
|
|
|
+ if((int) $location->customer_id !== (int) $customer->id) $form_exception->addError("An invalid location was picked.");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($form_exception->hasErrors()) throw $form_exception;
|
|
if($form_exception->hasErrors()) throw $form_exception;
|
|
|
|
|
|
|
|
|
|
+ $project->dts_start = (string) $dt_start->setTime(0, 0);
|
|
|
|
|
+ $project->dts_deadline = (string) $dt_deadline->setTime(23, 59, 59);
|
|
|
|
|
+ $project->dts_report = $dt_report ? (string) $dt_report->setTime(12, 0, 0) : null;
|
|
|
|
|
+
|
|
|
$success = $project->commit();
|
|
$success = $project->commit();
|
|
|
if(!$success) throw new Exception("Project could not be edited at this time. Please try again later.");
|
|
if(!$success) throw new Exception("Project could not be edited at this time. Please try again later.");
|
|
|
|
|
|
|
@@ -137,8 +144,8 @@ $project_locations = $project->getLocations();
|
|
|
$project_location_ids = array_column($project_locations, "id");
|
|
$project_location_ids = array_column($project_locations, "id");
|
|
|
|
|
|
|
|
$locations = $customer->getLocations();
|
|
$locations = $customer->getLocations();
|
|
|
-$locations = array_filter($locations, function(Location $location) use ($project_location_ids) {
|
|
|
|
|
- if(in_array($location->id, $project_location_ids)) return true;
|
|
|
|
|
|
|
+$locations = array_filter($locations, static function(Location $location) use ($project_location_ids) {
|
|
|
|
|
+ if(in_array($location->id, $project_location_ids, false)) return true;
|
|
|
if($location->closed || $location->isArchived()) return false;
|
|
if($location->closed || $location->isArchived()) return false;
|
|
|
return true;
|
|
return true;
|
|
|
});
|
|
});
|