public function getParticipants($eventid) { $participant = Participant::where('eventid', $eventid)->get(); if ($participant == null) { $array = array('success' => false, 'message' => 'No participants found'); return json_encode($array); } $array = array('success' => true, 'participant' => $participant); return json_encode($array); }
public function lookupWinner($itemid) { $winner = Winner::where('itemid', $itemid)->first(); if ($winner != null) { $luckyWinner = Participant::where('id', $winner->participantid)->first(); $array = array('success' => true, 'winner' => $luckyWinner); return json_encode($array); } else { $array = array('success' => false, 'message' => "NO WINNER CHOSEN"); return json_encode($array); } }
//get currently logged on host// $userid = $resourceServer->getAccessToken()->getSession()->getOwnerId(); //verify that current host owns the event of the item// if ($event->verifyHost($item->eventid, $userid)) { //pick a random ticket// if (sizeof($tickets) > 0) { $numTix = sizeof($tickets); $luckyNum = mt_rand(0, $numTix); $ticket = $tickets[$luckyNum]; //more messy json conversions...// $lucky = json_decode($winner->pickWinner($itemid, $ticket['participantid'])); $luckyWinner = $lucky->winner; //verify that the item has not been won// if ($luckyWinner != "Winner already chosen") { //get the winner's personal info to pass back with the winning ticket info// $luckyParticipant = Participant::where('id', $luckyWinner->participantid)->first(); $array = array('success' => true, 'ticket' => $ticket, 'participant' => $luckyParticipant); echo json_encode($array); } else { $array = array('success' => false, 'message' => "Winner already chosen"); echo json_encode($array); } } else { $array = array('success' => false, 'message' => "NO TICKETS PURCHASED!!"); echo json_encode($array); } } else { $array = array('success' => false, 'message' => "WRONG HOST"); echo json_encode($array); } } else {