mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
refactor generate alias, add transaction to addStatus
This commit is contained in:
@@ -781,6 +781,9 @@ class Status extends FHCAPI_Controller
|
||||
//Vor dem Studentenstatus müssen folgende Status eingetragen werden: {0}'
|
||||
//private $_statusAbfolgeVorStudent = [self::INTERESSENT_STATUS, self::BEWERBER_STATUS, self::AUFGENOMMENER_STATUS
|
||||
|
||||
// Start DB transaction
|
||||
$this->db->trans_start();
|
||||
|
||||
//getSemester of Status Aufgenommen
|
||||
$result = $this->PrestudentstatusModel->loadWhere([
|
||||
"prestudent_id" => $prestudent_id,
|
||||
@@ -878,26 +881,10 @@ class Status extends FHCAPI_Controller
|
||||
$aktivierungscode = getData($result);
|
||||
|
||||
//generate Alias
|
||||
//TODO(Manu) check if alias already exists
|
||||
$result = $this->BenutzerModel->generateAliasByPersonId($person_id);
|
||||
$this->getDataOrTerminateWithError($result);
|
||||
$alias = getData($result);
|
||||
|
||||
$result = $this->PersonModel->generateAliasByPersonId($person_id);
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
return $this->terminateWithError(getData($result), self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
|
||||
$alias = getData($result) ?: null;
|
||||
$alias = $alias->retval[0];
|
||||
|
||||
$sanitizedVorname = $this->_sanitizeAliasName($alias->vorname);
|
||||
$sanitizedNachname = $this->_sanitizeAliasName($alias->nachname);
|
||||
$alias = $sanitizedVorname . '.' . $sanitizedNachname;
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
|
||||
}
|
||||
$result = $this->BenutzerModel->insert(
|
||||
[
|
||||
'person_id' => $person_id,
|
||||
@@ -936,11 +923,11 @@ class Status extends FHCAPI_Controller
|
||||
$this->load->library('PrestudentLib');
|
||||
$result = $this->prestudentlib->setFirstStudent($prestudent_id, $studiensemester_kurzbz, $ausbildungssemester, $statusgrund_id, date('c'), getAuthUID(), $stg, $uidStudent);
|
||||
|
||||
if (isError($result)) {
|
||||
return $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
|
||||
} else
|
||||
$this->terminateWithSuccess($prestudent_id);
|
||||
$this->getDataOrTerminateWithError($result);
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
return $this->outputJsonSuccess(true);
|
||||
}
|
||||
|
||||
public function loadStatus()
|
||||
@@ -2011,6 +1998,14 @@ class Status extends FHCAPI_Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for sanitizing Alias Name
|
||||
* replaces empty spaces with underlines
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _sanitizeAliasName($str)
|
||||
{
|
||||
$str = sanitizeProblemChars($str);
|
||||
|
||||
@@ -94,9 +94,9 @@ class Benutzer_model extends DB_Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates alias for a uid.
|
||||
* @param $uid
|
||||
* @return array the alias if newly generated
|
||||
* Generates alias for a person_id
|
||||
* @param $person_id
|
||||
* @return string
|
||||
*/
|
||||
public function generateAliasByPersonId($person_id)
|
||||
{
|
||||
@@ -106,12 +106,19 @@ class Benutzer_model extends DB_Model
|
||||
|
||||
$nameresult = $this->execQuery($sql, array($person_id));
|
||||
|
||||
$nameresult = getData($nameresult) ?: null;
|
||||
$nameresult = current(getData($nameresult)) ?: null;
|
||||
|
||||
// if($aliasdata)
|
||||
// $alias = $this->_sanitizeAliasName($aliasdata->vorname).'.'.$this->_sanitizeAliasName($aliasdata->nachname);
|
||||
if($nameresult)
|
||||
{
|
||||
$alias = $this->_sanitizeAliasName($nameresult->vorname).'.'.$this->_sanitizeAliasName($nameresult->nachname);
|
||||
|
||||
return success($nameresult->vorname . " " . $nameresult->nachname);
|
||||
$aliasexists = $this->aliasExists($alias);
|
||||
|
||||
if (hasData($aliasexists) && current(getData($aliasexists)))
|
||||
$alias = "";
|
||||
}
|
||||
|
||||
return success($alias);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
@@ -122,6 +129,7 @@ class Benutzer_model extends DB_Model
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
|
||||
private function _sanitizeAliasName($str)
|
||||
{
|
||||
$str = sanitizeProblemChars($str);
|
||||
|
||||
@@ -375,53 +375,5 @@ class Person_model extends DB_Model
|
||||
]);
|
||||
}
|
||||
|
||||
public function generateAliasByPersonId($person_id)
|
||||
{
|
||||
|
||||
$this->addSelect('vorname, nachname');
|
||||
|
||||
return success ($this->loadWhere(array('person_id' => $person_id)));
|
||||
}
|
||||
|
||||
/* public function generateAliasByPersonId($person_id)
|
||||
{
|
||||
|
||||
$this->addSelect('vorname, nachname');
|
||||
|
||||
$result = $this->loadWhere(array('person_id' => $person_id));
|
||||
|
||||
// Überprüfe, ob ein Ergebnis zurückgegeben wurde
|
||||
if ($result) {
|
||||
$result = getData($result);
|
||||
$result = $result->retval[0];
|
||||
$vorname = $result->vorname;
|
||||
$nachname = $result->nachname;
|
||||
|
||||
// Sanitize the extracted names
|
||||
$sanitizedVorname = $this->sanitizeAliasName($vorname);
|
||||
$sanitizedNachname = $this->sanitizeAliasName($nachname);
|
||||
|
||||
// Erstelle den Alias
|
||||
$alias = $sanitizedVorname . '.' . $sanitizedNachname;
|
||||
|
||||
// Gib den Erfolg zurück mit dem generierten Alias
|
||||
return success($alias);
|
||||
} else {
|
||||
// Falls kein Ergebnis gefunden wurde, gib einen Fehler zurück
|
||||
return error('Person not found');
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Sanitizes a string used for alias. Replaces special characters, spaces, sets lower case.
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public function sanitizeAliasName($str)
|
||||
{
|
||||
$str = sanitizeProblemChars($str);
|
||||
return success (mb_strtolower(str_replace(' ','_', $str)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user