Status->isLastStatus corrected

This commit is contained in:
cgfhtw
2024-07-26 12:04:20 +02:00
parent 32a20f4783
commit d4db49e09e
2 changed files with 34 additions and 45 deletions
@@ -85,15 +85,8 @@ class Status extends FHCAPI_Controller
{
$result = $this->PrestudentstatusModel->checkIfLastStatusEntry($prestudent_id);
$result = $this->getDataOrTerminateWithError($result);
if (isError($result))
{
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
if($result->retval == "1")
{
$this->terminateWithError($this->p->t('lehre','error_lastRole'), self::ERROR_TYPE_GENERAL);
}
return $this->terminateWithSuccess($result);
}
@@ -963,7 +956,7 @@ class Status extends FHCAPI_Controller
{
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
if($result->retval == "1")
if($result->retval)
{
//Berechtigungen nach Check prüfen!
if(!$isBerechtigtAdmin && !$isBerechtigtNoStudstatusCheck)
@@ -1098,13 +1091,13 @@ class Status extends FHCAPI_Controller
$logId = $result->retval;
//Delete Studentlehrverband if no Status left
$result = $this->PrestudentstatusModel->checkIfLastStatusEntry($prestudent_id, true);
$result = $this->PrestudentstatusModel->checkIfLastStudentStatusEntry($prestudent_id);
if (isError($result))
{
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
}
if ($result->retval == "1")
if ($result->retval)
{
//get student_uid
$this->load->model('crm/Student_model', 'StudentModel');
@@ -484,48 +484,44 @@ class Prestudentstatus_model extends DB_Model
/**
* Check if there is only one prestudentstatus left
* @param integer $prestudent_id
* @return success("1") if last prestudentstatusentry, else success("0")
*
* @param integer $prestudent_id
*
* @return stdClass
*/
public function checkIfLastStatusEntry($prestudent_id, $isStudent=false )
public function checkIfLastStatusEntry($prestudent_id)
{
$qry = "SELECT
COUNT(*) as anzahl
FROM
public.tbl_prestudentstatus
WHERE
prestudent_id = ?
";
$this->addSelect('COUNT(*) AS anzahl', false);
if($isStudent)
{
$qry .= "AND status_kurzbz = 'Student'";
}
$result = $this->execQuery($qry, array($prestudent_id));
$result = $this->loadWhere([
'prestudent_id' => $prestudent_id
]);
if (isError($result))
{
return error($result);
}
return $result;
$resultObject = current(getData($result));
$resultObject = current($result->retval);
if (property_exists($resultObject, 'anzahl'))
{
$anzahl = (int) $resultObject->anzahl;
if ($anzahl <= 1 )
{
return success("1", $this->p->t('lehre','error_lastRole'));
}
else
return success("0", $this->p->t('lehre','anzahl_existingRoles', ['anzahl' => $anzahl]));
$anzahl = (int)$resultObject->anzahl;
}
else
{
return error($result);
}
if ($anzahl <= 1)
return success(true, $this->p->t('lehre', 'error_lastRole'));
return success(false, $this->p->t('lehre', 'anzahl_existingRoles', ['anzahl' => $anzahl]));
}
/**
* Check if there is only one "Student" prestudentstatus left
*
* @param integer $prestudent_id
*
* @return stdClass
*/
public function checkIfLastStudentStatusEntry($prestudent_id)
{
$this->db->where('status_kurzbz', self::STATUS_STUDENT);
return $this->checkIfLastStatusEntry($prestudent_id);
}
public function getAllPrestudentstatiWithStudiensemester($prestudent_id)