function main() { // Check whether this device needs to be redirected somewhere $dev = Device::fromDatabaseByIpAddress($_SERVER['REMOTE_ADDR']); if ($content = getContentForRedirect($dev, 0)) { $output = new JsonOutput(); $output->setContent($content); $output->output(); exit; } $td_code = gfGetVar('td_code', ''); $lastTicket = gfGetVar('lastTicket', 'A000'); $content = null; $startTime = time(); while (time() - $startTime < 120) { sleep(1); // Check every second $currentState = DisplayMain::fromDatabaseCompleteList($td_code); if (count($currentState) == 0) { continue; } if ($lastTicket != $currentState[0]->getTicket()) { // Something changed, compute new tickets $newTickets = array($currentState[0]); $i = 1; while ($i < count($currentState) && $i < 8 && $lastTicket != $currentState[$i]->getTicket()) { $newTickets[] = $currentState[$i]; $i++; } $content = array('status' => 'changed', 'count' => count($newTickets), 'entries' => $newTickets); break; } unset($currentState); } // End while if (!$content) { // Polling wait expired $content = array('status' => 'unchanged'); } $output = new JsonOutput(); $output->setContent($content); $output->output(); }
public static function addRecord($ticket) { $entry = DisplayMain::newRecord(); list($min, $max) = self::getMinMaxId(); $entry->dm_id = $max + 1; $entry->setTicket($ticket); $desk = $ticket->getDeskNumber(); $entry->setDesk($desk); $entry->save(); // Delete an old record? if ($max - $min == 99) { $old = self::fromDatabaseById($min); $old->delete(); } }
public static function serveNextTicket($topicalDomains, $op_code, $desk_number) { if (!$topicalDomains) { throw new Exception(__METHOD__ . " Provided empty topicalDomains array"); } $topicalDomains = (array) $topicalDomains; $desk_number = (int) $desk_number; $conn = Database::getConnection(); $topicalDomains = array_map('strtoupper', $topicalDomains); $topicalDomains = array_map(array($conn, 'quote'), $topicalDomains); $topicalDomains = implode(",", $topicalDomains); $row = self::getNextTicket($topicalDomains); if (!$row) { global $gvCallOtherTdWhenEmpty; if (!$gvCallOtherTdWhenEmpty) { // No ticket to be served return null; } // Try again with all topical domains $row = self::getNextTicket(false); if (!$row) { // No ticket at all in the queue return null; } } $ticket = self::newFromDatabaseRow($row, 'ticket_in'); $ticket->decrementNoticeCounter(); self::sendNotices(); $ticket->sendYourTurn(); $ticket->moveToNextTable($op_code, $desk_number); $ticket->save(); // Add ticket to display_main table DisplayMain::addRecord($ticket); return $ticket; }