$item = new Item(); $itemid = $app->request->post('itemid'); $item = $item->getItem($itemid); $item = json_decode($item); //check that item exists// if ($item->success) { $ticket = new Ticket(); $item = $item->item; //get all the tickets for the event and perform messy json conversions -_- // $ticketDecode = json_decode($ticket->getTickets($item->eventid), true); $tickets = $ticketDecode['tickets']; $event = new Event(); //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 {