public function responseInvitation()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idUser = Generic::mustCheck($_GET['id_user'], Keys::$ERR_NOT_FOUND_ID_USER);
     $idTracker = Generic::mustCheck($_GET['id_tracker'], Keys::$ERR_NOT_FOUND_ID_TRACKER);
     $response = Generic::mustCheck($_GET['response'], Keys::$ERR_TRACKER_REQUIRED_RESPONSE);
     $tracker = new TrackerRequestModel();
     $tracker->getByID($idTracker);
     $idOrder = $tracker->id_reference;
     $order = new MasterOrderModel();
     //cek apakah merespon invitation yang di tujukan kepada dia
     //        if ($tracker->id_to != $idUser)
     //            Generic::errorMsg("This is not your Request");
     if (Util::isTrackerAnswered($tracker)) {
         Generic::errorMsg(Keys::$ERR_TRACKER_RESPONDED);
     }
     //cek apakah request ini canceled
     if (Util::isTrackerCanceled($tracker)) {
         $tracker->status = Keys::$NO;
         $tracker->answered = Keys::$YES;
         $tracker->save();
         Generic::errorMsg(Keys::$ERR_TRACKER_CANCELED);
     }
     $tracker->answered = Keys::$YES;
     $tracker->save();
     if ($response == Keys::$YES) {
         Util::acceptInvitation($idOrder, $idUser);
     } else {
         Util::rejectInvitation($idOrder, $idUser);
     }
 }
 public static function pushResponseJoinTable($trackerModel, $response)
 {
     if (!$trackerModel instanceof TrackerRequestModel) {
         return;
     }
     $order = new MasterOrderModel();
     $order->getByID($trackerModel->id_reference);
     $resto = new MasterRestaurantModel();
     $resto->getByID($order->id_restaurant);
     $table = new MasterTableModel();
     $table->getByID($order->id_table);
     $pushType = "";
     $title = "Join Table ";
     $message = "Your Request Join Table No. " . $table->table_number . " at Restaurant " . $resto->name . " has been ";
     $idRef = "";
     $refDesc = "";
     $trackerModel->readed = Keys::$YES;
     $trackerModel->answered = Keys::$YES;
     $trackerModel->answer = $response;
     $trackerModel->save();
     switch ($response) {
         case Keys::$YES:
             $pushType = Keys::$typeAcceptJoinTable;
             $title .= "Accepted";
             $message .= "Accepted";
             $idRef = $order->id_restaurant;
             $refDesc = Keys::$TRACKER_REF_DESC_ID_RESTAURANT;
             Util::addGuestInOrder($order->id_order, $trackerModel->id_from);
             break;
         case Keys::$NO:
             $pushType = Keys::$typeRejectJoinTable;
             $title .= "Rejected";
             $message .= "Rejected";
             $idRef = "0";
             $refDesc = Keys::$TRACKER_REF_DESC_NONE;
             break;
     }
     //buat tracker untuk inbox
     $tracker = new TrackerRequestModel();
     $tracker->id_from = $order->id_user;
     $tracker->id_to = $trackerModel->id_from;
     $tracker->id_reference = $idRef;
     $tracker->reference_desc = $refDesc;
     $tracker->type = $pushType;
     $tracker->title = $title;
     $tracker->image = Keys::$EMPTY;
     $tracker->message = $message;
     $tracker->readed = 0;
     $tracker->answered = 0;
     $tracker->canceled = 0;
     $tracker->status = 1;
     $idTracker = $tracker->save();
     if (!$idTracker) {
         Generic::errorMsg(Keys::$ERR_FAILED_CREATE_TRACKER);
     }
     $tracker->getByID($idTracker);
     //push to friend
     //preparation
     $_POST["ids"] = $trackerModel->id_from;
     $_POST["msg"] = $message;
     $_POST["json"] = $idTracker;
     $_POST["type"] = $pushType;
     //        pr($_POST);
     $push = new PushTo();
     $results['push_status'] = $push->usersMR();
     $results['id_tracker'] = strval($idTracker);
     $results['tracker'] = Util::extractModel($tracker);
     Generic::finish($results);
 }
 public function requestRestoPermission($userModel, $tableModel)
 {
     $resto = new MasterRestaurantModel();
     $resto->getByID($tableModel->id_restaurant);
     // persiapan push message
     $msg = $userModel->user_name . " want to open table no. " . $tableModel->table_number;
     $j["user"] = $userModel;
     $j["table"] = $tableModel;
     //simpan di tracker untuk nantinya dilihat di inbox
     $tracker = new TrackerRequestModel();
     $tracker->id_from = $userModel->id_user;
     $tracker->id_to = $tableModel->id_restaurant;
     $tracker->id_reference = $tableModel->id_table;
     $tracker->type = $this->typeRequestOpenTable;
     $tracker->title = "Request Open Table";
     $tracker->message = $msg;
     $tracker->image = "";
     $tracker->readed = 0;
     $tracker->answered = 0;
     $tracker->canceled = 0;
     $tracker->status = 1;
     $tracker->save();
     $this->pushToRestoCashier($tableModel->id_restaurant, $msg, json_encode($j), $this->typeRequestOpenTable);
 }