added api for officecenter tvs

This commit is contained in:
2025-09-18 11:03:05 +02:00
parent 952dddef7e
commit 7c46bafe4b

View File

@@ -2,8 +2,17 @@
class CpeprovisioningController extends mfBaseController
{
protected function init()
{
protected function init() {
if (defined('TT_CPE_PROV_ALLOW_COUNTS_IP') &&
in_array($_SERVER['REMOTE_ADDR'], TT_CPE_PROV_ALLOW_COUNTS_IP) &&
!mfLoginController::isLoggedIn()) {
if ($this->action !== 'CountOpenProvisionings') {
http_response_code(403);
die('Forbidden');
}
return;
}
$this->needlogin = true;
$this->me = new User();
$this->me->loadMe();
@@ -583,5 +592,49 @@ class CpeprovisioningController extends mfBaseController
die();
}
protected function countOpenProvisioningsAction() {
$r = $this->request;
$filter = $this->getPreparedFilter($r->filter ?? []);
$filter['routerconfig_finished'] = 0; // only open ones
$orders = OrderModel::search($filter);
$orderproductsprefetch = OrderProductModel::precache();
$openCount = 0;
foreach ($orders as $order) {
if ($filter["hide_delayed_finish"] && $order->finish_after) {
if ($order->finish_after > date("U") + (31 * 86400)) {
continue;
}
}
if (isset($orderproductsprefetch['terminations'][$order->id]) && is_array($orderproductsprefetch['terminations'][$order->id]) && count($orderproductsprefetch['terminations'][$order->id])) {
if (!$order->cpeprovisioning_enabled && $orderproductsprefetch['terminations'][$order->id][0]['statuscode'] < TT_TERMSTATUS_CONNECTED) {
continue;
}
}
if (array_key_exists($order->id, $orderproductsprefetch)) {
foreach ($orderproductsprefetch[$order->id] as $orderproduct) {
if (!$orderproduct || !is_array($orderproduct)) continue;
if ($orderproduct['routerconfig_finished'] == 1) {
continue;
}
$productattributes = $orderproduct['attributes'];
if (is_array($productattributes) && count($productattributes)) {
if (array_key_exists("bras_type", $productattributes) && $productattributes) {
$openCount++;
}
}
}
}
}
self::returnJson(['open_count' => $openCount]);
}
}