mirror of
https://github.com/Mibew/mibew-operator-status-plugin.git
synced 2025-01-22 18:10:29 +03:00
parent
e532b91378
commit
8e5d1f6e47
@ -28,6 +28,7 @@ namespace Everyx\Mibew\Plugin\OperatorStatus\Controller;
|
|||||||
use Mibew\Controller\AbstractController;
|
use Mibew\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operator Status actions
|
* Operator Status actions
|
||||||
@ -37,30 +38,58 @@ class OperatorStatusController extends AbstractController
|
|||||||
/**
|
/**
|
||||||
* Returns true or false of whether an operator is online or not.
|
* Returns true or false of whether an operator is online or not.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response Rendered page content
|
* @return Response Rendered page content
|
||||||
*/
|
*/
|
||||||
public function indexAction(Request $request)
|
public function isOperatorOnlineAction(Request $request)
|
||||||
{
|
{
|
||||||
$is_online = "true";
|
$is_online = false;
|
||||||
|
|
||||||
$opcode = $request->attributes->get('opcode');
|
$opcode = $request->attributes->get('opcode');
|
||||||
$online_operators = get_online_operators();
|
$online_operators = get_online_operators();
|
||||||
|
foreach ($online_operators as $item) {
|
||||||
if ( count($online_operators) == 0 ) {
|
if ($opcode == $item['code']) {
|
||||||
$is_online = "false";
|
$is_online = true;
|
||||||
} else if ( !empty($opcode) ) {
|
break;
|
||||||
$is_online = "false";
|
|
||||||
foreach ($online_operators as $item) {
|
|
||||||
if ($item['code'] == $opcode) {
|
|
||||||
$is_online = "true";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new Response($is_online);
|
$callback = $request->query->get('callback');
|
||||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
return $this->prepareResponse($is_online, $callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true or false of whether an operator 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 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;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,6 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi
|
|||||||
*/
|
*/
|
||||||
public static function getVersion()
|
public static function getVersion()
|
||||||
{
|
{
|
||||||
return '0.2.0';
|
return '0.3.0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
README.md
24
README.md
@ -3,8 +3,28 @@ Plugin for Mibew, get statement based on the availability of operators.
|
|||||||
|
|
||||||
# Useage
|
# Useage
|
||||||
|
|
||||||
Request `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>`, your will get `true` when operator
|
1. Get any operators online status:
|
||||||
is online or `false` when operator is offline.
|
|
||||||
|
* request URL:`<MIBEW-BASE-URL>/opstatus`.
|
||||||
|
* return `true` when any operators is online and `false` when not.
|
||||||
|
|
||||||
|
2. Get an operator online status by operator code:
|
||||||
|
|
||||||
|
* Request URL: `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>`.
|
||||||
|
* return `true` when operator is online or `false` when not.
|
||||||
|
|
||||||
|
3. Use callback parameter:
|
||||||
|
|
||||||
|
Just inset `<script>` tag and set `src` to URL above and add `callback` parameter
|
||||||
|
|
||||||
|
* `<MIBEW-BASE-URL>/opstatus?callback=<CALLBACK_FUNCTION>`
|
||||||
|
* `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>?callback=<CALLBACK_FUNCTION>`
|
||||||
|
|
||||||
|
will return bellow and run `CALLBACK_FUNCTION` automatically.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
/**/CALLBACK_FUNCTION(status);
|
||||||
|
```
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
everyx_operator_status:
|
everyx_operator_status_has_online_operators:
|
||||||
|
path: /opstatus
|
||||||
|
defaults:
|
||||||
|
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::hasOnlineOperatorsAction
|
||||||
|
|
||||||
|
everyx_operator_status_is_operator_online:
|
||||||
path: /opstatus/{opcode}
|
path: /opstatus/{opcode}
|
||||||
defaults:
|
defaults:
|
||||||
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction
|
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::isOperatorOnlineAction
|
||||||
|
Loading…
Reference in New Issue
Block a user