mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 00:24:35 +00:00
Merge branch 'master' into feature-7434/Messages_Neue_Felder_zu_eingeloggtem_User_ergaenzen
This commit is contained in:
@@ -93,6 +93,8 @@ class FilterWidgetLib
|
||||
const OP_NOT_SET = 'nset';
|
||||
|
||||
// Filter options values
|
||||
const OPT_MINUTES = 'minutes';
|
||||
const OPT_HOURS = 'hours';
|
||||
const OPT_DAYS = 'days';
|
||||
const OPT_MONTHS = 'months';
|
||||
|
||||
@@ -884,8 +886,10 @@ class FilterWidgetLib
|
||||
// It it's a date type
|
||||
if (is_numeric($filterDefinition->condition)
|
||||
&& isset($filterDefinition->option)
|
||||
&& ($filterDefinition->option == self::OPT_DAYS
|
||||
|| $filterDefinition->option == self::OPT_MONTHS))
|
||||
&& ($filterDefinition->option == self::OPT_HOURS
|
||||
|| $filterDefinition->option == self::OPT_DAYS
|
||||
|| $filterDefinition->option == self::OPT_MONTHS
|
||||
|| $filterDefinition->option == self::OPT_MINUTES))
|
||||
{
|
||||
$condition = '< (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)';
|
||||
}
|
||||
@@ -899,8 +903,10 @@ class FilterWidgetLib
|
||||
// It it's a date type
|
||||
if (is_numeric($filterDefinition->condition)
|
||||
&& isset($filterDefinition->option)
|
||||
&& ($filterDefinition->option == self::OPT_DAYS
|
||||
|| $filterDefinition->option == self::OPT_MONTHS))
|
||||
&& ($filterDefinition->option == self::OPT_HOURS
|
||||
|| $filterDefinition->option == self::OPT_DAYS
|
||||
|| $filterDefinition->option == self::OPT_MONTHS
|
||||
|| $filterDefinition->option == self::OPT_MINUTES))
|
||||
{
|
||||
$condition = '> (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Library that contains all the needed functionalities to operate with the Jobs Queue System
|
||||
*/
|
||||
class JobsQueueLib
|
||||
{
|
||||
// Job statuses
|
||||
const STATUS_NEW = 'new';
|
||||
const STATUS_RUNNING = 'running';
|
||||
const STATUS_DONE = 'done';
|
||||
const STATUS_FAILED = 'failed';
|
||||
|
||||
// Job object properties
|
||||
const PROPERTY_JOBID = 'jobid';
|
||||
const PROPERTY_CREATIONTIME = 'creationtime';
|
||||
const PROPERTY_TYPE = 'type';
|
||||
const PROPERTY_STATUS = 'status';
|
||||
const PROPERTY_INPUT = 'input';
|
||||
const PROPERTY_OUTPUT = 'output';
|
||||
const PROPERTY_START_TIME = 'starttime';
|
||||
const PROPERTY_END_TIME = 'endtime';
|
||||
const PROPERTY_ERROR = 'error';
|
||||
|
||||
private $_ci; // CI instance
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($authenticate = true)
|
||||
{
|
||||
// Gets CI instance
|
||||
$this->_ci =& get_instance();
|
||||
|
||||
// Loads all needed models
|
||||
$this->_ci->load->model('system/JobsQueue_model', 'JobsQueueModel');
|
||||
$this->_ci->load->model('system/JobTypes_model', 'JobTypesModel');
|
||||
$this->_ci->load->model('system/JobStatuses_model', 'JobStatusesModel');
|
||||
$this->_ci->load->model('system/JobTriggers_model', 'JobTriggersModel');
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* To get all the most recently added jobs using the given job type
|
||||
*/
|
||||
public function getLastJobs($type)
|
||||
{
|
||||
$this->_ci->JobsQueueModel->resetQuery();
|
||||
|
||||
$this->_ci->JobsQueueModel->addOrder('creationtime', 'DESC');
|
||||
|
||||
return $this->_ci->JobsQueueModel->loadWhere(array('status' => self::STATUS_NEW, 'type' => $type));
|
||||
}
|
||||
|
||||
/**
|
||||
* To get all the jobs specified by the given parameters
|
||||
*/
|
||||
public function getJobsByTypeStatusInput($type, $status, $input)
|
||||
{
|
||||
$this->_ci->JobsQueueModel->resetQuery();
|
||||
|
||||
$this->_ci->JobsQueueModel->addOrder('creationtime', 'DESC');
|
||||
|
||||
return $this->_ci->JobsQueueModel->loadWhere(array('status' => $status, 'type' => $type, 'input' => $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new jobs in the jobs queue with the given type
|
||||
* jobs is an array of job objects
|
||||
*/
|
||||
public function addNewJobsToQueue($type, $jobs)
|
||||
{
|
||||
// Checks parameters
|
||||
if (isEmptyString($type)) return error('The provided type parameter is not a valid string');
|
||||
if (isEmptyArray($jobs)) return error('The provided jobs parameter is not a valid array');
|
||||
|
||||
// Get all the job types
|
||||
$dbResult = $this->_ci->JobTypesModel->load();
|
||||
if (isError($dbResult)) return $dbResult;
|
||||
$types = getData($dbResult);
|
||||
|
||||
// If the given type is not present in database
|
||||
if (!$this->_checkJobType($type, $types)) return error('The provided type parameter is not valid');
|
||||
|
||||
$results = $jobs; // returned values
|
||||
$errorOccurred = false; // very optimistic
|
||||
|
||||
// Get all the job statuses
|
||||
$dbResult = $this->_ci->JobStatusesModel->load();
|
||||
if (isError($dbResult)) return $dbResult;
|
||||
$statuses = getData($dbResult);
|
||||
|
||||
// Loops through all the provided jobs
|
||||
foreach ($results as $job)
|
||||
{
|
||||
// If the structure of the job object is valid AND the type is valid AND the status is valid
|
||||
if ($this->_checkNewJobStructure($job) && $this->_checkJobStatus($job, $statuses))
|
||||
{
|
||||
$this->_dropNotAllowedPropertiesNewJob($job); // remove the black listed properties from this object
|
||||
|
||||
$job->{self::PROPERTY_TYPE} = $type; // What you asked is what you get!
|
||||
|
||||
// Try to insert the single job into database
|
||||
$dbNewJobResult = $this->_ci->JobsQueueModel->insert($job);
|
||||
|
||||
// If an error occurred during while inserting in database
|
||||
if (isError($dbNewJobResult))
|
||||
{
|
||||
$job->{self::PROPERTY_ERROR} = getError($dbNewJobResult); // retrieve the cause and store it in job object
|
||||
$errorOccurred = true; // set error occurred flag
|
||||
}
|
||||
else // otherwise
|
||||
{
|
||||
$job->{self::PROPERTY_JOBID} = getData($dbNewJobResult); // get the jobid and store it in job object
|
||||
|
||||
$dbNewTriggeredJobResult = $this->_addNewTriggeredJobToQueue($type, $job, array(self::STATUS_NEW));
|
||||
// If an error occurred during while inserting in database
|
||||
if (isError($dbNewTriggeredJobResult)) return $dbNewTriggeredJobResult;
|
||||
}
|
||||
}
|
||||
else // otherwise
|
||||
{
|
||||
$errorOccurred = true; // set error occurred flag
|
||||
}
|
||||
}
|
||||
|
||||
// If an error occurred then returns the results in an error object
|
||||
if ($errorOccurred) return error($results);
|
||||
|
||||
return success($results); // otherwise return results in a success object
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates jobs already present in the jobs queue
|
||||
* jobs is an array of job objects
|
||||
*/
|
||||
public function updateJobsQueue($type, $jobs)
|
||||
{
|
||||
// Checks parameters
|
||||
if (isEmptyArray($jobs)) return error('The provided jobs parameter is not a valid array');
|
||||
|
||||
$results = $jobs; // returned values
|
||||
$errorOccurred = false; // very optimistic
|
||||
|
||||
// Get all the job statuses
|
||||
$dbResultStatuses = $this->_ci->JobStatusesModel->load();
|
||||
if (isError($dbResultStatuses)) return $dbResultStatuses;
|
||||
$statuses = getData($dbResultStatuses);
|
||||
|
||||
// Loops through all the provided jobs
|
||||
foreach ($results as $job)
|
||||
{
|
||||
// Check if the required job is present in the database
|
||||
$dbResultJobs = $this->_ci->JobsQueueModel->load($job->{self::PROPERTY_JOBID});
|
||||
if (isError($dbResultJobs))
|
||||
{
|
||||
$job->{self::PROPERTY_ERROR} = getError($dbResultJobs); // retrieve the cause and store it in job object
|
||||
$errorOccurred = true; // set error occurred flag
|
||||
}
|
||||
elseif (!hasData($dbResultJobs)) // if no jobs were found
|
||||
{
|
||||
$job->{self::PROPERTY_ERROR} = 'The required job is not present';
|
||||
$errorOccurred = true; // set error occurred flag
|
||||
}
|
||||
else // if a job was found then it could be updated
|
||||
{
|
||||
// If the structure of the job object is valid
|
||||
if ($this->_checkUpdateJobStructure($job) && $this->_checkJobStatus($job, $statuses))
|
||||
{
|
||||
$this->_dropNotAllowedPropertiesUpdateJob($job); // remove the black listed properties from this object
|
||||
|
||||
$job->{self::PROPERTY_TYPE} = $type; // What you asked is what you get!
|
||||
|
||||
// Try to update the single job into database
|
||||
$dbResult = $this->_ci->JobsQueueModel->update($job->{self::PROPERTY_JOBID}, (array)$job);
|
||||
|
||||
// If an error occurred during while updating in database
|
||||
if (isError($dbResult))
|
||||
{
|
||||
$job->{self::PROPERTY_ERROR} = getError($dbResult); // retrieve the cause and store it in job object
|
||||
$errorOccurred = true; // set error occurred flag
|
||||
}
|
||||
else // otherwise
|
||||
{
|
||||
$dbNewTriggeredJobResult = $this->_addNewTriggeredJobToQueue(
|
||||
$type,
|
||||
$job,
|
||||
array($job->status)
|
||||
);
|
||||
// If an error occurred during while inserting in database
|
||||
if (isError($dbNewTriggeredJobResult)) return $dbNewTriggeredJobResult;
|
||||
}
|
||||
}
|
||||
else // otherwise
|
||||
{
|
||||
$errorOccurred = true; // set error occurred flag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If an error occurred then returns the results in an error object
|
||||
if ($errorOccurred) return error($results);
|
||||
|
||||
return success($results); // otherwise return results in a success object
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Checks the job object structure when needed for insert
|
||||
*/
|
||||
private function _checkNewJobStructure(&$job)
|
||||
{
|
||||
// If job is a valid object and contains the required properties AND does NOT already contain the property error
|
||||
if (is_object($job)
|
||||
&& property_exists($job, self::PROPERTY_STATUS)
|
||||
&& !property_exists($job, self::PROPERTY_ERROR))
|
||||
{
|
||||
return true; // it is valid!
|
||||
}
|
||||
|
||||
// If not object then object it!
|
||||
if (!is_object($job)) $job = new stdClass();
|
||||
|
||||
// If an error property was not already previously stored then store an error message in job object
|
||||
if (!property_exists($job, self::PROPERTY_ERROR))
|
||||
{
|
||||
$job->{self::PROPERTY_ERROR} = 'The structure of the provided job is not valid';
|
||||
}
|
||||
|
||||
return false; // better sorry than wrong
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the job object structure when needed for update
|
||||
*/
|
||||
private function _checkUpdateJobStructure(&$job)
|
||||
{
|
||||
// If job is a valid object
|
||||
if (is_object($job) && property_exists($job, self::PROPERTY_JOBID)) return true; // it is valid!
|
||||
|
||||
// If not object then object it!
|
||||
if (!is_object($job)) $job = new stdClass();
|
||||
|
||||
// If an error property was not already previously stored then store an error message in job object
|
||||
if (!property_exists($job, self::PROPERTY_ERROR))
|
||||
{
|
||||
$job->{self::PROPERTY_ERROR} = 'The structure of the provided job is not valid';
|
||||
}
|
||||
|
||||
return false; // better sorry than wrong
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given job contains a valid type
|
||||
*/
|
||||
private function _checkJobType($type, $types)
|
||||
{
|
||||
return $this->_inArray($type, $types, self::PROPERTY_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given job contains a valid status
|
||||
*/
|
||||
private function _checkJobStatus(&$job, $statuses)
|
||||
{
|
||||
// If the given job doesn't have the property status then it is not valid
|
||||
if (!isset($job->{self::PROPERTY_STATUS}))
|
||||
{
|
||||
$found = false;
|
||||
}
|
||||
else // otherwise test if it valid
|
||||
{
|
||||
$found = $this->_inArray($job->{self::PROPERTY_STATUS}, $statuses, self::PROPERTY_STATUS);
|
||||
}
|
||||
|
||||
// No status was found and does NOT already contain the property error
|
||||
if (!$found && !property_exists($job, self::PROPERTY_ERROR))
|
||||
{
|
||||
$job->{self::PROPERTY_ERROR} = 'The provided status of this job is not valid'; // store the error message in the object
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search in an array the given value
|
||||
* The elements of the given array are objects
|
||||
* The given value is compared with the property specified by the $propertyName parameter of each object of the given array
|
||||
*/
|
||||
private function _inArray($value, $array, $propertyName)
|
||||
{
|
||||
$found = false;
|
||||
|
||||
foreach ($array as $element)
|
||||
{
|
||||
if ($value == $element->{$propertyName})
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop not allowed properties from the given job
|
||||
*/
|
||||
private function _dropNotAllowedPropertiesNewJob(&$job)
|
||||
{
|
||||
unset($job->{self::PROPERTY_JOBID});
|
||||
unset($job->{self::PROPERTY_CREATIONTIME});
|
||||
unset($job->{self::PROPERTY_TYPE});
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop not allowed properties from the given job
|
||||
*/
|
||||
private function _dropNotAllowedPropertiesUpdateJob(&$job)
|
||||
{
|
||||
unset($job->{self::PROPERTY_CREATIONTIME});
|
||||
unset($job->{self::PROPERTY_TYPE});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add e new triggered job to the jobs queue
|
||||
* NOTE:
|
||||
* - In this method there are less checks compared to addNewJobsToQueue method because
|
||||
* the new jobs that will be added are generate in this method
|
||||
* - Job ids in this case are not returned, therefore the caller is not going to be informed about these new jobs
|
||||
*/
|
||||
private function _addNewTriggeredJobToQueue($type, $job, $triggeredStatuses)
|
||||
{
|
||||
// Get all the job trigggers for the given type and for the given statuses
|
||||
$dbTriggersResult = $this->_ci->JobTriggersModel->getJobtriggersByTypeStatuses($type, $triggeredStatuses);
|
||||
|
||||
// If an error occurred while getting job triggers from database then return it
|
||||
if (isError($dbTriggersResult)) return $dbTriggersResult;
|
||||
if (hasData($dbTriggersResult)) // If triggers were retrieved
|
||||
{
|
||||
// The output of the trigging job is the input of the trigged job
|
||||
$triggeredJobInput = null;
|
||||
if (isset($job->{self::PROPERTY_OUTPUT})) $triggeredJobInput = $job->{self::PROPERTY_OUTPUT};
|
||||
|
||||
// For each trigger
|
||||
foreach (getData($dbTriggersResult) as $trigger)
|
||||
{
|
||||
$triggeredJob = array(
|
||||
self::PROPERTY_TYPE => $trigger->following_type, // the new type is the one defined in tbl_jobtriggers
|
||||
self::PROPERTY_STATUS => self::STATUS_NEW, // new job status is new
|
||||
self::PROPERTY_INPUT => $triggeredJobInput // new job input
|
||||
);
|
||||
|
||||
// Try to insert the single job into database
|
||||
$dbNewJob = $this->_ci->JobsQueueModel->insert($triggeredJob);
|
||||
// If an error occurred during while inserting in database
|
||||
if (isError($dbNewJob)) return $dbNewJob;
|
||||
}
|
||||
}
|
||||
|
||||
return success(); // if here then it was a success!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ class LogLib
|
||||
const P_NAME_LINE_INDEX = 'lineIndex';
|
||||
const P_NAME_DB_LOG_TYPE = 'dbLogType';
|
||||
const P_NAME_DB_EXECUTE_USER = 'dbExecuteUser';
|
||||
const P_NAME_REQUEST_ID = 'requestId';
|
||||
const P_NAME_REQUEST_DATA_FORMATTER = 'requestDataFormatter';
|
||||
|
||||
// Properties used to retrieve caller data
|
||||
private $_classIndex;
|
||||
@@ -52,6 +54,9 @@ class LogLib
|
||||
private $_dbLogType;
|
||||
private $_dbExecuteUser;
|
||||
|
||||
private $_requestId; // is it possible to specify a request id when loading this library
|
||||
private $_requestDataFormatter; // is possible to provide a function to format request data
|
||||
|
||||
/**
|
||||
* Set properties to a default value or overwrites them with the given parameters
|
||||
*/
|
||||
@@ -63,7 +68,18 @@ class LogLib
|
||||
$this->_lineIndex = self::LINE_INDEX;
|
||||
$this->_dbLogType = null;
|
||||
$this->_dbExecuteUser = self::DB_EXECUTE_USER;
|
||||
$this->_requestId = null;
|
||||
$this->_requestDataFormatter = null;
|
||||
|
||||
// If parameters are given then overwrite the default values
|
||||
if (!isEmptyArray($params)) $this->setConfigs($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store configuration parameters for this lib
|
||||
*/
|
||||
public function setConfigs($params)
|
||||
{
|
||||
// If parameters are given then overwrite the default values
|
||||
if (!isEmptyArray($params))
|
||||
{
|
||||
@@ -72,6 +88,8 @@ class LogLib
|
||||
if (isset($params[self::P_NAME_LINE_INDEX])) $this->_lineIndex = $params[self::P_NAME_LINE_INDEX];
|
||||
if (isset($params[self::P_NAME_DB_LOG_TYPE])) $this->_dbLogType = $params[self::P_NAME_DB_LOG_TYPE];
|
||||
if (isset($params[self::P_NAME_DB_EXECUTE_USER])) $this->_dbExecuteUser = $params[self::P_NAME_DB_EXECUTE_USER];
|
||||
if (isset($params[self::P_NAME_REQUEST_ID])) $this->_requestId = $params[self::P_NAME_REQUEST_ID];
|
||||
if (isset($params[self::P_NAME_REQUEST_DATA_FORMATTER])) $this->_requestDataFormatter = $params[self::P_NAME_REQUEST_DATA_FORMATTER];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,33 +126,33 @@ class LogLib
|
||||
/**
|
||||
* Writes an info log to database
|
||||
*/
|
||||
public function logInfoDB($requestId, $data)
|
||||
public function logInfoDB($data, $requestId = null)
|
||||
{
|
||||
$this->_logDB(self::INFO, $requestId, $data);
|
||||
$this->_logDB(self::INFO, $data, $requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a debug log to database
|
||||
*/
|
||||
public function logDebugDB($requestId, $data)
|
||||
public function logDebugDB($data, $requestId = null)
|
||||
{
|
||||
$this->_logDB(self::DEBUG, $requestId, $data);
|
||||
$this->_logDB(self::DEBUG, $data, $requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an warning log to database
|
||||
*/
|
||||
public function logWarningDB($requestId, $data)
|
||||
public function logWarningDB($data, $requestId = null)
|
||||
{
|
||||
$this->_logDB(self::WARNING, $requestId, $data);
|
||||
$this->_logDB(self::WARNING, $data, $requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an error log to database
|
||||
*/
|
||||
public function logErrorDB($requestId, $data)
|
||||
public function logErrorDB($data, $requestId = null)
|
||||
{
|
||||
$this->_logDB(self::ERROR, $requestId, $data);
|
||||
$this->_logDB(self::ERROR, $data, $requestId);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------
|
||||
@@ -151,8 +169,15 @@ class LogLib
|
||||
/**
|
||||
* Writes logs to database
|
||||
*/
|
||||
private function _logDB($level, $requestId, $data)
|
||||
private function _logDB($level, $data, $requestId, $executionTime = null)
|
||||
{
|
||||
// If there isn't a valid request id provided during the loading of this library or when any log to db method is called
|
||||
// NOTE: this message will be displayed only to the developer AND stops the execution
|
||||
if (isEmptyString($this->_requestId) && isEmptyString($requestId))
|
||||
{
|
||||
show_error('To log to database you need to specify or give the "'.self::P_NAME_REQUEST_ID.'" parameter when the LogLib is loaded or when log'.ucfirst($level).'DB is called');
|
||||
}
|
||||
|
||||
// If the _dbLogType parameter was not given when this library was loaded
|
||||
// NOTE: this message will be displayed only to the developer AND stops the execution
|
||||
if ($this->_dbLogType == null)
|
||||
@@ -175,14 +200,21 @@ class LogLib
|
||||
// Get caller data
|
||||
$callerData = $this->_getCaller();
|
||||
|
||||
// If a request data formatter was defined then use it
|
||||
$request_data = $data;
|
||||
if ($this->_requestDataFormatter != null && is_callable($this->_requestDataFormatter))
|
||||
{
|
||||
$request_data = call_user_func_array($this->_requestDataFormatter, array($data));
|
||||
}
|
||||
|
||||
// Writes a log to database
|
||||
$ci->WebservicelogModel->insert(array(
|
||||
'webservicetyp_kurzbz' => $this->_dbLogType,
|
||||
'request_id' => $requestId,
|
||||
'request_id' => (!isEmptyString($requestId) ? $requestId : $this->_requestId).' - '.$level,
|
||||
'beschreibung' => $this->_getDatabaseDescription($callerData),
|
||||
'request_data' => $data,
|
||||
'request_data' => $request_data,
|
||||
'execute_user' => $this->_dbExecuteUser,
|
||||
'execute_time' => 'NOW()' // current time
|
||||
'execute_time' => $executionTime == null ? 'NOW()' : $executionTime // default current time, if not otherwise specified
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -251,3 +283,4 @@ class LogLib
|
||||
return $formatted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -620,11 +620,24 @@ class MessageLib
|
||||
$this->_ci->load->model('person/Benutzer_model', 'BenutzerModel');
|
||||
|
||||
// And the receiver has an active account for the given organisation unit
|
||||
$benutzerResult = $this->_ci->BenutzerModel->getActiveUserByPersonIdAndOrganisationUnit($message->receiver_id, $message->sender_ou);
|
||||
$benutzerResult = $this->_ci->BenutzerModel->getActiveUserByPersonIdAndOrganisationUnit(
|
||||
$message->receiver_id,
|
||||
$message->sender_ou
|
||||
);
|
||||
|
||||
if (isError($benutzerResult)) return $benutzerResult; // if an error occured then return it
|
||||
|
||||
// Use the uid + domain email
|
||||
if (hasData($benutzerResult)) $message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN;
|
||||
// If an active user for the given organization unit was found
|
||||
if (hasData($benutzerResult))
|
||||
{
|
||||
// Checks if the user was NOT created in the last 24 hours
|
||||
if (getData($benutzerResult)[0]->insertamum < date('Y-m-d H:i:s', strtotime('-1 day')))
|
||||
{
|
||||
// Use the uid + domain email
|
||||
$message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN;
|
||||
}
|
||||
// otherwise do NOT use the internal email account
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise try with the private email
|
||||
@@ -669,7 +682,7 @@ class MessageLib
|
||||
// If there are presetudent
|
||||
if (hasData($prestudentResults))
|
||||
{
|
||||
$inArray = true;
|
||||
$privateOnly = false;
|
||||
$organisationUnits = getData($prestudentResults);
|
||||
|
||||
// Look if any of the organization units of this prestudent are in the list of the
|
||||
@@ -677,16 +690,21 @@ class MessageLib
|
||||
foreach ($organisationUnits as $organisationUnit)
|
||||
{
|
||||
// If the recipient organisation unit is NOT in the list of organisation units that sent only to private emails
|
||||
// NOTE: done in this way because it is easyer to check the result of array_search
|
||||
if (array_search($organisationUnit, $this->_ci->config->item(self::CFG_OU_RECEIVERS_PRIVATE)) === false)
|
||||
{
|
||||
$inArray = false;
|
||||
// NOP
|
||||
}
|
||||
else // otherwise If the recipient organisation unit is the list of organisation units that sent only to private emails
|
||||
{
|
||||
$privateOnly = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the recipient prestudent organization unit is not in in the list of the
|
||||
// organization units that will not send the notice email to the internal account
|
||||
if (!$inArray)
|
||||
if ($privateOnly)
|
||||
{
|
||||
// Then use the private email
|
||||
$privateEmailResult = $this->_getPrivateEmail($message->receiver_id);
|
||||
@@ -701,10 +719,37 @@ class MessageLib
|
||||
$this->_ci->BenutzerModel->addOrder('updateamum', 'DESC');
|
||||
$this->_ci->BenutzerModel->addOrder('insertamum', 'DESC');
|
||||
|
||||
$benutzerResult = $this->_ci->BenutzerModel->loadWhere(array('person_id' => $message->receiver_id));
|
||||
$benutzerResult = $this->_ci->BenutzerModel->loadWhere(
|
||||
array(
|
||||
'person_id' => $message->receiver_id
|
||||
)
|
||||
);
|
||||
if (isError($benutzerResult)) return $benutzerResult; // if an error occured then return it
|
||||
|
||||
$message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN; // Use the uid + domain email
|
||||
// If an active user for the given organization unit was found
|
||||
if (hasData($benutzerResult))
|
||||
{
|
||||
// For each benutzer found for this person
|
||||
foreach (getData($benutzerResult) as $benutzer)
|
||||
{
|
||||
// Checks if the user was NOT created in the last 24 hours
|
||||
if (getData($benutzerResult)[0]->insertamum < date('Y-m-d H:i:s', strtotime('-1 day')))
|
||||
{
|
||||
// Use the uid + domain as email address
|
||||
$message->receiverContact = getData($benutzerResult)[0]->uid .'@'.DOMAIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise try with the private email
|
||||
if (isEmptyString($message->receiverContact))
|
||||
{
|
||||
// Then use the private email
|
||||
$privateEmailResult = $this->_getPrivateEmail($message->receiver_id);
|
||||
if (isError($privateEmailResult)) return $privateEmailResult; // if an error occured then return it
|
||||
|
||||
if (hasData($privateEmailResult)) $message->receiverContact = getData($privateEmailResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ class PermissionLib
|
||||
|
||||
$accessType = '';
|
||||
|
||||
// Checks if the required access type is compliant with the HTTP method (GET => r, POST => w)
|
||||
// Set the access type
|
||||
if (strpos($requiredAccessType, PermissionLib::READ_RIGHT) !== false)
|
||||
{
|
||||
$accessType = PermissionLib::SELECT_RIGHT; // S
|
||||
@@ -184,12 +184,12 @@ class PermissionLib
|
||||
}
|
||||
else
|
||||
{
|
||||
show_error('The given permission array does not contain the called method or is not correctly set');
|
||||
show_error('The given permission array does not contain the given method or is not correctly set');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
show_error('You must give the permissions array as parameter to the constructor of the controller');
|
||||
show_error('The given permissions is not a valid array or it is an empty one');
|
||||
}
|
||||
|
||||
return $checkPermissions;
|
||||
|
||||
Reference in New Issue
Block a user