Add validations and checks for outlet

This commit is contained in:
Kendrick Chan 2018-01-17 23:54:00 +08:00
parent 14b432a11e
commit 7811c8a66e
3 changed files with 29 additions and 10 deletions

View file

@ -161,21 +161,34 @@ class OutletController extends BaseController
$em = $this->getDoctrine()->getManager();
$obj = new Outlet();
// initialize error list
$error_array = [];
// check if lat and lng are provided
if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat')))
{
$error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.';
}
if (empty($error_array))
{
// set object
$this->setObject($obj, $req);
// validate
$errors = $validator->validate($obj);
// initialize error list
$error_array = [];
// add errors to list
foreach ($errors as $error) {
foreach ($errors as $error)
{
$error_array[$error->getPropertyPath()] = $error->getMessage();
}
}
// check if any errors were found
if (!empty($error_array)) {
if (!empty($error_array))
{
// return validation failure response
return $this->json([
'success' => false,

View file

@ -26,12 +26,14 @@ class Outlet
// name of enrollee
/**
* @ORM\Column(type="string", length=80)
* Assert\NotBlank()
*/
protected $name;
// address
/**
* @ORM\Column(type="string", length=80)
* Assert\NotBlank()
*/
protected $address;
@ -45,18 +47,21 @@ class Outlet
// this is displayed in a textarea
/**
* @ORM\Column(type="string", length=200)
* Assert\NotBlank()
*/
protected $contact_nums;
// opening time
/**
* @ORM\Column(type="time")
* Assert\NotBlank()
*/
protected $time_open;
// closing time
/**
* @ORM\Column(type="time")
* Assert\NotBlank()
*/
protected $time_close;

View file

@ -92,7 +92,7 @@
<div class="form-group m-form__group row">
<div class="col-lg-12">
<label>
<label data-field="coordinates">
Map Coordinates
</label>
<input type="hidden" id="map_lat" name="coord_lat" value="">
@ -106,6 +106,7 @@
</span>
</div>
<div id="m_gmap" style="height:600px;"></div>
<div class="form-control-feedback hide" data-field="coordinates"></div>
</div>
</div>