attributes->get('opcode'); $online_operators = get_online_operators(); foreach ($online_operators as $item) { if ($opcode == $item['code']) { $is_online = true; break; } } $callback = $request->query->get('callback'); return $this->prepareResponse($is_online, $callback); } /** * Returns true or false of whether any operators is online or not. * * @param Request $request * @return Response Rendered page content */ public function hasOnlineOperatorsAction(Request $request) { $is_online = has_online_operators(); $callback = $request->query->get('callback'); return $this->prepareResponse($is_online, $callback); } /** * Returns true or false of whether any operators in specificed group is online or not. * * @param Request $request * @return Response Rendered page content */ public function isOperatorGroupOnlineAction(Request $request) { $is_online = false; $group_id = $request->attributes->get('group_id'); if (Settings::get('enablegroups') == '1') { $is_online = has_online_operators($group_id); } $callback = $request->query->get('callback'); return $this->prepareResponse($is_online, $callback); } /** * Returns prepared response: JSONP or plain text. * * @param Boolean $is_online * @param String $callback * @return Response Rendered page content */ private function prepareResponse($is_online, $callback) { $response = NULL; if ( empty($callback) ) { $response = new Response( $is_online ? 'true' : 'false' ); $response->headers->set('Access-Control-Allow-Origin', '*'); } else { $response = new JsonResponse($is_online); $response->setCallback($callback); } return $response; } }