diff --git a/application/controllers/system/infocenter/InfoCenter.php b/application/controllers/system/infocenter/InfoCenter.php index f8e46a8bf..57aca0876 100644 --- a/application/controllers/system/infocenter/InfoCenter.php +++ b/application/controllers/system/infocenter/InfoCenter.php @@ -2375,10 +2375,6 @@ class InfoCenter extends Auth_Controller if ($statusgrund === 'null' || $studiengang === 'null' || $abgeschickt === 'null' || empty($personen)) $this->terminateWithJsonError("Bitte füllen Sie alle Felder aus"); - if ($studiengang === 'all' && $abgeschickt !== 'all' || - $abgeschickt === 'all' && $studiengang !== 'all') - $this->terminateWithJsonError("Absage für alle Studiengänge ist nur in Kombination mit abgeschickt 'Beide' möglich!"); - if ($studiengang === 'all' && $abgeschickt === 'all') { foreach($personen as $person) @@ -2398,16 +2394,31 @@ class InfoCenter extends Auth_Controller } else { - foreach($personen as $person) + $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); + + $this->StudienplanModel->addSelect('1'); + $this->StudienplanModel->addJoin('lehre.tbl_studienordnung so', 'studienordnung_id'); + $escaped = $this->StudienplanModel->db->escape(strtoupper($studiengang)); + $this->StudienplanModel->db->where("UPPER(so.studiengangkurzbzlang || ':' || tbl_studienplan.orgform_kurzbz) = $escaped"); + $this->StudienplanModel->addLimit(1); + $studiengangResult = $this->StudienplanModel->load(); + + if (hasData($studiengangResult)) { - $prestudent = $this->PrestudentModel->getPrestudentByStudiengangAndPerson($studiengang, $person, $studienSemester, $abgeschickt); + foreach($personen as $person) + { + $prestudent = $this->PrestudentModel->getPrestudentByStudiengangAndPerson($studiengang, $person, $studienSemester, $abgeschickt, $abgeschickt === 'all'); - if (!hasData($prestudent)) - continue; + if (!hasData($prestudent)) + continue; - $prestudentData = getData($prestudent); - $this->saveAbsage($prestudentData[0]->prestudent_id, $statusgrund); + $prestudentData = getData($prestudent); + $this->saveAbsage($prestudentData[0]->prestudent_id, $statusgrund); + } } + else + $this->terminateWithJsonError("Falschen Studiengang übergeben!"); + } $this->outputJsonSuccess("Success"); diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 188158b4e..ff56c3268 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -677,7 +677,7 @@ class Prestudent_model extends DB_Model )); } - public function getPrestudentByStudiengangAndPerson($studiengang, $person, $studienSemester, $abgeschickt) + public function getPrestudentByStudiengangAndPerson($studiengang, $person, $studienSemester, $abgeschickt, $ignoreAbgeschickt = false) { $query = "SELECT ps.prestudent_id FROM public.tbl_prestudentstatus pss @@ -687,18 +687,22 @@ class Prestudent_model extends DB_Model JOIN lehre.tbl_studienordnung so USING(studienordnung_id) WHERE ps.person_id = ? AND UPPER(so.studiengangkurzbzlang || ':' || sp.orgform_kurzbz) = ? - AND pss.studiensemester_kurzbz = ? - AND"; + AND pss.studiensemester_kurzbz = ?"; - if ($abgeschickt === 'true') - $query .= " EXISTS"; - else - $query .= " NOT EXISTS"; + if (!$ignoreAbgeschickt) + { + $query .= "AND"; - $query .= " (SELECT 1 FROM public.tbl_prestudentstatus spss + if ($abgeschickt === 'true') + $query .= " EXISTS"; + else + $query .= " NOT EXISTS"; + + $query .= " (SELECT 1 FROM public.tbl_prestudentstatus spss JOIN public.tbl_prestudent sps USING(prestudent_id) WHERE sps.prestudent_id = ps.prestudent_id AND spss.bewerbung_abgeschicktamum IS NOT NULL)"; + } return $this->execQuery($query, array($person, $studiengang, $studienSemester)); }