Workorder mph/improve
This commit is contained in:
@@ -146,10 +146,10 @@ class GenieACS {
|
||||
return self::getParam($device, $param);
|
||||
}
|
||||
|
||||
public function createRemoteUser($deviceId) {
|
||||
$this->log->debug("GenieACS: createRemoteUser called", ['deviceId' => $deviceId]);
|
||||
public function createRemoteUser($deviceId, $forceRecreate = false) {
|
||||
$this->log->debug("GenieACS: createRemoteUser called", ['deviceId' => $deviceId, 'forceRecreate' => $forceRecreate]);
|
||||
$cacheKey = "remote_user_" . $deviceId;
|
||||
if ($cached = $this->getCache($cacheKey)) {
|
||||
if (!$forceRecreate && $cached = $this->getCache($cacheKey)) {
|
||||
$this->log->debug("GenieACS: Using cached credentials");
|
||||
return $cached;
|
||||
}
|
||||
|
||||
@@ -252,4 +252,63 @@ class Helper {
|
||||
|
||||
return array_map(fn($owner) => new Address($owner['id']), $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AddressDB Netzgebiet IDs that a user has access to based on their Network ownership
|
||||
* @param User $user The user to get networks for
|
||||
* @return array Array of addressdb netzgebiet IDs
|
||||
*/
|
||||
public static function getADBNetworksFromUser($user): array {
|
||||
if ($user->isAdmin()) {
|
||||
// Admin has access to all networks
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$sql = "SELECT id FROM Netzgebiet WHERE id IS NOT NULL";
|
||||
$result = $db->query($sql);
|
||||
$netzgebiete = $result ? $result->fetch_all(MYSQLI_ASSOC) : [];
|
||||
return array_column($netzgebiete, 'id');
|
||||
}
|
||||
|
||||
// Get networks where user's address is the owner
|
||||
$networks = NetworkModel::search(['owner_id' => $user->address_id]);
|
||||
|
||||
// Also check user flags for additional networks
|
||||
$flagNetworkIds = json_decode($user->getFlag("workordermph_networks")->value() ?: '[]', true);
|
||||
if (!empty($flagNetworkIds)) {
|
||||
$additionalNetworks = NetworkModel::search(['id' => $flagNetworkIds]);
|
||||
$networks = array_merge($networks, $additionalNetworks);
|
||||
}
|
||||
|
||||
// Extract adb_netzgebiet_id from networks
|
||||
$netzgebietIds = [];
|
||||
foreach ($networks as $network) {
|
||||
if ($network->adb_netzgebiet_id) {
|
||||
$netzgebietIds[] = $network->adb_netzgebiet_id;
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique(array_filter($netzgebietIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get network owners that have WorkorderMph entries (based on Netzgebiet)
|
||||
* @return array Array of Address objects representing network owners
|
||||
*/
|
||||
public static function getMphNetworkOwners(): array {
|
||||
$db = FronkDB::singleton();
|
||||
$addressDbName = defined('ADDRESSDB_DBNAME') ? ADDRESSDB_DBNAME : 'addressdb';
|
||||
$fronkDbName = FRONKDB_DBNAME;
|
||||
|
||||
$sql = "SELECT DISTINCT a.id, a.company, a.lastname, a.firstname
|
||||
FROM `$fronkDbName`.`WorkorderMph` wm
|
||||
INNER JOIN `$addressDbName`.`Hausnummer` hn ON wm.hausnummerId = hn.id
|
||||
INNER JOIN `$addressDbName`.`Netzgebiet` ng ON hn.netzgebiet_id = ng.id
|
||||
INNER JOIN `$fronkDbName`.`Network` n ON n.adb_netzgebiet_id = ng.id
|
||||
INNER JOIN `$fronkDbName`.`Address` a ON n.owner_id = a.id
|
||||
WHERE a.id IS NOT NULL
|
||||
ORDER BY a.company, a.lastname, a.firstname";
|
||||
|
||||
$results = $db->fetch_all_assoc($db->query($sql)) ?? [];
|
||||
|
||||
return array_map(fn($owner) => new Address($owner['id']), $results);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user