mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 16:32:20 +00:00
Merge branch 'master' into feature-3716/Messaging_inbox_outbox_user
This commit is contained in:
@@ -22,8 +22,7 @@ class Konto_model extends DB_Model
|
||||
$this->addJoin('wawi.tbl_konto_kostenstelle', 'konto_id');
|
||||
$konten = $this->loadWhere(array('kostenstelle_id' => $kostenstelle_id));
|
||||
|
||||
if ($konten->error)
|
||||
return error($konten->retval);
|
||||
if ($konten->error) return $konten;
|
||||
|
||||
return $konten;
|
||||
}
|
||||
|
||||
@@ -10,5 +10,324 @@ class Vertrag_model extends DB_Model
|
||||
parent::__construct();
|
||||
$this->dbTable = 'lehre.tbl_vertrag';
|
||||
$this->pk = 'vertrag_id';
|
||||
|
||||
$this->load->model('accounting/Vertragvertragsstatus_model', 'VertragvertragsstatusModel');
|
||||
$this->load->model('education/Lehreinheitmitarbeiter_model', 'LehreinheitmitarbeiterModel');
|
||||
$this->load->model('education/Projektbetreuer_model', 'ProjektbetreuerModel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves Vertrag for a Lehrauftrag and sets Vertragsstatus to 'bestellt'.
|
||||
* Also updates vertrag_id in tbl_lehreinheitmitarbeiter or tbl_projektbetreuer.
|
||||
* @param $person_id
|
||||
* @param $lehrveranstaltung_id
|
||||
* @param $lehreinheit_id
|
||||
* @param $projektarbeit_id
|
||||
* @param $betrag Monetary amount of that Lehreinheit / Projektbetreuung.
|
||||
* @param $vertragsstunden Working hours of that Lehreinheit / Projektbetreuung.
|
||||
* @param $studiensemester_kurzbz
|
||||
* @param $vertragstyp_kurzbz
|
||||
* @return array|null On success object. On failure null.
|
||||
*/
|
||||
public function save($person_id, $mitarbeiter_uid, $lehrveranstaltung_id, $lehreinheit_id, $projektarbeit_id = null, $vertragsstunden, $betrag, $studiensemester_kurzbz)
|
||||
{
|
||||
$person_id = (isset($person_id) && is_numeric($person_id))
|
||||
? $person_id
|
||||
: show_error('peron_id must be set and numeric.');
|
||||
$lehreinheit_id = (isset($lehreinheit_id) && is_numeric($lehreinheit_id))
|
||||
? $lehreinheit_id
|
||||
: show_error('lehreinheit_id must be set and numeric.');
|
||||
$lehrveranstaltung_id = (isset($lehrveranstaltung_id) && is_numeric($lehrveranstaltung_id))
|
||||
? $lehrveranstaltung_id
|
||||
: show_error('lehrveranstaltung_id must be set and numeric.');
|
||||
$projektarbeit_id = (isset($projektarbeit_id) && is_numeric($projektarbeit_id))
|
||||
? $projektarbeit_id
|
||||
: null;
|
||||
$vertragsstunden = (isset($vertragsstunden) && is_numeric($vertragsstunden))
|
||||
? $vertragsstunden
|
||||
: 0;
|
||||
$betrag = (isset($betrag) && is_numeric($betrag))
|
||||
? $betrag
|
||||
: 0;
|
||||
$mitarbeiter_uid = (isset($mitarbeiter_uid) && is_string($mitarbeiter_uid))
|
||||
? $mitarbeiter_uid
|
||||
: show_error('mitarbeiter_uid must be set and a string value.');;
|
||||
|
||||
$vertragstyp_kurzbz = (is_null($projektarbeit_id)) ? 'Lehrauftrag' : 'Betreuung';
|
||||
|
||||
// First check if Vertrag already exists for that Lehrauftrag or for that Projektbetreuerauftrag
|
||||
if ($vertragstyp_kurzbz == 'Lehrauftrag')
|
||||
{
|
||||
if ($this->LehreinheitmitarbeiterModel->hasVertrag($mitarbeiter_uid, $lehreinheit_id))
|
||||
{
|
||||
return error('Lehrauftrag existiert bereits'); // Exit if Lehrauftrag already has Vertrag
|
||||
}
|
||||
}
|
||||
elseif ($vertragstyp_kurzbz == 'Betreuung')
|
||||
{
|
||||
if ($this->ProjektbetreuerModel->hasVertrag($person_id, $projektarbeit_id))
|
||||
{
|
||||
return error('Lehrauftrag existiert bereits'); // Exit if Projektbetreuung already has Vertrag
|
||||
}
|
||||
}
|
||||
|
||||
// If Vertrag does not exist, create now
|
||||
// Vertragsbezeichnung
|
||||
$bezeichnung = $this->_writeVertragsbezeichung($lehrveranstaltung_id, $studiensemester_kurzbz);
|
||||
|
||||
// Start DB transaction
|
||||
$this->db->trans_start(false);
|
||||
|
||||
// Insert Vertragsdata
|
||||
$result = $this->insert(
|
||||
array(
|
||||
'person_id' => $person_id,
|
||||
'lehrveranstaltung_id' => $lehrveranstaltung_id,
|
||||
'vertragstyp_kurzbz' => $vertragstyp_kurzbz,
|
||||
'bezeichnung' => $bezeichnung,
|
||||
'betrag' => $betrag,
|
||||
'insertamum' => 'NOW()',
|
||||
'insertvon' => getAuthUID(),
|
||||
'vertragsdatum' => 'NOW()',
|
||||
'vertragsstunden' => $vertragsstunden,
|
||||
'vertragsstunden_studiensemester_kurzbz' => $studiensemester_kurzbz
|
||||
)
|
||||
);
|
||||
|
||||
// Retrieve primary key
|
||||
$vertrag_id = $result->retval;
|
||||
|
||||
// If Vertrag was created successfully, update vertrag_id
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// if Lehrtätigkeit, update vertrag_id in tbl_lehreinheitmitarbeiter
|
||||
if ($vertragstyp_kurzbz == 'Lehrauftrag')
|
||||
{
|
||||
$this->load->model('education/Lehreinheitmitarbeiter_model', 'LehreinheitmitarbeiterModel');
|
||||
$result = $this->LehreinheitmitarbeiterModel->update(
|
||||
array(
|
||||
'lehreinheit_id' => $lehreinheit_id,
|
||||
'mitarbeiter_uid' =>$mitarbeiter_uid
|
||||
),
|
||||
array(
|
||||
'vertrag_id' => $vertrag_id
|
||||
)
|
||||
);
|
||||
}
|
||||
// if (Projekt-)Betreuung, update vertrag_id in tbl_projektbetreuer
|
||||
elseif ($vertragstyp_kurzbz == 'Betreuung')
|
||||
{
|
||||
$this->load->model('education/Projektbetreuer_model', 'ProjektbetreuerModel');
|
||||
$result = $this->ProjektbetreuerModel->update(
|
||||
array(
|
||||
'person_id' => $person_id,
|
||||
'projektarbeit_id' => $projektarbeit_id
|
||||
),
|
||||
array(
|
||||
'vertrag_id' => $vertrag_id
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If updating vertrag_id was successfully, set Status to 'bestellt'
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->VertragvertragsstatusModel->setStatus($vertrag_id, $mitarbeiter_uid, 'bestellt');
|
||||
}
|
||||
|
||||
// Transaction complete!
|
||||
$this->db->trans_complete();
|
||||
|
||||
// Check if everything went ok during the transaction
|
||||
if ($this->db->trans_status() === false || isError($result))
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->trans_commit();
|
||||
return success($vertrag_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates Vertrag and, if resets vertragsstatus as follows:
|
||||
* - if vertragsstatus 'erteilt': delete status 'erteilt' and update date of status 'bestellt'
|
||||
* - if vertragsstatus 'bestellt': update date of status 'bestellt'
|
||||
* @param $vertrag_obj Object with vertrag properties vertrag_id, vertragsstunden, betrag.
|
||||
* @param $mitarbeiter_uid
|
||||
*/
|
||||
public function updateVertrag($vertrag_id, $vertragsstunden, $betrag, $mitarbeiter_uid)
|
||||
{
|
||||
$vertrag_id = (isset($vertrag_id) && is_numeric($vertrag_id))
|
||||
? $vertrag_id
|
||||
: show_error('vertrag_id must be set and numeric.');
|
||||
$vertragsstunden = (isset($vertragsstunden) && is_numeric($vertragsstunden))
|
||||
? $vertragsstunden
|
||||
: 0;
|
||||
$betrag = (isset($betrag) && is_numeric($betrag))
|
||||
? $betrag
|
||||
: 0;
|
||||
$mitarbeiter_uid = (isset($mitarbeiter_uid) && is_string($mitarbeiter_uid))
|
||||
? $mitarbeiter_uid
|
||||
: show_error('mitarbeiter_uid must be set and a string value.');
|
||||
|
||||
// Start DB transaction
|
||||
$this->db->trans_start(false);
|
||||
|
||||
// Update contract
|
||||
$result = $this->update(
|
||||
$vertrag_id,
|
||||
array(
|
||||
'vertragsstunden' => $vertragsstunden,
|
||||
'betrag' => $betrag,
|
||||
'updateamum' => $this->escape('NOW()'),
|
||||
'updatevon' => getAuthUID()
|
||||
)
|
||||
);
|
||||
|
||||
// If last vertragsstatus is 'erteilt', delete the status
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->VertragvertragsstatusModel->getLastStatus($vertrag_id, $mitarbeiter_uid);
|
||||
|
||||
$lastStatus = getData($result)[0]->vertragsstatus_kurzbz;
|
||||
|
||||
if ($lastStatus == 'erteilt')
|
||||
{
|
||||
$result = $this->VertragvertragsstatusModel->deleteStatus($vertrag_id, 'erteilt');
|
||||
}
|
||||
}
|
||||
|
||||
// Update date of status 'bestellt'
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->VertragvertragsstatusModel->updateStatus($vertrag_id, 'bestellt');
|
||||
}
|
||||
|
||||
// Transaction complete!
|
||||
$this->db->trans_complete();
|
||||
|
||||
// Check if everything went ok during the transaction
|
||||
if ($this->db->trans_status() === false || isError($result))
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->trans_commit();
|
||||
return success('Contract successfully updated.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Lehreinheit ID corresponding to the contract.
|
||||
* @param $vertrag_id
|
||||
* @return array
|
||||
*/
|
||||
public function getLehreinheitID($vertrag_id)
|
||||
{
|
||||
$vertragstyp_kurzbz = null;
|
||||
|
||||
$this->addSelect('vertragstyp_kurzbz');
|
||||
if ($result = getData($this->load($vertrag_id)))
|
||||
{
|
||||
$vertragstyp_kurzbz = $result[0]->vertragstyp_kurzbz;
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('Fehler beim Laden des Vertrags.');
|
||||
}
|
||||
|
||||
if ($vertragstyp_kurzbz == 'Lehrauftrag')
|
||||
{
|
||||
$this->LehreinheitmitarbeiterModel->addSelect('lehreinheit_id');
|
||||
if ($result = $this->LehreinheitmitarbeiterModel->loadWhere(array('vertrag_id' => $vertrag_id)))
|
||||
{
|
||||
return success($result->retval);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('Fehler beim Ermitteln der Lehreinheit ID');
|
||||
}
|
||||
|
||||
}
|
||||
elseif ($vertragstyp_kurzbz == 'Betreuung')
|
||||
{
|
||||
$this->addSelect('lehreinheit_id');
|
||||
$this->addJoin('lehre.tbl_projektbetreuer', 'vertrag_id');
|
||||
$this->addJoin('lehre.tbl_projektarbeit', 'projektarbeit_id');
|
||||
if ($result = $this->loadWhere(array('vertrag_id' => $vertrag_id)))
|
||||
{
|
||||
return success($result->retval);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('Fehler beim Ermitteln der Lehreinheit ID');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets (table) data of lehreinheit_id corresponding to the contract.
|
||||
* @param integer $vertrag_id
|
||||
* @param string $select To restrict fields, pass select string. e.g. 'lehrveranstaltung_id'.
|
||||
* @return array
|
||||
*/
|
||||
public function getLehreinheitData($vertrag_id, $select = '*')
|
||||
{
|
||||
if ($result = getData($this->getLehreinheitID($vertrag_id)))
|
||||
{
|
||||
$this->load->model('education/Lehreinheit_model', 'LehreinheitModel');
|
||||
$this->LehreinheitModel->addSelect($select);
|
||||
|
||||
if($result = $this->LehreinheitModel->load($result[0]->lehreinheit_id))
|
||||
{
|
||||
return success($result->retval);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('Fehler beim Laden der Lehreinheit');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('Fehler beim Ermitteln der Lehreinheit ID');
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Generate contract description.
|
||||
* Example: WS2017-BEE3-LIA-LAB
|
||||
* @param $lehrveranstaltung_id
|
||||
* @param $studiensemester_kurzbz Studiensemester of Lehrauftrag (= when the lector will teach the lehrveranstaltung)
|
||||
* @return string Returns e.g. WS2017-BBE5-GAP-LAB
|
||||
*/
|
||||
private function _writeVertragsbezeichung($lehrveranstaltung_id, $studiensemester_kurzbz)
|
||||
{
|
||||
$bezeichnung = '';
|
||||
$this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel');
|
||||
$this->LehrveranstaltungModel->addSelect('tbl_lehrveranstaltung.semester, tbl_lehrveranstaltung.kurzbz AS "lv_kurzbz", lehrform_kurzbz, public.tbl_studiengang.typ, public.tbl_studiengang.kurzbz');
|
||||
$this->LehrveranstaltungModel->addJoin('lehre.tbl_studienplan_lehrveranstaltung', 'lehrveranstaltung_id');
|
||||
$this->LehrveranstaltungModel->addJoin('lehre.tbl_studienplan', 'studienplan_id');
|
||||
$this->LehrveranstaltungModel->addJoin('lehre.tbl_studienordnung', 'studienordnung_id');
|
||||
$this->LehrveranstaltungModel->addJoin('public.tbl_studiengang', 'public.tbl_studiengang.studiengang_kz = lehre.tbl_studienordnung.studiengang_kz');
|
||||
$result = $this->LehrveranstaltungModel->load($lehrveranstaltung_id);
|
||||
|
||||
if (hasData($result))
|
||||
{
|
||||
$bezeichnung = $studiensemester_kurzbz. '-';
|
||||
$bezeichnung.= strtoupper($result->retval[0]->typ. $result->retval[0]->kurzbz). $result->retval[0]->semester. '-';
|
||||
$bezeichnung.= $result->retval[0]->lv_kurzbz. '-';
|
||||
$bezeichnung.= $result->retval[0]->lehrform_kurzbz;
|
||||
}
|
||||
|
||||
return $bezeichnung;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
class Vertragvertragsstatus_model extends DB_Model
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'lehre.tbl_vertrag_vertragsstatus';
|
||||
$this->pk = array('vertragsstatus_kurzbz', 'vertrag_id');
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vertrag has the given Vertragsstatus.
|
||||
* @param integer $vertrag_id
|
||||
* @param string $mitarbeiter_uid
|
||||
* @param string $vertragsstatus_kurzbz
|
||||
* @return array
|
||||
*/
|
||||
public function hasStatus($vertrag_id, $mitarbeiter_uid, $vertragsstatus_kurzbz)
|
||||
{
|
||||
$this->addSelect('1');
|
||||
$this->addLimit(1);
|
||||
|
||||
return $this->loadWhere(array(
|
||||
'vertrag_id' => $vertrag_id,
|
||||
'uid' => $mitarbeiter_uid,
|
||||
'vertragsstatus_kurzbz' => $vertragsstatus_kurzbz
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest Vertragsstatus for the given Vertrag and Mitarbeiter
|
||||
* @param integer $vertrag_id
|
||||
* @param string $mitarbeiter_uid
|
||||
* @return array
|
||||
*/
|
||||
public function getLastStatus($vertrag_id, $mitarbeiter_uid)
|
||||
{
|
||||
$this->addSelect('vertragsstatus_kurzbz');
|
||||
$this->addOrder('datum', 'DESC');
|
||||
$this->addLimit(1);
|
||||
return $this->loadWhere(
|
||||
array(
|
||||
'vertrag_id' => $vertrag_id,
|
||||
'uid' => $mitarbeiter_uid
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Vertragsstatus for the given Vertrag and Mitarbeiter.
|
||||
* @param integer $vertrag_id
|
||||
* @param string $mitarbeiter_uid
|
||||
* @param string $vertragsstatus_kurzbz
|
||||
* @return object On success, return success object.
|
||||
* If status already exists or earlier status is missing, return error object.
|
||||
*/
|
||||
public function setStatus($vertrag_id, $mitarbeiter_uid, $vertragsstatus_kurzbz){
|
||||
|
||||
// Check if vertrag has already this status
|
||||
$result = $this->hasStatus($vertrag_id, $mitarbeiter_uid, $vertragsstatus_kurzbz);
|
||||
|
||||
// If status is already set, return error message
|
||||
if (hasData($result))
|
||||
{
|
||||
return error('Fehler: Status bereits vorhanden.');
|
||||
}
|
||||
|
||||
// If new status should be 'akzeptiert', the latest status has to be 'erteilt'
|
||||
if ($vertragsstatus_kurzbz == 'akzeptiert')
|
||||
{
|
||||
$result = $this->getLastStatus($vertrag_id, $mitarbeiter_uid);
|
||||
$last_status = getData($result)[0]->vertragsstatus_kurzbz;
|
||||
|
||||
// If latest status is not 'erteilt', return error message
|
||||
if ($last_status != 'erteilt')
|
||||
{
|
||||
return error('Fehler: Vor Status \'angenommen\' muss erst Status \'erteilt\' gesetzt sein.');
|
||||
}
|
||||
}
|
||||
|
||||
// Set new status if passed all checks
|
||||
return $this->insert(
|
||||
array(
|
||||
'vertrag_id' => $vertrag_id,
|
||||
'vertragsstatus_kurzbz' => $vertragsstatus_kurzbz,
|
||||
'uid' => $mitarbeiter_uid,
|
||||
'datum' => $this->escape('NOW()'),
|
||||
'insertvon' => getAuthUID(),
|
||||
'insertamum' => $this->escape('NOW()')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the date of the given vertragsstatus.
|
||||
* @param $vertrag_id
|
||||
* @param $vertragsstatus_kurzbz
|
||||
* @return array
|
||||
*/
|
||||
public function updateStatus($vertrag_id, $vertragsstatus_kurzbz)
|
||||
{
|
||||
$user = getAuthUID();
|
||||
return $this->update(
|
||||
array(
|
||||
'vertrag_id' => $vertrag_id,
|
||||
'vertragsstatus_kurzbz' => $vertragsstatus_kurzbz
|
||||
),
|
||||
array(
|
||||
'datum' => $this->escape('NOW()'),
|
||||
'updateamum' => $this->escape('NOW()'),
|
||||
'updatevon' => $user,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given vertragsstatus of the contract.
|
||||
* @param $vertrag_id
|
||||
* @param $vertragsstatus_kurbz
|
||||
* @return array
|
||||
*/
|
||||
public function deleteStatus($vertrag_id, $vertragsstatus_kurzbz)
|
||||
{
|
||||
return $this->delete(
|
||||
array(
|
||||
'vertrag_id' => $vertrag_id,
|
||||
'vertragsstatus_kurzbz' => $vertragsstatus_kurzbz
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all contracts, where the status had been set to 'bestellt' on given date
|
||||
* @param string $string_date e.g. '01.11.2019' or special Date/Time inputs like 'YESTERDAY', 'TODAY', 'NOW'
|
||||
* @param bool $further_processed If true, ALL ordered contracts of that day are retrieved, even if they were
|
||||
* were ALSO approved/accepted/cancelled (further processed) on that same day.
|
||||
* @return array
|
||||
*/
|
||||
public function getOrdered_fromDate($string_date = 'TODAY', $further_processed = false)
|
||||
{
|
||||
$condition = '
|
||||
vertragsstatus_kurzbz = \'bestellt\' AND
|
||||
(datum)::date = date \''. $string_date .'\'
|
||||
';
|
||||
|
||||
if (!$further_processed)
|
||||
{
|
||||
$condition .= '
|
||||
AND
|
||||
vertrag_id NOT IN (
|
||||
SELECT vertrag_id
|
||||
FROM lehre.tbl_vertrag_vertragsstatus
|
||||
WHERE vertragsstatus_kurzbz IN (\'erteilt\', \'akzeptiert\', \'storno\')
|
||||
)
|
||||
';
|
||||
}
|
||||
|
||||
return $this->loadWhere($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all contracts, where the status had been set to 'erteilt' on given date
|
||||
* @param string $string_date e.g. '01.11.2019' or special Date/Time inputs like 'YESTERDAY', 'TODAY', 'NOW'
|
||||
* @param bool $further_processed If true, ALL contracts approved on that day are retrieved, even if they were
|
||||
* were ALSO accepted/cancelled (further processed) on that same day.
|
||||
* @return array
|
||||
*/
|
||||
public function getApproved_fromDate($string_date = 'TODAY', $further_processed = false)
|
||||
{
|
||||
$condition = '
|
||||
vertragsstatus_kurzbz = \'erteilt\' AND
|
||||
(datum)::date = date \''. $string_date .'\'
|
||||
';
|
||||
|
||||
if (!$further_processed)
|
||||
{
|
||||
$condition .= '
|
||||
AND
|
||||
vertrag_id NOT IN (
|
||||
SELECT vertrag_id
|
||||
FROM lehre.tbl_vertrag_vertragsstatus
|
||||
WHERE vertragsstatus_kurzbz IN (\'akzeptiert\', \'storno\')
|
||||
)
|
||||
';
|
||||
}
|
||||
|
||||
return $this->loadWhere($condition);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
class Bisiozweck_model extends DB_Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'bis.tbl_bisio_zweck';
|
||||
$this->pk = array('bisio_id', 'zweck_code');
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,34 @@ class Bisverwendung_model extends DB_Model
|
||||
$this->dbTable = 'bis.tbl_bisverwendung';
|
||||
$this->pk = 'bisverwendung_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest (active) Verwendung of the user.
|
||||
* @param string $uid
|
||||
* @param bool $active If false, returns latest Verwendung no matter if actual or not (ignores ending/beginning date).
|
||||
* @return array
|
||||
*/
|
||||
public function getLast($uid, $active = true)
|
||||
{
|
||||
$this->addLimit(1);
|
||||
|
||||
if ($active)
|
||||
{
|
||||
$condition = '
|
||||
mitarbeiter_uid = '. $this->escape($uid). '
|
||||
AND ( beginn <= NOW() OR beginn IS NULL )
|
||||
AND ( ende >= NOW() OR ende IS NULL )
|
||||
ORDER BY ende DESC NULLS LAST, beginn DESC NULLS LAST
|
||||
';
|
||||
}
|
||||
else
|
||||
{
|
||||
$condition = '
|
||||
mitarbeiter_uid = '. $this->escape($uid). '
|
||||
ORDER BY ende DESC NULLS LAST, beginn DESC NULLS LAST
|
||||
';
|
||||
}
|
||||
|
||||
return $this->loadWhere($condition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +186,7 @@ class Akte_model extends DB_Model
|
||||
|
||||
$dokumente = $this->loadWhere($where);
|
||||
|
||||
if($dokumente->error)
|
||||
return error($dokumente->retval);
|
||||
if($dokumente->error) return $dokumente;
|
||||
|
||||
return success($dokumente->retval);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ class Prestudent_model extends DB_Model
|
||||
parent::__construct();
|
||||
$this->dbTable = 'public.tbl_prestudent';
|
||||
$this->pk = 'prestudent_id';
|
||||
|
||||
$this->load->model('crm/prestudentstatus_model', 'PrestudentstatusModel');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,12 +210,11 @@ class Prestudent_model extends DB_Model
|
||||
return error('prestudent could not be loaded');
|
||||
|
||||
//Prestudentstatus
|
||||
$this->load->model('crm/prestudentstatus_model', 'PrestudentstatusModel');
|
||||
$lastStatus = $this->PrestudentstatusModel->getLastStatus($prestudent_id);
|
||||
|
||||
if ($lastStatus->error)
|
||||
{
|
||||
return error($lastStatus->retval);
|
||||
return $lastStatus;
|
||||
}
|
||||
|
||||
if (count($lastStatus->retval) > 0)
|
||||
@@ -221,7 +222,7 @@ class Prestudent_model extends DB_Model
|
||||
//get Studiengangname from Studienplan and -ordnung
|
||||
$studienordnung = $this->PrestudentstatusModel->getStudienordnungFromPrestudent($prestudent_id);
|
||||
if ($studienordnung->error)
|
||||
return error($studienordnung->retval);
|
||||
return $studienordnung;
|
||||
|
||||
if (count($studienordnung->retval) > 0)
|
||||
{
|
||||
@@ -238,7 +239,7 @@ class Prestudent_model extends DB_Model
|
||||
$language = $this->SpracheModel->load($lastStatus->retval[0]->sprache);
|
||||
|
||||
if ($language->error)
|
||||
return error($language->retval);
|
||||
return $language;
|
||||
|
||||
if (count($language->retval) > 0)
|
||||
$lastStatus->retval[0]->sprachedetails = $language->retval[0];
|
||||
@@ -256,7 +257,7 @@ class Prestudent_model extends DB_Model
|
||||
)
|
||||
);
|
||||
if ($bewerbungstermin->error)
|
||||
return error($bewerbungstermin->retval);
|
||||
return $bewerbungstermin;
|
||||
|
||||
if (count($bewerbungstermin->retval) > 0)
|
||||
{
|
||||
@@ -310,8 +311,6 @@ class Prestudent_model extends DB_Model
|
||||
if (!hasData($prestudents))
|
||||
return $bewerbungen;
|
||||
|
||||
$this->load->model('crm/prestudentstatus_model', 'PrestudentstatusModel');
|
||||
|
||||
foreach ($prestudents->retval as $prestudent)
|
||||
{
|
||||
$lastStatus = $this->PrestudentstatusModel->getLastStatus($prestudent->prestudent_id, $studiensemester_kurzbz);
|
||||
@@ -424,7 +423,6 @@ class Prestudent_model extends DB_Model
|
||||
if (!hasData($prestudent))
|
||||
return false;
|
||||
|
||||
$this->load->model('prestudentstatus_model', 'PrestudentstatusModel');
|
||||
$lastStatus = $this->PrestudentstatusModel->getLastStatus($prestudent_id, null, 'Interessent');
|
||||
|
||||
if (!hasData($lastStatus))
|
||||
|
||||
@@ -123,7 +123,7 @@ class Prestudentstatus_model extends DB_Model
|
||||
|
||||
if ($lastStatus->error)
|
||||
{
|
||||
return error($lastStatus->retval);
|
||||
return $lastStatus;
|
||||
}
|
||||
|
||||
if (count($lastStatus->retval) > 0)
|
||||
@@ -158,7 +158,7 @@ class Prestudentstatus_model extends DB_Model
|
||||
|
||||
if ($lastStatus->error)
|
||||
{
|
||||
return error($lastStatus->retval);
|
||||
return $lastStatus;
|
||||
}
|
||||
|
||||
if (count($lastStatus->retval) > 0)
|
||||
|
||||
@@ -28,6 +28,7 @@ class Lehreinheit_model extends DB_Model
|
||||
{
|
||||
$lehreinheiten = array();
|
||||
|
||||
$this->addOrder('lehreinheit_id');
|
||||
$les = $this->loadWhere(
|
||||
array('lehrveranstaltung_id' => $lehrveranstaltung_id,
|
||||
'studiensemester_kurzbz' => $studiensemester)
|
||||
@@ -62,17 +63,17 @@ class Lehreinheit_model extends DB_Model
|
||||
if (hasData($studiengangresponse))
|
||||
{
|
||||
$studiengang = $studiengangresponse->retval[0];
|
||||
$stgkuerzel = mb_strtoupper($studiengang->typ . $studiengang->kurzbz);
|
||||
$stgkuerzel = mb_strtoupper($studiengang->typ.$studiengang->kurzbz);
|
||||
|
||||
$letoadd->lehreinheitgruppen[] = array(
|
||||
'semester' => $lehreinheitgruppe->semester,
|
||||
'verband' => $lehreinheitgruppe->verband,
|
||||
'gruppe' => $lehreinheitgruppe->gruppe,
|
||||
'gruppe_kurzbz' => $lehreinheitgruppe->gruppe_kurzbz,
|
||||
'direktinskription' => $lehreinheitgruppe->direktinskription,
|
||||
'studiengang_kz' => $lehreinheitgruppe->studiengang_kz,
|
||||
'studiengang_kuerzel' => $stgkuerzel
|
||||
);
|
||||
$letoadd->lehreinheitgruppen[] = array(
|
||||
'semester' => $lehreinheitgruppe->semester,
|
||||
'verband' => $lehreinheitgruppe->verband,
|
||||
'gruppe' => $lehreinheitgruppe->gruppe,
|
||||
'gruppe_kurzbz' => $lehreinheitgruppe->gruppe_kurzbz,
|
||||
'direktinskription' => $lehreinheitgruppe->direktinskription,
|
||||
'studiengang_kz' => $lehreinheitgruppe->studiengang_kz,
|
||||
'studiengang_kuerzel' => $stgkuerzel
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,8 @@ class Lehreinheitgruppe_model extends DB_Model
|
||||
'semester' => $lvadata->semester,
|
||||
'bezeichnung' => $bezeichnung,
|
||||
'aktiv' => true,
|
||||
'mailgrp' => false,
|
||||
'sichtbar' => true,
|
||||
'mailgrp' => true,
|
||||
'sichtbar' => false,
|
||||
'generiert' => false,
|
||||
'insertamum' => date('Y-m-d H:i:s'),
|
||||
'insertvon' => $loggedInUser,
|
||||
|
||||
@@ -11,4 +11,34 @@ class Lehreinheitmitarbeiter_model extends DB_Model
|
||||
$this->dbTable = 'lehre.tbl_lehreinheitmitarbeiter';
|
||||
$this->pk = array('mitarbeiter_uid', 'lehreinheit_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Lehrauftrag has a contract.
|
||||
* @param $mitarbeiter_uid
|
||||
* @param $lehreinheit_id
|
||||
* @return array|bool|int Returns vertrag_id if contract exists. False if doesnt exist. On error array.
|
||||
*/
|
||||
public function hasVertrag($mitarbeiter_uid, $lehreinheit_id)
|
||||
{
|
||||
if(is_string($mitarbeiter_uid) && is_numeric($lehreinheit_id))
|
||||
{
|
||||
$result = $this->load(array(
|
||||
'mitarbeiter_uid' => $mitarbeiter_uid,
|
||||
'lehreinheit_id' => $lehreinheit_id
|
||||
));
|
||||
|
||||
if (hasData($result))
|
||||
{
|
||||
return (is_null($result->retval[0]->vertrag_id)) ? false : intval($result->retval[0]->vertrag_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return error ('Incorrect parameter type');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ class Lehrveranstaltung_model extends DB_Model
|
||||
parent::__construct();
|
||||
$this->dbTable = 'lehre.tbl_lehrveranstaltung';
|
||||
$this->pk = 'lehrveranstaltung_id';
|
||||
|
||||
$this->load->model('organisation/studiengang_model', 'StudiengangModel');
|
||||
$this->load->model('organisation/studiensemester_model', 'StudiensemesterModel');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,8 +25,6 @@ class Lehrveranstaltung_model extends DB_Model
|
||||
*/
|
||||
public function getLehrveranstaltungGroupNames($studiensemester_kurzbz, $ausbildungssemester = null, $studiengang_kz = null, $lehrveranstaltung_ids = null)
|
||||
{
|
||||
$this->load->model('organisation/studiengang_model', 'StudiengangModel');
|
||||
|
||||
$studiengang_kz_arr = array();
|
||||
$ausbildungssemester_arr = array();
|
||||
$lehrveranstaltung_id_arr = array();
|
||||
@@ -59,13 +60,12 @@ class Lehrveranstaltung_model extends DB_Model
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->model('organisation/studiensemester_model', 'StudiensemesterModel');
|
||||
foreach ($studiengang_kz_arr as $studiengang_kz_item)
|
||||
{
|
||||
$result = $this->StudiensemesterModel->getAusbildungssemesterByStudiensemesterAndStudiengang($studiensemester_kurzbz, $studiengang_kz_item);
|
||||
|
||||
if (isError($result))
|
||||
return error($result->retval);
|
||||
return error(getError($result));
|
||||
|
||||
foreach ($result->retval as $semester)
|
||||
{
|
||||
@@ -104,7 +104,7 @@ class Lehrveranstaltung_model extends DB_Model
|
||||
|
||||
if (count($studiengang_kz_arr) > 0)
|
||||
$query .= " AND tbl_lehrveranstaltung.studiengang_kz IN (". implode(", ", $studiengang_kz_arr).")";
|
||||
|
||||
|
||||
if (count($lehrveranstaltung_id_arr) > 0)
|
||||
{
|
||||
$query .= " AND tbl_lehrveranstaltung.lehrveranstaltung_id IN (". implode(', ', $lehrveranstaltung_id_arr).")";
|
||||
@@ -144,7 +144,7 @@ class Lehrveranstaltung_model extends DB_Model
|
||||
WHERE
|
||||
vw_student_lehrveranstaltung.studiensemester_kurzbz=?
|
||||
AND
|
||||
vw_student_lehrveranstaltung.lehrveranstaltung_id=?
|
||||
vw_student_lehrveranstaltung.lehrveranstaltung_id=?
|
||||
ORDER BY nachname, vorname, person_id, tbl_bisio.bis DESC";
|
||||
|
||||
return $this->execQuery($query, array($studiensemester_kurzbz, $lehrveranstaltung_id));
|
||||
@@ -214,8 +214,6 @@ class Lehrveranstaltung_model extends DB_Model
|
||||
*/
|
||||
public function getLvsWithIncomingPlaces($studiensemester_kurzbz)
|
||||
{
|
||||
$this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel');
|
||||
|
||||
$studsemres = $this->StudiensemesterModel->load($studiensemester_kurzbz);
|
||||
|
||||
if (!hasData($studsemres))
|
||||
|
||||
@@ -11,4 +11,34 @@ class Projektbetreuer_model extends DB_Model
|
||||
$this->dbTable = 'lehre.tbl_projektbetreuer';
|
||||
$this->pk = array('betreuerart_kurzbz', 'projektarbeit_id', 'person_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Projektauftrag has a contract.
|
||||
* @param $person_id
|
||||
* @param $projektarbeit_id
|
||||
* @return array|bool|int Returns vertrag_id if contract exists. False if doesnt exist. On error array.
|
||||
*/
|
||||
public function hasVertrag($person_id, $projektarbeit_id)
|
||||
{
|
||||
if (is_numeric($person_id) && is_numeric($projektarbeit_id))
|
||||
{
|
||||
$result = $this->load(array(
|
||||
'person_id' => $person_id,
|
||||
'projektarbeit_id' => $projektarbeit_id
|
||||
));
|
||||
|
||||
if (hasData($result))
|
||||
{
|
||||
return (is_null($result->retval[0]->vertrag_id)) ? false : intval($result->retval[0]->vertrag_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return error ('Incorrect parameter type');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,4 +165,27 @@ class Organisationseinheit_model extends DB_Model
|
||||
return $this->execQuery(sprintf($query, $aktivstring, $aktivstring), array($oe_kurzbz));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one parent only.
|
||||
* Easily retrieve department of a studiengang or fakultät of department etc.
|
||||
* @param $oe_kurzbz
|
||||
* @return array|null
|
||||
*/
|
||||
public function getParent($oe_kurzbz)
|
||||
{
|
||||
if (is_string($oe_kurzbz))
|
||||
{
|
||||
$condition = '
|
||||
oe_kurzbz = (
|
||||
SELECT
|
||||
oe_parent_kurzbz
|
||||
FROM
|
||||
public.tbl_organisationseinheit
|
||||
WHERE
|
||||
oe_kurzbz = \''. $oe_kurzbz. '\'
|
||||
)
|
||||
';
|
||||
}
|
||||
return $this->loadWhere($condition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class Studienplan_model extends DB_Model
|
||||
return $this->loadWhere(array("studiengang_kz" => $studiengang_kz));
|
||||
}
|
||||
|
||||
public function getStudienplaeneBySemester($studiengang_kz, $studiensemester_kurzbz, $ausbildungssemester = null, $orgform_kurzbz = null)
|
||||
public function getStudienplaeneBySemester($studiengang_kz, $studiensemester_kurzbz, $ausbildungssemester = null, $orgform_kurzbz = null, $sprache = null)
|
||||
{
|
||||
$this->addJoin("lehre.tbl_studienordnung", "studienordnung_id");
|
||||
$this->addJoin("lehre.tbl_studienplan_semester", "studienplan_id");
|
||||
@@ -40,6 +40,11 @@ class Studienplan_model extends DB_Model
|
||||
$whereArray["orgform_kurzbz"] = $orgform_kurzbz;
|
||||
}
|
||||
|
||||
if(!is_null($sprache))
|
||||
{
|
||||
$whereArray["tbl_studienplan.sprache"] = $sprache;
|
||||
}
|
||||
|
||||
return $this->StudienplanModel->loadWhere($whereArray);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,22 @@ class Studiensemester_model extends DB_Model
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
|
||||
// Get next study semester
|
||||
public function getNext()
|
||||
{
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM
|
||||
public.tbl_studiensemester
|
||||
WHERE
|
||||
start > now()
|
||||
ORDER BY start
|
||||
LIMIT 1;
|
||||
';
|
||||
|
||||
return $this->execQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* getLastOrAktSemester
|
||||
*/
|
||||
@@ -61,7 +77,7 @@ class Studiensemester_model extends DB_Model
|
||||
start,
|
||||
ende
|
||||
FROM public.tbl_studiensemester
|
||||
WHERE start > (
|
||||
WHERE start >= (
|
||||
SELECT ende
|
||||
FROM public.tbl_studiensemester
|
||||
WHERE studiensemester_kurzbz = ?
|
||||
@@ -72,6 +88,26 @@ class Studiensemester_model extends DB_Model
|
||||
return $this->execQuery($query, array($studiensemester_kurzbz));
|
||||
}
|
||||
|
||||
/**
|
||||
* getPreviousFrom
|
||||
*/
|
||||
public function getPreviousFrom($studiensemester_kurzbz)
|
||||
{
|
||||
$query = 'SELECT studiensemester_kurzbz,
|
||||
start,
|
||||
ende
|
||||
FROM public.tbl_studiensemester
|
||||
WHERE ende <= (
|
||||
SELECT start
|
||||
FROM public.tbl_studiensemester
|
||||
WHERE studiensemester_kurzbz = ?
|
||||
)
|
||||
ORDER BY start DESC
|
||||
LIMIT 1';
|
||||
|
||||
return $this->execQuery($query, array($studiensemester_kurzbz));
|
||||
}
|
||||
|
||||
/**
|
||||
* getNearest
|
||||
*/
|
||||
|
||||
@@ -15,8 +15,7 @@ class Benutzer_model extends DB_Model
|
||||
|
||||
public function getFromPersonId($person_id)
|
||||
{
|
||||
/*$this->addSelect('uid, aktiv, alias');*/
|
||||
$this->loadWhere(array('person_id' => $person_id));
|
||||
return $this->loadWhere(array('person_id' => $person_id, 'aktiv' => true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Benutzerfunktion_model extends DB_Model
|
||||
|
||||
if (is_string($funktion_kurzbz))
|
||||
{
|
||||
$query .= " AND funktion_kurzbz = ".$funktion_kurzbz.")";
|
||||
$query .= " AND funktion_kurzbz = '".$funktion_kurzbz."'";
|
||||
}
|
||||
elseif (is_array($funktion_kurzbz) && count($funktion_kurzbz) > 0)
|
||||
{
|
||||
@@ -104,4 +104,38 @@ class Benutzerfunktion_model extends DB_Model
|
||||
|
||||
return $this->execQuery($query, $parametersArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active Studiengangsleitung(en) of the user by UID.
|
||||
* @param $uid
|
||||
*/
|
||||
public function getSTGLByUID($uid)
|
||||
{
|
||||
$query = '
|
||||
SELECT
|
||||
uid,
|
||||
oe_kurzbz,
|
||||
studiengang_kz,
|
||||
typ,
|
||||
tbl_studiengang.bezeichnung
|
||||
FROM
|
||||
public.tbl_benutzerfunktion
|
||||
JOIN public.tbl_studiengang USING (oe_kurzbz)
|
||||
WHERE
|
||||
funktion_kurzbz = \'Leitung\'
|
||||
AND (datum_von IS NULL OR datum_von <= now())
|
||||
AND (datum_bis IS NULL OR datum_bis >= now())
|
||||
AND uid = ?
|
||||
ORDER BY
|
||||
oe_kurzbz
|
||||
';
|
||||
|
||||
$parameters_array = array();
|
||||
if (is_string($uid))
|
||||
{
|
||||
$parameters_array[] = $uid;
|
||||
}
|
||||
|
||||
return $this->execQuery($query, $parameters_array);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ class Person_model extends DB_Model
|
||||
parent::__construct();
|
||||
$this->dbTable = 'public.tbl_person';
|
||||
$this->pk = 'person_id';
|
||||
|
||||
$this->load->model('person/kontakt_model', 'KontaktModel');
|
||||
$this->load->model('person/adresse_model', 'AdresseModel');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,29 +158,24 @@ class Person_model extends DB_Model
|
||||
|
||||
$person = $this->load($person_id);
|
||||
|
||||
if($person->error)
|
||||
return error($person->retval);
|
||||
if($person->error) return $person;
|
||||
|
||||
//return null if not found
|
||||
if(count($person->retval) < 1)
|
||||
return success(null);
|
||||
|
||||
$this->load->model('person/kontakt_model', 'KontaktModel');
|
||||
$this->load->model('person/adresse_model', 'AdresseModel');
|
||||
|
||||
$this->KontaktModel->addDistinct();
|
||||
$this->KontaktModel->addSelect('kontakttyp, anmerkung, kontakt, zustellung');
|
||||
$this->KontaktModel->addOrder('kontakttyp');
|
||||
$where = $zustellung_only === true ? array('person_id' => $person_id, 'zustellung' => true) : array('person_id' => $person_id);
|
||||
$kontakte = $this->KontaktModel->loadWhere($where);
|
||||
if($kontakte->error)
|
||||
return error($kontakte->retval);
|
||||
if($kontakte->error) return $kontakte;
|
||||
|
||||
$where = $zustellung_only === true ? array('person_id' => $person_id, 'zustelladresse' => true) : array('person_id' => $person_id);
|
||||
$this->AdresseModel->addSelect('public.tbl_adresse.*, bis.tbl_nation.kurztext AS nationkurztext');
|
||||
$this->AdresseModel->addJoin('bis.tbl_nation', 'tbl_adresse.nation = tbl_nation.nation_code', 'LEFT');
|
||||
$adressen = $this->AdresseModel->loadWhere($where);
|
||||
if($adressen->error)
|
||||
return error($adressen->retval);
|
||||
if($adressen->error) return $adressen;
|
||||
|
||||
$stammdaten = $person->retval[0];
|
||||
$stammdaten->kontakte = $kontakte->retval;
|
||||
|
||||
@@ -11,4 +11,33 @@ class Mitarbeiter_model extends DB_Model
|
||||
$this->dbTable = 'public.tbl_mitarbeiter';
|
||||
$this->pk = 'mitarbeiter_uid';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user is a Mitarbeiter.
|
||||
* @param string $uid
|
||||
* @param boolean null $fixangestellt
|
||||
* @return array
|
||||
*/
|
||||
public function isMitarbeiter($uid, $fixangestellt = null)
|
||||
{
|
||||
$this->addSelect('1');
|
||||
|
||||
if (is_bool($fixangestellt))
|
||||
{
|
||||
$result = $this->loadWhere(array('mitarbeiter_uid' => $uid, 'fixangestellt' => $fixangestellt));
|
||||
}
|
||||
else // default
|
||||
{
|
||||
$result = $this->loadWhere(array('mitarbeiter_uid' => $uid));
|
||||
}
|
||||
|
||||
if(hasData($result))
|
||||
{
|
||||
return success(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return success(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class Benutzerrolle_model extends DB_Model
|
||||
$this->dbTable = 'system.tbl_benutzerrolle';
|
||||
$this->pk = 'benutzerberechtigung_id';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given user is an admin
|
||||
*/
|
||||
@@ -19,9 +19,9 @@ class Benutzerrolle_model extends DB_Model
|
||||
{
|
||||
// Join with the table tbl_benutzer
|
||||
$this->addJoin('public.tbl_benutzer', 'uid');
|
||||
|
||||
|
||||
$result = $this->loadWhere(array('person_id' => $person_id, 'rolle_kurzbz' => 'admin'));
|
||||
|
||||
|
||||
if (!isError($result))
|
||||
{
|
||||
if (hasData($result))
|
||||
@@ -33,7 +33,35 @@ class Benutzerrolle_model extends DB_Model
|
||||
$result = success(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user who are authorized with berechtigung and, if given, authorized for the specific organisational unit.
|
||||
* @param $berechtigung_kurzbz
|
||||
* @param null $oe_kurzbz
|
||||
* @return array
|
||||
*/
|
||||
public function getBenutzerByBerechtigung($berechtigung_kurzbz, $oe_kurzbz = null)
|
||||
{
|
||||
$params = array();
|
||||
$query = '
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
system.vw_berechtigung_nichtrekursiv
|
||||
WHERE
|
||||
berechtigung_kurzbz = ?';
|
||||
|
||||
$params[] = $berechtigung_kurzbz;
|
||||
|
||||
if (!is_null($oe_kurzbz))
|
||||
{
|
||||
$query .= ' AND oe_kurzbz = ?';
|
||||
$params[] = $oe_kurzbz;
|
||||
}
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
class FAS_UDF_model extends DB_Model
|
||||
{
|
||||
// String values of booleans
|
||||
const STRING_NULL = 'null';
|
||||
const STRING_TRUE = 'true';
|
||||
const STRING_FALSE = 'false';
|
||||
|
||||
const UDF_DROPDOWN_TYPE = 'dropdown';
|
||||
const UDF_MULTIPLEDROPDOWN_TYPE = 'multipledropdown';
|
||||
|
||||
/**
|
||||
* Methods to save data from FAS
|
||||
*/
|
||||
public function saveUDFs($udfs)
|
||||
{
|
||||
$result = error('No way man!');
|
||||
$resultPerson = success('person');
|
||||
$resultPrestudent = success('prestudent');
|
||||
|
||||
$person_id = null;
|
||||
if (isset($udfs['person_id'])) $person_id = $udfs['person_id'];
|
||||
unset($udfs['person_id']);
|
||||
|
||||
$prestudent_id = null;
|
||||
if (isset($udfs['prestudent_id'])) $prestudent_id = $udfs['prestudent_id'];
|
||||
unset($udfs['prestudent_id']);
|
||||
|
||||
$jsons = array();
|
||||
|
||||
//
|
||||
if (isset($person_id))
|
||||
{
|
||||
// Load model Person_model
|
||||
$this->load->model('person/Person_model', 'PersonModel');
|
||||
|
||||
$result = $this->load(array('public', 'tbl_person'));
|
||||
if (isSuccess($result) && count($result->retval) == 1)
|
||||
{
|
||||
$jsons = json_decode($result->retval[0]->jsons);
|
||||
}
|
||||
|
||||
$udfs = $this->_fillMissingTextUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingChkboxUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
|
||||
|
||||
$resultPerson = $this->PersonModel->update($person_id, $udfs);
|
||||
}
|
||||
|
||||
//
|
||||
if (isset($prestudent_id))
|
||||
{
|
||||
// Load model Prestudent_model
|
||||
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
|
||||
$result = $this->load(array('public', 'tbl_prestudent'));
|
||||
if (isSuccess($result) && count($result->retval) == 1)
|
||||
{
|
||||
$jsons = json_decode($result->retval[0]->jsons);
|
||||
}
|
||||
|
||||
$udfs = $this->_fillMissingTextUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingChkboxUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
|
||||
|
||||
$resultPrestudent = $this->PrestudentModel->update($prestudent_id, $udfs);
|
||||
}
|
||||
|
||||
if (isSuccess($resultPerson) && isSuccess($resultPrestudent))
|
||||
{
|
||||
$result = success(array($resultPerson->retval, $resultPrestudent->retval));
|
||||
}
|
||||
else if(isError($resultPerson))
|
||||
{
|
||||
$result = $resultPerson;
|
||||
}
|
||||
else if(isError($resultPrestudent))
|
||||
{
|
||||
$result = $resultPrestudent;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingChkboxUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingChkboxUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDFLib::CHKBOX_TYPE)
|
||||
{
|
||||
if (!isset($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_FALSE)
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = false;
|
||||
}
|
||||
else if ($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_TRUE)
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingChkboxUDF;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingDropdownUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingDropdownUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDF_model::UDF_DROPDOWN_TYPE
|
||||
|| $udfDescription->{UDFLib::TYPE} == UDF_model::UDF_MULTIPLEDROPDOWN_TYPE)
|
||||
{
|
||||
if (!isset($_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
else if($_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_NULL)
|
||||
{
|
||||
$_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingDropdownUDF;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingTextUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingTextUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == 'textarea'
|
||||
|| $udfDescription->{UDFLib::TYPE} == 'textfield')
|
||||
{
|
||||
if (!isset($_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
else if(trim($_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}]) == '')
|
||||
{
|
||||
$_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingTextUDF;
|
||||
}
|
||||
}
|
||||
@@ -37,17 +37,7 @@ class MessageToken_model extends DB_Model
|
||||
WHERE r.token = ?
|
||||
LIMIT 1';
|
||||
|
||||
$result = $this->db->query($sql, array(MSG_STATUS_DELETED, $token));
|
||||
|
||||
// If no errors occurred
|
||||
if ($result)
|
||||
{
|
||||
return success($result->result());
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
return $this->execQuery($sql, array(MSG_STATUS_DELETED, $token));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,25 +64,24 @@ class MessageToken_model extends DB_Model
|
||||
WHERE r.token = ?
|
||||
LIMIT 1';
|
||||
|
||||
$msgs = $this->db->query($sql, array(MSG_STATUS_ARCHIVED, $token));
|
||||
$msgsResult = $this->execQuery($sql, array(MSG_STATUS_ARCHIVED, $token));
|
||||
|
||||
// If no errors occurred
|
||||
if ($msgs)
|
||||
if (isSuccess($msgsResult))
|
||||
{
|
||||
$msgs_result = $msgs->result();
|
||||
// If at least a record is present
|
||||
if (count($msgs_result) > 0)
|
||||
if (hasData($msgsResult))
|
||||
{
|
||||
$msg = $msgs_result[0];
|
||||
$msg = getData($msgsResult)[0];
|
||||
$msgStatusResult = error();
|
||||
|
||||
$msgStatusResult = false; // pessimistic expectation
|
||||
$this->load->model('system/MsgStatus_model', 'MsgStatusModel');
|
||||
|
||||
// If the status of the message is unread
|
||||
if ($msg->status == MSG_STATUS_UNREAD)
|
||||
{
|
||||
// Insert the read status
|
||||
$msgStatusResult = $this->db->insert(
|
||||
'public.tbl_msg_status',
|
||||
$msgStatusResult = $this->MsgStatusModel->insert(
|
||||
array(
|
||||
'message_id' => $msg->message_id,
|
||||
'person_id' => $msg->receiver_id,
|
||||
@@ -108,31 +97,23 @@ class MessageToken_model extends DB_Model
|
||||
// If the status of the message is read
|
||||
else if ($msg->status == MSG_STATUS_READ)
|
||||
{
|
||||
// Update updateamum to current date
|
||||
$this->db->set('updateamum', 'NOW()');
|
||||
|
||||
$this->db->where('message_id', $msg->message_id);
|
||||
$this->db->where('person_id', $msg->receiver_id);
|
||||
$this->db->where('status', MSG_STATUS_READ);
|
||||
|
||||
$msgStatusResult = $this->db->update('public.tbl_msg_status');
|
||||
$msgStatusResult = $this->MsgStatusModel->update(
|
||||
array(
|
||||
'message_id' => $msg->message_id,
|
||||
'person_id' => $msg->receiver_id,
|
||||
'status' => MSG_STATUS_READ
|
||||
),
|
||||
array('updateamum' => 'NOW()')
|
||||
);
|
||||
}
|
||||
|
||||
// If some of the previous DB manipulation (update or insert) has failed
|
||||
if (!$msgStatusResult)
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
return $msgStatusResult;
|
||||
}
|
||||
|
||||
return success($msgs_result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
return $msgsResult;
|
||||
}
|
||||
|
||||
return success($result->result());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,8 +143,8 @@ class MessageToken_model extends DB_Model
|
||||
{
|
||||
$sql = 'SELECT m.mitarbeiter_uid
|
||||
FROM public.tbl_person p
|
||||
LEFT JOIN public.tbl_benutzer b USING(person_id)
|
||||
LEFT JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
|
||||
JOIN public.tbl_benutzer b USING(person_id)
|
||||
JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
|
||||
WHERE p.person_id = ?
|
||||
AND b.aktiv = TRUE';
|
||||
|
||||
@@ -193,28 +174,6 @@ class MessageToken_model extends DB_Model
|
||||
LIMIT 1
|
||||
';
|
||||
|
||||
$result = $this->db->query($sql, array($oe_kurzbz));
|
||||
if ($result) // If no errors occurred
|
||||
{
|
||||
$result_arr = $result->result();
|
||||
// If data are present
|
||||
if (is_array($result_arr)
|
||||
&& count($result_arr) > 0
|
||||
&& is_object($result_arr[0])
|
||||
&& isset($result_arr[0]->oe_kurzbz))
|
||||
{
|
||||
return success($result_arr[0]->oe_kurzbz);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $this->execQuery($sql, array($oe_kurzbz));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ class PersonLock_model extends DB_Model
|
||||
|
||||
$result = $this->loadWhere($lockdata);
|
||||
|
||||
if ($result->error)
|
||||
return error($result->retval);
|
||||
if ($result->error) return $result;
|
||||
|
||||
if (count($result->retval) > 0)
|
||||
return success($result->retval);
|
||||
@@ -49,8 +48,7 @@ class PersonLock_model extends DB_Model
|
||||
{
|
||||
$locked = $this->checkIfLocked($person_id, $app);
|
||||
|
||||
if ($locked->error)
|
||||
return error($locked->retval);
|
||||
if ($locked->error) return $locked;
|
||||
|
||||
//insert only if not already locked
|
||||
if ($locked->retval === null)
|
||||
@@ -77,8 +75,7 @@ class PersonLock_model extends DB_Model
|
||||
foreach ($locks->retval as $lock)
|
||||
{
|
||||
$result = $this->delete($lock->lock_id);
|
||||
if ($result->error)
|
||||
return error($result->retval);
|
||||
if ($result->error) return $result;
|
||||
|
||||
$deleted[] = $lock;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,6 @@
|
||||
|
||||
class UDF_model extends DB_Model
|
||||
{
|
||||
// String values of booleans
|
||||
const STRING_NULL = 'null';
|
||||
const STRING_TRUE = 'true';
|
||||
const STRING_FALSE = 'false';
|
||||
|
||||
const UDF_DROPDOWN_TYPE = 'dropdown';
|
||||
const UDF_MULTIPLEDROPDOWN_TYPE = 'multipledropdown';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -38,164 +30,4 @@ class UDF_model extends DB_Model
|
||||
|
||||
return $udfResults;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
// These methods work only with the this version of FAS, not with the future versions
|
||||
|
||||
/**
|
||||
* Methods to save data from FAS
|
||||
*/
|
||||
public function saveUDFs($udfs)
|
||||
{
|
||||
$result = error('No way man!');
|
||||
$resultPerson = success('person');
|
||||
$resultPrestudent = success('prestudent');
|
||||
|
||||
$person_id = null;
|
||||
if (isset($udfs['person_id'])) $person_id = $udfs['person_id'];
|
||||
unset($udfs['person_id']);
|
||||
|
||||
$prestudent_id = null;
|
||||
if (isset($udfs['prestudent_id'])) $prestudent_id = $udfs['prestudent_id'];
|
||||
unset($udfs['prestudent_id']);
|
||||
|
||||
$jsons = array();
|
||||
|
||||
//
|
||||
if (isset($person_id))
|
||||
{
|
||||
// Load model Person_model
|
||||
$this->load->model('person/Person_model', 'PersonModel');
|
||||
|
||||
$result = $this->load(array('public', 'tbl_person'));
|
||||
if (isSuccess($result) && count($result->retval) == 1)
|
||||
{
|
||||
$jsons = json_decode($result->retval[0]->jsons);
|
||||
}
|
||||
|
||||
$udfs = $this->_fillMissingTextUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingChkboxUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
|
||||
|
||||
$resultPerson = $this->PersonModel->update($person_id, $udfs);
|
||||
}
|
||||
|
||||
//
|
||||
if (isset($prestudent_id))
|
||||
{
|
||||
// Load model Prestudent_model
|
||||
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
|
||||
$result = $this->load(array('public', 'tbl_prestudent'));
|
||||
if (isSuccess($result) && count($result->retval) == 1)
|
||||
{
|
||||
$jsons = json_decode($result->retval[0]->jsons);
|
||||
}
|
||||
|
||||
$udfs = $this->_fillMissingTextUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingChkboxUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
|
||||
|
||||
$resultPrestudent = $this->PrestudentModel->update($prestudent_id, $udfs);
|
||||
}
|
||||
|
||||
if (isSuccess($resultPerson) && isSuccess($resultPrestudent))
|
||||
{
|
||||
$result = success(array($resultPerson->retval, $resultPrestudent->retval));
|
||||
}
|
||||
else if(isError($resultPerson))
|
||||
{
|
||||
$result = $resultPerson;
|
||||
}
|
||||
else if(isError($resultPrestudent))
|
||||
{
|
||||
$result = $resultPrestudent;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingChkboxUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingChkboxUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDFLib::CHKBOX_TYPE)
|
||||
{
|
||||
if (!isset($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_FALSE)
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = false;
|
||||
}
|
||||
else if ($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_TRUE)
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingChkboxUDF;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingDropdownUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingDropdownUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDF_model::UDF_DROPDOWN_TYPE
|
||||
|| $udfDescription->{UDFLib::TYPE} == UDF_model::UDF_MULTIPLEDROPDOWN_TYPE)
|
||||
{
|
||||
if (!isset($_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
else if($_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_NULL)
|
||||
{
|
||||
$_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingDropdownUDF;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingTextUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingTextUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == 'textarea'
|
||||
|| $udfDescription->{UDFLib::TYPE} == 'textfield')
|
||||
{
|
||||
if (!isset($_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
else if(trim($_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}]) == '')
|
||||
{
|
||||
$_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingTextUDF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,92 @@ class Variable_model extends DB_Model
|
||||
parent::__construct();
|
||||
$this->dbTable = 'public.tbl_variable';
|
||||
$this->pk = array('uid', 'name');
|
||||
$this->hasSequence = false;
|
||||
|
||||
$this->load->model('system/Variablenname_model', 'VariablennameModel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets user variables and values for a uid.
|
||||
* If no value found in tbl_variable, default as defined in variablename_model is retrieved.
|
||||
* @param $uid
|
||||
* @param null $names optionally get only certain variables
|
||||
* @return array
|
||||
*/
|
||||
public function getVariables($uid, $names = null)
|
||||
{
|
||||
if (isEmptyString($uid) || (isset($names) && !is_array($names)))
|
||||
$result = error('wrong parameters passed');
|
||||
else
|
||||
{
|
||||
$vardata = array();
|
||||
|
||||
$qry = "SELECT name, wert FROM public.tbl_variable WHERE uid = ?";
|
||||
|
||||
if (isset($names))
|
||||
{
|
||||
$qry .= " AND name IN ('".implode(',', $names)."')";
|
||||
}
|
||||
$qry .= ";";
|
||||
|
||||
$varresults = $this->execQuery($qry, array($uid));
|
||||
|
||||
if (hasData($varresults))
|
||||
{
|
||||
$varresults = getData($varresults);
|
||||
foreach ($varresults as $varresult)
|
||||
{
|
||||
if (isset($varresult->wert))
|
||||
$vardata[$varresult->name] = $varresult->wert;
|
||||
}
|
||||
}
|
||||
|
||||
$vardefaults = $this->VariablennameModel->getDefaults($names);
|
||||
|
||||
if (hasData($vardefaults))
|
||||
{
|
||||
$vardefaults = getData($vardefaults);
|
||||
|
||||
|
||||
foreach ($vardefaults as $vardefault)
|
||||
{
|
||||
if (!isset($vardata[$vardefault->name]) && isset($vardefault->defaultwert))
|
||||
{
|
||||
$vardata[$vardefault->name] = $vardefault->defaultwert;
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = success($vardata);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a variable value for a uid. Adds new entry if not present, updates entry otherwise.
|
||||
* @param $uid
|
||||
* @param $name
|
||||
* @param $wert
|
||||
* @return array
|
||||
*/
|
||||
public function setVariable($uid, $name, $wert)
|
||||
{
|
||||
$result = error('error when setting variable!');
|
||||
if (!isEmptyString($uid) && !isEmptyString($name) && !isEmptyString($wert))
|
||||
{
|
||||
$varres = $this->loadWhere(array('uid' => $uid, 'name' => $name));
|
||||
|
||||
if (isSuccess($varres))
|
||||
{
|
||||
if (hasData($varres))
|
||||
{
|
||||
$result = $this->VariableModel->update(array('uid' => $uid, 'name' => $name), array('wert' => $wert));
|
||||
}
|
||||
else
|
||||
$result = $this->VariableModel->insert(array('uid' => $uid, 'name' => $name, 'wert' => $wert));
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
class Variablenname_model extends DB_Model
|
||||
{
|
||||
// Contains SQL queries retrieving default variable values if no default is set.
|
||||
private $_dynamic_defaults = array(
|
||||
'semester_aktuell' => 'SELECT studiensemester_kurzbz FROM public.tbl_studiensemester WHERE ende>now() ORDER BY start LIMIT 1',
|
||||
'infocenter_studiensemester' => 'SELECT studiensemester_kurzbz FROM (
|
||||
SELECT DISTINCT ON (studienjahr_kurzbz) start, studiensemester_kurzbz
|
||||
FROM public.tbl_studiensemester
|
||||
ORDER BY studienjahr_kurzbz, start
|
||||
) sem
|
||||
WHERE start > now()
|
||||
LIMIT 1;'
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'public.tbl_variablenname';
|
||||
$this->pk ='name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets defaults for user variables.
|
||||
* If no default value present in table, SQL can be executed for retrieving the value.
|
||||
* @param $names optionally get only defaults for certain variables
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaults($names = null)
|
||||
{
|
||||
$defaults = array();
|
||||
|
||||
$qry = "SELECT name, defaultwert FROM public.tbl_variablenname";
|
||||
|
||||
if (!isEmptyArray($names))
|
||||
{
|
||||
$qry .= " WHERE name IN ?";
|
||||
}
|
||||
$qry .= ";";
|
||||
|
||||
$defaultsres = $this->execQuery($qry, array('name' => $names));
|
||||
|
||||
if (hasData($defaultsres))
|
||||
{
|
||||
$defaults = getData($defaultsres);
|
||||
|
||||
foreach ($defaults as $default)
|
||||
{
|
||||
if (!isset($default->defaultwert))
|
||||
{
|
||||
if (isset($this->_dynamic_defaults[$default->name]))
|
||||
{
|
||||
$dyndefault = $this->execQuery($this->_dynamic_defaults[$default->name]);
|
||||
if (hasData($dyndefault))
|
||||
{
|
||||
$dyndefault = getData($dyndefault);
|
||||
|
||||
if (count($dyndefault) === 1)
|
||||
{
|
||||
foreach ($dyndefault[0] as $value)
|
||||
{
|
||||
$default->defaultwert = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success($defaults);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
class Webservicelog_model extends DB_Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->dbTable = 'system.tbl_webservicelog';
|
||||
$this->pk = 'webservicelog_id';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user