Merge branch 'fronkdev' into 'master'
Added Journal/History/Contacts to ConstructionConsent See merge request fronk/thetool!938
This commit is contained in:
@@ -7,16 +7,44 @@ class ConstructionConsent extends mfBaseModel {
|
||||
private $adb_hausnummer;
|
||||
private $adb_strasse;
|
||||
private $owners;
|
||||
private $contacts;
|
||||
private $file;
|
||||
private $creator;
|
||||
private $editor;
|
||||
private $preorder_count;
|
||||
private $journal;
|
||||
private $history;
|
||||
|
||||
private $footer_text = "Energie Steiermark Breitband GmbH, A-8010 Graz, Leonhardgürtel 10, Telefon +43 (0)316 9000-0\nSitz Graz, FN 576705x, Landesgericht für ZRS Graz, ATU 77949678, breitband@e-steiermark.com, www.e-steiermark.com";
|
||||
private $footer_font = "ITC Officina Sans Std";
|
||||
private $footer_size = "8";
|
||||
|
||||
|
||||
protected function afterSave() {
|
||||
$this->createHistory();
|
||||
}
|
||||
|
||||
private function createHistory() {
|
||||
if(!$this->id) return true;
|
||||
|
||||
$changed = $this->getChangedFields();
|
||||
|
||||
try {
|
||||
foreach($changed as $field) {
|
||||
$this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
|
||||
$history = ConstructionConsentHistory::create([
|
||||
"constructionconsent_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());
|
||||
}
|
||||
}
|
||||
|
||||
public function createConsentFormPdf(ConstructionConsentOwner $owner = null) : ?string {
|
||||
if($owner) {
|
||||
$owners = [$owner];
|
||||
@@ -53,6 +81,21 @@ class ConstructionConsent extends mfBaseModel {
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "journal") {
|
||||
$journal = ConstructionConsentJournal::search(["constructionconsent_id" => $this->id], false, "id DESC");
|
||||
if($journal) {
|
||||
$this->journal = $journal;
|
||||
}
|
||||
return $journal;
|
||||
}
|
||||
if($name == "history") {
|
||||
$history = ConstructionConsentHistory::search(["constructionconsent_id" => $this->id], false, "id DESC");
|
||||
if($history) {
|
||||
$this->history = $history;
|
||||
}
|
||||
return $history;
|
||||
}
|
||||
|
||||
if($name == "project") {
|
||||
$project = new ConstructionConsentProject($this->constructionconsentproject_id);
|
||||
if($project->id) {
|
||||
@@ -98,7 +141,7 @@ class ConstructionConsent extends mfBaseModel {
|
||||
}
|
||||
|
||||
if($name == "owners") {
|
||||
if(!$this->id) return null;
|
||||
if(!$this->id) return [];
|
||||
|
||||
$owners = ConstructionConsentOwner::search(["constructionconsent_id" => $this->id]);
|
||||
if(count($owners)) {
|
||||
@@ -107,8 +150,23 @@ class ConstructionConsent extends mfBaseModel {
|
||||
return $this->owners;
|
||||
}
|
||||
|
||||
if($name == "contacts") {
|
||||
if(!$this->id) return [];
|
||||
$contacts = [];
|
||||
foreach(ConstructionConsentContact::search(["constructionconsent_id" => $this->id]) as $contact) {
|
||||
if(!array_key_exists($contact->type, $contacts)) {
|
||||
$contacts[$contact->type] = [];
|
||||
}
|
||||
$contacts[$contact->type][] = $contact;
|
||||
}
|
||||
if(count($contacts)) {
|
||||
$this->contacts = $contacts;
|
||||
}
|
||||
return $contacts;
|
||||
}
|
||||
|
||||
if($name == "file") {
|
||||
if(!$this->id) return null;
|
||||
if(!$this->id) return [];
|
||||
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id]);
|
||||
if($file) {
|
||||
$this->file = $file;
|
||||
|
||||
@@ -268,9 +268,22 @@ class ConstructionConsentController extends mfBaseController {
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
$history = ConstructionConsentHistory::create([
|
||||
"constructionconsent_id" => $item->id,
|
||||
"key" => "plan_upload",
|
||||
"old_value" => ($item->file) ? $item->file->file->id : null,
|
||||
"new_value" => $file->id
|
||||
]);
|
||||
|
||||
} else {
|
||||
if($r->submit_plan_file_id) {
|
||||
$file = new File($r->submit_plan_file_id);
|
||||
$history = ConstructionConsentHistory::create([
|
||||
"constructionconsent_id" => $item->id,
|
||||
"key" => "rimo_plan",
|
||||
"old_value" => ($item->file) ? $item->file->file->id : null,
|
||||
"new_value" => $file->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,6 +304,8 @@ class ConstructionConsentController extends mfBaseController {
|
||||
if (!$ccf->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern des Plans", "warning");
|
||||
}
|
||||
|
||||
$history->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
class ConstructionConsentContact extends mfBaseModel {
|
||||
private $consent;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ConstructionConsentContact();
|
||||
|
||||
$table_fields = [
|
||||
"constructionconsent_id", "type", "name", "street", "zip", "city",
|
||||
"phone", "fax", "email", "create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ConstructionConsentContact", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ConstructionConsentContact($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT ConstructionConsentContact.* FROM ConstructionConsentContact
|
||||
WHERE $where
|
||||
ORDER BY adb_netzgebiet_id
|
||||
LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ConstructionConsentContact($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM ConstructionConsentContact
|
||||
WHERE $where
|
||||
ORDER BY adb_netzgebiet_id
|
||||
";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$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, $order = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "name ASC";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT ConstructionConsentContact.* FROM ConstructionConsentContact
|
||||
WHERE $where
|
||||
GROUP BY ConstructionConsentContact.id
|
||||
ORDER BY $order";
|
||||
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ConstructionConsentContact($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
|
||||
if(array_key_exists("constructionconsent_id", $filter)) {
|
||||
$constructionconsent_id = $filter["constructionconsent_id"];
|
||||
if(is_numeric($constructionconsent_id)) {
|
||||
$where .= " AND constructionconsent_id='$constructionconsent_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("type", $filter)) {
|
||||
$type = $db->escape($filter["type"]);
|
||||
if($type) {
|
||||
$where .= " AND `type`='$type'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
class ConstructionConsentContactController extends mfBaseController
|
||||
{
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
$this->needlogin = true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me", $me);
|
||||
|
||||
if (!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
//var_dump($r->get());exit;
|
||||
$id = $r->contact_id;
|
||||
if (is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$item = new ConstructionConsentContact($id);
|
||||
if (!$item->id) {
|
||||
$this->layout()->setFlash("Ansprechpartner nicht gefunden", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$cc_id = $r->constructionconsent_id;
|
||||
$cc = new ConstructionConsent($cc_id);
|
||||
if(!$cc_id || !$cc->id) {
|
||||
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data["constructionconsent_id"] = $cc_id;
|
||||
$data["type"] = $r->type;
|
||||
$data["name"] = $r->name;
|
||||
$data["street"] = $r->street;
|
||||
$data["zip"] = $r->zip;
|
||||
$data["city"] = $r->city;
|
||||
$data["country"] = $r->country;
|
||||
$data["phone"] = $r->phone;
|
||||
$data["fax"] = $r->fax;
|
||||
$data["email"] = $r->email;
|
||||
|
||||
if($mode == "add") {
|
||||
$item = ConstructionConsentContact::create($data);
|
||||
} else {
|
||||
$item->update($data);
|
||||
}
|
||||
|
||||
if(!$item->save()) {
|
||||
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
|
||||
} else {
|
||||
$this->layout()->setFlash("Ansprechpartner wurde erfolgreich gespeichert.", "success");
|
||||
}
|
||||
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $cc_id]);
|
||||
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get());exit;
|
||||
$id = $r->contact_id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Ansprechpartner nicht gefunden", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
|
||||
$contact = new ConstructionConsentContact($id);
|
||||
if(!$contact->id) {
|
||||
$this->layout()->setFlash("Ansprechpartner nicht gefunden", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
|
||||
$cc_id = $contact->constructionconsent_id;
|
||||
$cc = new ConstructionConsent($cc_id);
|
||||
if(!$cc_id || !$cc->id) {
|
||||
$this->layout()->setFlash("Beim Löschen ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
|
||||
$contact->delete();
|
||||
|
||||
$this->layout()->setFlash("Ansprechpartner wurde gelöscht.", "success");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $cc_id]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
class ConstructionConsentHistory extends mfBaseModel {
|
||||
private $consent;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
public function getValue($type = "new", $raw = false) {
|
||||
if($type != "old" && $type != "new") return null;
|
||||
|
||||
if($type == "new") {
|
||||
$value = $this->new_value;
|
||||
} else {
|
||||
$value = $this->old_value;
|
||||
}
|
||||
|
||||
if($raw) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$m = [];
|
||||
if(preg_match('/(.+)_id/', $this->key, $m)) {
|
||||
if(array_key_exists(1, $m)) {
|
||||
$object = ucfirst($m[1]);
|
||||
if($object == "Status") $object = "Preorderstatus";
|
||||
if($object == "Partner") $object = "Address";
|
||||
if($object == "Adb_hausnummer") $object = "ADBHausnummer";
|
||||
if($object == "Adb_wohneinheit") $object = "ADBWohneinheit";
|
||||
if($object == "Constructionconsentproject") $object = "ConstructionConsentProject";
|
||||
if(class_exists($object)) {
|
||||
$value = new $object($value);
|
||||
if(!$value->id) return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getKey() {
|
||||
$key = $this->key;
|
||||
|
||||
if(preg_match('/^preorderstatusflag-(\d+)-/', $key, $m)) {
|
||||
if(array_key_exists(1, $m)) {
|
||||
$id = $m[1];
|
||||
$psf = new Preorderstatusflag($id);
|
||||
return "Status Flag ".$psf->code." - ".$psf->name;
|
||||
}
|
||||
}
|
||||
|
||||
switch($key) {
|
||||
case "usage_length":
|
||||
return "Nutzung Länge";
|
||||
case "usage_pipe_on_plot":
|
||||
return "Nutzung LWL auf Gst.";
|
||||
case "usage_pipe_in_building":
|
||||
return "Nutzung LWL in Gebäuden";
|
||||
case "usage_manhole":
|
||||
return "Nutzung Schacht/Verteiler/Abschluss";
|
||||
case "usage_owner":
|
||||
return "Nutzung Eigenvers. GE";
|
||||
|
||||
case "rimo_plan":
|
||||
return "Plan/Skizze aus Rimo";
|
||||
case "plan_upload":
|
||||
return "Plan/Skizze Upload";
|
||||
case "constructionconsentproject_id":
|
||||
return "Projekt";
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if(get_class($value) == "ConstructionConsentProject") {
|
||||
return $value->name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "old" || $name == "new") {
|
||||
return $this->getValue($name, false);
|
||||
}
|
||||
if($name == "old_raw") {
|
||||
return $this->getValue("old", true);
|
||||
}
|
||||
if($name == "new_raw") {
|
||||
return $this->getValue("new", true);
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
$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 = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||
if($this->editor === null) {
|
||||
$this->editor = new User($this->edit_by);
|
||||
if($this->editor->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new ConstructionConsentHistory();
|
||||
|
||||
$table_fields = [
|
||||
"constructionconsent_id", "key", "old_value", "new_value",
|
||||
"create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
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 getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("ConstructionConsentHistory", "*", "1 = 1 ORDER BY `create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new ConstructionConsentHistory($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT ConstructionConsentHistory.* FROM ConstructionConsentHistory
|
||||
WHERE $where
|
||||
ORDER BY adb_netzgebiet_id
|
||||
LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ConstructionConsentHistory($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM ConstructionConsentHistory
|
||||
WHERE $where
|
||||
ORDER BY adb_netzgebiet_id
|
||||
";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$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, $order = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "`create` ASC";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT ConstructionConsentHistory.* FROM ConstructionConsentHistory
|
||||
WHERE $where
|
||||
GROUP BY ConstructionConsentHistory.id
|
||||
ORDER BY $order";
|
||||
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new ConstructionConsentHistory($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
|
||||
if(array_key_exists("constructionconsent_id", $filter)) {
|
||||
$constructionconsent_id = $filter["constructionconsent_id"];
|
||||
if(is_numeric($constructionconsent_id)) {
|
||||
$where .= " AND constructionconsent_id='$constructionconsent_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("key", $filter)) {
|
||||
$key = $db->escape($filter["key"]);
|
||||
if($key) {
|
||||
$where .= " AND `key`='$key'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,32 @@
|
||||
|
||||
class ConstructionConsentJournal extends mfBaseModel {
|
||||
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
$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 = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||
if($this->editor === null) {
|
||||
$this->editor = new User($this->edit_by);
|
||||
if($this->editor->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||
}
|
||||
}
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
@@ -33,7 +56,7 @@ class ConstructionConsentJournal extends mfBaseModel {
|
||||
$model = new ConstructionConsentJournal();
|
||||
|
||||
$table_fields = [
|
||||
"constructionconsent_id", "type", "value", "text",
|
||||
"constructionconsent_id", "text",
|
||||
"create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
class ConstructionConsentJournalController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r);exit;
|
||||
$consent_id = $r->consent_id;
|
||||
|
||||
if(!is_numeric($consent_id) || $consent_id < 1) {
|
||||
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden!", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
|
||||
$consent = new ConstructionConsent($consent_id);
|
||||
if(!$consent->id) {
|
||||
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden!", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
|
||||
$text = trim(htmlentities($r->text));
|
||||
if(!$text) {
|
||||
$this->layout()->setFlash("Bitte Text eingeben", "error");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
|
||||
}
|
||||
|
||||
|
||||
$journal = ConstructionConsentJournal::create([
|
||||
"constructionconsent_id" => $consent->id,
|
||||
"text" => $text
|
||||
]);
|
||||
|
||||
if(!$journal->save()) {
|
||||
$this->layout()->setFlash("Fehler beim speichern!", "error");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Journaleintrag gespeichert", "success");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,31 @@ class ConstructionConsentOwner extends mfBaseModel {
|
||||
private $result_file;
|
||||
|
||||
|
||||
protected function afterSave() {
|
||||
$this->createHistory();
|
||||
}
|
||||
|
||||
private function createHistory() {
|
||||
if(!$this->id) return true;
|
||||
|
||||
$changed = $this->getChangedFields();
|
||||
|
||||
try {
|
||||
foreach($changed as $field) {
|
||||
$this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'");
|
||||
$history = ConstructionConsentHistory::create([
|
||||
"constructionconsent_id" => $this->id,
|
||||
"key" => "owner-".$this->id."-$field",
|
||||
"old_value" => $this->_old_data->$field,
|
||||
"new_value" => $this->data->$field
|
||||
]);
|
||||
$history->save();
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$this->log->debug($e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ class ConstructionConsentOwnerController extends mfBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!in_array($new_status, ["new", "requested", "answered"])) {
|
||||
if(!in_array($new_status, ['new', 'sent', 'returned', 'outstanding'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -164,26 +164,16 @@ class ConstructionConsentOwnerController extends mfBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
// allow empty result
|
||||
if($new_result) {
|
||||
if(!in_array($new_result, ["success", "failure"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$owner->result = $new_result;
|
||||
} else {
|
||||
$owner->result = null;
|
||||
if(!in_array($new_result, ['open', 'accepted', 'denied', 'unresolvable'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$owner->result = $new_result;
|
||||
if(!$owner->save()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($owner->result) {
|
||||
return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => $owner->result, "result_text" => __($owner->result, "consent")]];
|
||||
} else {
|
||||
return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => null, "result_text" => ""]];
|
||||
}
|
||||
return ["message" => "Result saved successfully", "update" => ["id" => $owner->id, "result" => $owner->result, "result_text" => __($owner->result, "consent")]];
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user