function getResponse() { global $RESPONSE, $SESSION; if (!isset($_POST['sessionID'])) { $RESPONSE = 'missing session ID'; return; } try { $SESSION = Session::fromSessionID($_POST['sessionID']); } catch (DoesNotExistException $e) { $RESPONSE = 'invalid session ID'; return; } switch ($SESSION->getStatus()) { case Session::awaiting_user_input: processInput(); break; case Session::group_request_pending: // assuming a request is pending in the queue, has it expired? if ($request = GroupRequestQueue::retrieveRequest($SESSION)) { if ($request->expired()) { // okay, we're done with this request // delete it from the database GroupRequestQueue::deleteRequests(array($request)); // $RESPONSE = 'no partner found! exiting. (TODO: exit trail)'; //TODO: exit trail $SESSION->startExitTrail(); startStep(); return; } } // nothing to do, except wait, because if a suitable partner comes along, the request pending status will be changed $RESPONSE = array('action' => 'wait'); // TODO: countdown? break; case Session::group_request_fulfilled: startStep(); break; case Session::finished_step: if (readyToMoveOn()) { executeGroupCallbacks(); advanceStep(); } else { /* * readyToMoveOn sets the RESPONSE to the HTML of the waiting file. * But because their status was already finished_step, * we can assume that the waiting screen has already been loaded. * So we just tell them to wait (overriding the response). */ // $RESPONSE = array('action' => 'wait'); } break; case Session::callback_done: advanceStep(); break; case Session::finished: case Session::terminated: $RESPONSE = 'session ended'; break; default: throw new Exception('unknown session status'); break; } }