mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-04 05:39:28 +00:00
d8cd786079
- application/libraries/* -> CS compliant - FHC_Model isEntitled method now return error() or success() - Updated all code that uses isEntitled method from FHC_Model - Removed Squiz.PHP.DisallowSizeFunctionsInLoops from CS ruleset - Removed depracated method replace from DB_Model - Removed unused method pgArrayPhp from DB_Model - Renamed method arrayMergeIndex to _arrayCombine in DB_Model and set as private - Added method _manageUDFs to DB_Model (a wrapper for UDFLib->manageUDFs)
139 lines
4.2 KiB
PHP
139 lines
4.2 KiB
PHP
<?php
|
|
|
|
class Person_model extends DB_Model
|
|
{
|
|
/**
|
|
*
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->dbTable = 'public.tbl_person';
|
|
$this->pk = 'person_id';
|
|
}
|
|
|
|
/**
|
|
* getPersonKontaktByZugangscode
|
|
*/
|
|
public function getPersonKontaktByZugangscode($zugangscode, $email)
|
|
{
|
|
$this->addJoin('public.tbl_kontakt', 'person_id');
|
|
|
|
return $this->loadWhere(array('zugangscode' => $zugangscode, 'kontakt' => $email));
|
|
}
|
|
|
|
/**
|
|
* checkBewerbung
|
|
*/
|
|
public function checkBewerbung($email, $studiensemester_kurzbz = null)
|
|
{
|
|
if (isError($ent = $this->isEntitled('public.tbl_person', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)))
|
|
return $ent;
|
|
if (isError($ent = $this->isEntitled('public.tbl_kontakt', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)))
|
|
return $ent;
|
|
if (isError($ent = $this->isEntitled('public.tbl_benutzer', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)))
|
|
return $ent;
|
|
if (isError($ent = $this->isEntitled('public.tbl_prestudent', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)))
|
|
return $ent;
|
|
if (isError($ent = $this->isEntitled('public.tbl_prestudentstatus', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)))
|
|
return $ent;
|
|
|
|
$checkBewerbungQuery = '';
|
|
$parametersArray = array($email, $email, $email);
|
|
|
|
if (is_null($studiensemester_kurzbz))
|
|
{
|
|
$checkBewerbungQuery = 'SELECT DISTINCT p.person_id, p.zugangscode, p.insertamum
|
|
FROM public.tbl_person p JOIN public.tbl_kontakt k ON p.person_id = k.person_id
|
|
LEFT JOIN public.tbl_benutzer b ON p.person_id = b.person_id
|
|
WHERE k.kontakttyp = \'email\'
|
|
AND (kontakt = ? OR alias || \'@' . DOMAIN . '\' = ? OR uid || \'@' . DOMAIN . '\' = ?)
|
|
ORDER BY p.insertamum DESC
|
|
LIMIT 1';
|
|
}
|
|
else
|
|
{
|
|
$checkBewerbungQuery = 'SELECT DISTINCT p.person_id, p.zugangscode, p.insertamum
|
|
FROM public.tbl_person p JOIN public.tbl_kontakt k ON p.person_id = k.person_id
|
|
LEFT JOIN public.tbl_benutzer b ON p.person_id = b.person_id
|
|
JOIN public.tbl_prestudent ps ON p.person_id = ps.person_id
|
|
JOIN public.tbl_prestudentstatus pst ON pst.prestudent_id = ps.prestudent_id
|
|
WHERE k.kontakttyp = \'email\'
|
|
AND (kontakt = ? OR alias || \'@' . DOMAIN . '\' = ? OR uid || \'@' . DOMAIN . '\' = ?)
|
|
AND studiensemester_kurzbz = ?
|
|
ORDER BY p.insertamum DESC
|
|
LIMIT 1';
|
|
|
|
array_push($parametersArray, $studiensemester_kurzbz);
|
|
}
|
|
|
|
return $this->execQuery($checkBewerbungQuery, $parametersArray);
|
|
}
|
|
|
|
/**
|
|
* updatePerson
|
|
*/
|
|
public function updatePerson($person)
|
|
{
|
|
if (isset($person['svnr']) && $person['svnr'] != '')
|
|
{
|
|
$this->PersonModel->addOrder('svnr', 'DESC');
|
|
$result = $this->PersonModel->loadWhere(array(
|
|
'person_id != ' => $person['person_id'],
|
|
'SUBSTRING(svnr FROM 1 FOR 10) = ' => $person['svnr'])
|
|
);
|
|
if (hasData($result))
|
|
{
|
|
if (count($result->retval) == 1 && $result->retval[0]->svnr == $person['svnr'])
|
|
{
|
|
$person['svnr'] = $person['svnr'] . 'v1';
|
|
}
|
|
else
|
|
{
|
|
$person['svnr'] = $person['svnr'] . 'v' . ($result->retval[0]->svnr{11} + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $this->PersonModel->update($person['person_id'], $person);
|
|
}
|
|
|
|
/**
|
|
* getPersonFromStatus
|
|
*/
|
|
public function getPersonFromStatus($status_kurzbz, $von, $bis)
|
|
{
|
|
// Checks if the operation is permitted by the API caller
|
|
if (isError($ent = $this->isEntitled('public.tbl_prestudent', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)))
|
|
return $ent;
|
|
if (isError($ent = $this->isEntitled('public.tbl_prestudentstatus', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)))
|
|
return $ent;
|
|
|
|
$this->addJoin('public.tbl_prestudent', 'person_id');
|
|
|
|
$result = $this->loadTree(
|
|
'public.tbl_person',
|
|
array(
|
|
'public.tbl_prestudent'
|
|
),
|
|
'EXISTS (
|
|
SELECT
|
|
1
|
|
FROM
|
|
public.tbl_prestudentstatus
|
|
JOIN public.tbl_prestudent USING(prestudent_id)
|
|
WHERE
|
|
person_id=tbl_person.person_id
|
|
AND status_kurzbz='.$this->escape($status_kurzbz).'
|
|
AND datum >= '.$this->escape($von).'
|
|
AND datum <= '.$this->escape($bis).'
|
|
)',
|
|
array(
|
|
'prestudenten'
|
|
)
|
|
);
|
|
|
|
return $result;
|
|
}
|
|
}
|