Add notification number to hub. #552

This commit is contained in:
Korina Cordero 2021-04-23 06:07:21 +00:00
parent 3f2467f8f7
commit f24f3e2bb9
4 changed files with 78 additions and 9 deletions

View file

@ -19,6 +19,7 @@ use Catalyst\MenuBundle\Annotation\Menu;
use App\Service\MapTools;
use App\Service\RiderTracker;
use App\Service\RisingTideGateway;
class HubController extends Controller
{
@ -143,6 +144,8 @@ class HubController extends Controller
$time_open = DateTime::createFromFormat($format, $req->request->get('time_open'));
$time_close = DateTime::createFromFormat($format, $req->request->get('time_close'));
error_log($req->request->get('notif_number'));
// set and save values
$obj->setName($req->request->get('name'))
->setBranch($req->request->get('branch'))
@ -154,7 +157,8 @@ class HubController extends Controller
->setBranchCode($req->request->get('branch_code', ''))
->setStatusOpen($req->request->get('status_open', false))
->setRiderSlots($req->request->get('rider_slots', 0))
->setHubViewFlag($req->request->get('flag_hub_view', false));
->setHubViewFlag($req->request->get('flag_hub_view', false))
->setNotifNumber('63' . $req->request->get('notif_number'));
}
protected function setQueryFilters($datatable, QueryBuilder $query)
@ -166,7 +170,7 @@ class HubController extends Controller
}
}
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, RisingTideGateway $rt)
{
$this->denyAccessUnlessGranted('hub.add', null, 'No access.');
@ -176,14 +180,20 @@ class HubController extends Controller
$em = $this->getDoctrine()->getManager();
$obj = new Hub();
// initialize error list
$error_array = [];
// validate the notification number
$mobile = $req->request->get('notif_number');
$is_valid = $rt->validatePhoneNumber($mobile);
if (!$is_valid)
$error_array['notif_number'] = 'Invalid notification number';
$this->setObject($obj, $req);
// validate
$errors = $validator->validate($obj);
// initialize error list
$error_array = [];
// add errors to list
foreach ($errors as $error) {
$error_array[$error->getPropertyPath()] = $error->getMessage();
@ -231,7 +241,7 @@ class HubController extends Controller
return $this->render('hub/form.html.twig', $params);
}
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id)
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id, RisingTideGateway $rt)
{
$this->denyAccessUnlessGranted('hub.update', null, 'No access.');
@ -243,14 +253,20 @@ class HubController extends Controller
if (empty($obj))
throw $this->createNotFoundException('The item does not exist');
// initialize error list
$error_array = [];
// validate the notification number
$mobile = $req->request->get('notif_number');
$is_valid = $rt->validatePhoneNumber($mobile);
if (!$is_valid)
$error_array['notif_number'] = 'Invalid notification number';
$this->setObject($obj, $req);
// validate
$errors = $validator->validate($obj);
// initialize error list
$error_array = [];
// add errors to list
foreach ($errors as $error) {
$error_array[$error->getPropertyPath()] = $error->getMessage();

View file

@ -68,6 +68,12 @@ class Hub
*/
protected $flag_hub_view;
// notification number to send SMS to if hub doesn't have item
/**
* @ORM\Column(type="string", length=30)
*/
protected $notif_number;
public function __construct()
{
$this->time_open = new DateTime();
@ -76,6 +82,7 @@ class Hub
$this->outlets = new ArrayCollection();
$this->status_open = true;
$this->flag_hub_view = false;
$this->notif_number = '';
}
public function getRiders()
@ -185,5 +192,15 @@ class Hub
return $this->flag_hub_view;
}
public function setNotifNumber($notif_number)
{
$this->notif_number = $notif_number;
return $this;
}
public function getNotifNumber()
{
return $this->notif_number;
}
}

View file

@ -83,4 +83,28 @@ class RisingTideGateway
error_log($result);
}
public function validatePhoneNumber($mobile)
{
// check valid number
$num = trim($mobile);
// should be 10 digits
if (strlen($num) != 10)
return false;
// should start with '9'
if ($num[0] != '9')
return false;
// should be numeric
if (!is_numeric($num))
return false;
// should not be 9900000000
if ($num == '9900000000')
return false;
return true;
}
}

View file

@ -90,6 +90,18 @@
<input type="text" name="branch_code" class="form-control m-input" value="{{ obj.getBranchCode() }}">
<div class="form-control-feedback hide" data-field="branch_code"></div>
</div>
<div class="col-lg-6">
<label for="notif_number" data-field="notif_number">
Notification Number
</label>
<div class="input-group m-input-group">
<span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="notif_number" class="form-control m-input" value="{{ obj.getNotifNumber|default('') }}" data-name="notif_number">
<div class="form-control-feedback hide" data-field="notif_number"></div>
</div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-3">
<label for="rider_slots" data-field="rider_slots">
Number of Riders Per Slot