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
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
$query->where('q.outletname LIKE :filter')
|
||||
->orWhere('q.first_name LIKE :filter')
|
||||
->orWhere('q.last_name LIKE :filter')
|
||||
->orWhere('q.email LIKE :filter')
|
||||
->orWhere('q.contact_num LIKE :filter')
|
||||
$query->where('q.name LIKE :filter')
|
||||
->orWhere('q.address LIKE :filter')
|
||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||
}
|
||||
|
||||
|
|
@ -91,12 +88,11 @@ class OutletController extends BaseController
|
|||
foreach ($obj_rows as $orow) {
|
||||
// add row data
|
||||
$row['id'] = $orow->getID();
|
||||
$row['outletname'] = $orow->getName();
|
||||
$row['first_name'] = $orow->getFirstName();
|
||||
$row['last_name'] = $orow->getLastName();
|
||||
$row['email'] = $orow->getEmail();
|
||||
$row['contact_num'] = $orow->getContactNumber();
|
||||
$row['enabled'] = $orow->isEnabled();
|
||||
$row['name'] = $orow->getName();
|
||||
$row['address'] = $orow->getAddress();
|
||||
$row['contact_nums'] = $orow->getContactNumbers();
|
||||
$row['time_open'] = $orow->getTimeOpen()->format('h:i A');
|
||||
$row['time_close'] = $orow->getTimeClose()->format('h:i A');
|
||||
|
||||
|
||||
// add row metadata
|
||||
|
|
@ -105,13 +101,6 @@ class OutletController extends BaseController
|
|||
'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
|
||||
if ($this->isGranted('outlet.update'))
|
||||
$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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('outlet.add', null, 'No access.');
|
||||
|
|
@ -150,24 +158,7 @@ class OutletController extends BaseController
|
|||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = new Outlet();
|
||||
|
||||
// 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'));
|
||||
|
||||
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);
|
||||
$this->setObject($obj, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
|
@ -187,16 +178,16 @@ class OutletController extends BaseController
|
|||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 422);
|
||||
} else {
|
||||
// validated! save the entity
|
||||
$em->persist($obj);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
// validated! save the entity
|
||||
$em->persist($obj);
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateForm($id)
|
||||
|
|
@ -207,14 +198,14 @@ class OutletController extends BaseController
|
|||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = $em->getRepository(Outlet::class)->find($id);
|
||||
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($row))
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
$params['row'] = $row;
|
||||
$params['values'] = [];
|
||||
$params['obj'] = $obj;
|
||||
$params['mode'] = 'update';
|
||||
|
||||
// response
|
||||
return $this->render('outlet/form.html.twig', $params);
|
||||
|
|
@ -224,38 +215,18 @@ class OutletController extends BaseController
|
|||
{
|
||||
$this->denyAccessUnlessGranted('outlet.update', null, 'No access.');
|
||||
|
||||
// get row data
|
||||
// get object data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = $em->getRepository(Outlet::class)->find($id);
|
||||
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($row))
|
||||
// make sure this object exists
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// set and save values
|
||||
$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);
|
||||
}
|
||||
}
|
||||
$this->setObject($obj, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($row);
|
||||
$errors = $validator->validate($obj);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
|
@ -265,24 +236,6 @@ class OutletController extends BaseController
|
|||
$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
|
||||
if (!empty($error_array)) {
|
||||
// return validation failure response
|
||||
|
|
@ -290,15 +243,15 @@ class OutletController extends BaseController
|
|||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 422);
|
||||
} else {
|
||||
// validated! save the entity
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
// validated! save the entity
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
|
|
@ -307,15 +260,15 @@ class OutletController extends BaseController
|
|||
|
||||
$params = $this->initParameters('outlet_list');
|
||||
|
||||
// get row data
|
||||
// get objext data
|
||||
$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');
|
||||
|
||||
// delete this row
|
||||
$em->remove($row);
|
||||
// delete this object
|
||||
$em->remove($obj);
|
||||
$em->flush();
|
||||
|
||||
// response
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
<label for="contact_nums" data-field="contact_nums">
|
||||
Contact Numbers
|
||||
</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>
|
||||
</div>
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
Time Open
|
||||
</label>
|
||||
<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">
|
||||
<i class="la la-clock-o"></i>
|
||||
</span>
|
||||
|
|
@ -81,7 +81,7 @@
|
|||
Time Close
|
||||
</label>
|
||||
<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">
|
||||
<i class="la la-clock-o"></i>
|
||||
</span>
|
||||
|
|
@ -192,16 +192,16 @@ $("#m_gmap_address").keypress(function(e) {
|
|||
|
||||
// END google maps stuff
|
||||
|
||||
// timepickers
|
||||
$(document).ready(function() {
|
||||
// timepickers
|
||||
$('#timepicker_open, #timepicker_close').timepicker();
|
||||
/*
|
||||
minuteStep: 15,
|
||||
showSeconds: false,
|
||||
showMeridian: false,
|
||||
snapToStep: true
|
||||
});
|
||||
*/
|
||||
|
||||
// check if we need to set map
|
||||
{% if mode == 'update' %}
|
||||
var latlng = new google.maps.LatLng({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }});
|
||||
selectPoint(map, latlng);
|
||||
{% endif %}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
<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">
|
||||
<span>
|
||||
<i class="la la-user"></i>
|
||||
<i class="fa fa-building"></i>
|
||||
<span>New Outlet</span>
|
||||
</span>
|
||||
</a>
|
||||
|
|
@ -81,39 +81,24 @@
|
|||
width: 30
|
||||
},
|
||||
{
|
||||
field: 'username',
|
||||
title: 'Outletname'
|
||||
field: 'name',
|
||||
title: 'Name'
|
||||
},
|
||||
{
|
||||
field: 'first_name',
|
||||
title: 'First Name'
|
||||
field: 'address',
|
||||
title: 'Address'
|
||||
},
|
||||
{
|
||||
field: 'last_name',
|
||||
title: 'Last Name'
|
||||
field: 'contact_nums',
|
||||
title: 'Contact Numbers'
|
||||
},
|
||||
{
|
||||
field: 'email',
|
||||
title: 'E-mail'
|
||||
field: 'time_open',
|
||||
title: 'Time Open'
|
||||
},
|
||||
{
|
||||
field: 'contact_num',
|
||||
title: 'Contact No.'
|
||||
},
|
||||
{
|
||||
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: 'time_close',
|
||||
title: 'Time Close'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
|
|
|
|||
Loading…
Reference in a new issue