diff --git a/application/libraries/PrestudentstatusCheckLib.php b/application/libraries/PrestudentstatusCheckLib.php index 86066fdda..20b42b46a 100644 --- a/application/libraries/PrestudentstatusCheckLib.php +++ b/application/libraries/PrestudentstatusCheckLib.php @@ -620,6 +620,7 @@ class PrestudentstatusCheckLib $old_studiensemester_kurzbz, $old_ausbildungssemester ) { + // TODO(chris): TEST $result = $this->prepareStatusHistory( $prestudent_id, $status_kurzbz, @@ -645,6 +646,7 @@ class PrestudentstatusCheckLib */ public function checkPersonenkennzeichen($prestudent_id) { + // TODO(chris): TEST $this->_ci->PrestudentstatusModel->addSelect('tbl_prestudentstatus.prestudent_id'); $this->_ci->PrestudentstatusModel->addSelect('tbl_student.matrikelnr'); @@ -675,7 +677,23 @@ class PrestudentstatusCheckLib return success($jahr == mb_substr($data->matrikelnr, 0, 2)); } - // TODO(chris): check status history error_bewerberOrgformUngleichStudentOrgform + /** + * Checks if Orgform of Student status and Bewerber status match. + * + * @param integer $prestudent_id + * + * @return stdClass + */ + public function checkStudentOrgform($prestudent_id) + { + // TODO(chris): TEST + $result = $this->_ci->PrestudentstatusModel->getBewerberWhereOrgformNotStudent($prestudent_id); + + if (isError($result)) + return $result; + + return success(!hasData($result)); + } /** * Check if History of StatusData is valid diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index a19c465ec..e52bbf577 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -698,4 +698,39 @@ class Prestudentstatus_model extends DB_Model return $result; } + + /** + * For checks if Orgform of Student status and Bewerber status match. + * Returns any Bewerber status that does not match the first Student + * status' Orgform. + * + * @param integer $prestudent_id + * + * @return stdClass + */ + public function getBewerberWhereOrgformNotStudent($prestudent_id) + { + $this->addSelect('plan.orgform_kurzbz'); + + $this->addJoin('lehre.tbl_studienplan plan', 'studienplan_id', 'LEFT'); + + $this->addOrder('tbl_prestudentstatus.datum', 'DESC'); + $this->addOrder('tbl_prestudentstatus.insertamum', 'DESC'); + $this->addOrder('tbl_prestudentstatus.ext_id', 'DESC'); + + $this->addLimit(1); + + $this->db->where('prestudent_id', $prestudent_id); + $this->db->where('status_kurzbz', self::STATUS_STUDENT); + + $sql = $this->db->get_compiled_select($this->dbTable); + + $this->addJoin('lehre.tbl_studienplan plan', 'studienplan_id', 'LEFT'); + + $this->db->where('plan.orgform_kurzbz !=', '(' . $sql . ')', false); + return $this->loadWhere([ + 'prestudent_id' => $prestudent_id, + 'status_kurzbz' => self::STATUS_BEWERBER + ]); + } }