ADB Statusflag done & Preorder statusflag import
This commit is contained in:
@@ -7,6 +7,7 @@ class ADBHausnummer extends mfBaseModel {
|
||||
private $strasse;
|
||||
private $plz;
|
||||
private $status;
|
||||
private $statusflags;
|
||||
private $freigaben = [];
|
||||
private $wohneinheiten = [];
|
||||
|
||||
@@ -173,6 +174,18 @@ class ADBHausnummer extends mfBaseModel {
|
||||
$this->status = new ADBStatus($this->status_id);
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
if($name == "statusflags") {
|
||||
$flags = [];
|
||||
foreach(ADBStatusflagModel::getAll() as $flag) {
|
||||
$flag->hausnummer_id = $this->id;
|
||||
$flags[$flag->id] = $flag;
|
||||
}
|
||||
if(count($flags)) {
|
||||
$this->statusflags = $flags;
|
||||
}
|
||||
return $this->statusflags;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
|
||||
@@ -1,9 +1,64 @@
|
||||
<?php
|
||||
|
||||
class ADBStatusflag extends mfBaseModel {
|
||||
private $value;
|
||||
public $hausnummer_id;
|
||||
|
||||
|
||||
public function init() {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$this->table = "Statusflag";
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "value") {
|
||||
if(!$this->hausnummer_id) return null;
|
||||
$value = ADBHausnummerStatusflagValueModel::getFirst(["hausnummer_id" => $this->hausnummer_id, "flag_id" => $this->id]);
|
||||
if(!$value) {
|
||||
$value = ADBHausnummerStatusflagValueModel::create([
|
||||
"hausnummer_id" => $this->hausnummer_id,
|
||||
"flag_id" => $this->id
|
||||
]);
|
||||
}
|
||||
$this->value = $value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($user) {
|
||||
$this->creator = $user;
|
||||
return $this->creator;
|
||||
}
|
||||
$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 = new User($this->edit_by);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ class Preorder extends mfBaseModel {
|
||||
mfValuecache::singleton()->set("preorder-save-nesting-level-" . $this->id, $nesting_level);
|
||||
|
||||
if($nesting_level > 1) {
|
||||
$this->log->debug(__METHOD__.": (Preorder ".$this->id.") Nesting level limit reached ($nesting_level) -> aborting");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -73,7 +74,10 @@ class Preorder extends mfBaseModel {
|
||||
$this->cascadeStatus();
|
||||
// Cascade status changes down all active preorders with the same hausnummer
|
||||
$this->cascadeStatusToPreorders();
|
||||
}
|
||||
|
||||
public function resetSaveNesting() {
|
||||
mfValuecache::singleton()->delete("preorder-save-nesting-level-" . $this->id);
|
||||
}
|
||||
|
||||
public function createHistoryEntry() {
|
||||
@@ -158,7 +162,7 @@ class Preorder extends mfBaseModel {
|
||||
* Cascade status changes down to adb_hausnummer and adb_wohneinheit
|
||||
*/
|
||||
public function cascadeStatus() {
|
||||
|
||||
$this->log->debug(__METHOD__. " entered");
|
||||
/*
|
||||
* defines status alignments of preorder status to hausnummer (h) and wohneinheit (w)
|
||||
* if h or w are greater than defined here, don't change them
|
||||
|
||||
@@ -780,12 +780,36 @@ class PreorderController extends mfBaseController {
|
||||
$invalidcode = 0;
|
||||
$nochange = 0;
|
||||
$saved = 0;
|
||||
$flags_saved = 0;
|
||||
|
||||
$statusflags = [];
|
||||
|
||||
$filename = $file->getFullPath();
|
||||
$input = fopen($filename, "r");
|
||||
while($csv = fgetcsv($input, 0, ";")) {
|
||||
$i++;
|
||||
if($i == 1 && $headline_included) continue;
|
||||
|
||||
if($i == 1 && $headline_included) {
|
||||
// get statusflag order in header
|
||||
$col = 2;
|
||||
while(array_key_exists($col, $csv) && trim($csv[$col])) {
|
||||
$code = trim($csv[$col]);
|
||||
if(!is_numeric($code)) {
|
||||
$this->layout()->setFlash("Ungültige Überschrift für Spalte ".++$col, "error");
|
||||
$this->redirect("Preorder", "statusupdateimport");
|
||||
}
|
||||
|
||||
$sflag = PreorderStatusflagModel::getFirst(["code" => $code]);
|
||||
if(!$sflag) {
|
||||
$this->layout()->setFlash("Statusflag mit Code $code nicht gefunden", "error");
|
||||
$this->redirect("Preorder", "statusupdateimport");
|
||||
}
|
||||
$sflag->col = $col;
|
||||
$statusflags[$code] = $sflag;
|
||||
$col++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!trim($csv[0])) {
|
||||
continue;
|
||||
@@ -813,23 +837,69 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
$preorder->status_id = $new_status->id;
|
||||
$preorder->save();
|
||||
$preorder->resetSaveNesting();
|
||||
$saved++;
|
||||
} else {
|
||||
$nochange++;
|
||||
}
|
||||
|
||||
if(count($statusflags)) {
|
||||
foreach($statusflags as $code => $origin_sflag) {
|
||||
$this->log->debug(__METHOD__.": $oaid - testing flag $code for update.");
|
||||
$sflag = clone($origin_sflag);
|
||||
$sflag->preorder_id = $preorder->id;
|
||||
|
||||
if(!$sflag->col) {
|
||||
$this->layout()->setFlash("Kann Statusflagcode $code nicht zuordnen. Line $i col ".$sflag->col, "error");
|
||||
$this->redirect("Preorder", "statusupdateimport");
|
||||
}
|
||||
|
||||
if(!array_key_exists($sflag->col, $csv)) {
|
||||
$this->log->debug(__METHOD__.": no col.");
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = trim($csv[$sflag->col]);
|
||||
if(!strlen($value)) {
|
||||
$this->log->debug(__METHOD__.": no val");
|
||||
continue;
|
||||
}
|
||||
|
||||
if($value) {
|
||||
$sflag->value->value = 1;
|
||||
} else {
|
||||
$sflag->value->value = 0;
|
||||
}
|
||||
|
||||
$this->log->debug(__METHOD__.": $oaid - saving flag value $code value: ".$sflag->value->value." ($value)");
|
||||
$sflag->value->save();
|
||||
|
||||
$flags_saved++;
|
||||
//$this->log->debug(__METHOD__.": $oaid - loading preorder again");
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirstActive(["oaid" => $oaid]);
|
||||
$preorder->resetSaveNesting();
|
||||
$preorder->afterSave();
|
||||
$preorder = PreorderModel::getFirstActive(["oaid" => $oaid]);
|
||||
$preorder->resetSaveNesting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$message = "Import erfolgreich. $saved Statusupdates importiert";
|
||||
if($flags_saved) {
|
||||
$message .= "<br />$flags_saved Statusflags upgedatet";
|
||||
}
|
||||
if($notfound) {
|
||||
$message .= "<br />$notfound Bestellungen nicht gefunden";
|
||||
}
|
||||
if($forbidden) {
|
||||
$message .= "<br />$forbidden Bestellungen in falschem Netzgebiet";
|
||||
}
|
||||
if($nochange) {
|
||||
/*if($nochange) {
|
||||
$message .= "<br />$nochange Bestelllungen haben bereits den neuen Status";
|
||||
}
|
||||
}*/
|
||||
if($invalidcode) {
|
||||
$message .= "<br />$invalidcode ungültige Statuscodes";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user