diff --git a/application/controllers/jobs/Prestudentstatus.php b/application/controllers/jobs/Prestudentstatus.php index 2f3e3aa95..7d9bb60b7 100644 --- a/application/controllers/jobs/Prestudentstatus.php +++ b/application/controllers/jobs/Prestudentstatus.php @@ -61,7 +61,8 @@ class Prestudentstatus extends FHC_Controller tbl_prestudentstatus.status_kurzbz, tbl_prestudent.studiengang_kz, tbl_prestudentstatus.studienplan_id, - tbl_studienplan.orgform_kurzbz'); + tbl_studienplan.orgform_kurzbz, + tbl_prestudent.person_id'); $this->PrestudentstatusModel->addJoin('public.tbl_prestudent', 'prestudent_id'); $this->PrestudentstatusModel->addJoin('lehre.tbl_studienplan', 'studienplan_id','LEFT'); $this->PrestudentstatusModel->addJoin('lehre.tbl_studienordnung', 'studienordnung_id','LEFT'); @@ -105,6 +106,14 @@ class Prestudentstatus extends FHC_Controller $this->PrestudentstatusModel->update($pk_arr, array('studienplan_id' => $studienplan->retval[0]->studienplan_id)); $sum_corrected++; + + if($row_status->status_kurzbz == 'Interessent') + { + $this->correctReihungstest( + $row_status->person_id, + $row_status->studienplan_id, + $studienplan->retval[0]->studienplan_id); + } } } else @@ -124,4 +133,58 @@ class Prestudentstatus extends FHC_Controller echo "Not Corrected:".$sum_notcorrected."\n"; echo "Overall incorrect:".$sum_overall."\n"; } + + /** + * Corrects the Assignment to a Placement Test + * Corrects the Studyplan and adds the Studyplan to the Placement test + * @param $person_id ID of the Person + * @param $studienplan_id_old ID of the old Studyplan + * @param $studienplan_id ID of the new Studyplan + */ + private function correctReihungstest($person_id, $studienplan_id_old, $studienplan_id) + { + $this->load->model('crm/RtPerson_model', 'RtPersonModel'); + $this->load->model('crm/RtStudienplan_model', 'RtStudienplanModel'); + + $this->RtPersonModel->resetQuery(); + // Correct also Assignments to Placement test + $this->RtPersonModel->addJoin( + 'public.tbl_reihungstest', + 'tbl_reihungstest.reihungstest_id = tbl_rt_person.rt_id' + ); + + $rt = $this->RtPersonModel->loadWhere(array( + "person_id" => $person_id, + "studienplan_id" => $studienplan_id_old + )); + + // "tbl_reihungstest.datum > " => date('Y-m-d H:i:s') + + if(hasData($rt)) + { + foreach($rt->retval as $row_rt) + { + // Update RTPerson Record + $this->RtPersonModel->update($row_rt->rt_person_id, array( + 'studienplan_id' => $studienplan_id, + 'updateamum' => date('Y-m-d H:i:s'), + 'updatevon' => 'cron' + )); + + // Add new Studyplan to RtStudienplan if missing + $rt_studienplan = $this->RtStudienplanModel->loadWhere(array( + "reihungstest_id" => $row_rt->reihungstest_id, + "studienplan_id" => $studienplan_id + )); + + if(!hasData($rt_studienplan)) + { + $this->RtStudienplanModel->insert(array( + "reihungstest_id" => $row_rt->reihungstest_id, + "studienplan_id" => $studienplan_id + )); + } + } + } + } } diff --git a/application/models/crm/RtStudienplan_model.php b/application/models/crm/RtStudienplan_model.php new file mode 100644 index 000000000..0e6fdeef3 --- /dev/null +++ b/application/models/crm/RtStudienplan_model.php @@ -0,0 +1,15 @@ +dbTable = "public.tbl_rt_studienplan"; + $this->pk = array("rt_id", "studienplan_id"); + $this->hasSequence = false; + } +}