Merge branch 'master' into fronkdev
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class AddressModel {
|
||||
public $fax;
|
||||
public $mobile;
|
||||
public $email;
|
||||
public $birthday;
|
||||
public $uid;
|
||||
public $billing_type;
|
||||
public $billing_delivery;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class PreorderHistory extends mfBaseModel {
|
||||
protected $forcestr = ["old_value", "new_value"];
|
||||
private $preorder;
|
||||
private $creator;
|
||||
private $editor;
|
||||
@@ -25,14 +26,54 @@ class PreorderHistory extends mfBaseModel {
|
||||
if(preg_match('/(.+)_id/', $this->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<br />";
|
||||
}
|
||||
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) {
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
5
application/PreorderStatusflag/PreorderStatusflag.php
Normal file
5
application/PreorderStatusflag/PreorderStatusflag.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class PreorderStatusflag extends mfBaseModel {
|
||||
|
||||
}
|
||||
133
application/PreorderStatusflag/PreorderStatusflagModel.php
Normal file
133
application/PreorderStatusflag/PreorderStatusflagModel.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
class PreorderStatusflagModel {
|
||||
|
||||
public $code;
|
||||
public $name;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreorderStatusflag();
|
||||
|
||||
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();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class PreorderStatusflagValue extends mfBaseModel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
class PreorderStatusflagValueModel {
|
||||
|
||||
public $preorder_id;
|
||||
public $flag_id;
|
||||
public $value;
|
||||
public $old_value;
|
||||
public $new_value;
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreorderStatusflagValue();
|
||||
|
||||
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();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user