clients in varibale genommen
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
class HauptManager extends IPSModule
|
||||
{
|
||||
private $clients = [];
|
||||
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
@@ -13,6 +11,7 @@ class HauptManager extends IPSModule
|
||||
$this->RegisterPropertyInteger("Ueberschussleistung", 0);
|
||||
$this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0
|
||||
$this->RegisterPropertyString("Verbraucher_Liste", "[]");
|
||||
$this->RegisterVariableString("Clients", "Clients", "", 0);
|
||||
|
||||
// Timer registrieren
|
||||
$this->RegisterTimer("Timer_DistributeEnergy", 5000, "IPS_RequestAction(" .$this->InstanceID .', "DistributeEnergy", "");');
|
||||
@@ -86,25 +85,38 @@ class HauptManager extends IPSModule
|
||||
|
||||
public function AddClient($conn)
|
||||
{
|
||||
$this->clients[] = $conn;
|
||||
$clients = json_decode($this->GetValue("Clients"), true);
|
||||
if ($clients === null) {
|
||||
$clients = [];
|
||||
}
|
||||
$clients[] = (string)$conn->resourceId;
|
||||
$this->SetValue("Clients", json_encode($clients));
|
||||
$this->UpdateClientList();
|
||||
}
|
||||
|
||||
public function RemoveClient($conn)
|
||||
{
|
||||
$index = array_search($conn, $this->clients);
|
||||
if ($index !== false) {
|
||||
unset($this->clients[$index]);
|
||||
$this->clients = array_values($this->clients); // Reindizieren des Arrays
|
||||
$this->UpdateClientList();
|
||||
$clients = json_decode($this->GetValue("Clients"), true);
|
||||
if ($clients !== null) {
|
||||
$index = array_search((string)$conn->resourceId, $clients);
|
||||
if ($index !== false) {
|
||||
unset($clients[$index]);
|
||||
$clients = array_values($clients); // Reindizieren des Arrays
|
||||
$this->SetValue("Clients", json_encode($clients));
|
||||
$this->UpdateClientList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function UpdateClientList()
|
||||
{
|
||||
$clients = json_decode($this->GetValue("Clients"), true);
|
||||
if ($clients === null) {
|
||||
$clients = [];
|
||||
}
|
||||
$clientList = [];
|
||||
foreach ($this->clients as $client) {
|
||||
$clientList[] = ['Client' => (string)$client->resourceId];
|
||||
foreach ($clients as $client) {
|
||||
$clientList[] = ['Client' => $client];
|
||||
}
|
||||
$this->UpdateFormField('ClientList', 'values', json_encode($clientList));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user