- Added new library libraries/SearchBarLib

- Added new controller components/SearchBar
- Removed not anymore used view application/views/system/logs/logsViewerData.php
This commit is contained in:
Paolo
2022-06-24 17:59:01 +02:00
parent 24b78454d3
commit 147ab92bae
3 changed files with 242 additions and 66 deletions
@@ -0,0 +1,43 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
*
*/
class SearchBar extends FHC_Controller
{
const SEARCHSTR_PARAM = 'searchstr';
const TYPES_PARAM = 'types';
/**
*
*/
public function __construct()
{
parent::__construct();
//
$this->load->library('SearchBarLib');
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
public function index()
{
$this->load->view('test');
}
/**
*
*/
public function search()
{
$searchstr = $this->input->post(self::SEARCHSTR_PARAM);
$types = $this->input->post(self::TYPES_PARAM);
$this->outputJson($this->searchbarlib->search($searchstr, $types));
}
}
+199
View File
@@ -0,0 +1,199 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
*
*/
class SearchBarLib
{
//
const ERROR_WRONG_SEARCHSTR = 'ERR001';
const ERROR_NO_TYPES = 'ERR002';
const ERROR_WRONG_TYPES = 'ERR003';
//
const ALLOWED_TYPES = ['mitarbeiter', 'organisationunit', 'raum', 'person', 'student', 'prestudent', 'document', 'cms'];
private $_ci; // Code igniter instance
/**
* Gets the CI instance and loads model
*/
public function __construct()
{
$this->_ci =& get_instance(); // get code igniter instance
//
$this->_ci->load->model('person/Benutzer_model', 'BenutzerModel');
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
*
*/
public function search($searchstr, $types)
{
//
$search = $this->_checkParameters($searchstr, $types);
//
if (isSuccess($search)) $search = $this->_search($searchstr, $types);
return $search; //
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
*
*/
private function _checkParameters($searchstr, $types)
{
//
if (isEmptyString($searchstr))
{
return error(self::ERROR_WRONG_SEARCHSTR);
}
//
if (isEmptyArray($types))
{
return error(self::ERROR_NO_TYPES);
}
else
{
//
if (!isEmptyArray(array_diff($types, self::ALLOWED_TYPES)))
{
return error(self::ERROR_WRONG_TYPES);
}
}
return success(); //
}
/**
*
*/
private function _search($searchstr, $types)
{
$data = array(); //
//
foreach ($types as $type)
{
//
$data = array_merge($data, $this->{'_'.$type}($searchstr, $type));
}
$result = new stdClass();
$result->data = $data;
return $result;
}
/**
*
*/
private function _mitarbeiter($searchstr, $type)
{
$dbModel = new DB_Model();
$employees = $dbModel->execReadOnlyQuery('
SELECT
\''.$type.'\' AS type,
b.uid,
p.person_id,
p.vorname || \' \' || p.nachname AS name,
b.uid AS email,
m.telefonklappe AS phone
FROM public.tbl_mitarbeiter m
JOIN public.tbl_benutzer b ON(b.uid = m.mitarbeiter_uid)
JOIN public.tbl_person p USING(person_id)
WHERE m.mitarbeiter_uid ILIKE \'%'.$dbModel->escapeLike($searchstr).'%\'
');
//
if (hasData($employees)) return getData($employees);
//
return array();
}
/**
*
*/
private function _organisationunit($searchstr, $type)
{
$dbModel = new DB_Model();
$ous = $dbModel->execReadOnlyQuery('
SELECT
\''.$type.'\' AS type,
o.oe_kurzbz,
o.bezeichnung AS name,
o.oe_parent_kurzbz AS parentoe_kurzbz,
o.oe_parent_kurzbz AS parentoe_name
FROM public.tbl_organisationseinheit o
WHERE o.oe_kurzbz ILIKE \'%'.$dbModel->escapeLike($searchstr).'%\'
');
//
if (hasData($ous)) return getData($ous);
//
return array();
}
/**
*
*/
private function _person($searchstr, $type)
{
return array();
}
/**
*
*/
private function _student($searchstr, $type)
{
return array();
}
/**
*
*/
private function _prestudent($searchstr, $type)
{
return array();
}
/**
*
*/
private function _document($searchstr, $type)
{
return array();
}
/**
*
*/
private function _cms($searchstr, $type)
{
return array();
}
/**
*
*/
private function raum($searchstr, $type)
{
return array();
}
}
@@ -1,66 +0,0 @@
<?php
$filterWidgetArray = array(
'query' => '
SELECT wsl.webservicelog_id AS "LogId",
wsl.request_id AS "RequestId",
wsl.execute_time AS "ExecutionTime",
wsl.execute_user AS "ExecutedBy",
wsl.beschreibung AS "Description",
wsl.request_data AS "Data",
wsl.webservicetyp_kurzbz AS "WebserviceType"
FROM system.tbl_webservicelog wsl
ORDER BY wsl.execute_time DESC
',
'requiredPermissions' => 'admin',
'datasetRepresentation' => 'tablesorter',
'columnsAliases' => array(
'Log id',
'Request id',
'Execution time',
'Executed by',
'Producer',
'Data',
'Webservice type'
),
'formatRow' => function($datasetRaw) {
$datasetRaw->ExecutionTime = date_format(date_create($datasetRaw->ExecutionTime), 'd.m.Y H:i:s:u');
return $datasetRaw;
},
'markRow' => function($datasetRaw) {
$mark = '';
if (strpos($datasetRaw->RequestId, 'error') != false)
{
$mark = 'text-red';
}
if (strpos($datasetRaw->RequestId, 'info') != false)
{
$mark = 'text-green';
}
if (strpos($datasetRaw->RequestId, 'warning') != false)
{
$mark = 'text-orange';
}
if (strpos($datasetRaw->RequestId, 'debug') != false)
{
$mark = 'text-info';
}
return $mark;
}
);
$filterWidgetArray['app'] = 'core';
$filterWidgetArray['datasetName'] = 'logs';
$filterWidgetArray['filter_id'] = $this->input->get('filter_id');
echo $this->widgetlib->widget('FilterWidget', $filterWidgetArray);
?>