-
+
-
Status-Historie
+
Status Historie
| Zeitpunkt |
@@ -493,6 +493,26 @@
+
+
Gesamte Historie
+
+
+ | Zeitpunkt |
+ Benutzer |
+ Feld |
+ Alter Wert |
+ Neuer Wert |
+
+ history as $history): ?>
+
+ | =date("d.m.Y H:i:s", $history->create)?> |
+ =$history->creator->name?> |
+ =$history->key?> |
+ =$history->getText("old")?> |
+ =$history->getText("new")?> |
+
+
+
diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php
index 7a25bec41..4e0085f0d 100644
--- a/application/Address/AddressController.php
+++ b/application/Address/AddressController.php
@@ -266,7 +266,17 @@ class AddressController extends mfBaseController {
$data['email'] = trim($r->email);
$data['note'] = trim($r->note);
$data['uid'] = trim($r->uid);
-
+
+ if(trim($r->birthdate)) {
+ try {
+ $data["birthdate"] = (DateTime::createFromFormat("d.m.Y", trim($r->birthdate)))->format("Y-m-d");
+ } catch(Exception $e) {
+ $this->layout()->setFlash("Ungültiges Geburtsdaum", "warning");
+ }
+
+ }
+
+
if($this->me->can("Fibu")) {
$data["sepa_date"] = ($r->sepa_date) ? Layout::dateToInt($r->sepa_date) : null;
diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php
index cd8b2053c..1c0f2841f 100644
--- a/application/Address/AddressModel.php
+++ b/application/Address/AddressModel.php
@@ -22,6 +22,7 @@ class AddressModel {
public $fax;
public $mobile;
public $email;
+ public $birthday;
public $uid;
public $billing_type;
public $billing_delivery;
diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php
index 1e12c17d8..2eadcf591 100644
--- a/application/Preorder/Preorder.php
+++ b/application/Preorder/Preorder.php
@@ -39,6 +39,7 @@ class Preorder extends mfBaseModel {
$this->creator = null;
$this->editor = null;
+ // prevent potential infinite loop
$nesting_level = mfValuecache::singleton()->get("preorder-save-nesting-level-".$this->id);
if(!$nesting_level) {
$nesting_level = 1;
@@ -51,9 +52,6 @@ class Preorder extends mfBaseModel {
return true;
}
- // prevent potential infinite loop
- //if($this->in_after_save) return true;
- //$this->in_after_save++;
// update preorder OAID if it's different from the unit OAID
// but only if the unit OAID is of the same origin as the campaign
$old_oaid = $this->oaid;
@@ -64,10 +62,9 @@ class Preorder extends mfBaseModel {
}
//TODO: history start
- if($this->status_id != $this->_old_data->status_id) {
+ //if($this->status_id != $this->_old_data->status_id) {
$this->createHistoryEntry();
- $this->_old_data->status_id = $this->status_id;
- }
+ //}
// run triggers based on new status
$this->runStatusTrigger();
@@ -79,13 +76,20 @@ class Preorder extends mfBaseModel {
}
public function createHistoryEntry() {
- $history = PreorderHistoryModel::create([
- "preorder_id" => $this->id,
- "key" => 'preorderstatus_id',
- "old_value" => $this->_old_data->status_id,
- "new_value" => $this->status_id
- ]);
- $history->save();
+ if(!$this->id) return true;
+
+ $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();
+ }
}
public function runStatusTrigger() {
diff --git a/application/PreorderHistory/PreorderHistory.php b/application/PreorderHistory/PreorderHistory.php
index fb39c4711..d52d38c26 100644
--- a/application/PreorderHistory/PreorderHistory.php
+++ b/application/PreorderHistory/PreorderHistory.php
@@ -1,6 +1,7 @@
key, $m)) {
if(array_key_exists(1, $m)) {
$object = ucfirst($m[1]);
-
- $value = new $object($value);
- if(!$value->id) return null;
+ if($object == "Status") $object = "Preorderstatus";
+ if($object == "Partner") $object = "Address";
+ if($object == "Adb_hausnummer") $object = "ADBHausnummer";
+ if($object == "Adb_wohneinheit") $object = "ADBWohneinheit";
+ if(class_exists($object)) {
+ $value = new $object($value);
+ if(!$value->id) return null;
+ }
}
}
return $value;
+ }
+ 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(!is_object($value)) {
+ return $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;
+ }
}
public function getProperty($name) {
diff --git a/application/PreorderHistory/PreorderHistoryModel.php b/application/PreorderHistory/PreorderHistoryModel.php
index e216d6908..e13ef7fd7 100644
--- a/application/PreorderHistory/PreorderHistoryModel.php
+++ b/application/PreorderHistory/PreorderHistoryModel.php
@@ -41,7 +41,7 @@ class PreorderHistoryModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
- $res = $db->select("PreorderHistory", "*", "$where ORDER BY preorder_id,`key`,`create` LIMIT 1");
+ $res = $db->select("PreorderHistory", "*", "$where ORDER BY `create`,`key` LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PreorderHistory($data);
@@ -59,7 +59,7 @@ class PreorderHistoryModel {
$db = FronkDB::singleton();
- $res = $db->select("PreorderHistory", "*", "1=1 ORDER BY preorder_id,`key`,`create`");
+ $res = $db->select("PreorderHistory", "*", "1=1 ORDER BY `create`,`key`");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new PreorderHistory($data);
@@ -91,7 +91,7 @@ class PreorderHistoryModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderHistory
WHERE $where
- ORDER BY preorder_id,`key`,`create`";
+ ORDER BY `create`,`key`";
mfLoghandler::singleton()->debug($sql);
if (is_array($limit) && count($limit)) {
diff --git a/application/PreorderStatusflag/PreorderStatusflag.php b/application/PreorderStatusflag/PreorderStatusflag.php
new file mode 100644
index 000000000..a57a2cfaa
--- /dev/null
+++ b/application/PreorderStatusflag/PreorderStatusflag.php
@@ -0,0 +1,5 @@
+ $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();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("PreorderStatusflag", "*", "$where ORDER BY code LIMIT 1");
+ if ($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new PreorderStatusflag($data);
+ if ($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("PreorderStatusflag", "*", "1=1 ORDER BY code");
+ if ($db->num_rows($res)) {
+ while ($data = $db->fetch_object($res)) {
+ $items[] = new PreorderStatusflag($data);
+ }
+ }
+ return $items;
+ }
+
+ public static function count($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) as cnt FROM PreorderStatusflag
+ 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();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT * FROM PreorderStatusflag
+ WHERE $where
+ ORDER BY code";
+
+ 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 PreorderStatusflag($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ if (array_key_exists("code", $filter)) {
+ $code = $filter['code'];
+ if (is_numeric($code)) {
+ $where .= " AND PreorderStatusflag.code=$code";
+ }
+ }
+
+ if (array_key_exists("create_by", $filter)) {
+ $create_by = $filter['create_by'];
+ if (is_numeric($create_by)) {
+ $where .= " AND PreorderStatusflag.create_by=$create_by";
+ }
+ }
+
+ return $where;
+ }
+
+}
diff --git a/application/PreorderStatusflagValue/PreorderStatusflagValue.php b/application/PreorderStatusflagValue/PreorderStatusflagValue.php
new file mode 100644
index 000000000..67f739735
--- /dev/null
+++ b/application/PreorderStatusflagValue/PreorderStatusflagValue.php
@@ -0,0 +1,5 @@
+ $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();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("PreorderStatusflagValue", "*", "$where ORDER BY statusflag_id LIMIT 1");
+ if ($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new PreorderStatusflagValue($data);
+ if ($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("PreorderStatusflagValue", "*", "1=1 ORDER BY statusflag_id");
+ if ($db->num_rows($res)) {
+ while ($data = $db->fetch_object($res)) {
+ $items[] = new PreorderStatusflagValue($data);
+ }
+ }
+ return $items;
+ }
+
+ public static function count($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) as cnt FROM PreorderStatusflagValue
+ 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();
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT * FROM PreorderStatusflagValue
+ WHERE $where
+ ORDER BY statusflag_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 PreorderStatusflagValue($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+
+
+ if (array_key_exists("preorder_id", $filter)) {
+ $preorder_id = $filter['preorder_id'];
+ if (is_numeric($preorder_id)) {
+ $where .= " AND PreorderStatusflagValue.preorder_id=$preorder_id";
+ }
+ }
+
+ if (array_key_exists("flag_id", $filter)) {
+ $flag_id = $filter['flag_id'];
+ if (is_numeric($flag_id)) {
+ $where .= " AND PreorderStatusflagValue.flag_id=$flag_id";
+ }
+ }
+
+ if (array_key_exists("value", $filter)) {
+ $value = $filter['value'];
+ if (is_numeric($value)) {
+ $where .= " AND PreorderStatusflagValue.value=$value";
+ }
+ }
+
+
+ if (array_key_exists("create_by", $filter)) {
+ $create_by = $filter['create_by'];
+ if (is_numeric($create_by)) {
+ $where .= " AND PreorderStatusflagValue.create_by=$create_by";
+ }
+ }
+
+ return $where;
+ }
+
+}
diff --git a/db/migrations/20240717144237_create_preorderstatus_flag.php b/db/migrations/20240717144237_create_preorderstatus_flag.php
new file mode 100644
index 000000000..d77ab98d3
--- /dev/null
+++ b/db/migrations/20240717144237_create_preorderstatus_flag.php
@@ -0,0 +1,86 @@
+getEnvironment() == "thetool") {
+ $psf = $this->table("PreorderStatusflag");
+ $psf->addColumn("code", "integer", ["null" => false]);
+ $psf->addColumn("name", "string", ["null" => false, "limit" => 64]);
+ $psf->addColumn("connection_type", "enum", ["null" => false, "values" => "all,single,multi", "default" => "all"]);
+ $psf->addColumn("create_by", "integer", ["null" => false]);
+ $psf->addColumn("edit_by", "integer", ["null" => false]);
+ $psf->addColumn("create", "integer", ["null" => false]);
+ $psf->addColumn("edit", "integer", ["null" => false]);
+ $psf->create();
+
+ $psf->insert([
+ [
+ "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();
+
+ $psfv = $this->table("PreorderStatusflagValue");
+ $psfv->addColumn("flag_id", "integer", ["null" => false]);
+ $psfv->addColumn("value", "integer", ["null" => false]);
+ $psfv->addColumn("create_by", "integer", ["null" => false]);
+ $psfv->addColumn("edit_by", "integer", ["null" => false]);
+ $psfv->addColumn("create", "integer", ["null" => false]);
+ $psfv->addColumn("edit", "integer", ["null" => false]);
+ $psfv->save();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+ $this->table("PreorderStatusflagValue")->drop()->save();
+ $this->table("PreorderStatusflag")->drop()->save();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}
diff --git a/db/migrations/20240718123809_address_add_birthdate.php b/db/migrations/20240718123809_address_add_birthdate.php
new file mode 100644
index 000000000..15240d16d
--- /dev/null
+++ b/db/migrations/20240718123809_address_add_birthdate.php
@@ -0,0 +1,31 @@
+getEnvironment() == "thetool") {
+ $table = $this->table("Address");
+ $table->addColumn("birthdate", "date", ["null" => true, "default" => null, "after" => "uid"]);
+ $table->update();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+ $this->table("Address")->removeColumn("birthdate")->update();
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}
diff --git a/lib/mvcfronk/mfBase/mfBaseModel.php b/lib/mvcfronk/mfBase/mfBaseModel.php
index 0a704798f..206a3f9d1 100644
--- a/lib/mvcfronk/mfBase/mfBaseModel.php
+++ b/lib/mvcfronk/mfBase/mfBaseModel.php
@@ -4,314 +4,357 @@
* Does most of the dirty work in getting Database entries into
* an object.
* Takes an ID, or FronkDB table row for automatic loading
- * @author fronk
* @param optional ID or table row $_
+ * @author fronk
*/
if(!defined("FRONKDB")) {
- define("FRONKDB", true);
+ define("FRONKDB", true);
}
class mfBaseModel {
- public $id;
- public $data;
- public $_old_data;
- protected $create;
- protected $edit;
- private $worker;
- protected $forcestr;
+ public $id;
+ public $data;
+ public $_old_data;
+ protected $create;
+ protected $edit;
+ private $worker;
+ protected $forcestr;
- protected $mode = "new";
- protected $saved = 0;
- protected $db;
- protected $log;
- protected $table=false;
- protected $fieldprefix=false;
+ protected $mode = "new";
+ protected $saved = 0;
+ protected $db;
+ protected $log;
+ protected $table = false;
+ protected $fieldprefix = false;
- /**
- * Takes ID or DB row as arguments
- * @param id or table row $_
- */
- public function __construct($_=NULL) {
- $this->log=mfLoghandler::singleton();
- $this->table=get_class($this);
- $this->data = new stdClass();
- $this->_old_data = new stdClass();
+ /**
+ * Takes ID or DB row as arguments
+ * @param id or table row $_
+ */
+ public function __construct($_ = NULL) {
+ $this->log = mfLoghandler::singleton();
+ $this->table = get_class($this);
+ $this->data = new stdClass();
+ $this->_old_data = new stdClass();
- if(defined("MFMODEL_USEFIELDPREFIX") && MFMODEL_USEFIELDPREFIX==true) {
- $this->prefixfields=true;
- }
-
- $this->data = new stdClass();
-
- if(FRONKDB) {
- $this->db=FronkDB::singleton();
- }
-
- if(method_exists($this, "init")) {
- $this->init($_);
- }
-
- if(is_numeric($_)) {
- $this->fetch($_);
- } elseif(is_object($_)) {
- $this->load($_);
- }
- }
-
- public function load($row) {
- if(!is_object($this->data)) {
- $this->data = new stdClass();
- }
-
- foreach($row as $field => $value) {
- if($this->fieldprefix) {
- if(preg_match('/^'.$this->fieldprefix.'_(.+)$/',$field,$m)) {
- $field=$m[1];
- }
- }
- if($field=="id"
- || $field=="create"
- || $field=="edit") continue;
- $this->data->$field=$value;
- }
-
- $this->id=$row->id;
-
- if(!property_exists($row, "create")) {
- $row->create = date("U");
- }
- if(!property_exists($row, "edit")) {
- $row->edit = date("U");
- }
-
- $this->create=$row->create;
- $this->edit=$row->edit;
- if($this->fieldprefix) {
- $prop=$this->fieldprefix."_id";
- $this->id=$row->$prop;
- }
-
- $this->_old_data = clone($this->data);
- $this->_old_data->id = $this->id;
- $this->_old_data->create = $this->create;
- $this->_old_data->edit = $this->edit;
-
- $this->mode = "update";
-
- if(method_exists($this, "afterLoad")) {
- $this->afterLoad();
- }
-
- return true;
- }
-
- public function fetch($id) {
- $where="id=$id";
- if($this->fieldprefix) {
- $where=$this->fieldprefix."_id=$id";
- }
-
- $res=$this->db->select($this->table,"*","$where");
- if($this->db->num_rows($res)) {
- $data=$this->db->fetch_object($res);
- $this->load($data);
- return true;
- }
- return false;
- }
-
- public function update(Array $data) {
- foreach($data as $key => $value) {
- if($value === null) {
- $this->$key = null;
- } else {
- $this->$key = $value;
- }
- }
- }
-
- public function save() {
- if(method_exists($this, "beforeSave")) {
- $this->beforeSave();
- }
- $fields=$this->buildFields();
-
- $forcestr = array();
-
- if(!$this->fieldprefix && is_array($this->forcestr) && count($this->forcestr)) {
- $forcestr = $this->forcestr;
- }
-
- if(is_array($this->forcestr) && count($this->forcestr)) {
- foreach($this->forcestr as $fstr) {
- $forcestr[] = $this->fieldprefix . "_$fstr";
- }
- }
-
- if(!is_array($fields) or !count($fields)) {
- return false;
- }
-
- if($this->id) {
- $id=$this->id;
- $where="`id`=$id";
- if($this->fieldprefix) {
- $where="`".$this->fieldprefix."_id`=$id";
- }
- if($this->db->update($this->table,$fields,$where,$forcestr)) {
- $this->saved++;
- if(method_exists($this, "afterSave")) {
- $this->afterSave();
+ if(defined("MFMODEL_USEFIELDPREFIX") && MFMODEL_USEFIELDPREFIX == true) {
+ $this->prefixfields = true;
}
- return $id;
- }
- } else {
- if($this->db->insert($this->table,$fields,$forcestr)) {
- $id=mysqli_insert_id($this->db->link);
- $this->id=$id;
- $this->saved++;
- if(method_exists($this, "afterSave")) {
- $this->afterSave();
+
+ $this->data = new stdClass();
+
+ if(FRONKDB) {
+ $this->db = FronkDB::singleton();
}
- return $id;
- }
- }
- return false;
- }
- protected function buildFields() {
- $fields = array();
- foreach($this->data as $field => $value) {
- if($this->fieldprefix && !strstr($field,"_")) {
- $field = $this->fieldprefix."_$field";
- }
- $fields[$field]=$value;
- }
+ if(method_exists($this, "init")) {
+ $this->init($_);
+ }
- if(!$this->create) {
- $this->create = date('U');
- }
- $this->edit = date('U');
-
- foreach(array("create","edit") as $f) {
- $fields[$f] = $this->$f;
- }
-
- if(method_exists($this, "afterBuildFields")) {
- $fields = $this->afterBuildFields($fields);
+ if(is_numeric($_)) {
+ $this->fetch($_);
+ } elseif(is_object($_)) {
+ $this->load($_);
+ }
}
-
- return $fields;
- }
- public function delete() {
- if($this->id) {
- $id=$this->id;
- $where="id=$id";
- if($this->fieldprefix && !strstr($field,"_")) {
- $where=$this->fieldprefix."_id=$id";
- }
+ public function load($row) {
+ if(!is_object($this->data)) {
+ $this->data = new stdClass();
+ }
+
+ foreach($row as $field => $value) {
+ if($this->fieldprefix) {
+ if(preg_match('/^' . $this->fieldprefix . '_(.+)$/', $field, $m)) {
+ $field = $m[1];
+ }
+ }
+ if($field == "id"
+ || $field == "create"
+ || $field == "edit") continue;
+ $this->data->$field = $value;
+ }
+
+ $this->id = $row->id;
+
+ if(!property_exists($row, "create")) {
+ $row->create = date("U");
+ }
+ if(!property_exists($row, "edit")) {
+ $row->edit = date("U");
+ }
+
+ $this->create = $row->create;
+ $this->edit = $row->edit;
+ if($this->fieldprefix) {
+ $prop = $this->fieldprefix . "_id";
+ $this->id = $row->$prop;
+ }
+
+ $this->_old_data = clone($this->data);
+ $this->_old_data->id = $this->id;
+ $this->_old_data->create = $this->create;
+ $this->_old_data->edit = $this->edit;
+
+ $this->mode = "update";
+
+ if(method_exists($this, "afterLoad")) {
+ $this->afterLoad();
+ }
+
+ return true;
+ }
+
+ public function fetch($id) {
+ $where = "id=$id";
+ if($this->fieldprefix) {
+ $where = $this->fieldprefix . "_id=$id";
+ }
+
+ $res = $this->db->select($this->table, "*", "$where");
+ if($this->db->num_rows($res)) {
+ $data = $this->db->fetch_object($res);
+ $this->load($data);
+ return true;
+ }
+ return false;
+ }
+
+ public function update(array $data) {
+ foreach($data as $key => $value) {
+ if($value === null) {
+ $this->$key = null;
+ } else {
+ $this->$key = $value;
+ }
+ }
+ }
+
+ public function save() {
+ if(method_exists($this, "beforeSave")) {
+ $this->beforeSave();
+ }
+ $fields = $this->buildFields();
+
+ $forcestr = array();
+
+ if(!$this->fieldprefix && is_array($this->forcestr) && count($this->forcestr)) {
+ $forcestr = $this->forcestr;
+ }
+
+ if(is_array($this->forcestr) && count($this->forcestr)) {
+ foreach($this->forcestr as $fstr) {
+ $forcestr[] = $this->fieldprefix . "_$fstr";
+ }
+ }
+
+ if(!is_array($fields) or !count($fields)) {
+ return false;
+ }
+
+ if($this->id) {
+ $id = $this->id;
+ $where = "`id`=$id";
+ if($this->fieldprefix) {
+ $where = "`" . $this->fieldprefix . "_id`=$id";
+ }
+ if($this->db->update($this->table, $fields, $where, $forcestr)) {
+ $this->saved++;
+ if(method_exists($this, "afterSave")) {
+ $this->afterSave();
+ }
+ return $id;
+ }
+ } else {
+ if($this->db->insert($this->table, $fields, $forcestr)) {
+ $id = mysqli_insert_id($this->db->link);
+ $this->id = $id;
+ $this->saved++;
+ if(method_exists($this, "afterSave")) {
+ $this->afterSave();
+ }
+ return $id;
+ }
+ }
+ return false;
+ }
+
+ protected function buildFields() {
+ $fields = array();
+ foreach($this->data as $field => $value) {
+ if($this->fieldprefix && !strstr($field, "_")) {
+ $field = $this->fieldprefix . "_$field";
+ }
+ $fields[$field] = $value;
+ }
+
+ if(!$this->create) {
+ $this->create = date('U');
+ }
+ $this->edit = date('U');
+
+ foreach(array("create", "edit") as $f) {
+ $fields[$f] = $this->$f;
+ }
+
+ if(method_exists($this, "afterBuildFields")) {
+ $fields = $this->afterBuildFields($fields);
+ }
+
+ return $fields;
+ }
+
+ public function delete() {
+ if($this->id) {
+ $id = $this->id;
+ $where = "id=$id";
+ if($this->fieldprefix && !strstr($field, "_")) {
+ $where = $this->fieldprefix . "_id=$id";
+ }
if(method_exists($this, "beforeDelete")) {
// delete can be canceled
if(!$this->beforeDelete()) {
return false;
}
}
- if($this->db->delete($this->table,$where)) {
- if(method_exists($this, "afterDelete")) {
- $this->afterDelete();
+ if($this->db->delete($this->table, $where)) {
+ if(method_exists($this, "afterDelete")) {
+ $this->afterDelete();
+ }
+ $this->data = new stdClass();
+ $this->id = "";
+ return true;
+ }
}
- $this->data=new stdClass();
- $this->id="";
- return true;
- }
- }
- return false;
- }
-
- public function new() {
- if($this->mode == "new" && $this->saved <= 1) {
- return "new";
- } else {
- return "update";
+ return false;
}
- }
-
- public function startTransaction() {
- $this->db->query("START TRANSACTION");
- }
-
- public function commitTransaction() {
- $this->db->query("COMMIT");
- }
-
- public function rollbackTransaction() {
- $this->db->query("ROLLBACK");
- }
- // generic functions for entity-classes
- public function toArray() {
- if(!$this->id) {
- return [];
- }
-
- $item = [];
- $item['id'] = $this->id;
- foreach($this->data as $key => $value) {
- $item[$key] = $value;
- }
-
- return $item;
- }
-
-
- public function __toString() {
- return (string) $this->data->Name;
- }
-
- public function __get($name) {
- if($name == "create" || $name == "edit") {
- if(isset($this->data->$name)) {
- return $this->data->$name;
- } else {
- return $this->$name;
- }
- }
-
-
- if(isset($this->data->$name)) {
- return $this->data->$name;
- } elseif(property_exists($this, $name)) {
- if(method_exists($this, "getProperty")) {
- $prop = $this->getProperty($name);
- if($prop === null){
- return null;
+ protected function getChangedFields($include_system = false) {
+ if(!$this->_old_data->id) return [];
+ if(!is_object($this->data) || !is_object($this->_old_data)) {
+ return [];
}
- return $prop;
- } else {
- return $this->$name;
- }
- }
- return null;
- }
- public function __set($name,$value) {
- if($name=="create") {
- $this->create=intval($value);
- }
- $this->data->$name=$value;
- return true;
- }
+ $changes = [];
- public function __unset($name) {
- unset($this->data->$name);
- }
-
- public function __debugInfo() {
- $vars = get_object_vars($this);
- if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
- if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
- return $vars;
- }
+ foreach($this->data as $field => $value) {
+ if(!$include_system && in_array($field, ["id", "create_by", "edit_by", "create", "edit"])) continue;
+ if(is_object($value)) continue;
+
+ if(!property_exists($this->_old_data, $field)) {
+ $changes[] = $field;
+ continue;
+ }
+ if($value != $this->_old_data->$field) {
+ $changes[] = $field;
+ }
+ }
+
+ foreach($this->_old_data as $field => $value) {
+ if(!$include_system && in_array($field, ["id", "create_by", "edit_by", "create", "edit"])) continue;
+ if(is_object($value)) continue;
+
+ if(in_array($field, $changes)) {
+ continue;
+ }
+ if(!property_exists($this->data, $field)) {
+ $changes[] = $field;
+ continue;
+ }
+
+ if($value != $this->data->$field) {
+ $changes[] = $field;
+ }
+
+ }
+
+
+ return $changes;
+ }
+
+ public function new() {
+ if($this->mode == "new" && $this->saved <= 1) {
+ return "new";
+ } else {
+ return "update";
+ }
+ }
+
+ public function startTransaction() {
+ $this->db->query("START TRANSACTION");
+ }
+
+ public function commitTransaction() {
+ $this->db->query("COMMIT");
+ }
+
+ public function rollbackTransaction() {
+ $this->db->query("ROLLBACK");
+ }
+
+ // generic functions for entity-classes
+ public function toArray() {
+ if(!$this->id) {
+ return [];
+ }
+
+ $item = [];
+ $item['id'] = $this->id;
+ foreach($this->data as $key => $value) {
+ $item[$key] = $value;
+ }
+
+ return $item;
+ }
+
+
+ public function __toString() {
+ return (string)$this->data->Name;
+ }
+
+ public function __get($name) {
+ if($name == "create" || $name == "edit") {
+ if(isset($this->data->$name)) {
+ return $this->data->$name;
+ } else {
+ return $this->$name;
+ }
+ }
+
+
+ if(isset($this->data->$name)) {
+ return $this->data->$name;
+ } elseif(property_exists($this, $name)) {
+ if(method_exists($this, "getProperty")) {
+ $prop = $this->getProperty($name);
+ if($prop === null) {
+ return null;
+ }
+ return $prop;
+ } else {
+ return $this->$name;
+ }
+ }
+ return null;
+ }
+
+ public function __set($name, $value) {
+ if($name == "create") {
+ $this->create = intval($value);
+ }
+ $this->data->$name = $value;
+ return true;
+ }
+
+ public function __unset($name) {
+ unset($this->data->$name);
+ }
+
+ public function __debugInfo() {
+ $vars = get_object_vars($this);
+ if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
+ if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
+ return $vars;
+ }
}
diff --git a/public/plugins/vue/tt-components/tt-table.js b/public/plugins/vue/tt-components/tt-table.js
index 2aebd6873..25c82c5ed 100644
--- a/public/plugins/vue/tt-components/tt-table.js
+++ b/public/plugins/vue/tt-components/tt-table.js
@@ -149,21 +149,21 @@ Vue.component('tt-table', {
(column.filter === 'dateRange' ? 'min-width: 260px;' : '') +
(originalColumnWidths[column.key] ? 'width: ' + originalColumnWidths[column.key] + 'px;' : '')"
>
-
+ @click="column.sortable && !disableFiltering ? setOrder(column.key) : undefined">
{{ column.text }}
-
-
-
-
-
-
-
+
+
+
+
+
+