/**
  * Set the access token.
  *
  * @param string The access token
  */
 private function _setAccessToken($token)
 {
     Session::set('access_token', $token);
     $this->_client->setAccessToken($token);
 }
// GrandTraining autoloader
require PATH_LIBRARIES . 'slaymaster3000/airbase-php/vendor/autoload.php';
// AirBase autoloader
use AirBase\AirBase;
use AirBase\Session;
use AirBase\Bootstrap;
use AirBase\PageNotFoundException;
use AirBase\NotLoggedInException;
use AirBase\NotLoggedOutException;
// init the lib library
AirBase::init();
AirBase::setIsLoggedInFunction(function () {
    return Session::get('user_id') > 0;
});
try {
    Session::start();
    // start a session
    $bootstrap = new Bootstrap(NAMESPACE_CONTROLLERS, PATH_CONTROLLERS, 'url');
    // process the request
} catch (PageNotFoundException $e) {
    require PATH_ERROR_PAGES . '404.php';
    exit;
} catch (NotLoggedInException $e) {
    header('location: ' . URL_LOGIN);
    // by default, redirect the user to the login page
    exit;
} catch (NotLoggedOutException $e) {
    header('location: ' . URL);
    // by default, redirect the user to the home page
    exit;
} catch (PDOException $e) {
 /**
  * Return's the courseid posted to the page.
  * If there is no posted courseid, it is pulled from the session data if avaliable,
  * otherwise false is returned.
  * @return Ambigous <boolean, integer>
  */
 private function _getCourseId()
 {
     $courseid = false;
     if (isset($_POST['course'])) {
         $courseid = $_POST['course'];
         Session::set('bookcourse_courseid', $courseid);
     } else {
         $courseid = Session::get('bookcourse_courseid');
     }
     return $courseid;
 }
 public function calculateDatesCosts()
 {
     $bookings_attendees = Session::get('bookings_attendees');
     if ($bookings_attendees === false) {
         return array();
         // no attendees booked
     }
     // split the attendees into groups based on the date they booked
     $dates = array();
     foreach ($bookings_attendees as &$attendee) {
         if (!array_key_exists($attendee['date'], $dates)) {
             $dates[$attendee['date']] = array();
         }
         $dates[$attendee['date']][] = $attendee;
     }
     $datescosts = array();
     // to return
     // go through each group (the dates)
     foreach ($dates as $date => &$attendees) {
         $datescosts[$date] = array('subtotal' => 0, 'discount' => 0, 'total' => 0);
         // init this date's cost
         $daycounts = array();
         // go through each group of attendees
         foreach ($attendees as $key => &$attendee) {
             $daycounts[$key] = self::countDaysBitwise($attendee['day']);
             $datescosts[$date]['subtotal'] += $attendee['cost'];
         }
         // reverse sort for incase days are not equal for all attendees
         rsort($daycounts);
         // add discount for multiple days booked for attendees beound the first
         foreach ($daycounts as $key => $days) {
             if ($key == 0) {
                 continue;
             }
             // no discount for frist attendee
             if ($days >= 5) {
                 $datescosts[$date]['discount'] += 50;
             } else {
                 if ($days >= 4) {
                     $datescosts[$date]['discount'] += 40;
                 } else {
                     if ($days >= 3) {
                         $datescosts[$date]['discount'] += 30;
                     }
                 }
             }
         }
         // calculate and set the total
         $datescosts[$date]['total'] = $datescosts[$date]['subtotal'] - $datescosts[$date]['discount'];
     }
     return $datescosts;
 }