Finish outlet list and update forms
This commit is contained in:
parent
55b59cf003
commit
8e404dbd91
3 changed files with 81 additions and 143 deletions
|
|
@ -63,11 +63,8 @@ class OutletController extends BaseController
|
||||||
|
|
||||||
// check if filter is present
|
// check if filter is present
|
||||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
$query->where('q.outletname LIKE :filter')
|
$query->where('q.name LIKE :filter')
|
||||||
->orWhere('q.first_name LIKE :filter')
|
->orWhere('q.address LIKE :filter')
|
||||||
->orWhere('q.last_name LIKE :filter')
|
|
||||||
->orWhere('q.email LIKE :filter')
|
|
||||||
->orWhere('q.contact_num LIKE :filter')
|
|
||||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,12 +88,11 @@ class OutletController extends BaseController
|
||||||
foreach ($obj_rows as $orow) {
|
foreach ($obj_rows as $orow) {
|
||||||
// add row data
|
// add row data
|
||||||
$row['id'] = $orow->getID();
|
$row['id'] = $orow->getID();
|
||||||
$row['outletname'] = $orow->getName();
|
$row['name'] = $orow->getName();
|
||||||
$row['first_name'] = $orow->getFirstName();
|
$row['address'] = $orow->getAddress();
|
||||||
$row['last_name'] = $orow->getLastName();
|
$row['contact_nums'] = $orow->getContactNumbers();
|
||||||
$row['email'] = $orow->getEmail();
|
$row['time_open'] = $orow->getTimeOpen()->format('h:i A');
|
||||||
$row['contact_num'] = $orow->getContactNumber();
|
$row['time_close'] = $orow->getTimeClose()->format('h:i A');
|
||||||
$row['enabled'] = $orow->isEnabled();
|
|
||||||
|
|
||||||
|
|
||||||
// add row metadata
|
// add row metadata
|
||||||
|
|
@ -105,13 +101,6 @@ class OutletController extends BaseController
|
||||||
'delete_url' => ''
|
'delete_url' => ''
|
||||||
];
|
];
|
||||||
|
|
||||||
// check if they have access to super admin outlets
|
|
||||||
if (!$this->isGranted('outlet.role.sadmin') && $orow->isSuperAdmin())
|
|
||||||
{
|
|
||||||
$rows[] = $row;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add crud urls
|
// add crud urls
|
||||||
if ($this->isGranted('outlet.update'))
|
if ($this->isGranted('outlet.update'))
|
||||||
$row['meta']['update_url'] = $this->generateUrl('outlet_update', ['id' => $row['id']]);
|
$row['meta']['update_url'] = $this->generateUrl('outlet_update', ['id' => $row['id']]);
|
||||||
|
|
@ -140,6 +129,25 @@ class OutletController extends BaseController
|
||||||
return $this->render('outlet/form.html.twig', $params);
|
return $this->render('outlet/form.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function setObject(Outlet $obj, Request $req)
|
||||||
|
{
|
||||||
|
// coordinates
|
||||||
|
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
|
||||||
|
|
||||||
|
// times
|
||||||
|
$format = 'h:i A';
|
||||||
|
$time_open = DateTime::createFromFormat($format, $req->request->get('time_open'));
|
||||||
|
$time_close = DateTime::createFromFormat($format, $req->request->get('time_close'));
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$obj->setName($req->request->get('name'))
|
||||||
|
->setAddress($req->request->get('address'))
|
||||||
|
->setContactNumbers($req->request->get('contact_nums'))
|
||||||
|
->setTimeOpen($time_open)
|
||||||
|
->setTimeClose($time_close)
|
||||||
|
->setCoordinates($point);
|
||||||
|
}
|
||||||
|
|
||||||
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('outlet.add', null, 'No access.');
|
$this->denyAccessUnlessGranted('outlet.add', null, 'No access.');
|
||||||
|
|
@ -150,24 +158,7 @@ class OutletController extends BaseController
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$obj = new Outlet();
|
$obj = new Outlet();
|
||||||
|
|
||||||
// coordinates
|
$this->setObject($obj, $req);
|
||||||
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
|
|
||||||
|
|
||||||
// times
|
|
||||||
$format = 'h:i A';
|
|
||||||
$time_open = DateTime::createFromFormat($format, $req->request->get('time_open'));
|
|
||||||
$time_close = DateTime::createFromFormat($format, $req->request->get('time_close'));
|
|
||||||
|
|
||||||
error_log(print_r($time_open, true));
|
|
||||||
error_log(print_r(DateTime::getLastErrors(), true));
|
|
||||||
|
|
||||||
// set and save values
|
|
||||||
$obj->setName($req->request->get('name'))
|
|
||||||
->setAddress($req->request->get('address'))
|
|
||||||
->setContactNumbers($req->request->get('contact_nums'))
|
|
||||||
->setTimeOpen($time_open)
|
|
||||||
->setTimeClose($time_close)
|
|
||||||
->setCoordinates($point);
|
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
$errors = $validator->validate($obj);
|
$errors = $validator->validate($obj);
|
||||||
|
|
@ -187,16 +178,16 @@ class OutletController extends BaseController
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'errors' => $error_array
|
'errors' => $error_array
|
||||||
], 422);
|
], 422);
|
||||||
} else {
|
}
|
||||||
// validated! save the entity
|
|
||||||
$em->persist($obj);
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
// return successful response
|
// validated! save the entity
|
||||||
return $this->json([
|
$em->persist($obj);
|
||||||
'success' => 'Changes have been saved!'
|
$em->flush();
|
||||||
]);
|
|
||||||
}
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateForm($id)
|
public function updateForm($id)
|
||||||
|
|
@ -207,14 +198,14 @@ class OutletController extends BaseController
|
||||||
|
|
||||||
// get row data
|
// get row data
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$row = $em->getRepository(Outlet::class)->find($id);
|
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
// make sure this row exists
|
// make sure this row exists
|
||||||
if (empty($row))
|
if (empty($obj))
|
||||||
throw $this->createNotFoundException('The item does not exist');
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
$params['row'] = $row;
|
$params['obj'] = $obj;
|
||||||
$params['values'] = [];
|
$params['mode'] = 'update';
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->render('outlet/form.html.twig', $params);
|
return $this->render('outlet/form.html.twig', $params);
|
||||||
|
|
@ -224,38 +215,18 @@ class OutletController extends BaseController
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('outlet.update', null, 'No access.');
|
$this->denyAccessUnlessGranted('outlet.update', null, 'No access.');
|
||||||
|
|
||||||
// get row data
|
// get object data
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$row = $em->getRepository(Outlet::class)->find($id);
|
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
// make sure this row exists
|
// make sure this object exists
|
||||||
if (empty($row))
|
if (empty($obj))
|
||||||
throw $this->createNotFoundException('The item does not exist');
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
// set and save values
|
$this->setObject($obj, $req);
|
||||||
$row->setOutletname($req->request->get('outletname'))
|
|
||||||
->setFirstName($req->request->get('first_name'))
|
|
||||||
->setLastName($req->request->get('last_name'))
|
|
||||||
->setEmail($req->request->get('email'))
|
|
||||||
->setContactNumber($req->request->get('contact_no'))
|
|
||||||
->setEnabled($req->request->get('enabled') ? true : false)
|
|
||||||
->clearRoles();
|
|
||||||
|
|
||||||
// set roles
|
|
||||||
$roles = $req->request->get('roles');
|
|
||||||
|
|
||||||
if (!empty($roles)) {
|
|
||||||
foreach ($roles as $role_id) {
|
|
||||||
// check if role exists
|
|
||||||
$role = $em->getRepository(Role::class)->find($role_id);
|
|
||||||
|
|
||||||
if (!empty($role))
|
|
||||||
$row->addRole($role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
$errors = $validator->validate($row);
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
// initialize error list
|
// initialize error list
|
||||||
$error_array = [];
|
$error_array = [];
|
||||||
|
|
@ -265,24 +236,6 @@ class OutletController extends BaseController
|
||||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get password inputs
|
|
||||||
$password = $req->request->get('password');
|
|
||||||
$confirm_password = $req->request->get('confirm_password');
|
|
||||||
|
|
||||||
// custom validation for password fields
|
|
||||||
if ($password || $confirm_password) {
|
|
||||||
if ($password != $confirm_password) {
|
|
||||||
$error_array['confirm_password'] = 'Passwords do not match.';
|
|
||||||
} else {
|
|
||||||
// encode password
|
|
||||||
$enc = $ef->getEncoder($row);
|
|
||||||
$encoded_password = $enc->encodePassword($req->request->get('password'), $row->getSalt());
|
|
||||||
|
|
||||||
// set password
|
|
||||||
$row->setPassword($encoded_password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
|
|
@ -290,15 +243,15 @@ class OutletController extends BaseController
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'errors' => $error_array
|
'errors' => $error_array
|
||||||
], 422);
|
], 422);
|
||||||
} else {
|
}
|
||||||
// validated! save the entity
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
// return successful response
|
// validated! save the entity
|
||||||
return $this->json([
|
$em->flush();
|
||||||
'success' => 'Changes have been saved!'
|
|
||||||
]);
|
// return successful response
|
||||||
}
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
|
|
@ -307,15 +260,15 @@ class OutletController extends BaseController
|
||||||
|
|
||||||
$params = $this->initParameters('outlet_list');
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
// get row data
|
// get objext data
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$row = $em->getRepository(Outlet::class)->find($id);
|
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
if (empty($row))
|
if (empty($obj))
|
||||||
throw $this->createNotFoundException('The item does not exist');
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
// delete this row
|
// delete this object
|
||||||
$em->remove($row);
|
$em->remove($obj);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
// response
|
// response
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@
|
||||||
<label for="contact_nums" data-field="contact_nums">
|
<label for="contact_nums" data-field="contact_nums">
|
||||||
Contact Numbers
|
Contact Numbers
|
||||||
</label>
|
</label>
|
||||||
<textarea class="form-control m-input" id="contact_nums" rows="3" name="contact_nums">{{ obj.getAddress }}</textarea>
|
<textarea class="form-control m-input" id="contact_nums" rows="3" name="contact_nums">{{ obj.getContactNumbers }}</textarea>
|
||||||
<div class="form-control-feedback hide" data-field="contact_nums"></div>
|
<div class="form-control-feedback hide" data-field="contact_nums"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -69,7 +69,7 @@
|
||||||
Time Open
|
Time Open
|
||||||
</label>
|
</label>
|
||||||
<div class="input-group timepicker">
|
<div class="input-group timepicker">
|
||||||
<input id="timepicker_open" type="text" name="time_open" class="form-control m-input" readonly placeholder="Select time" type="text"/>
|
<input id="timepicker_open" type="text" name="time_open" class="form-control m-input" readonly placeholder="Select time" type="text" value="{{ obj.getTimeOpen.format('h:i A') }}" />
|
||||||
<span class="input-group-addon">
|
<span class="input-group-addon">
|
||||||
<i class="la la-clock-o"></i>
|
<i class="la la-clock-o"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -81,7 +81,7 @@
|
||||||
Time Close
|
Time Close
|
||||||
</label>
|
</label>
|
||||||
<div class="input-group timepicker">
|
<div class="input-group timepicker">
|
||||||
<input id="timepicker_close" type="text" name="time_close" class="form-control m-input" readonly placeholder="Select time" type="text"/>
|
<input id="timepicker_close" type="text" name="time_close" class="form-control m-input" readonly placeholder="Select time" type="text" value="{{ obj.getTimeClose.format('h:i A') }}" />
|
||||||
<span class="input-group-addon">
|
<span class="input-group-addon">
|
||||||
<i class="la la-clock-o"></i>
|
<i class="la la-clock-o"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -192,16 +192,16 @@ $("#m_gmap_address").keypress(function(e) {
|
||||||
|
|
||||||
// END google maps stuff
|
// END google maps stuff
|
||||||
|
|
||||||
// timepickers
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
// timepickers
|
||||||
$('#timepicker_open, #timepicker_close').timepicker();
|
$('#timepicker_open, #timepicker_close').timepicker();
|
||||||
/*
|
|
||||||
minuteStep: 15,
|
// check if we need to set map
|
||||||
showSeconds: false,
|
{% if mode == 'update' %}
|
||||||
showMeridian: false,
|
var latlng = new google.maps.LatLng({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }});
|
||||||
snapToStep: true
|
selectPoint(map, latlng);
|
||||||
});
|
{% endif %}
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
<a href="{{ url('outlet_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
<a href="{{ url('outlet_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
<span>
|
<span>
|
||||||
<i class="la la-user"></i>
|
<i class="fa fa-building"></i>
|
||||||
<span>New Outlet</span>
|
<span>New Outlet</span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
@ -81,39 +81,24 @@
|
||||||
width: 30
|
width: 30
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'username',
|
field: 'name',
|
||||||
title: 'Outletname'
|
title: 'Name'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'first_name',
|
field: 'address',
|
||||||
title: 'First Name'
|
title: 'Address'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'last_name',
|
field: 'contact_nums',
|
||||||
title: 'Last Name'
|
title: 'Contact Numbers'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'email',
|
field: 'time_open',
|
||||||
title: 'E-mail'
|
title: 'Time Open'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'contact_num',
|
field: 'time_close',
|
||||||
title: 'Contact No.'
|
title: 'Time Close'
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'enabled',
|
|
||||||
title: 'Status',
|
|
||||||
template: function (row, index, datatable) {
|
|
||||||
var tag = '';
|
|
||||||
|
|
||||||
if (row.enabled === true) {
|
|
||||||
tag = '<span class="m-badge m-badge--success m-badge--wide">Enabled</span>';
|
|
||||||
} else {
|
|
||||||
tag = '<span class="m-badge m-badge--danger m-badge--wide">Disabled</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Actions',
|
field: 'Actions',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue