mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-23 18:02:18 +00:00
- Added functions isSuccess, isError and hasData in message helper
- Updated the code using these new functions
This commit is contained in:
@@ -53,7 +53,7 @@ class Nation extends APIv1_Controller
|
||||
$result = $this->NationModel->addOrder('engltext');
|
||||
}
|
||||
|
||||
if ($result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
if ($this->get('ohnesperre'))
|
||||
{
|
||||
|
||||
@@ -118,12 +118,7 @@ class Studiensemester extends APIv1_Controller
|
||||
$result = $this->StudiensemesterModel->loadWhere(array('start <=' => 'NOW()', 'ende >=' => 'NOW()'));
|
||||
}
|
||||
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) &&
|
||||
count($result->retval) > 0)
|
||||
{
|
||||
// Return $result
|
||||
}
|
||||
else
|
||||
if (!hasData($result))
|
||||
{
|
||||
$this->StudiensemesterModel->addOrder('ende');
|
||||
$this->StudiensemesterModel->addLimit(1);
|
||||
|
||||
@@ -93,7 +93,7 @@ class Person extends APIv1_Controller
|
||||
$person = $this->_parseData($this->post());
|
||||
$validation = $this->_validate($this->post());
|
||||
|
||||
if (is_object($validation) && $validation->error == EXIT_SUCCESS)
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
if(isset($person["person_id"]) && !(is_null($person["person_id"])) && ($person["person_id"] != ""))
|
||||
{
|
||||
|
||||
@@ -112,7 +112,7 @@ class Message extends APIv1_Controller
|
||||
{
|
||||
$validation = $this->_validatePostMessage($this->post());
|
||||
|
||||
if (is_object($validation) && $validation->error == EXIT_SUCCESS)
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
$result = $this->messagelib->sendMessage(
|
||||
isset($this->post()['person_id']) ? $this->post()['person_id'] : null,
|
||||
@@ -139,7 +139,7 @@ class Message extends APIv1_Controller
|
||||
{
|
||||
$validation = $this->_validatePostMessageVorlage($this->post());
|
||||
|
||||
if (is_object($validation) && $validation->error == EXIT_SUCCESS)
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
$result = $this->messagelib->sendMessageVorlage(
|
||||
isset($this->post()['sender_id']) ? $this->post()['sender_id'] : null,
|
||||
|
||||
@@ -30,4 +30,40 @@ function error($retval = '', $code = null, $msg_indx_prefix = 'fhc_')
|
||||
$error->retval = $retval;
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the result represents a success
|
||||
*/
|
||||
function isSuccess($result)
|
||||
{
|
||||
if (is_object($result) && isset($result->error) && $result->error == EXIT_SUCCESS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the result represents a success and also if it contains data from DB
|
||||
*/
|
||||
function hasData($result)
|
||||
{
|
||||
if (isSuccess($result) && isset($result->retval) &&
|
||||
is_array($result->retval) && count($result->retval) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the result represents an error
|
||||
* Wrapper function of isSuccess, more readable code
|
||||
*/
|
||||
function isError($result)
|
||||
{
|
||||
return !isSuccess($result);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class CallerLib
|
||||
$this->ci =& get_instance();
|
||||
|
||||
// Loads helper message to manage returning messages
|
||||
$this->ci->load->helper('message');
|
||||
$this->ci->load->helper('Message');
|
||||
|
||||
// Loads permission library
|
||||
$this->ci->load->library('PermissionLib');
|
||||
@@ -65,7 +65,7 @@ class CallerLib
|
||||
$validation = $this->_validateCall($parameters);
|
||||
|
||||
// If the validation was passed
|
||||
if ($validation->error == EXIT_SUCCESS)
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
$loaded = null;
|
||||
// If the given resource is a model
|
||||
@@ -73,7 +73,7 @@ class CallerLib
|
||||
{
|
||||
// Try to load the model
|
||||
$result = $this->_loadModel($parameters->resourcePath, $parameters->resourceName);
|
||||
if ($result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$loaded = $result->retval;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class CallerLib
|
||||
$parameters->function,
|
||||
$permissionType
|
||||
);
|
||||
if ($result->error == EXIT_ERROR)
|
||||
if (isError($result))
|
||||
{
|
||||
$loaded = null;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class CallerLib
|
||||
{
|
||||
// Try to load the library
|
||||
$result = $this->_loadLibrary($parameters->resourcePath, $parameters->resourceName);
|
||||
if ($result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$loaded = $result->retval;
|
||||
}
|
||||
|
||||
@@ -48,11 +48,11 @@ class DmsLib
|
||||
$result = $this->ci->DmsModel->loadWhere(array('dms_id' => $dms_id, 'version' => $version));
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
|
||||
if (hasData($result))
|
||||
{
|
||||
$resultFS = $this->ci->DmsFSModel->read($result->retval[0]->filename);
|
||||
if (is_object($resultFS) && $resultFS->error == EXIT_SUCCESS)
|
||||
if (isSuccess($resultFS))
|
||||
{
|
||||
$result->retval[0]->{DmsLib::FILE_CONTENT_PROPERTY} = $resultFS->retval;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class DmsLib
|
||||
unset($dms['new']);
|
||||
|
||||
$result = $this->_saveFileOnInsert($dms);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$filename = $result->retval;
|
||||
if(isset($dms['dms_id']) && $dms['dms_id'] != '')
|
||||
@@ -91,7 +91,7 @@ class DmsLib
|
||||
else
|
||||
{
|
||||
$result = $this->ci->DmsModel->insert($this->ci->DmsModel->filterFields($dms));
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->ci->DmsVersionModel->insert(
|
||||
$this->ci->DmsVersionModel->filterFields($dms, $result->retval, $filename)
|
||||
@@ -103,10 +103,10 @@ class DmsLib
|
||||
else
|
||||
{
|
||||
$result = $this->_saveFileOnUpdate($dms);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->ci->DmsModel->update($dms['dms_id'], $this->ci->DmsModel->filterFields($dms));
|
||||
if ($result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->ci->DmsVersionModel->update(
|
||||
array(
|
||||
@@ -137,7 +137,7 @@ class DmsLib
|
||||
|
||||
// Get akte_id from table tbl_akte
|
||||
$result = $this->ci->AkteModel->loadWhere(array('person_id' => $person_id, 'dms_id' => $dms_id));
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// Delete all entries in tbl_akte
|
||||
for ($i = 0; $i < count($result->retval); $i++)
|
||||
@@ -147,11 +147,11 @@ class DmsLib
|
||||
|
||||
// Get all filenames related to this dms
|
||||
$resultFileNames = $this->ci->DmsVersionModel->loadWhere(array('dms_id' => $dms_id));
|
||||
if (is_object($resultFileNames) && $resultFileNames->error == EXIT_SUCCESS)
|
||||
if (isSuccess($resultFileNames))
|
||||
{
|
||||
// Delete from tbl_dms_version
|
||||
$result = $this->ci->DmsVersionModel->delete(array('dms_id' => $dms_id));
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// Delete from tbl_dms
|
||||
$result = $this->ci->DmsModel->delete($dms_id);
|
||||
@@ -163,7 +163,7 @@ class DmsLib
|
||||
$this->ci->db->trans_complete();
|
||||
|
||||
// Check if everything went ok during the transaction
|
||||
if ($this->ci->db->trans_status() === false || (is_object($result) && $result->error != EXIT_SUCCESS))
|
||||
if ($this->ci->db->trans_status() === false || isError($result))
|
||||
{
|
||||
$this->ci->db->trans_rollback();
|
||||
$result = error($result->msg, EXIT_ERROR);
|
||||
@@ -175,7 +175,7 @@ class DmsLib
|
||||
}
|
||||
|
||||
// If everything is ok
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// Remove all files related to this person and dms
|
||||
for ($i = 0; $i < count($resultFileNames->retval); $i++)
|
||||
@@ -200,7 +200,7 @@ class DmsLib
|
||||
$filename = uniqid() . '.' . pathinfo($dms['name'], PATHINFO_EXTENSION);
|
||||
|
||||
$result = $this->ci->DmsFSModel->write($filename, $dms['file_content']);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result->retval = $filename;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class DmsLib
|
||||
{
|
||||
$result = $this->read($dms['dms_id'], $dms['version']);
|
||||
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
$result = $this->ci->DmsFSModel->write($result->retval[0]->filename, $dms['file_content']);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ class MessageLib
|
||||
return $this->_error('', MSG_ERR_INVALID_TOKEN);
|
||||
|
||||
$result = $this->ci->RecipientModel->getMessageByToken($token);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
// Searches for a status that is different from unread
|
||||
$found = -1;
|
||||
@@ -144,7 +144,7 @@ class MessageLib
|
||||
|
||||
$resultIns = $this->ci->MsgStatusModel->insert($statusKey);
|
||||
// If an error occured while writing on data base, then return it
|
||||
if ($resultIns->error == EXIT_ERROR)
|
||||
if (isError($resultIns))
|
||||
{
|
||||
$result = $resultIns;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ class MessageLib
|
||||
|
||||
// Searches if the status is already present
|
||||
$result = $this->ci->MsgStatusModel->load(array($message_id, $person_id, $status));
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
// status already present
|
||||
}
|
||||
@@ -215,7 +215,7 @@ class MessageLib
|
||||
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
|
||||
|
||||
// If everything went ok
|
||||
if (is_object($receivers) && $receivers->error == EXIT_SUCCESS && is_array($receivers->retval))
|
||||
if (isSuccess($receivers) && is_array($receivers->retval))
|
||||
{
|
||||
// If no receivers were found for this organization unit
|
||||
if (count($receivers->retval) == 0)
|
||||
@@ -237,7 +237,7 @@ class MessageLib
|
||||
$result = $this->_saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz);
|
||||
// If no errors were occurred
|
||||
// Leave the code commented
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If the system is configured to send messages immediately
|
||||
if ($this->ci->config->item('send_immediately') === true)
|
||||
@@ -297,7 +297,7 @@ class MessageLib
|
||||
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
|
||||
|
||||
// If everything went ok
|
||||
if (is_object($receivers) && $receivers->error == EXIT_SUCCESS && is_array($receivers->retval))
|
||||
if (isSuccess($receivers) && is_array($receivers->retval))
|
||||
{
|
||||
// If no receivers were found for this organization unit
|
||||
if (count($receivers->retval) == 0)
|
||||
@@ -316,7 +316,7 @@ class MessageLib
|
||||
$receiver_id = $receivers->retval[$i]->person_id;
|
||||
|
||||
$result = $this->ci->PersonModel->load($receiver_id);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
// Set the language with the global value
|
||||
$sprache = DEFAULT_LEHREINHEIT_SPRACHE;
|
||||
@@ -328,7 +328,7 @@ class MessageLib
|
||||
|
||||
// Loads template data
|
||||
$result = $this->ci->vorlagelib->loadVorlagetext($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz, $sprache);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If the text and the subject of the template are not empty
|
||||
if (is_array($result->retval) && count($result->retval) > 0 &&
|
||||
@@ -341,7 +341,7 @@ class MessageLib
|
||||
// Save message
|
||||
$result = $this->_saveMessage($sender_id, $receiver_id, $subject, $parsedText, $relationmessage_id, $oe_kurzbz);
|
||||
// If no errors were occurred
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If the system is configured to send messages immediately
|
||||
if ($this->ci->config->item('send_immediately') === true)
|
||||
@@ -426,7 +426,7 @@ class MessageLib
|
||||
$this->ci->maillib->getConfigs()->email_number_to_sent
|
||||
);
|
||||
// Checks if errors were occurred
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If data are present
|
||||
if (is_array($result->retval) && count($result->retval) > 0)
|
||||
@@ -557,7 +557,7 @@ class MessageLib
|
||||
$message_id
|
||||
);
|
||||
// Checks if errors were occurred
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If data are present
|
||||
if (is_array($result->retval) && count($result->retval) > 0)
|
||||
@@ -693,7 +693,7 @@ class MessageLib
|
||||
// Changes the status of the message from unread to read
|
||||
$resultUpdate = $this->ci->RecipientModel->update(array($receiver_id, $message_id), $parameters);
|
||||
// Checks if errors were occurred
|
||||
if (is_object($resultUpdate) && $resultUpdate->error == EXIT_SUCCESS && is_array($resultUpdate->retval))
|
||||
if (isSuccess($resultUpdate) && is_array($resultUpdate->retval))
|
||||
{
|
||||
$updated = true;
|
||||
}
|
||||
@@ -783,7 +783,7 @@ class MessageLib
|
||||
// Load Person_model
|
||||
$this->ci->load->model('person/Person_model', 'PersonModel');
|
||||
$result = $this->ci->PersonModel->load($receiver_id);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -809,7 +809,7 @@ class MessageLib
|
||||
'oe_kurzbz' => $oe_kurzbz
|
||||
);
|
||||
$result = $this->ci->MessageModel->insert($msgData);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// Link the message with the receiver
|
||||
$msg_id = $result->retval;
|
||||
@@ -819,7 +819,7 @@ class MessageLib
|
||||
'token' => generateToken()
|
||||
);
|
||||
$result = $this->ci->RecipientModel->insert($recipientData);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// Save message status
|
||||
$statusData = array(
|
||||
@@ -833,7 +833,7 @@ class MessageLib
|
||||
|
||||
$this->ci->db->trans_complete();
|
||||
|
||||
if ($this->ci->db->trans_status() === false || (is_object($result) && $result->error != EXIT_SUCCESS))
|
||||
if ($this->ci->db->trans_status() === false || isError($result))
|
||||
{
|
||||
$this->ci->db->trans_rollback();
|
||||
$result = $this->_error($result->msg, EXIT_ERROR);
|
||||
|
||||
@@ -7,7 +7,12 @@ class OrganisationseinheitLib
|
||||
public function __construct()
|
||||
{
|
||||
$this->ci =& get_instance();
|
||||
|
||||
// Loads model Organisationseinheit_model
|
||||
$this->ci->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel');
|
||||
|
||||
// Loads helper message to manage returning messages
|
||||
$this->ci->load->helper('Message');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +52,7 @@ class OrganisationseinheitLib
|
||||
|
||||
$result = $this->ci->OrganisationseinheitModel->getOneLevel($schema, $table, $select, $where, $orderby, $oe_kurzbz);
|
||||
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
if ($result->retval[0]->_ppk != null && $result->retval[0]->oe_kurzbz == null)
|
||||
{
|
||||
|
||||
@@ -119,7 +119,7 @@ class PhrasesLib
|
||||
{
|
||||
$result = $this->ci->PhraseModel->getPhrases($app, $sprache, $phrase, $orgeinheit_kurzbz, $orgform_kurzbz);
|
||||
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
$parser = new \Netcarver\Textile\Parser();
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ class VorlageLib
|
||||
|
||||
$vorlage = $this->ci->VorlageStudiengangModel->loadWhere($queryParameters);
|
||||
// If the searched template was not found
|
||||
if (is_object($vorlage) && $vorlage->error == EXIT_SUCCESS && is_array($vorlage->retval) && count($vorlage->retval) == 0)
|
||||
if (hasData($vorlage))
|
||||
{
|
||||
$vorlage = $this->ci->organisationseinheitlib->treeSearch(
|
||||
'public',
|
||||
|
||||
@@ -36,7 +36,7 @@ class Notiz_model extends DB_Model
|
||||
$this->db->trans_start(false);
|
||||
|
||||
$result = $this->delete(array('notiz_id' => $notiz_id));
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->NotizzuordnungModel->delete(array('notiz_id' => $notiz_id));
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class Notiz_model extends DB_Model
|
||||
$this->db->trans_complete();
|
||||
|
||||
// Check if everything went ok during the transaction
|
||||
if ($this->db->trans_status() === false || (is_object($result) && $result->error != EXIT_SUCCESS))
|
||||
if ($this->db->trans_status() === false || isError($result))
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
$result = error($result->msg, EXIT_ERROR);
|
||||
@@ -72,7 +72,7 @@ class Notiz_model extends DB_Model
|
||||
|
||||
$result = $this->insert(array('titel' => $titel, 'text' => $text, 'erledigt' => true));
|
||||
$notiz_id = $result->retval;
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$result = $this->NotizzuordnungModel->insert(array('notiz_id' => $notiz_id, 'prestudent_id' => $prestudent_id));
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class Notiz_model extends DB_Model
|
||||
$this->db->trans_complete();
|
||||
|
||||
// Check if everything went ok during the transaction
|
||||
if ($this->db->trans_status() === false || (is_object($result) && $result->error != EXIT_SUCCESS))
|
||||
if ($this->db->trans_status() === false || isError($result))
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
$result = error($result->msg, EXIT_ERROR);
|
||||
|
||||
@@ -82,8 +82,7 @@ class Person_model extends DB_Model
|
||||
"person_id != " => $person["person_id"],
|
||||
"SUBSTRING(svnr FROM 1 FOR 10) = " => $person["svnr"])
|
||||
);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS &&
|
||||
is_array($result->retval) && count($result->retval) > 0)
|
||||
if (hasData($result))
|
||||
{
|
||||
if (count($result->retval) == 1 && $result->retval[0]->svnr == $person["svnr"])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user