Merge branch 'master' into feature-3716/Messaging_inbox_outbox_user

This commit is contained in:
Paolo
2020-01-16 16:36:57 +01:00
457 changed files with 39585 additions and 46623 deletions
@@ -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);
}
}
+169
View File
@@ -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;
}
-168
View File
@@ -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';
}