|
|
@@ -277,13 +277,11 @@ if($submit) {
|
|
|
$month = http::value("month", "int");
|
|
|
$day = http::value("day", "int");
|
|
|
|
|
|
- $unix_due = 0;
|
|
|
- if($year && $month && $day) {
|
|
|
-
|
|
|
- $month = str_pad($month, 2, "0", STR_PAD_LEFT);
|
|
|
- $day = str_pad($day, 2, "0", STR_PAD_LEFT);
|
|
|
+ $dt_due = null;
|
|
|
|
|
|
- $unix_due = strtotime("$year-$month-$day");
|
|
|
+ if($year && $month && $day) {
|
|
|
+ $dt_due = CarbonImmutable::now(TIMEZONE);
|
|
|
+ $dt_due = $dt_due->setDate($year, $month, $day)->endOfDay();
|
|
|
}
|
|
|
|
|
|
$message = http::value("message");
|
|
|
@@ -302,38 +300,23 @@ if($submit) {
|
|
|
];
|
|
|
|
|
|
$test = Test::queryOne($nvp);
|
|
|
- if(!$test) throw new Exception("A test does not exist for this location.");
|
|
|
+ if(!$test) {
|
|
|
+ throw new RuntimeException("A test does not exist for this location.");
|
|
|
+ }
|
|
|
|
|
|
$address_id = http::value("address_id", "int");
|
|
|
$address = UserAddress::get($address_id);
|
|
|
- if(!$address) throw new Exception("User address cannot be found.");
|
|
|
+ if(!$address) {
|
|
|
+ throw new RuntimeException("User address cannot be found.");
|
|
|
+ }
|
|
|
|
|
|
$user = $address->getUser();
|
|
|
- if($user->level == User::LEVEL_BANNED) throw new Exception("A test cannot be assigned to an banned user.");
|
|
|
- if($user->level == User::LEVEL_REGISTERED) throw new Exception("A test cannot be assigned to an unverified user.");
|
|
|
- if($user->level == User::LEVEL_UNVERIFIED) throw new Exception("A test cannot be assigned to an unverified user.");
|
|
|
- if($user->level == User::LEVEL_DEACTIVATED) throw new Exception("A test cannot be assigned to a deactivated user.");
|
|
|
- if($user->level != User::LEVEL_TESTER) throw new Exception("A test cannot be assigned to a user that's not a tester.");
|
|
|
-
|
|
|
- $test->status = Test::STATUS_ASSIGNED;
|
|
|
- $test->tester_id = $user->id;
|
|
|
- $test->dts_assigned = Util::getDateTime();
|
|
|
- $test->dts_rejected = null;
|
|
|
- $test->dts_updated = Util::getDateTime();
|
|
|
-
|
|
|
- if($unix_due) {
|
|
|
- $test->dts_due = "$year-$month-$day 23:59:59";
|
|
|
-
|
|
|
- if(strcmp($test->dts_due, $project->dts_start) < 0) throw new Exception("The date due cannot be before the project start date.");
|
|
|
- if(strcmp($test->dts_due, $project->dts_deadline) > 0) throw new Exception("The date due cannot be beyond the project deadline.");
|
|
|
|
|
|
+ $success = $test->assignTester($user, $dt_due, $message);
|
|
|
+ if(!$success) {
|
|
|
+ throw new RuntimeException("Test cannot be assigned, please try again later.");
|
|
|
}
|
|
|
|
|
|
- $success = $test->commit();
|
|
|
- if(!$success) throw new Exception("Test cannot be assigned, please try again later.");
|
|
|
-
|
|
|
- $test->sendAssignEmail($message);
|
|
|
-
|
|
|
JSON::success();
|
|
|
|
|
|
break;
|