diff --git a/application/controllers/components/stv/Status.php b/application/controllers/components/stv/Status.php index 1618a3d52..fa1ec9295 100644 --- a/application/controllers/components/stv/Status.php +++ b/application/controllers/components/stv/Status.php @@ -111,7 +111,14 @@ class Status extends FHC_Controller $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); return $this->outputJson(getError($result)); } - $lastStatusData = current(getData($result)); + elseif(!hasData($result)) + { + $lastStatusData = []; +/* $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + return $this->outputJson("donn holt nittan");*/ + } + else + $lastStatusData = current(getData($result)); //var_dump($lastStatusData); //Different handling depending on newStatus @@ -214,7 +221,7 @@ class Status extends FHC_Controller } } - //TODO(Manu) permission not working here... + //TODO(Manu) check permission... $hasPermissionToSkipStatusCheck = $this->permissionlib->isBerechtigt('student/keine_studdatuspruefung'); /* var_dump($hasPermissionToSkipStatusCheck); @@ -309,8 +316,9 @@ class Status extends FHC_Controller $status_kurzbz = $this->input->post('status_kurzbz'); $ausbildungssemester = $this->input->post('ausbildungssemester'); $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); + $deletePrestudent = false; - //TODO(Manu) check: warum sind beim Löschen andere Berechtigungen? + //TODO(Manu) check permissions: warum sind beim Löschen andere Berechtigungen? //ich darf keine Stati anlegen, aber löschen, wenn mehr als einer übrig??? /* $granted_Ass = $this->permissionlib->getSTG_isEntitledFor('assistenz'); $granted_Adm = $this->permissionlib->getSTG_isEntitledFor('admin'); @@ -346,22 +354,28 @@ class Status extends FHC_Controller } - if(!$isBerechtigtAdmin && !$isBerechtigtNoStudstatusCheck) + //check if last status + $result = $this->PrestudentstatusModel->checkIfLastStatusEntry($prestudent_id); + if (isError($result)) { - //check if last status - $result = $this->PrestudentstatusModel->checkIfLastStatusEntry($prestudent_id); - if (isError($result)) - { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson($result); - } - if($result->retval == "1") + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + return $this->outputJson($result); + } + if($result->retval == "1") + { + //Berechtigungen nach Check prüfen! + if(!$isBerechtigtAdmin && !$isBerechtigtNoStudstatusCheck) { $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); return $this->outputJson($result->code); } + else + { + $deletePrestudent = true; + } } + //TODO(manu) $this->db->trans_start(false); and rollback? //Delete Status $result = $this->PrestudentstatusModel->delete( array( @@ -376,29 +390,31 @@ class Status extends FHC_Controller $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); $this->outputJson($result); } - elseif(!hasData($result)) { + if(!hasData($result)) { $this->outputJson($result); } - //return $this->outputJsonSuccess(current(getData($result))); - // Delete Studentlehrverband if no Status left + //Delete Studentlehrverband if no Status left $result = $this->PrestudentstatusModel->getLastStatus($prestudent_id, $studiensemester_kurzbz); - if(isError($result)) - { + if (isError($result)) { $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); return $this->outputJson(getError($result)); } - if(!hasData($result)) + if (!hasData($result)) { //get student_uid $this->load->model('crm/Student_model', 'StudentModel'); $result = $this->StudentModel->checkIfUid($prestudent_id); - if(isError($result)) + if (isError($result)) { $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); return $this->outputJson(getError($result)); } + if (!hasData($result)) + { + $this->outputJson($result); + } $student_uid = $result->retval; $this->load->model('education/Studentlehrverband_model', 'StudentlehrverbandModel'); @@ -413,16 +429,42 @@ class Status extends FHC_Controller $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); $this->outputJson("Fehler beim Löschen der Lehrverbandszuordnung"); } - if(!hasData($result)) { + if (!hasData($result)) + { + $this->outputJson($result); + var_dump("no data2"); + } + $this->outputJsonSuccess(true); + + } + + //Delete Prestudent if no data is left + if($deletePrestudent) + { + //TODO(manu) check all connected tables and delete them + //es wird noch auf prestudent_dokumentprestudent verwiesen + //löschen zuerst von Doks + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $result = $this->PrestudentModel->delete( + array( + 'prestudent_id' => $prestudent_id + ) + ); + if (isError($result)) + { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); $this->outputJson($result); } - return $this->outputJsonSuccess(true); + if(!hasData($result)) + { + $this->outputJson($result); + } + $this->outputJson($result); + + } - //TODO(manu) $this->db->trans_start(false); and rollback? - //TODO(manu) ganzen Prestudenten löschen, wenn kein Eintrag mehr + return $this->outputJsonSuccess(true); - - } public function updateStatus($key_prestudent_id, $key_status_kurzbz, $key_studiensemester_kurzbz, $key_ausbildungssemester) @@ -498,7 +540,7 @@ class Status extends FHC_Controller } } - //TODO(Manu) permission not working here... + //TODO(Manu) check permissions $hasPermissionToSkipStatusCheck = $this->permissionlib->isBerechtigt('student/keine_studdatuspruefung'); /* var_dump($hasPermissionToSkipStatusCheck); diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 08653c481..1938e661a 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -743,7 +743,7 @@ class Prestudent_model extends DB_Model { return getData($result); } - if($result->retval != "0") + if($result->retval == "0") //wenn kein studentlehrband eingetragen { $query = " SELECT @@ -782,7 +782,7 @@ class Prestudent_model extends DB_Model { $query = " SELECT - ps.status_kurzbz2, + ps.status_kurzbz, ps.studiensemester_kurzbz, ps.ausbildungssemester, CASE WHEN ps.status_kurzbz IN ('Student', 'Diplomand') THEN CONCAT(lv.semester, lv.verband, lv.gruppe) END AS lehrverband, diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index e824ebaf3..593a13452 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -504,13 +504,19 @@ class Prestudentstatus_model extends DB_Model $new_status_semesterstart = $studiensemester->start; //get all prestudentstati + //TODO(manu) errorlogic $resultPs = $this->getAllPrestudentstatiWithStudiensemester($prestudent_id); if (isError($resultPs)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($resultPs)); + $resultArr = []; } - $resultArr = $resultPs->retval; + if(!hasData($resultPs)) + { + $resultArr = []; + } + else + $resultArr = $resultPs->retval; + $statusArr = array(); $newStatusInserted = false; @@ -625,7 +631,7 @@ class Prestudentstatus_model extends DB_Model return error($result); } if (!hasData($result)) { - return error('No Statusdata vorhanden'); + return success("0",'No Statusdata vorhanden'); } return $result; diff --git a/application/models/crm/Student_model.php b/application/models/crm/Student_model.php index 9ccaff1a4..364524df9 100644 --- a/application/models/crm/Student_model.php +++ b/application/models/crm/Student_model.php @@ -82,7 +82,7 @@ class Student_model extends DB_Model if(isError($result)) { - return error("0", "Error while checking student_uid"); + return error( "Error while checking student_uid"); } if (!hasData($result)) diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Prestudent.js b/public/js/components/Stv/Studentenverwaltung/Details/Prestudent.js index aaab14983..7f3517ee9 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Prestudent.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Prestudent.js @@ -198,6 +198,7 @@ export default {