/**
  * @param $user_id
  * @param $event_id
  * @param $result
  * @param $errors
  */
 public static function validateParticipantEvent($user_id, $event_id, &$result, &$errors)
 {
     $intEventCount = EventRead::validateEvent($event_id);
     if ($intEventCount > 0) {
         $intValidate = self::validateUser($user_id, $event_id);
         // Validate is user participant before
         switch ($intValidate) {
             // Validated
             case 1:
                 $result = "Success";
                 return 1;
                 // Duplicated
             // Duplicated
             case 2:
                 $result = "Duplicate";
                 $errors = "Duplicate";
                 return 2;
                 // Errors
             // Errors
             case 3:
                 $result = "Error Occurs";
                 $errors = "Error Occurs";
                 return 3;
         }
     } else {
         $result = "Invalid Event";
         $errors = "Invalid Event";
     }
 }
 public function getEventWinners($intEventId)
 {
     if (empty($intEventId)) {
         $intEventId = 1;
     }
     $intEventId = (int) $intEventId;
     //Get all partipant from Event
     $arrParticipants = EventParticipantRead::getParticipantUser($intEventId);
     $eventData = EventRead::getEventDetail($intEventId)[0];
     $intWinnerAmounts = $eventData['total_winner'];
     $arrWinners = self::getRandomWinners($intWinnerAmounts, $arrParticipants);
     // Get Voucher Public key
     $strPublicKey = Event::genPublicKey();
     // Voucher will be created for the winner
     foreach ($arrWinners as $winnerId) {
         $arrVoucherData = array();
         $arrUserVoucher = array();
         // Create voucher
         // Set voucher expired date with the Event Set duration
         $arrVoucherData['event_id'] = $intEventId;
         $arrVoucherData['user_id'] = $winnerId;
         $arrVoucherData['public_key'] = $strPublicKey;
         $arrVoucherData['expired_at'] = self::getExpiredDate($eventData['redeem_duration']);
         // Create voucher with all the detail
         $intVoucherId = VoucherCreate::createVouchers($arrVoucherData);
         // Insert Log into User Voucher table for quick references (voucher id, user_id,created_date
         $arrUserVoucher['user_id'] = $winnerId;
         $arrUserVoucher['voucher_id'] = $intVoucherId;
         UserVoucherCreate::insertUserVoucher($arrUserVoucher);
         // Reset Count for user Participant count to 0
         UserParticipantManage::resetCount($winnerId);
     }
 }
Example #3
0
 public function getNextEvent(Request $request)
 {
     $errors = "";
     $status_code = 200;
     $status = true;
     $result = "";
     $public_access_key = $request->query('api_key');
     // Get android callback
     $android_callback = $request->query('caller');
     // If the Api Key is valid
     if (UtilityController::validateApiKey($public_access_key)) {
         $result = EventRead::getNextEvent();
     } else {
         // Access Denied detected
         $errors = "Access Denied";
         $status_code = HttpRequest::$ACCESS_DENIED_CODE;
         $status = false;
     }
     $arrResponse = array('api_ver' => self::$API_VERSION, 'caller' => $android_callback, 'error' => $errors, 'status_code' => $status_code, 'status' => $status, 'result' => $result);
     return $arrResponse;
 }