mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-16 22:42:16 +00:00
5b264bb6a9
- added getVerwendungen method person/Benutzer_model - added comment person/Benutzerfunktion_model - added getBenutzerFunktionByUid method ressource/Mitarbeiter_model - added getVorgesetzte method - extended getPersonal method
129 lines
3.1 KiB
PHP
129 lines
3.1 KiB
PHP
<?php
|
|
class Benutzer_model extends DB_Model
|
|
{
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->dbTable = 'public.tbl_benutzer';
|
|
$this->pk = array('uid');
|
|
$this->hasSequence = false;
|
|
}
|
|
|
|
public function getFromPersonId($person_id)
|
|
{
|
|
return $this->loadWhere(array('person_id' => $person_id, 'aktiv' => true));
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function getActiveUserByPersonIdAndOrganisationUnit($person_id, $oe_kurzbz)
|
|
{
|
|
$sql = 'SELECT b.uid
|
|
FROM public.tbl_benutzer b
|
|
JOIN public.tbl_prestudent ps USING (person_id)
|
|
JOIN public.tbl_studiengang sg USING (studiengang_kz)
|
|
WHERE ps.person_id = ?
|
|
AND sg.oe_kurzbz = ?
|
|
AND b.aktiv = TRUE';
|
|
|
|
return $this->execQuery($sql, array($person_id, $oe_kurzbz));
|
|
}
|
|
|
|
/**
|
|
* Checks if alias exists
|
|
* @param $alias
|
|
*/
|
|
public function aliasExists($alias)
|
|
{
|
|
$this->addSelect('1');
|
|
$result = $this->loadWhere(array('alias' => $alias));
|
|
|
|
if (!isError($result))
|
|
{
|
|
if (hasData($result))
|
|
{
|
|
$result = success(array(true));
|
|
}
|
|
else if (!hasData($result))
|
|
{
|
|
$result = success(array(false));
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Generates alias for a uid.
|
|
* @param $uid
|
|
* @return array the alias if newly generated
|
|
*/
|
|
public function generateAlias($uid)
|
|
{
|
|
$aliasres = '';
|
|
$this->addSelect('vorname, nachname');
|
|
$this->addJoin('public.tbl_person', 'person_id');
|
|
$nameresult = $this->loadWhere(array('uid' => $uid));
|
|
|
|
if (hasData($nameresult))
|
|
{
|
|
$aliasdata = getData($nameresult);
|
|
$alias = $this->_sanitizeAliasName($aliasdata[0]->vorname).'.'.$this->_sanitizeAliasName($aliasdata[0]->nachname);
|
|
$aliasexists = $this->aliasExists($alias);
|
|
|
|
if (hasData($aliasexists) && !getData($aliasexists)[0])
|
|
$aliasres = $alias;
|
|
}
|
|
return success($aliasres);
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
// Private methods
|
|
|
|
/**
|
|
* Sanitizes a string used for alias. Replaces special characters, spaces, upper case.
|
|
* @param string $str
|
|
* @return string
|
|
*/
|
|
private function _sanitizeAliasName($str)
|
|
{
|
|
$enc = 'UTF-8';
|
|
|
|
$acentos = array(
|
|
'A' => '/À|Á|Â|Ã|Å/',
|
|
'Ae' => '/Ä/',
|
|
'a' => '/à|á|â|ã|å/',
|
|
'ae'=> '/ä/',
|
|
'C' => '/Ç/',
|
|
'c' => '/ç/',
|
|
'E' => '/È|É|Ê|Ë/',
|
|
'e' => '/è|é|ê|ë/',
|
|
'I' => '/Ì|Í|Î|Ï/',
|
|
'i' => '/ì|í|î|ï/',
|
|
'N' => '/Ñ/',
|
|
'n' => '/ñ/',
|
|
'O' => '/Ò|Ó|Ô|Õ/',
|
|
'Oe' => '/Ö/',
|
|
'o' => '/ò|ó|ô|õ/',
|
|
'oe' => '/ö/',
|
|
'U' => '/Ù|Ú|Û/',
|
|
'Ue' => '/Ü/',
|
|
'u' => '/ù|ú|û/',
|
|
'ue' => '/ü/',
|
|
'Y' => '/Ý/',
|
|
'y' => '/ý|ÿ/',
|
|
'a.' => '/ª/',
|
|
'o.' => '/º/',
|
|
'ss' => '/ß/',
|
|
);
|
|
|
|
$str = preg_replace($acentos, array_keys($acentos), htmlentities($str,ENT_NOQUOTES, $enc));
|
|
return mb_strtolower(str_replace(' ','_', $str));
|
|
}
|
|
}
|