mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
Added new Logging System for Persons
Added a Wrapper to call CI functions from outside Codeigniter
This commit is contained in:
@@ -209,6 +209,7 @@ $config['fhc_acl'] = array
|
||||
'system.tbl_webservicetyp' => 'basis/webservicetyp',
|
||||
'system.tbl_udf' => 'system/udf',
|
||||
'system.tbl_extensions' => 'system/extensions',
|
||||
'system.tbl_log' => 'basis/log',
|
||||
'testtool.tbl_ablauf' => 'basis/ablauf',
|
||||
'testtool.tbl_antwort' => 'basis/antwort',
|
||||
'testtool.tbl_frage' => 'basis/frage',
|
||||
|
||||
@@ -14,16 +14,17 @@ class CallerLib
|
||||
const LIB_FILE_EXTENSION = '.php';
|
||||
const LIBS_PATH = 'libraries';
|
||||
const MODEL_PREFIX = '_model';
|
||||
|
||||
|
||||
// Black list of resources that are no allowed to be used
|
||||
private static $RESOURCES_BLACK_LIST = array(
|
||||
'CallerLib', // disabled self loading
|
||||
'LogLib', // hardly usefull and virtually dangerous
|
||||
'MigrationLib', // virtually dangerous, DB manipulation
|
||||
'FilesystemLib', // virtually dangerous, direct access to file system
|
||||
'PermissionLib' // usefull?
|
||||
'PermissionLib', // usefull?
|
||||
'PersonLogLib'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Object initialization
|
||||
*/
|
||||
@@ -31,14 +32,14 @@ class CallerLib
|
||||
{
|
||||
// Gets CI instance
|
||||
$this->ci =& get_instance();
|
||||
|
||||
|
||||
// Loads helper message to manage returning messages
|
||||
$this->ci->load->helper('Message');
|
||||
|
||||
|
||||
// Loads permission library
|
||||
$this->ci->load->library('PermissionLib');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper method for _call
|
||||
*/
|
||||
@@ -46,7 +47,7 @@ class CallerLib
|
||||
{
|
||||
return $this->_call($callParameters, $permissionType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper method for _call
|
||||
*/
|
||||
@@ -54,7 +55,7 @@ class CallerLib
|
||||
{
|
||||
return $this->_call($callParameters, $permissionType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Everything starts here...
|
||||
*/
|
||||
@@ -63,7 +64,7 @@ class CallerLib
|
||||
$result = null;
|
||||
$parameters = $this->_getParameters($callParameters);
|
||||
$validation = $this->_validateCall($parameters);
|
||||
|
||||
|
||||
// If the validation was passed
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
@@ -119,7 +120,7 @@ class CallerLib
|
||||
{
|
||||
$result = error('Neither a lib nor model: '.$parameters->resourcePath.$parameters->resourceName);
|
||||
}
|
||||
|
||||
|
||||
// If the resource was found and loaded
|
||||
if (!is_null($loaded))
|
||||
{
|
||||
@@ -134,10 +135,10 @@ class CallerLib
|
||||
{
|
||||
$result = $validation;
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the parameters from the http call
|
||||
* Search for parameters <RESOURCE_PARAMETER> and <FUNCTION_PARAMETER>
|
||||
@@ -181,7 +182,7 @@ class CallerLib
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate the given parameters
|
||||
*/
|
||||
@@ -224,7 +225,7 @@ class CallerLib
|
||||
{
|
||||
$loaded = null;
|
||||
$result = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$loaded = $this->ci->load->model($resourcePath.$resourceName);
|
||||
@@ -234,15 +235,15 @@ class CallerLib
|
||||
// Errors while loading the model
|
||||
$result = error('Errors while loading the model: '.$e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
if (!is_null($loaded))
|
||||
{
|
||||
$result = success($loaded);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Search for a valid permission for this library that should be present with this format:
|
||||
* '<library path>.<library name>.<library method name>' => '<permission>'
|
||||
@@ -251,14 +252,14 @@ class CallerLib
|
||||
{
|
||||
$result = null;
|
||||
$permissionPath = '';
|
||||
|
||||
|
||||
if ($resourcePath != '')
|
||||
{
|
||||
$permissionPath = $resourcePath;
|
||||
}
|
||||
|
||||
|
||||
$permissionPath .= $resourceName.'.'.$function;
|
||||
|
||||
|
||||
if ($this->ci->permissionlib->isEntitled($permissionPath, $permissionType) === false)
|
||||
{
|
||||
$result = error(FHC_NORIGHT, FHC_NORIGHT);
|
||||
@@ -267,10 +268,10 @@ class CallerLib
|
||||
{
|
||||
$result = success('Has permission');
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads a library using the given path and name
|
||||
*
|
||||
@@ -286,7 +287,7 @@ class CallerLib
|
||||
private function _loadLibrary($resourcePath, $resourceName)
|
||||
{
|
||||
$loaded = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Gets all the configured resources paths
|
||||
@@ -328,15 +329,15 @@ class CallerLib
|
||||
// Errors while loading the library
|
||||
$result = error('Errors while loading the library: '.$e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
if (!is_null($loaded))
|
||||
{
|
||||
$result = success($loaded);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls a method of a class with the given parameters and returns its result
|
||||
*
|
||||
@@ -347,7 +348,7 @@ class CallerLib
|
||||
private function _callThis($resourceName, $function, $parameters)
|
||||
{
|
||||
$result = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Get informations about the function
|
||||
@@ -402,7 +403,7 @@ class CallerLib
|
||||
{
|
||||
$result = error($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Logging Actions of Persons
|
||||
*/
|
||||
class PersonLogLib
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->ci =& get_instance();
|
||||
$this->ci->load->model('system/PersonLog_model', 'PersonLogModel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a Log for a Person
|
||||
* @param int $person_id ID of the Person.
|
||||
* @param string $logtype_kurzbz Type of Log.
|
||||
* @param array $logdata Array of the JSON Data to save.
|
||||
* @param string $app Application that log belongs to.
|
||||
* @param string $oe_kurzbz Organisation Unit the Log belongs to.
|
||||
* @param string $user User who created the log.
|
||||
* @return boolean true if success
|
||||
*/
|
||||
public function log($person_id, $logtype_kurzbz, $logdata, $app = 'core', $oe_kurzbz = null, $user = null)
|
||||
{
|
||||
$data = array(
|
||||
'person_id' => $person_id,
|
||||
'zeitpunkt' => date('Y-m-d H:i:s'),
|
||||
'app' => $app,
|
||||
'oe_kurzbz' => $oe_kurzbz,
|
||||
'logtype_kurzbz' => $logtype_kurzbz,
|
||||
'logdata' => json_encode($logdata),
|
||||
'insertvon' => $user
|
||||
);
|
||||
|
||||
$result = $this->ci->PersonLogModel->insert($data);
|
||||
if (isSuccess($result))
|
||||
return true;
|
||||
else
|
||||
show_error($result->retval);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* PersonLog Extends from CI_Model instead of DB_Model
|
||||
* to be able to write Log without a loggedin User!
|
||||
*/
|
||||
class PersonLog_model extends CI_Model
|
||||
{
|
||||
private $dbTable;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
|
||||
$this->dbTable = 'system.tbl_log';
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a Log for a Person
|
||||
* @param array $data Data of Log Entry to save.
|
||||
* @return success object if true
|
||||
*/
|
||||
public function insert($data)
|
||||
{
|
||||
$result = $this->db->insert($this->dbTable, $data);
|
||||
if ($result)
|
||||
return success($this->db->insert_id());
|
||||
else
|
||||
return error();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the last Log Entry of a Person
|
||||
* @param int $person_id ID of the Person.
|
||||
* @param string $app Name of the App.
|
||||
* @param string $oe_kurzbz Organisations Unit.
|
||||
* @return object $result
|
||||
*/
|
||||
public function getLastLog($person_id, $app = null, $oe_kurzbz = null)
|
||||
{
|
||||
// Check Permissions
|
||||
$this->load->library('PermissionLib');
|
||||
if(!$this->permissionlib->isEntitled('system.tbl_log',PermissionLib::SELECT_RIGHT))
|
||||
show_error('Permission denied - You need Access to system.tbl_log');
|
||||
|
||||
$this->db->order_by('zeitpunkt', 'DESC');
|
||||
$this->db->order_by('log_id', 'DESC');
|
||||
$this->db->limit(1);
|
||||
if (!is_null($app))
|
||||
$this->db->where('app='.$this->db->escape($app));
|
||||
if (!is_null($oe_kurzbz))
|
||||
$this->db->where('oe_kurzbz='.$this->db->escape($oe_kurzbz));
|
||||
|
||||
$result = $this->db->get_where($this->dbTable, "person_id=".$this->db->escape($person_id));
|
||||
|
||||
return success($result->result());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user