|
@@ -1,15 +1,16 @@
|
|
|
<?php
|
|
<?php
|
|
|
/**
|
|
/**
|
|
|
- * @author Open Mind
|
|
|
|
|
- * @date 28/03/2018
|
|
|
|
|
- * @time 09:13
|
|
|
|
|
* @param array $array
|
|
* @param array $array
|
|
|
* @param array $keysToExtract
|
|
* @param array $keysToExtract
|
|
|
* @return array
|
|
* @return array
|
|
|
|
|
+ * @author Open Mind
|
|
|
|
|
+ * @date 28/03/2018
|
|
|
|
|
+ * @time 09:13
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
namespace OpenMind\FindBox;
|
|
namespace OpenMind\FindBox;
|
|
|
|
|
|
|
|
|
|
+use Exception;
|
|
|
use OpenMind\System\System;
|
|
use OpenMind\System\System;
|
|
|
|
|
|
|
|
function array_filter_keys(array $array, array $keysToExtract)
|
|
function array_filter_keys(array $array, array $keysToExtract)
|
|
@@ -32,7 +33,7 @@ class FindBoxCoreSystem
|
|
|
* @param int $port
|
|
* @param int $port
|
|
|
* @param string $APIKey
|
|
* @param string $APIKey
|
|
|
* @param string $Password
|
|
* @param string $Password
|
|
|
- * @throws \Exception
|
|
|
|
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public function __construct(string $host, int $port, string $APIKey, string $Password)
|
|
public function __construct(string $host, int $port, string $APIKey, string $Password)
|
|
|
{
|
|
{
|
|
@@ -50,7 +51,7 @@ class FindBoxCoreSystem
|
|
|
$ret = $this->CallAPI($URI, "");
|
|
$ret = $this->CallAPI($URI, "");
|
|
|
|
|
|
|
|
if ($ret['err'] != 0)
|
|
if ($ret['err'] != 0)
|
|
|
- throw new \Exception("Can't connect to FindBox server:<br/><br/>{$ret['value']}");
|
|
|
|
|
|
|
+ throw new Exception("Can't connect to FindBox server:<br/><br/>{$ret['value']}");
|
|
|
|
|
|
|
|
if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
|
|
if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
|
|
|
$details = $ret['value']['value'];
|
|
$details = $ret['value']['value'];
|
|
@@ -194,4 +195,48 @@ class FindBoxCoreSystem
|
|
|
|
|
|
|
|
return $fbOS_Response['value']['value'];
|
|
return $fbOS_Response['value']['value'];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Request all label status to FindBox core.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bool $force true = ask status directly to ESL and not from FindBox Core Cache
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return null|array return array with labelID => status_struct
|
|
|
|
|
+ */
|
|
|
|
|
+ public function GetAllESLStatus(bool $force = false): ?array
|
|
|
|
|
+ {
|
|
|
|
|
+ // Get all offline labels
|
|
|
|
|
+ $URI = '/1.0.0/index.php/smartesl.getstatus/4.0.0/[[],false]';
|
|
|
|
|
+ $ret = $this->CallAPI($URI, "");
|
|
|
|
|
+ if ($ret['err'] != 0)
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
|
|
+ $fbOSResponse = $this->getLabelsFromResponse($ret);
|
|
|
|
|
+ if (!$fbOSResponse) {
|
|
|
|
|
+ $this->log->write($ret['value']['value'], 'd/m/Y H:i:s');
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $labels = $fbOSResponse;
|
|
|
|
|
+
|
|
|
|
|
+ if ($force)
|
|
|
|
|
+ return $labels;
|
|
|
|
|
+
|
|
|
|
|
+ $eslStatus = [];
|
|
|
|
|
+ foreach($labels as $labelID => $status) {
|
|
|
|
|
+ // Get only ONLINE labels
|
|
|
|
|
+ $labelStatus = strtoupper($status['data']['esl_state']);
|
|
|
|
|
+ if (!$force && in_array($labelStatus, ['OFFLINE', 'BLOCKED,FC']))
|
|
|
|
|
+ continue;
|
|
|
|
|
+
|
|
|
|
|
+ // Force get status from label
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.getstatus/4.0.0/[[\"{$labelID}\"],true]";
|
|
|
|
|
+ $fbOSResponse = $this->getLabelsFromResponse($this->CallAPI($URI, ""));
|
|
|
|
|
+ if ($fbOSResponse != null)
|
|
|
|
|
+ $eslStatus[] = $fbOSResponse;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $eslStatus;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|