resq/src/Controller/CustomerAppAPI/ScheduleController.php

61 lines
2 KiB
PHP

<?php
namespace App\Controller\CustomerAppAPI;
use Symfony\Component\HttpFoundation\Request;
use Catalyst\ApiBundle\Component\Response as ApiResponse;
use DateTime;
class ScheduleController extends ApiController
{
public function scheduleOptionStatus(Request $req)
{
// validate params
$validity = $this->validateRequest($req);
if (!$validity['is_valid']) {
return new ApiResponse(false, $validity['error']);
}
$schedule_choice = true;
// remove the time check after ECQ. This will then always return true
// get current time
$current_datetime = new DateTime();
//$current_datetime = DateTime::createFromFormat('Y-m-d H:i', '2020-04-30 17:01');
// get the hour
$hour = $current_datetime->format('G');
// commenting out the time check since we can now book 24/7
// this will get uncommented out if and when ECQ will kick in
//if (($hour < 8) || ($hour > 16))
// $schedule_choice = false;
// add checking if customer has a pre-registered hub
$cust = $this->session->getCustomer();
if ($cust == null) {
return new ApiResponse(false, 'No customer information found.');
}
// check if customer has customer tag promo
if (($cust->getCustomerTag('TAG_CAR_CLUB_OFFICER_PROMO')) ||
($cust->getCustomerTag('TAG_CAR_CLUB_MEMBER_PROMO'))
) {
// if has customer tag, customer has not availed of promo, get the hub where customer is pre-registered
$car_club_hub = $cust->getCarClubCustomerHub();
if ($car_club_hub != null) {
$schedule_choice = false;
}
}
// schedule_choice will always be true aka customer can opt to
// Book Now or Schedule Order EXCEPT if customer has customer tag promo
// or ECQ comes back
// response
return new ApiResponse(true, '', [
'display_schedule_choice' => $schedule_choice,
]);
}
}