122 lines
3.4 KiB
PHP
122 lines
3.4 KiB
PHP
<?php
|
|
|
|
class Citycom_OanApiHelper {
|
|
private $log;
|
|
private $api;
|
|
|
|
public function __construct(Citycom_OanApiClient $apiClient) {
|
|
$this->api = $apiClient;
|
|
}
|
|
|
|
public function findOrCreateProduct($specs = []) {
|
|
if(!array_key_exists("up", $specs) || !array_key_exists("down", $specs) || !is_numeric($specs["up"]) || !is_numeric($specs["down"])) {
|
|
return false;
|
|
}
|
|
|
|
$up = $specs["up"];
|
|
$down = $specs["down"];
|
|
|
|
$search_name = false;
|
|
if(array_key_exists("name", $specs) && $specs["name"]) {
|
|
$search_name = $specs["name"];
|
|
}
|
|
|
|
$products = $this->api->getProducts();
|
|
foreach($products as $product) {
|
|
if($up == $product->bb_up && $down == $product->bb_down) {
|
|
if($search_name) {
|
|
if($product->name == $search_name) {
|
|
return $product->id;
|
|
}
|
|
} else {
|
|
return $product->id;
|
|
}
|
|
}
|
|
}
|
|
|
|
// not found, so create new product
|
|
|
|
$name = "xinon_tt_{$down}_{$up}";
|
|
if(array_key_exists("name", $specs)) {
|
|
$name = $specs["name"];
|
|
}
|
|
|
|
$product_id = $this->api->createProduct([
|
|
"name" => $name,
|
|
"bb_down" => $down,
|
|
"bb_up" => $up
|
|
]);
|
|
|
|
if(!$product_id) {
|
|
return false;
|
|
}
|
|
|
|
return $product_id;
|
|
}
|
|
|
|
public function orderServices($preorder, $sublocation_id, $data) {
|
|
if(!is_numeric($sublocation_id) || !$sublocation_id) {
|
|
return false;
|
|
}
|
|
|
|
if(!array_key_exists("up", $data) || !array_key_exists("down", $data) || !is_numeric($data["up"]) || !is_numeric($data["down"])) {
|
|
return false;
|
|
}
|
|
|
|
if(!array_key_exists("services", $data) || is_array($data["services"]) || !count($data["services"])) {
|
|
return false;
|
|
}
|
|
|
|
$up = $data["up"];
|
|
$down = $data["down"];
|
|
$product_name = $data["product_name"];
|
|
$execution_date = $data["execution_date"];
|
|
$services = $data["services"];
|
|
|
|
if(!$execution_date) {
|
|
$execution_date = date("Y-m-d");
|
|
}
|
|
|
|
|
|
$product_data = [
|
|
"bb_up" => $up,
|
|
"bb_down" => $down,
|
|
"name" => $product_name
|
|
];
|
|
|
|
// find or craete product
|
|
$product_id = $this->findOrCreateProduct($product_data);
|
|
if(!$product_id) {
|
|
$this->log->debug(__METHOD__.": no citycom product for query ".print_r($product_data, true));
|
|
return false;
|
|
}
|
|
|
|
// order all services and save ctags
|
|
$cc_service_types = $this->api->getServices();
|
|
|
|
$new_services = [];
|
|
foreach($cc_service_types as $stype) {
|
|
$service_data = [
|
|
"service_type" => $stype->id,
|
|
"product" => $product_id,
|
|
"billing_date" => $execution_date,
|
|
"ctag"
|
|
];
|
|
$new_service = $this->api->createService($sublocation_id, $service_data);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
public static function citycomIdToHausnummerExtref($id) {
|
|
if(!$id) return false;
|
|
return "citycom-$id";
|
|
}
|
|
|
|
public static function hausnummerExtrefToCitycomId($extref) {
|
|
if(!$extref) return false;
|
|
return str_replace("citycom-", "", $extref);
|
|
}
|
|
} |