* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBAjax'); /** * Simple AJAX Caller: EventObserver * * Poll site events and such. * * @version 0.1.0 * @package WB * @subpackage base */ class WBAjax_EventObserver extends WBAjax { /** * second construcotr * * Called by constructer of super class. * * @see include/WB/WBAjax#init() */ protected function init() { } /** * poll site events * * Check whether there are any queued events and report them * * @return string comment list HTML */ protected function poll() { $cnt = intval($this->req->get('count', 0)); $data = array( 'timestamp' => time(), 'count' => $cnt, 'delay' => 100 ); // set dynamic delay switch ($cnt) { case 10: case 9: case 8: case 7: case 6: $data['delay'] = 30; break; case 5: case 4: case 3: case 2: $data['delay'] = 20; break; case 1: case 0: $data['delay'] = 10; break; default: if (20 > $cnt) { $data['dalay'] = 50; } break; } return json_encode($data); } }