Add validation for model year. #686
This commit is contained in:
parent
bbb562d366
commit
accd6fd0f6
1 changed files with 33 additions and 0 deletions
|
|
@ -1467,6 +1467,33 @@ class JobOrderController extends APIController
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check model year
|
||||||
|
// (1) if empty
|
||||||
|
// (2) if numeric
|
||||||
|
// (2)if it falls between a range of years
|
||||||
|
$model_year = $r->get('vehicle_model_year');
|
||||||
|
if (empty($model_year))
|
||||||
|
{
|
||||||
|
$message = 'Vehicle model year is empty.';
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
if (!is_numeric($model_year))
|
||||||
|
{
|
||||||
|
$message = 'Invalid model year. Not a number.';
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
$year_options = $this->generateYearOptions();
|
||||||
|
// get first and last element
|
||||||
|
$first_year = $year_options[0];
|
||||||
|
$last_year = end($year_options);
|
||||||
|
if (($model_year < $first_year) ||
|
||||||
|
($model_year > $last_year))
|
||||||
|
{
|
||||||
|
$message = 'Invalid model year.';
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
// confirm that vehicle model's manufacturer is the same as the one in vehicle
|
// confirm that vehicle model's manufacturer is the same as the one in vehicle
|
||||||
if ($vmodel->getManufacturer()->getID() != $vmanu_id)
|
if ($vmodel->getManufacturer()->getID() != $vmanu_id)
|
||||||
{
|
{
|
||||||
|
|
@ -1777,5 +1804,11 @@ class JobOrderController extends APIController
|
||||||
{
|
{
|
||||||
return strtolower(trim($name));
|
return strtolower(trim($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function generateYearOptions()
|
||||||
|
{
|
||||||
|
$start_year = 1950;
|
||||||
|
return range($start_year, date("Y") + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue