Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Mibew/mibew-operator-status-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.0
Choose a base ref
...
head repository: Mibew/mibew-operator-status-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Mar 18, 2017

  1. Add any operators online and JSONP support

    closes #1, closes #2
    everyx committed Mar 18, 2017
    Copy the full SHA
    8e5d1f6 View commit details

Commits on Mar 20, 2017

  1. Change namespace to Mibew

    The repository was transferred to Mibew organization
    faf committed Mar 20, 2017
    Copy the full SHA
    682ac0c View commit details
  2. Merge pull request #5 from Mibew/mibew_transfer

    Change namespace to Mibew
    everyx authored Mar 20, 2017
    Copy the full SHA
    66ee83b View commit details
  3. add gulp support, fix #6

    everyx committed Mar 20, 2017
    Copy the full SHA
    3025f9e View commit details
  4. add build content

    everyx committed Mar 20, 2017
    Copy the full SHA
    5284d7e View commit details

Commits on Mar 21, 2017

  1. Change name for release archives

    faf committed Mar 21, 2017
    Copy the full SHA
    3ddcb22 View commit details
  2. Update installation instructions

    faf authored Mar 21, 2017
    Copy the full SHA
    240cfad View commit details
  3. Unify title in README file

    faf authored Mar 21, 2017
    Copy the full SHA
    15e1850 View commit details

Commits on Mar 22, 2017

  1. Merge pull request #7 from Mibew/release-name

    Change name for release archives
    everyx authored Mar 22, 2017
    Copy the full SHA
    cccbdc3 View commit details

Commits on Mar 25, 2017

  1. add group support and fix #8

    everyx committed Mar 25, 2017
    Copy the full SHA
    0375ef4 View commit details
  2. Copy the full SHA
    ecc4484 View commit details
  3. add group support document

    everyx committed Mar 25, 2017
    Copy the full SHA
    638cfea View commit details

Commits on Mar 29, 2017

  1. Bump version

    faf committed Mar 29, 2017
    Copy the full SHA
    1d9daa2 View commit details
  2. Copy the full SHA
    a8941cf View commit details
  3. Merge pull request #9 from Mibew/fix_settings

    Fix error with missed Settings class
    everyx authored Mar 29, 2017
    Copy the full SHA
    e662cc5 View commit details
  4. Merge pull request #10 from Mibew/0.4.0

    New release
    everyx authored Mar 29, 2017
    Copy the full SHA
    0269150 View commit details

Commits on Mar 30, 2017

  1. Copy the full SHA
    84c94f4 View commit details

Commits on Sep 24, 2018

  1. Fix typo in README

    faf authored Sep 24, 2018
    Copy the full SHA
    13b30db View commit details
  2. Fix typo in README

    faf authored Sep 24, 2018
    Copy the full SHA
    4a0a561 View commit details

Commits on Nov 27, 2018

  1. Copy the full SHA
    47f9184 View commit details

Commits on Jan 29, 2021

  1. Copy the full SHA
    0aa7e62 View commit details
  2. Switch go Gulp 4 for builds

    faf committed Jan 29, 2021
    Copy the full SHA
    7ebb2f8 View commit details
Showing with 181 additions and 64 deletions.
  1. +6 −2 .gitignore
  2. +65 −16 Controller/OperatorStatusController.php
  3. +2 −2 Plugin.php
  4. +40 −5 README.md
  5. +0 −22 build.sh
  6. +0 −15 composer.json
  7. +44 −0 gulpfile.js
  8. +12 −0 package.json
  9. +12 −2 routing.yml
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.zip
*.gz
# Do not index node.js modules that are used for building
node_modules
package-lock.json

# Do not index releases
release
81 changes: 65 additions & 16 deletions Controller/OperatorStatusController.php
Original file line number Diff line number Diff line change
@@ -23,11 +23,13 @@
* SOFTWARE.
*/

namespace Everyx\Mibew\Plugin\OperatorStatus\Controller;
namespace Mibew\Mibew\Plugin\OperatorStatus\Controller;

use Mibew\Settings;
use Mibew\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
* Operator Status actions
@@ -37,30 +39,77 @@ class OperatorStatusController extends AbstractController
/**
* Returns true or false of whether an operator is online or not.
*
* @param Request $request
* @param Request $request
* @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');
$online_operators = get_online_operators();

if ( count($online_operators) == 0 ) {
$is_online = "false";
} else if ( !empty($opcode) ) {
$is_online = "false";
foreach ($online_operators as $item) {
if ($item['code'] == $opcode) {
$is_online = "true";
break;
}
foreach ($online_operators as $item) {
if ($opcode == $item['code']) {
$is_online = true;
break;
}
}

$response = new Response($is_online);
$response->headers->set('Access-Control-Allow-Origin', '*');
$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;
}
}
4 changes: 2 additions & 2 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
* SOFTWARE.
*/

namespace Everyx\Mibew\Plugin\OperatorStatus;
namespace Mibew\Mibew\Plugin\OperatorStatus;

/**
* Main plugin class.
@@ -46,6 +46,6 @@ public function run()
*/
public static function getVersion()
{
return '0.2.0';
return '0.4.0';
}
}
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
# mibew-operator-status-plugin
# Mibew Operator Status plugin
Plugin for Mibew, get statement based on the availability of operators.

# Useage
# Usage

Request `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>`, your will get `true` when operator
is online or `false` when operator is offline.
1. Get any operators online status:

* request URL: `<MIBEW-BASE-URL>/opstatus`.
* return `true` when any operators is online and `false` when not.

2. Get any operators online status in specificed group:

* request URL: `<MIBEW-BASE-URL>/opstatus/group/<GROUP-ID>`.
* return `true` when any operators in this group is online and `false` when not.

3. 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.

4. Use callback parameter:

Just insert `<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

1. Get the archive with the plugin sources from [release page](https://github.com/everyx/mibew-operator-status-plugin/releases):
1. Get the archive with the plugin sources. You can download it from the [official site](https://mibew.org/plugins#mibew-operator-status) or build the plugin from sources.

2. Untar/unzip the plugin's archive.
@@ -33,6 +58,16 @@ plugins:
...
```
# Build from sources
1. Obtain a copy of the repository using `git clone`, download button, or another way.
2. Install [node.js](http://nodejs.org/) and [npm](https://www.npmjs.org/).
3. Install [Gulp](http://gulpjs.com/).
4. Install npm dependencies using `npm install`.
5. Run Gulp to build the sources using `gulp default`.
Finally `.tar.gz` and `.zip` archives of the ready-to-use Plugin will be available in release directory.
# License
[MIT](LICENSE)
22 changes: 0 additions & 22 deletions build.sh

This file was deleted.

15 changes: 0 additions & 15 deletions composer.json

This file was deleted.

44 changes: 44 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var eventStream = require('event-stream'),
gulp = require('gulp'),
chmod = require('gulp-chmod'),
zip = require('gulp-zip'),
tar = require('gulp-tar'),
gzip = require('gulp-gzip'),
rename = require('gulp-rename');

gulp.task('prepare-release', function() {
var version = require('./package.json').version;

return eventStream.merge(
getSources()
.pipe(zip('operator-status-plugin-' + version + '.zip')),
getSources()
.pipe(tar('operator-status-plugin-' + version + '.tar'))
.pipe(gzip())
)
.pipe(chmod(0644))
.pipe(gulp.dest('release'));
});

// Builds and packs plugins sources
gulp.task('default', gulp.series('prepare-release'));

/**
* Returns files stream with the plugin sources.
*
* @returns {Object} Stream with VinylFS files.
*/
var getSources = function() {
return gulp.src([
'Controller/*',
'LICENSE',
'Plugin.php',
'README.md',
'routing.yml'
],
{base: './'}
)
.pipe(rename(function(path) {
path.dirname = 'Mibew/Mibew/Plugin/OperatorStatus/' + path.dirname;
}));
}
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.4.0",
"devDependencies": {
"event-stream": "3.3.4",
"gulp": "^4.0.0",
"gulp-chmod": "~3.0.0",
"gulp-gzip": "~1.1.0",
"gulp-rename": "~1.2.2",
"gulp-tar": "~3.1.0",
"gulp-zip": "~3.0.2"
}
}
14 changes: 12 additions & 2 deletions routing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
everyx_operator_status:
mibew_operator_status_has_online_operators:
path: /opstatus
defaults:
_controller: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::hasOnlineOperatorsAction

mibew_operator_status_has_online_group_operators:
path: /opstatus/group/{group_id}
defaults:
_controller: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::isOperatorGroupOnlineAction

mibew_operator_status_is_operator_online:
path: /opstatus/{opcode}
defaults:
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction
_controller: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::isOperatorOnlineAction