Added Document upload to ConstructionConsent Owners
This commit is contained in:
@@ -16,6 +16,44 @@ class ConstructionConsentOwnerController extends mfBaseController
|
||||
}
|
||||
}
|
||||
|
||||
protected function uploadDocumentAction() {
|
||||
$owner_id = $this->request->owner_id;
|
||||
$filename = trim($this->request->name);
|
||||
|
||||
$owner = new ConstructionConsentOwner($owner_id);
|
||||
if(!$owner->id) {
|
||||
$this->layout()->setFlash("Besitzer nicht gefunden!", "error");
|
||||
$this->redirect("ConstructionConsent");
|
||||
}
|
||||
|
||||
if(is_array($_FILES) && array_key_exists("consentOwnerUpload", $_FILES) && !$_FILES['consentOwnerUpload']['error']) {
|
||||
try {
|
||||
// returns File object or throws Exception on error
|
||||
$file = mfUpload::handleFormUpload("consentOwnerUpload", false, TT_CONSTRUCTIONCONSENT_FILE_UPLOAD_SUBFOLDER);
|
||||
} catch (Exception $ex) {
|
||||
$this->layout()->setFlash("Fehler beim Hochladen: " . $ex->getMessage(), "warning");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
$ccof = ConstructionConsentOwnerFile::create([
|
||||
'constructionconsentowner_id' => $owner->id,
|
||||
'file_id' => $file->id,
|
||||
'filename' => $filename,
|
||||
]);
|
||||
|
||||
if(!$ccof->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Hochladen", "error");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $owner->constructionconsent_id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Datei erfolgreich hochgeladen", "success");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $owner->constructionconsent_id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Keine Datei ausgewählt", "info");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $owner->constructionconsent_id]);
|
||||
}
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
@@ -67,4 +105,85 @@ class ConstructionConsentOwnerController extends mfBaseController
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $cc_id]);
|
||||
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "updateStatus":
|
||||
$return = $this->updateStatusApi();
|
||||
break;
|
||||
case "updateResult":
|
||||
$return = $this->updateResultApi();
|
||||
break;
|
||||
default:
|
||||
$this->log->warn(__METHOD__ . ": Called API function '$do' does not exist");
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function updateStatusApi() {
|
||||
$owner_id = trim($this->request->id);
|
||||
$new_status = trim($this->request->status);
|
||||
|
||||
$owner = new ConstructionConsentOwner($owner_id);
|
||||
if(!$owner->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!in_array($new_status, ["new", "requested", "answered"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$owner->status = $new_status;
|
||||
if(!$owner->save()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ["message" => "Status saved successfully", "update" => ["id" => $owner->id, "status" => $owner->status, "status_text" => __($owner->status, "consent")]];
|
||||
}
|
||||
|
||||
private function updateResultApi() {
|
||||
$owner_id = trim($this->request->id);
|
||||
$new_result = trim($this->request->result);
|
||||
|
||||
$owner = new ConstructionConsentOwner($owner_id);
|
||||
if(!$owner->id) {
|
||||
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(!$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" => ""]];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user