loadMe(); $data["edit_by"] = $me->id; } return $data; } public function getValue($type = "new", $raw = false) { if($type != "old" && $type != "new") return null; if($type == "new") { $value = $this->new_value; } else { $value = $this->old_value; } if($raw) { return $value; } $m = []; if(preg_match('/(.+)_id/', $this->key, $m)) { if(array_key_exists(1, $m)) { $object = ucfirst($m[1]); if($object == "Status") $object = "Preorderstatus"; if($object == "Partner") $object = "Address"; if($object == "Adb_hausnummer") $object = "ADBHausnummer"; if($object == "Adb_wohneinheit") $object = "ADBWohneinheit"; if($object == "Constructionconsentproject") $object = "ConstructionConsentProject"; if(class_exists($object)) { $value = new $object($value); if(!$value->id) return null; } } } return $value; } public function getKey() { $key = $this->key; if(preg_match('/^preorderstatusflag-(\d+)-/', $key, $m)) { if(array_key_exists(1, $m)) { $id = $m[1]; $psf = new Preorderstatusflag($id); return "Status Flag ".$psf->code." - ".$psf->name; } } switch($key) { case "usage_length": return "Nutzung Länge"; case "usage_pipe_on_plot": return "Nutzung LWL auf Gst."; case "usage_pipe_in_building": return "Nutzung LWL in Gebäuden"; case "usage_manhole": return "Nutzung Schacht/Verteiler/Abschluss"; case "usage_owner": return "Nutzung Eigenvers. GE"; case "approve_override": return "Genehmigung überschreiben"; case "rimo_plan": return "Plan/Skizze aus Rimo"; case "plan_upload": return "Plan/Skizze Upload"; case "constructionconsentproject_id": return "Projekt"; case "inspection_planner": return "Status Begehung mit Planer"; case "inspection_electrician"; return "Status Begehung mit Elektriker"; case "conduit_installed_building": return "Status Leerohr in FTTx Location"; case "conduit_installed_ftu": return "Status Leerohr bis HAK"; case "inhouse_cabling": return "Status Inhouseverkabelung"; } return $key; } public function getText($type = "new") { $value = $this->getValue($type); if($value === null) return ""; if($this->key == "attributes") { $attribs = ""; $jdec = json_decode($value); if(is_object($jdec)) { foreach(get_object_vars($jdec) as $k => $v) { $attribs .= "$k: $v
"; } return $attribs; } } if($this->key == "inspection_date_planner" || $this->key == "inspection_date_electrician" && $value) { $value = date("d.m.Y", $value); } if(in_array($this->key, ["inspection_planner","inspection_electrician","conduit_installed_building","conduit_installed_ftu","inhouse_cabling"])) { $value = ($value > 0) ? 1 : 0; } if(!is_object($value)) { return htmlentities($value); } if(get_class($value) == "Preorderstatus") { return $value->code." - ".$value->name; } if(get_class($value) == "Address") { return $value->getCompanyOrName(); } if(get_class($value) == "ADBHausnummer") { return $value->getAddress(); } if(get_class($value) == "ADBWohneinheit") { return $value->id." - ".(string)$value; } if(get_class($value) == "Preordercampaign") { return $value->name; } if(get_class($value) == "ConstructionConsentProject") { return $value->name; } } public function getProperty($name) { if($this->$name == null) { if($name == "old" || $name == "new") { return $this->getValue($name, false); } if($name == "old_raw") { return $this->getValue("old", true); } if($name == "new_raw") { return $this->getValue("new", true); } if($name == "creator") { $this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); if($this->creator === null) { $this->creator = new User($this->create_by); if($this->creator->id) { mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator); } } return $this->creator; } if($name == "editor") { $this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by); if($this->editor === null) { $this->editor = new User($this->edit_by); if($this->editor->id) { mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor); } } return $this->editor; } $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); if(!$this->$name) { $this->$name = new $classname($this->$idfield); } if($this->$name->id) { mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name); return $this->$name; } else { return null; } } return $this->$name; } /******************************** * Begin static Model functions */ public static function create(Array $data) { $model = new ConstructionConsentHistory(); $table_fields = [ "constructionconsent_id", "key", "old_value", "new_value", "create_by","edit_by","create","edit" ]; foreach($data as $field => $value) { if(in_array($field, $table_fields)) { $model->$field = $value; } } $me = new User(); $me->loadMe(); if($model->create_by === null) { $model->create_by = $me->id; } if($model->edit_by === null) { $model->edit_by = $me->id; } return $model; } public static function getAll() { $items = []; $db = FronkDB::singleton(); $res = $db->select("ConstructionConsentHistory", "*", "1 = 1 ORDER BY `create`"); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new ConstructionConsentHistory($data); } } return $items; } public static function getFirst($filter) { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $sql = "SELECT ConstructionConsentHistory.* FROM ConstructionConsentHistory WHERE $where ORDER BY adb_netzgebiet_id LIMIT 1"; //var_dump($sql);exit; $res = $db->query($sql); if($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new ConstructionConsentHistory($data); if($item->id) { return $item; } else { return null; } } return null; } public static function count($filter) { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $sql = "SELECT COUNT(*) as cnt FROM ConstructionConsentHistory WHERE $where ORDER BY adb_netzgebiet_id "; //mfLoghandler::singleton()->debug($sql); $res = $db->query($sql); if($db->num_rows($res)) { $data = $db->fetch_object($res); return $data->cnt; } return 0; } public static function search($filter, $limit = false, $order = false) { //var_dump($filter);exit; $items = []; if(!$order) { $order = "`create` ASC"; } $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $sql = "SELECT ConstructionConsentHistory.* FROM ConstructionConsentHistory WHERE $where GROUP BY ConstructionConsentHistory.id ORDER BY $order"; if(is_array($limit) && count($limit)) { if(is_numeric($limit['start']) && is_numeric($limit['count'])) { $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; } elseif(is_numeric($limit['count'])) { $sql .= " LIMIT ".$limit['count']; } } mfLoghandler::singleton()->debug($sql); $res = $db->query($sql); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[$data->id] = new ConstructionConsentHistory($data); } } return $items; } private static function getSqlFilter($filter) { $where = "1=1 "; $db = FronkDB::singleton(); if(array_key_exists("constructionconsent_id", $filter)) { $constructionconsent_id = $filter["constructionconsent_id"]; if(is_numeric($constructionconsent_id)) { $where .= " AND constructionconsent_id='$constructionconsent_id'"; } } if(array_key_exists("key", $filter)) { $key = $db->escape($filter["key"]); if($key) { $where .= " AND `key`='$key'"; } } if(array_key_exists("add-where", $filter)) { $where .= " ".$filter['add-where']; } //var_dump($filter, $where);exit; return $where; } }