Fixed Termination and Building Workflowitem loading

This commit is contained in:
Frank Schubert
2022-02-17 21:34:53 +01:00
parent b63640e232
commit 08630e9942
6 changed files with 63 additions and 43 deletions

View File

@@ -558,6 +558,7 @@
</tr>
<?php $order_count = 0; ?>
<?php foreach($orders as $order): ?>
<?php //$this->log->debug("blah: ".print_r($order->terminations[0]->workflowitems["customer_setup_date"]->value,true)); ?>
<tr class="order-list-tr pb-0 <?=($order_count % 2 == 0) ? "table-bg-even" : ""?>" id="order-<?=$order->id?>">
<td><?=$order->id?></td>
<td onclick="toggleOrder(<?=$order->id?>)">
@@ -653,7 +654,7 @@
<div class="row">
<div class="mr-4 order-date-pill <?=($order->terminations[0]->workflowitems["bautermin"]->value->value_string) ? "active" : ""?>">Tiefbau: <span class="text-monospace"><?=($order->terminations[0]->workflowitems["bautermin"]->value->value_string) ? "<span class='text-success'>".$order->terminations[0]->workflowitems["bautermin"]->value->value_string."</span>" : "--.--.----"?></span></div>
<div class="mr-4 order-date-pill <?=($order->terminations[0]->workflowitems["backbone_setup_date"]->value->value_string) ? "active" : ""?>">Leitungsbau Backbone: <span class="text-monospace"><?=($order->terminations[0]->workflowitems["backbone_setup_date"]->value->value_string) ? "<span class='text-success'>".$order->terminations[0]->workflowitems["backbone_setup_date"]->value->value_string."</span>" : "--.--.----"?></span></div>
<div class="mr-4 order-date-pill <?=($order->terminations[0]->workflowitems["customer_setup_date"]->value->value_string) ? "active" : ""?>">Leitungsbau Kunde: <span class="text-monospace"><?=($order->terminations[0]->workflowitems["customer_setup_date"]->value->value_string) ? "<span class='text-success'>".$order->terminations[0]->workflowitems["customer_setup_date"]->value->value_string."</span>" : "--.--.----"?></span></div>
<div class="mr-4 order-date-pill <?=($order->terminations[0]->getWorkflowvalue("customer_setup_date")) ? "active" : ""?>">Leitungsbau Kunde: <span class="text-monospace"><?=($order->terminations[0]->getWorkflowvalue("customer_setup_date")) ? "<span class='text-success'>".$order->terminations[0]->getWorkflowvalue("customer_setup_date")."</span>" : "--.--.----"?></span></div>
<div class="mr-4 order-date-pill <?=($order->shippingdate) ? "active" : ""?>">Versandtermin: <span class="text-monospace"><?=($order->shippingdate) ? "<span class='text-success'>".date("d.m.Y", $order->shippingdate)."</span>" : "--.--.----"?></span></div>
<div id="date-pill-<?=$order->id?>-install_date" class="order-date-pill <?=($order->install_date) ? "active" : ""?>" id="order-install-date-<?=$order->id?>">Vorortinstallation: <span class="text-monospace"><?=($order->install_date) ? "<span class='text-success'>".date("d.m.Y",$order->install_date)."</span>" : "--.--.----"?></span></div>
</div>

View File

@@ -80,13 +80,6 @@ class Building extends mfBaseModel {
}
public function loadWorkflowItems() {
/*foreach(WorkflowitemModel::search(["object_type" => "building", "active" => 1]) as $item) {
$item->setObjectId($this->id);
$this->workflowitems[$item->name] = $item;
mfValuecache::singleton()->set("wfBuilding-".$item->name, $item);
}*/
$item_ids = [];
$building_wfitems = mfValuecache::singleton()->get("wfitems-building-active");
@@ -96,26 +89,27 @@ class Building extends mfBaseModel {
}
foreach($building_wfitems as $item) {
$item->setObjectId($this->id);
$this->workflowitems[$item->name] = $item;
mfValuecache::singleton()->set("wfBuilding-name-".$item->name, $item);
mfValuecache::singleton()->set("wfBuilding-id-".$item->id, $item);
$item_ids[] = $item->id;
}
$item->setObjectId($this->id);
foreach($item_ids as $id) {
mfValuecache::singleton()->set("wfItemvalue-item-".$id."-object-".$this->id, new Workflowvalue());
$new_value = new Workflowvalue();
$new_value->item_id = $item->id;
$new_value->object_id = $this->id;
mfValuecache::singleton()->set("wfItemvalue-item-".$item->id."-object-".$this->id, $new_value);
$item->setValue($new_value);
$this->workflowitems[$item->name] = $item;
}
// get values
$values = WorkflowvalueModel::search(["object_id" => $this->id]);
//var_dump($values);exit;
$values = WorkflowvalueModel::search(["object_id" => $this->id, "object_type" => "building"]);
foreach($values as $value) {
if(array_key_exists($value->item->name, $this->workflowitems)) {
//var_dump($value);exit;
$this->workflowitems[$value->item->name]->setValue($value);
mfValuecache::singleton()->set("wfItemvalue-item-".$value->item_id."-object-".$this->id, $value);
}
$this->log->debug(print_r($value->item, true));
$this->workflowitems[$value->item->name]->setValue($value);
mfValuecache::singleton()->set("wfItemvalue-item-".$value->item_id."-object-".$this->id, $value);
}
}

View File

