PrestudentstatusCheckLib: checkIfExistingPrestudentRolle

This commit is contained in:
cgfhtw
2024-07-22 13:42:13 +02:00
parent fe4b5bf582
commit 0ee57e488d
2 changed files with 102 additions and 70 deletions
@@ -406,6 +406,26 @@ class Status extends FHCAPI_Controller
'integer' => $this->p->t('ui', 'error_fieldNotInteger', ['field' => 'Ausbildungssemester']) 'integer' => $this->p->t('ui', 'error_fieldNotInteger', ['field' => 'Ausbildungssemester'])
]); ]);
$this->form_validation->set_rules('_global', '', [
//check if Rolle already exists
['checkIfExistingPrestudentRolle', function () use (
$prestudent_id,
$status_kurzbz,
$studiensemester_kurzbz,
$ausbildungssemester
) {
$result = $this->prestudentstatuschecklib->checkIfExistingPrestudentRolle(
$prestudent_id,
$status_kurzbz,
$studiensemester_kurzbz,
$ausbildungssemester
);
return $this->getDataOrTerminateWithError($result);
}]
], [
'checkIfExistingPrestudentRolle' => $this->p->t('lehre', 'error_rolleBereitsVorhanden')
]);
if (!$this->form_validation->run()) if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array()); $this->terminateWithValidationErrors($this->form_validation->error_array());
@@ -434,19 +454,6 @@ class Status extends FHCAPI_Controller
} }
//check if Rolle already exists
$result = $this->prestudentstatuschecklib->checkIfExistingPrestudentRolle(
$prestudent_id,
$status_kurzbz,
$studiensemester_kurzbz,
$ausbildungssemester
);
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
//Check Reihungstest //Check Reihungstest
if(REIHUNGSTEST_CHECK) if(REIHUNGSTEST_CHECK)
{ {
@@ -520,7 +527,7 @@ class Status extends FHCAPI_Controller
{ {
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
} }
$isStudent = true; $isStudent = getData($result);
} }
$isBerechtigtNoStudstatusCheck = $this->permissionlib->isBerechtigt('student/keine_studstatuspruefung'); $isBerechtigtNoStudstatusCheck = $this->permissionlib->isBerechtigt('student/keine_studstatuspruefung');
@@ -770,7 +777,7 @@ class Status extends FHCAPI_Controller
} }
} }
public function addStudent($prestudent_id) public function addStudent($prestudent_id)
{ {
//get Studiengang von prestudent_id //get Studiengang von prestudent_id
$this->load->model('crm/Prestudent_model', 'PrestudentModel'); $this->load->model('crm/Prestudent_model', 'PrestudentModel');
@@ -1611,21 +1618,37 @@ class Status extends FHCAPI_Controller
} }
} }
//check if Rolle already exists //Form Validation
if(($key_studiensemester_kurzbz != $studiensemester_kurzbz) $this->load->library('form_validation');
|| ($key_ausbildungssemester != $ausbildungssemester))
{ $this->form_validation->set_rules('_global', '', [
$result = $this->prestudentstatuschecklib->checkIfExistingPrestudentRolle( //check if Rolle already exists
['checkIfExistingPrestudentRolle', function () use (
$prestudent_id, $prestudent_id,
$status_kurzbz, $status_kurzbz,
$studiensemester_kurzbz, $studiensemester_kurzbz,
$ausbildungssemester $ausbildungssemester,
); $key_studiensemester_kurzbz,
if (isError($result)) $key_ausbildungssemester
{ ) {
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); if ($key_studiensemester_kurzbz == $studiensemester_kurzbz
} && $key_ausbildungssemester == $ausbildungssemester
} )
return true;
$result = $this->prestudentstatuschecklib->checkIfExistingPrestudentRolle(
$prestudent_id,
$status_kurzbz,
$studiensemester_kurzbz,
$ausbildungssemester
);
return $this->getDataOrTerminateWithError($result);
}]
], [
'checkIfExistingPrestudentRolle' => $this->p->t('lehre', 'error_rolleBereitsVorhanden')
]);
if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array());
//check if studentrolle already exists //check if studentrolle already exists
if($status_kurzbz == Prestudentstatus_model::STATUS_STUDENT || $status_kurzbz == Prestudentstatus_model::STATUS_DIPLOMAND ) if($status_kurzbz == Prestudentstatus_model::STATUS_STUDENT || $status_kurzbz == Prestudentstatus_model::STATUS_DIPLOMAND )
@@ -1638,7 +1661,7 @@ class Status extends FHCAPI_Controller
{ {
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
} }
$isStudent = true; $isStudent = getData($result);
} }
@@ -1806,17 +1829,45 @@ class Status extends FHCAPI_Controller
$ausbildungssem_next = $key_ausbildungssemester+1; $ausbildungssem_next = $key_ausbildungssemester+1;
//check if Rolle already exists //Form Validation
$result = $this->prestudentstatuschecklib->checkIfExistingPrestudentRolle( $this->load->library('form_validation');
$key_prestudent_id,
$key_status_kurzbz, $last_status_kurzbz = $lastStatusData->status_kurzbz; // TODO(chris): copy pasta!
$studiensem_next,
$ausbildungssem_next $this->form_validation->set_rules('_global', '', [
); //check if Rolle already exists
if (isError($result)) ['checkIfExistingPrestudentRolle', function () use (
{ $key_prestudent_id,
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); $key_status_kurzbz,
} $studiensem_next,
$ausbildungssem_next
) {
$result = $this->prestudentstatuschecklib->checkIfExistingPrestudentRolle(
$key_prestudent_id,
$key_status_kurzbz,
$studiensem_next,
$ausbildungssem_next
);
return $this->getDataOrTerminateWithError($result);
}],
['status_stud_exists', function () use ($key_prestudent_id, $key_status_kurzbz, $last_status_kurzbz) {
if ($key_status_kurzbz != Prestudentstatus_model::STATUS_STUDENT
&& $key_status_kurzbz != Prestudentstatus_model::STATUS_DIPLOMAND
&& $last_status_kurzbz != Prestudentstatus_model::STATUS_STUDENT
)
return true;
$result = $this->prestudentstatuschecklib->checkIfExistingStudentRolle($key_prestudent_id);
return $this->getDataOrTerminateWithError($result);
}]
], [
'checkIfExistingPrestudentRolle' => $this->p->t('lehre', 'error_rolleBereitsVorhanden'),
'status_stud_exists' => $this->p->t('lehre', 'error_noStudstatus')
]);
if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array());
//check if studentrolle already exists //check if studentrolle already exists
// if($key_status_kurzbz == Prestudentstatus_model::STATUS_STUDENT) // if($key_status_kurzbz == Prestudentstatus_model::STATUS_STUDENT)
@@ -1832,14 +1883,6 @@ class Status extends FHCAPI_Controller
// return $this->terminateWithError($this->p->t('lehre','error_noStudstatus'), self::ERROR_TYPE_GENERAL); // return $this->terminateWithError($this->p->t('lehre','error_noStudstatus'), self::ERROR_TYPE_GENERAL);
// } // }
// } // }
if($key_status_kurzbz == Prestudentstatus_model::STATUS_STUDENT || $key_status_kurzbz == Prestudentstatus_model::STATUS_DIPLOMAND || $lastStatusData->status_kurzbz == Prestudentstatus_model::STATUS_STUDENT)
{
$result = $this->prestudentstatuschecklib->checkIfExistingStudentRolle($key_prestudent_id);
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
}
// Start DB transaction // Start DB transaction
$this->db->trans_begin(); $this->db->trans_begin();
@@ -98,43 +98,32 @@ class PrestudentstatusCheckLib
); );
} }
/** /**
* Checks if a prestudent role already exists. * Checks if a prestudent role already exists.
* @return error if invalid *
* @return 1 if role already exists, 0 if it does not * @param integer $prestudent_id
* @param string $status_kurzbz
* @param string $studiensemester_kurzbz
* @param integer $ausbildungssemester
*
* @return stdClass
*/ */
public function checkIfExistingPrestudentRolle( public function checkIfExistingPrestudentRolle(
$prestudent_id, $prestudent_id,
$status_kurzbz, $status_kurzbz,
$tudiensemester_kurzbz, $tudiensemester_kurzbz,
$ausbildungssemester $ausbildungssemester
) ) {
{
$resultApp = $this->_getApplicationData($prestudent_id);
if(isError($resultApp))
{
return getData($resultApp);
}
$resultApp = current(getData($resultApp));
$studentName = trim ($resultApp->vorname.' '.$resultApp->nachname);
$result = $this->_ci->PrestudentstatusModel->checkIfExistingPrestudentRolle( $result = $this->_ci->PrestudentstatusModel->checkIfExistingPrestudentRolle(
$prestudent_id, $prestudent_id,
$status_kurzbz, $status_kurzbz,
$tudiensemester_kurzbz, $tudiensemester_kurzbz,
$ausbildungssemester $ausbildungssemester
); );
if(isError($result)) if (isError($result))
{ return $result;
return getData($result);
}
$result = getData($result);
if($result == '1') return success(getData($result) != '1');
{
return error($studentName . ": " . $this->_ci->p->t('lehre', 'error_rolleBereitsVorhanden'));
}
return success($result);
} }
/** /**