ADDRESSDB_DBHOST, 'user' => ADDRESSDB_DBUSER, 'pass' => ADDRESSDB_DBPASS, 'name' => ADDRESSDB_DBNAME ]; protected static array $__journalFieldMap = [ 'name' => 'Name', 'extref' => 'ExtRef', 'rimo_id' => 'RIMO ID', 'source' => 'Source', 'source_id' => 'Source ID', 'borderpoly' => 'Border Polygon', 'freigabe' => 'Freigaben', 'options' => 'Options', 'create' => 'Erstellt', 'edit' => 'Bearbeitet', ]; public int $id; public ?string $name = null; public ?string $extref = null; public ?string $rimo_id = null; public ?string $source = null; public ?string $source_id = null; public ?string $borderpoly = null; public ?string $freigabe = '["interest", "provision", "order", "reorder"]'; public int $unit_count = 0; public int $unit_count_sd = 0; public int $unit_count_md = 0; public int $unit_create_oaid = 0; public ?string $options = '{"create_address_parts": 0, "update_freigabe": 1, "update_address": 1, "hausnummer_dont_overwrite_netzgebiet": 0, "create_preorder": 0, "preorder_only_oaid": 0, "wo_ignore_status": 0, "delete_units": 0, "mph_min_homes_tool_automatic_count": 3, "unit_create_oaid": 0}'; public int $create; public int $edit; private ?array $__gemeinden = null; private ?ADBNetzgebietRelations $__relations = null; public function __get(string $name) { if ($name === 'gemeinden') { if ($this->__gemeinden === null) { $this->__gemeinden = []; foreach (ADBGemeindeNetzgebietModel::search(["netzgebiet_id" => $this->id]) as $gem_netz) { $g = $gem_netz->gemeinde; if (!$g || array_key_exists($g->id, $this->__gemeinden)) continue; $this->__gemeinden[$g->id] = $g; } } return $this->__gemeinden; } if ($name === 'relations') { return $this->__relations ??= $this->loadRelations(); } return null; } public function loadByExtref(string $extref): bool { $extref = trim($extref); if (empty($extref)) return false; $found = static::getFirst(['=extref' => $extref]); if ($found) { foreach (get_object_vars($found) as $key => $value) { if (property_exists($this, $key) && !str_starts_with($key, '__')) { $this->$key = $value; } } return true; } return false; } public function getOption(string $opt): mixed { $options = $this->getOptions(); return $options && property_exists($options, $opt) ? $options->$opt : null; } public function getOptions(): ?object { if (empty($this->options)) return null; $opts = json_decode($this->options); return json_last_error() === JSON_ERROR_NONE ? $opts : null; } public function getFreigabe(): array { if (empty($this->freigabe)) return []; $freigabe = json_decode($this->freigabe, true); return json_last_error() === JSON_ERROR_NONE ? $freigabe : []; } public function loadRelations(): ADBNetzgebietRelations { $rel = new ADBNetzgebietRelations(); $networks = NetworkModel::search(['adb_netzgebiet_id' => $this->id]); foreach ($networks as $network) { $rel->networks[] = ['id' => $network->id, 'name' => $network->name]; } $networkIds = array_column($rel->networks, 'id'); if (!empty($networkIds)) { $campaigns = PreordercampaignModel::search(['network_id' => $networkIds]); foreach ($campaigns as $campaign) { $rel->campaigns[] = ['id' => $campaign->id, 'name' => $campaign->name]; } } $rel->consentProjects = ConstructionConsentProject::getByAdbNetzgebietId($this->id); return $rel; } }