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); } }
private static function validateUser($user_id, $event_id) { $intCountParticipant = EventParticipantRead::validateUser($user_id, $event_id); // Do not found user from this event. if ($intCountParticipant == 0) { return 1; } else { if ($intCountParticipant > 0) { return 2; } else { return 3; } } }