Add validations and checks for outlet
This commit is contained in:
parent
14b432a11e
commit
7811c8a66e
3 changed files with 29 additions and 10 deletions
|
|
@ -161,21 +161,34 @@ class OutletController extends BaseController
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$obj = new Outlet();
|
$obj = new Outlet();
|
||||||
|
|
||||||
$this->setObject($obj, $req);
|
|
||||||
|
|
||||||
// validate
|
|
||||||
$errors = $validator->validate($obj);
|
|
||||||
|
|
||||||
// initialize error list
|
// initialize error list
|
||||||
$error_array = [];
|
$error_array = [];
|
||||||
|
|
||||||
// add errors to list
|
// check if lat and lng are provided
|
||||||
foreach ($errors as $error) {
|
if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat')))
|
||||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error)
|
||||||
|
{
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// check if any errors were found
|
// check if any errors were found
|
||||||
if (!empty($error_array)) {
|
if (!empty($error_array))
|
||||||
|
{
|
||||||
// return validation failure response
|
// return validation failure response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,14 @@ class Outlet
|
||||||
// name of enrollee
|
// name of enrollee
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
// address
|
// address
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $address;
|
protected $address;
|
||||||
|
|
||||||
|
|
@ -45,18 +47,21 @@ class Outlet
|
||||||
// this is displayed in a textarea
|
// this is displayed in a textarea
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=200)
|
* @ORM\Column(type="string", length=200)
|
||||||
|
* Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $contact_nums;
|
protected $contact_nums;
|
||||||
|
|
||||||
// opening time
|
// opening time
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="time")
|
* @ORM\Column(type="time")
|
||||||
|
* Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $time_open;
|
protected $time_open;
|
||||||
|
|
||||||
// closing time
|
// closing time
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="time")
|
* @ORM\Column(type="time")
|
||||||
|
* Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $time_close;
|
protected $time_close;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@
|
||||||
|
|
||||||
<div class="form-group m-form__group row">
|
<div class="form-group m-form__group row">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<label>
|
<label data-field="coordinates">
|
||||||
Map Coordinates
|
Map Coordinates
|
||||||
</label>
|
</label>
|
||||||
<input type="hidden" id="map_lat" name="coord_lat" value="">
|
<input type="hidden" id="map_lat" name="coord_lat" value="">
|
||||||
|
|
@ -106,6 +106,7 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="m_gmap" style="height:600px;"></div>
|
<div id="m_gmap" style="height:600px;"></div>
|
||||||
|
<div class="form-control-feedback hide" data-field="coordinates"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue