Added Statusflags in AddressDB

This commit is contained in:
Frank Schubert
2024-08-14 16:15:11 +02:00
parent 4f1964b694
commit 7531d700c0
14 changed files with 838 additions and 19 deletions

View File

@@ -28,6 +28,7 @@
<link href="<?=self::getResourcePath()?>css/bootstrap-datepicker3.min.css" rel="stylesheet" type="text/css" />
<link href="<?=self::getResourcePath()?>plugins/summernote/summernote-bs4.css" rel="stylesheet" type="text/css" />
<link href="<?=self::getResourcePath()?>plugins/notification/notify.min.css" rel="stylesheet" type="text/css" />
<link href="<?=self::getResourcePath()?>plugins/ekko-lightbox/ekko-lightbox.css" type="text/css" />
<link href="<?=self::getResourcePath()?>datatables/datatables.min.css?<?=$git_merge_ts?>" rel="stylesheet" type="text/css" />
<?php if(isset($additionalCSS) && is_array($additionalCSS) && count($additionalCSS)): ?>

View File

@@ -0,0 +1,73 @@
<?php
class ADBHausnummerStatusflagValue extends mfBaseModel {
private $flag;
public function init() {
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$this->table = "HausnummerStatusflagValue";
}
protected function afterSave() {
if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
// cascade new status to all preorders
foreach(PreorderModel::search(["adb_hausnummer_id" => $this->hausnummer_id]) as $preorder) {
// get PreorederStatusflag
$pflag = PreorderStatusflagModel::getFirst(["code" => $this->getProperty("flag")->code]);
if(!$pflag) {
$this->log->debug(__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found");
return true;
}
// find PreorderStatusflagValue or create it
$new = false;
$pflagval = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder->id, "flag_id" => $pflag->id]);
if(!$pflagval) {
$new = true;
$pflagval = PreorderStatusflagValueModel::create([
"preorder_id" => $preorder->id,
"flag_id" => $pflag->id,
"value" => 0
]);
}
if($new || $pflagval->value != $this->value) {
$pflagval->value = $this->value;
//$this->log->debug(__METHOD__.": ".print_r($pflagval, true));
$pflagval->save();
$this->log->debug(__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id);
}
}
}
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "flag") {
if(!$this->flag_id) return null;
$flag = new ADBStatusflag($this->flag_id);
if($flag->id) {
$this->flag = $flag;
}
return $this->flag;
}
$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;
}
}

View File

@@ -0,0 +1,155 @@
<?php
class ADBHausnummerStatusflagValueModel {
public $hausnummer_id;
public $flag_id;
public $value;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new ADBHausnummerStatusflagValue();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if(!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
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 getFirst($filter) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT HausnummerStatusflagValue.* FROM HausnummerStatusflagValue
WHERE $where
ORDER BY hausnummer_id,flag_id
LIMIT 1";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ADBHausnummerStatusflagValue($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$res = $db->select("HausnummerStatusflagValue", "*", "1=1 ORDER BY hausnummer_id,flag_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ADBHausnummerStatusflagValue($data);
}
}
return $items;
}
public static function count($filter) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM HausnummerStatusflagValue
WHERE $where
";
$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) {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT HausnummerStatusflagValue.* FROM HausnummerStatusflagValue
WHERE $where
ORDER BY hausnummer_id,flag_id";
mfLoghandler::singleton()->debug($sql);
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'];
}
}
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ADBHausnummerStatusflagValue($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("hausnummer_id", $filter)) {
$hausnummer_id = $filter['hausnummer_id'];
if(is_numeric($hausnummer_id)) {
$where .= " AND hausnummer_id=$hausnummer_id";
} elseif(is_array($hausnummer_id) && count($hausnummer_id)) {
$where .= " AND hausnummer_id IN (". implode(",", $hausnummer_id).")";
} elseif($hausnummer_id === null) {
$where .= " AND hausnummer_id IS NULL";
}
}
if(array_key_exists("flag_id", $filter)) {
$flag_id = $filter['flag_id'];
if(is_numeric($flag_id)) {
$where .= " AND flag_id=$flag_id";
} elseif(is_array($flag_id) && count($flag_id)) {
$where .= " AND flag_id IN (". implode(",", $flag_id).")";
} elseif($flag_id === null) {
$where .= " AND flag_id IS NULL";
}
}
if(array_key_exists("value", $filter)) {
$value = FronkDB::singleton()->escape($filter['value']);
if($value) {
$where .= " AND `value`='$value'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,9 @@
<?php
class ADBStatusflag extends mfBaseModel {
public function init() {
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$this->table = "Statusflag";
}
}

View File

@@ -0,0 +1,140 @@
<?php
class ADBStatusflagModel {
public $code;
public $name;
public $connection_type;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new ADBStatusflag();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if(!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
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 getFirst($filter) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT Statusflag.* FROM Statusflag
WHERE $where
ORDER BY code,name
LIMIT 1";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ADBStatusflag($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$res = $db->select("Statusflag", "*", "1=1 ORDER BY code,name");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ADBStatusflag($data);
}
}
return $items;
}
public static function count($filter) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM Statusflag
WHERE $where
";
$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) {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT Statusflag.* FROM Statusflag
WHERE $where
ORDER BY code,name";
mfLoghandler::singleton()->debug($sql);
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'];
}
}
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ADBStatusflag($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("code", $filter)) {
$code = FronkDB::singleton()->escape($filter['code']);
if($code) {
$where .= " AND `code`='$code'";
}
}
if(array_key_exists("connection_type", $filter)) {
$connection_type = FronkDB::singleton()->escape($filter['connection_type']);
if($connection_type) {
$where .= " AND `connection_type`='$connection_type'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -0,0 +1,73 @@
<?php
class ADBWohneinheitStatusflagValue extends mfBaseModel {
private $flag;
public function init() {
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$this->table = "WohneinheitStatusflagValue";
}
protected function afterSave() {
if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
// cascade new status to all preorders
foreach(PreorderModel::search(["adb_wohneinheit_id" => $this->wohneinheit_id]) as $preorder) {
// get PreorederStatusflag
$pflag = PreorderStatusflagModel::getFirst(["code" => $this->getProperty("flag")->code]);
if(!$pflag) {
$this->log->debug(__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found");
return true;
}
// find PreorderStatusflagValue or create it
$new = false;
$pflagval = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder->id, "flag_id" => $pflag->id]);
if(!$pflagval) {
$new = true;
$pflagval = PreorderStatusflagValueModel::create([
"preorder_id" => $preorder->id,
"flag_id" => $pflag->id,
"value" => 0
]);
}
if($new || $pflagval->value != $this->value) {
$pflagval->value = $this->value;
//$this->log->debug(__METHOD__.": ".print_r($pflagval, true));
$pflagval->save();
$this->log->debug(__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id);
}
}
}
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "flag") {
if(!$this->flag_id) return null;
$flag = new ADBStatusflag($this->flag_id);
if($flag->id) {
$this->flag = $flag;
}
return $this->flag;
}
$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;
}
}

View File

@@ -0,0 +1,155 @@
<?php
class ADBWohneinheitStatusflagValueModel {
public $wohneinheit_id;
public $flag_id;
public $value;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new ADBWohneinheitStatusflagValue();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if(!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
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 getFirst($filter) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT WohneinheitStatusflagValue.* FROM WohneinheitStatusflagValue
WHERE $where
ORDER BY wohneinheit_id,flag_id
LIMIT 1";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ADBWohneinheitStatusflagValue($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$res = $db->select("WohneinheitStatusflagValue", "*", "1=1 ORDER BY wohneinheit_id,flag_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ADBWohneinheitStatusflagValue($data);
}
}
return $items;
}
public static function count($filter) {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM WohneinheitStatusflagValue
WHERE $where
";
$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) {
$items = [];
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$sql = "SELECT WohneinheitStatusflagValue.* FROM WohneinheitStatusflagValue
WHERE $where
ORDER BY wohneinheit_id,flag_id";
mfLoghandler::singleton()->debug($sql);
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'];
}
}
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ADBWohneinheitStatusflagValue($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("wohneinheit_id", $filter)) {
$wohneinheit_id = $filter['wohneinheit_id'];
if(is_numeric($wohneinheit_id)) {
$where .= " AND wohneinheit_id=$wohneinheit_id";
} elseif(is_array($wohneinheit_id) && count($wohneinheit_id)) {
$where .= " AND wohneinheit_id IN (". implode(",", $wohneinheit_id).")";
} elseif($wohneinheit_id === null) {
$where .= " AND wohneinheit_id IS NULL";
}
}
if(array_key_exists("flag_id", $filter)) {
$flag_id = $filter['flag_id'];
if(is_numeric($flag_id)) {
$where .= " AND flag_id=$flag_id";
} elseif(is_array($flag_id) && count($flag_id)) {
$where .= " AND flag_id IN (". implode(",", $flag_id).")";
} elseif($flag_id === null) {
$where .= " AND flag_id IS NULL";
}
}
if(array_key_exists("value", $filter)) {
$value = FronkDB::singleton()->escape($filter['value']);
if($value) {
$where .= " AND `value`='$value'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}

View File

@@ -1038,6 +1038,13 @@ class PreorderApicontroller extends mfBaseApicontroller {
$return['orderDate'] = date("Y-m-d",$preorder->order_date);
}
$return['status'] = $preorder->status->getApiArray();
/*foreach($preorder->statusflags as $sflag) {
$return['status']['flags'][$sflag->code] = [
"code" => $sflag->code,
"text" => $sflag->name,
"value" => ($sflag->value->value == 1)
];
}*/
if($addon_data) {
$return["additionalData"] = $addon_data;
}

View File

@@ -81,15 +81,19 @@ class Preorder extends mfBaseModel {
$changed = $this->getChangedFields();
foreach($changed as $field) {
$this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
$history = PreorderHistoryModel::create([
"preorder_id" => $this->id,
"key" => $field,
"old_value" => $this->_old_data->$field,
"new_value" => $this->data->$field
]);
$history->save();
try {
foreach($changed as $field) {
$this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
$history = PreorderHistoryModel::create([
"preorder_id" => $this->id,
"key" => $field,
"old_value" => $this->_old_data->$field,
"new_value" => $this->data->$field
]);
$history->save();
}
} catch(Exception $e) {
$this->log->debug($e->getTraceAsString());
}
}
@@ -142,6 +146,7 @@ class Preorder extends mfBaseModel {
$trigger = new $classname($this, $new_status);
$trigger->run();
}
@@ -231,6 +236,58 @@ class Preorder extends mfBaseModel {
}
}
$flags = $this->getProperty("statusflags");
if(is_array($flags) && count($flags)) {
foreach($flags as $flag) {
if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_MATRIX)) {
$flag_matrix_item = TT_PREORDER_STATUS_MATRIX[$flag->code];
if(!$flag_matrix_item["flag"]) continue;
// set hausnummer flag
if($flag_matrix_item["h"]) {
$hflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["h"]]);
if(!$hflag) {
$this->log->warn("Statusflag Code ".$flag->code." does not exist");
}
$hflagval = ADBHausnummerStatusflagValueModel::getFirst(["hausnummer_id" => $this->adb_hausnummer_id, "flag_id" => $hflag->id]);
if(!$hflagval) {
$hflagval = ADBHausnummerStatusflagValueModel::create([
"hausnummer_id" => $this->adb_hausnummer_id,
"flag_id" => $hflag->id,
"value" => 0
]);
}
$hflagval->value = $flag->value->value;
$hflagval->save();
$this->log->debug(__METHOD__.": Hausnummer flag ".$hflag->code." gespeichert");
}
// set wohneiheit flag
if($flag_matrix_item["w"] && $this->adb_wohneinheit_id) {
$wflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["w"]]);
if(!$wflag) {
$this->log->warn("Statusflag Code ".$flag->code." does not exist");
}
$wflagval = ADBWohneinheitStatusflagValueModel::getFirst(["wohneinheit_id" => $this->adb_wohneinheit_id, "flag_id" => $wflag->id]);
if(!$wflagval) {
$wflagval = ADBWohneinheitStatusflagValueModel::create([
"wohneinheit_id" => $this->adb_wohneinheit_id,
"flag_id" => $wflag->id,
"value" => 0
]);
}
$wflagval->value = $flag->value->value;
$wflagval->save();
$this->log->debug(__METHOD__.": Wohneinheit flag ".$hflag->code." gespeichert");
}
}
}
}
return true;
}
@@ -544,6 +601,15 @@ class Preorder extends mfBaseModel {
$hausnummer = $this->getProperty("adb_hausnummer");
$wohneinheit = $this->getProperty("adb_wohneinheit");
$campaign = $this->getProperty("campaign");
$status = $this->getProperty("status")->getApiArray();
/*foreach($this->getProperty("statusflags") as $sflag) {
$status["flags"][$sflag->code] = [
"code" => $sflag->code,
"text" => $sflag->name,
"value" => ($sflag->value->value == 1)
];
}*/
$a = [];
@@ -551,7 +617,7 @@ class Preorder extends mfBaseModel {
$a['oaid'] = $this->oaid;
$a['extref'] = $this->extref;
$a['orderDate'] = ($this->order_date) ? date("Y-m-d", $this->order_date) : null;
$a['status'] = $this->getProperty("status")->getApiArray();
$a['status'] = $status;
$a['ciftoken'] = ($this->ciftoken) ? $this->ciftoken : null;
$a['cifurl'] = ($this->cifurl) ? $this->cifurl : null;
$a['cifcableurl'] = ($this->cifcableurl) ? $this->cifcableurl : null;

View File

@@ -953,9 +953,13 @@ class PreorderController extends mfBaseController {
}
$flagvalue->value = ($value) ? 1 : 0;
if(!$flagvalue->save()) {
return false;
//var_dump($flagvalue);exit;
try {
if(!$flagvalue->save()) {
return false;
}
} catch(Exception $e) {
$this->log->debug($e->getTraceAsString());
}
return ["message" => "Statusflag saved successfully"];

View File

@@ -1,16 +1,39 @@
<?php
class PreorderStatusflagValue extends mfBaseModel {
private $preorder;
protected function afterSave() {
if($this->_old_data->value != $this->value) {
if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
$history = PreorderHistoryModel::create([
"preorder_id" => $this->preorder_id,
"key" => "preorderstatusflag-".$this->flag_id."-value",
"old_value" => $this->_old_data->value,
"preorder_id" => $this->data->preorder_id,
"key" => "preorderstatusflag-".$this->data->flag_id."-value",
"old_value" => property_exists($this->_old_data, "value") ? $this->_old_data->value : null,
"new_value" => $this->data->value
]);
$history->save();
$this->getProperty("preorder")->afterSave();
}
}
public function getProperty($name) {
if($this->$name == null) {
$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;
}
}

View File

@@ -10,7 +10,8 @@ class Preorderstatus extends mfBaseModel {
$a = [];
$a['code'] = (int)$this->code;
$a['text'] = $this->name;
//$a['flags'] = [];
return $a;
}
}

View File

@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateAdbStatusFlag extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
}
if($this->getEnvironment() == "addressdb") {
$hflag = $this->table("Statusflag");
$hflag->addColumn("code", "integer", ["null" => false]);
$hflag->addColumn("name", "string", ["null" => false, "limit" => 64]);
$hflag->addColumn("connection_type", "enum", ["null" => false, "values" => "all,single,multi", "default" => "all"]);
$hflag->addColumn("create_by", "integer", ["null" => false]);
$hflag->addColumn("edit_by", "integer", ["null" => false]);
$hflag->addColumn("create", "integer", ["null" => false]);
$hflag->addColumn("edit", "integer", ["null" => false]);
$hflag->create();
$hflag->insert([
[
"code" => 141,
"name" => "Conduit on property border and FCP prepaired",
"connection_type" => "all",
"create_by" => 1,
"edit_by" => 1,
"create" => date("U"),
"edit" => date("U")
],
[
"code" => 145,
"name" => "Installation kit picked up or shipped",
"connection_type" => "all",
"create_by" => 1,
"edit_by" => 1,
"create" => date("U"),
"edit" => date("U")
],
[
"code" => 150,
"name" => "Borderpoint connected",
"connection_type" => "all",
"create_by" => 1,
"edit_by" => 1,
"create" => date("U"),
"edit" => date("U")
],
[
"code" => 200,
"name" => "Conduit in building",
"connection_type" => "all",
"create_by" => 1,
"edit_by" => 1,
"create" => date("U"),
"edit" => date("U")
],
[
"code" => 242,
"name" => "Inhouse cabeling finished",
"connection_type" => "all",
"create_by" => 1,
"edit_by" => 1,
"create" => date("U"),
"edit" => date("U")
],
])->save();
$hvalue = $this->table("HausnummerStatusflagValue");
$hvalue->addColumn("hausnummer_id", "integer", ["null" => false]);
$hvalue->addColumn("flag_id", "integer", ["null" => false]);
$hvalue->addColumn("value", "integer", ["null" => false]);
$hvalue->addColumn("create_by", "integer", ["null" => false]);
$hvalue->addColumn("edit_by", "integer", ["null" => false]);
$hvalue->addColumn("create", "integer", ["null" => false]);
$hvalue->addColumn("edit", "integer", ["null" => false]);
$hvalue->addIndex("hausnummer_id");
$hvalue->addIndex(["hausnummer_id", "flag_id"]);
$hvalue->create();
$wvalue = $this->table("WohneinheitStatusflagValue");
$wvalue->addColumn("wohneinheit_id", "integer", ["null" => false]);
$wvalue->addColumn("flag_id", "integer", ["null" => false]);
$wvalue->addColumn("value", "integer", ["null" => false]);
$wvalue->addColumn("create_by", "integer", ["null" => false]);
$wvalue->addColumn("edit_by", "integer", ["null" => false]);
$wvalue->addColumn("create", "integer", ["null" => false]);
$wvalue->addColumn("edit", "integer", ["null" => false]);
$wvalue->addIndex("wohneinheit_id");
$wvalue->addIndex(["wohneinheit_id", "flag_id"]);
$wvalue->create();
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
}
if($this->getEnvironment() == "addressdb") {
$this->table("WohneinheitStatusflagValue")->drop()->save();
$this->table("HausnummerStatusflagValue")->drop()->save();
$this->table("Statusflag")->drop()->save();
}
}
}

View File

@@ -1,6 +1,6 @@
#!/usr/bin/php
<?php
exit;
//require 'vendor/autoload.php';
require("../../config/config.php");