@@ -35,8 +35,9 @@ class Termination extends mfBaseModel {
return $address;
}
public function loadWorkflowItems() {
$item_ids = [];
//$this->log->debug("in loadWorkflowItems() - terminstaiton_id: ".$this->id);
$term_wfitems = mfValuecache::singleton()->get("wfitems-term-active");
if(!$term_wfitems) {
@@ -45,32 +46,28 @@ class Termination extends mfBaseModel {
}
foreach($term_wfitems as $item) {
$item->setObjectId($this->id);
$this->workflowitems[$item->name] = $item;
mfValuecache::singleton()->set("wfTerm-name-".$item->name, $item);
mfValuecache::singleton()->set("wfTerm-id-".$item->id, $item);
$item_ids[] = $item->id;
$item->setObjectId($this->id);
$new_value = new Workflowvalue();
$new_value->item_id = $item->id;
$new_value->object_id = $this->id;
//$this->log->debug("empty value has item_id: ".$new_value->item_id." - object_id: ".$new_value->object_id. ". Goes into cache as wfItemvalue-item-".$item->id."-object-".$this->id." value: ".$new_value->value_string);
mfValuecache::singleton()->set("wfItemvalue-item-".$item->id."-object-".$this->id, $new_value);
$item->setValue($new_value);
$this->workflowitems[$item->name] = $item;
}
foreach($item_ids as $id) {
mfValuecache::singleton()->set("wfItemvalue-item-".$id."-object-".$this->id, new Workflowvalue());
}
// get values
$values = WorkflowvalueModel::search(["object_id" => $this->id]);
//var_dump($values);exit;
foreach($values as $value) {
if(array_key_exists($value->item->name, $this->workflowitems)) {
//var_dump($value);exit;
$this->workflowitems[$value->item->name]->setValue($value);
mfValuecache::singleton()->set("wfItemvalue-item-".$value->item_id."-object-".$this->id, $value);
}
}
/*if($this->id == 42) {
//var_dump(array_keys(mfValuecache::singleton()->getCache()));exit;
var_dump(mfValuecache::singleton()->get("wfItemvalue-item-20-object-42"));exit;
}*/
}
public function getWorkflowvalue($itemname, $type = false) {
@@ -83,6 +80,7 @@ class Termination extends mfBaseModel {
mfValuecache::singleton()->set("wfTerm-name-".$itemname, $item);
mfValuecache::singleton()->set("wfTerm-id-".$item->id, $item);
}
$item->setObjectId($this->id);
switch($item->type) {
case "string":
@@ -116,9 +114,8 @@ class Termination extends mfBaseModel {
$value_type = "string";
}
if(array_key_exists($itemname, $this->getProperty("workflowitems"))) {
//$this->log->debug(__FILE__.": $itemname => ".$this->getProperty("workflowitems")[$itemname]->value->{"value_$value_type"});
return $this->getProperty("workflowitems")[$itemname]->value->{"value_$value_type"};
if(array_key_exists($itemname, $this->workflowitems)) {
return $this->workflowitems[$itemname]->value->{"value_$value_type"};
}
return null;
@@ -142,7 +139,6 @@ class Termination extends mfBaseModel {
$done = true;
foreach($item_names as $name) {
//$this->log->debug(__FILE__.": (Termination ".$this->id.") $name => $type == '".$this->getWorkflowvalue($name)."' (ist: '".$this->getWorkflowvalue("ist_".$name)."')");
if(!strlen($this->getWorkflowvalue($name)) && !strlen($this->getWorkflowvalue("ist_".$name))) {
$done = false;
break;

View File

@@ -12,6 +12,10 @@ class Workflowitem extends mfBaseModel {
return true;
}
public function unsetObjectId() {
$this->object_id = null;
}
public function setValue(Workflowvalue $value) {
$this->value = $value;
}
@@ -22,6 +26,14 @@ class Workflowitem extends mfBaseModel {
if($name == "value") {
if(!$this->object_id) {
$this->log->warn(__CLASS__."::getProperty('value'): Object ID not set");
$this->log->debug("[Backtrace] ================");
$this->log->debug("[Backtrace] START Backtrace");
$bt = debug_backtrace();
foreach($bt as $n => $b) {
$this->log->debug($n.") ".$b["file"]."(".$b['line']."): ".$b['class']."->".$b['function']."()" );
}
$this->log->debug("[Backtrace] $sql");
$this->log->debug("[Backtrace] END Backtrace");
return null;
}
$value = mfValuecache::singleton()->get("wfItemvalue-item-".$this->id."-object-".$this->object_id);

View File

@@ -137,6 +137,8 @@ class Workflowvalue extends mfBaseModel {
if(!$this->item) {
$this->item = new Workflowitem($this->item_id);
if($this->item->id) {
$item = $this->item;
$item->unsetObjectId();
mfValuecache::singleton()->set("wfItem-id-".$this->item->id, $this->item);
}
}

View File

@@ -94,7 +94,12 @@ class WorkflowvalueModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Workflowvalue", "*", $where);
$sql = "SELECT Workflowvalue.* FROM Workflowvalue
LEFT JOIN Workflowitem ON (Workflowitem.id = Workflowvalue.item_id)
WHERE $where";
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Workflowvalue($data);
@@ -137,6 +142,16 @@ class WorkflowvalueModel {
}
}
if(array_key_exists("object_type", $filter)) {
$object_type = $filter["object_type"];
if(strtolower($object_type) == "termination") {
$where .= " AND Workflowitem.object_type = 'Termination' ";
}
if(strtolower($object_type) == "building") {
$where .= " AND Workflowitem.object_type = 'Building' ";
}
}
//var_dump($filter, $where);exit;