mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
- Changed system/dbupdate_3.3.php to create table system.tbl_filters and what its needed
- Added model system/Filters_model to manage system.tbl_filters - Removed method execQuery from model system/UDF_model - Added property executedQueryMetaData to DB_Model - Added property executedQueryListFields to DB_Model - Added method getExecutedQueryListFields to DB_Model - Added method getExecutedQueryMetaData to DB_Model - Added method execReadOnlyQuery to DB_Model to execute read only queries from outside a model - Changed DB_Model method _toPhp to store infos about an executed query into properties executedQueryMetaData and executedQueryListFields - Updated library UDFLib to use execReadOnlyQuery - Added widget FilterWidget to render and manage a filter into VileSci - Added views widgets/filter/selectFields, widgets/filter/selectFilters and widgets/filter/tableDataset used by FilterWidget
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Test extends VileSci_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->library('WidgetLib');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
echo $this->widgetlib->widget(
|
||||
'FilterWidget',
|
||||
array(
|
||||
'app' => 'OpenProject',
|
||||
'datasetName' => 'Arbeitspakete',
|
||||
'query' => '
|
||||
SELECT p.person_id AS PersonId,
|
||||
p.nachname AS Nachname,
|
||||
p.vorname AS Vorname,
|
||||
k.kontakt AS Email
|
||||
FROM public.tbl_person p INNER JOIN public.tbl_kontakt k USING(person_id)
|
||||
WHERE p.aktiv = TRUE
|
||||
AND p.person_id = k.person_id
|
||||
AND k.kontakttyp = \'email\'
|
||||
AND p.person_id < 1000
|
||||
'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,9 @@ class DB_Model extends FHC_Model
|
||||
protected $hasSequence; // False if this table has a composite primary key that is not using a sequence
|
||||
// True if this table has a primary key that uses a sequence
|
||||
|
||||
private $executedQueryMetaData;
|
||||
private $executedQueryListFields;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -670,6 +673,44 @@ class DB_Model extends FHC_Model
|
||||
return $this->fieldExists(UDFLib::COLUMN_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of the fields after having executed a query
|
||||
*/
|
||||
public function getExecutedQueryListFields()
|
||||
{
|
||||
return $this->executedQueryListFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get meda data info about the retrived fields after having executed a query
|
||||
*/
|
||||
public function getExecutedQueryMetaData()
|
||||
{
|
||||
return $this->executedQueryMetaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like execQuery, but it allows only to perform queries to read data
|
||||
*/
|
||||
public function execReadOnlyQuery($query, $parametersArray = null)
|
||||
{
|
||||
//
|
||||
if (!stripos($query, 'INSERT')
|
||||
&& !stripos($query, 'UPDATE')
|
||||
&& !stripos($query, 'DELETE')
|
||||
&& !stripos($query, 'CREATE')
|
||||
&& !stripos($query, 'ALTER')
|
||||
&& !stripos($query, 'GRANT')
|
||||
&& !stripos($query, 'DROP'))
|
||||
{
|
||||
return $this->execQuery($query, $parametersArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('You are allowed to run only query for reading data');
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
// Protected methods
|
||||
|
||||
@@ -809,20 +850,23 @@ class DB_Model extends FHC_Model
|
||||
if (is_object($result))
|
||||
{
|
||||
$toBeConverterdArray = array(); // Fields to be converted
|
||||
$metaDataArray = $result->field_data(); // Fields information
|
||||
for ($i = 0; $i < count($metaDataArray); $i++) // Looking for booleans and arrays
|
||||
|
||||
$this->executedQueryMetaData = $result->field_data(); // Fields information
|
||||
$this->executedQueryListFields = $result->list_fields(); // List of the retrived fields
|
||||
|
||||
for ($i = 0; $i < count($this->executedQueryMetaData); $i++) // Looking for booleans and arrays
|
||||
{
|
||||
// If array type, boolean type OR a UDF
|
||||
if (strpos($metaDataArray[$i]->type, DB_Model::PGSQL_ARRAY_TYPE) !== false
|
||||
|| $metaDataArray[$i]->type == DB_Model::PGSQL_BOOLEAN_TYPE
|
||||
|| $this->udflib->isUDFColumn($metaDataArray[$i]->name, $metaDataArray[$i]->type))
|
||||
if (strpos($this->executedQueryMetaData[$i]->type, DB_Model::PGSQL_ARRAY_TYPE) !== false
|
||||
|| $this->executedQueryMetaData[$i]->type == DB_Model::PGSQL_BOOLEAN_TYPE
|
||||
|| $this->udflib->isUDFColumn($this->executedQueryMetaData[$i]->name, $this->executedQueryMetaData[$i]->type))
|
||||
{
|
||||
// Name and type of the field to be converted
|
||||
$toBeConverted = new stdClass();
|
||||
// Set the type of the field to be converted
|
||||
$toBeConverted->type = $metaDataArray[$i]->type;
|
||||
$toBeConverted->type = $this->executedQueryMetaData[$i]->type;
|
||||
// Set the name of the field to be converted
|
||||
$toBeConverted->name = $metaDataArray[$i]->name;
|
||||
$toBeConverted->name = $this->executedQueryMetaData[$i]->name;
|
||||
// Add the field to be converted to $toBeConverterdArray
|
||||
array_push($toBeConverterdArray, $toBeConverted);
|
||||
}
|
||||
|
||||
@@ -625,7 +625,7 @@ class UDFLib
|
||||
elseif (isset($jsonSchema->{UDFLib::LIST_VALUES}->sql))
|
||||
{
|
||||
// UDFModel is loaded in method _loadUDF that is called before the current method
|
||||
$queryResult = $this->_ci->UDFModel->execQuery($jsonSchema->{UDFLib::LIST_VALUES}->sql);
|
||||
$queryResult = $this->_ci->UDFModel->execReadOnlyQuery($jsonSchema->{UDFLib::LIST_VALUES}->sql);
|
||||
if (hasData($queryResult))
|
||||
{
|
||||
$parameters = $queryResult->retval;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class Filters_model extends DB_Model
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'system.tbl_filters';
|
||||
$this->pk = 'filter_id';
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ class UDF_model extends DB_Model
|
||||
const STRING_NULL = 'null';
|
||||
const STRING_TRUE = 'true';
|
||||
const STRING_FALSE = 'false';
|
||||
|
||||
|
||||
const UDF_DROPDOWN_TYPE = 'dropdown';
|
||||
const UDF_MULTIPLEDROPDOWN_TYPE = 'multipledropdown';
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -20,41 +20,14 @@ class UDF_model extends DB_Model
|
||||
$this->pk = array('schema', 'table');
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override DB_Model method execQuery to allow only to perform queries to read data
|
||||
*/
|
||||
public function execQuery($query, $parametersArray = null)
|
||||
{
|
||||
//
|
||||
if (
|
||||
(
|
||||
substr($query, 0, 6) == 'SELECT'
|
||||
|| substr($query, 0, 4) == 'WITH'
|
||||
)
|
||||
&&
|
||||
(
|
||||
!stripos($query, 'INSERT')
|
||||
&& !stripos($query, 'UPDATE')
|
||||
&& !stripos($query, 'DELETE')
|
||||
)
|
||||
)
|
||||
{
|
||||
return parent::execQuery($query, $parametersArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('You are allowed to run only query for reading data');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the UDF for this table
|
||||
*/
|
||||
public function getUDFsDefinitions($schemaAndTable)
|
||||
{
|
||||
$st = $this->getSchemaAndTable($schemaAndTable);
|
||||
|
||||
|
||||
$this->addSelect(UDFLib::COLUMN_JSON_DESCRIPTION);
|
||||
$udfResults = $this->loadWhere(
|
||||
array(
|
||||
@@ -62,13 +35,13 @@ class UDF_model extends DB_Model
|
||||
'table' => $st->table
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
return $udfResults;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
// These methods work only with the this version of FAS, not with the future versions
|
||||
|
||||
|
||||
/**
|
||||
* Methods to save data from FAS
|
||||
*/
|
||||
@@ -77,53 +50,53 @@ class UDF_model extends DB_Model
|
||||
$result = error('No way man!');
|
||||
$resultPerson = success('person');
|
||||
$resultPrestudent = success('prestudent');
|
||||
|
||||
|
||||
$person_id = $udfs['person_id'];
|
||||
unset($udfs['person_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));
|
||||
@@ -136,17 +109,17 @@ class UDF_model extends DB_Model
|
||||
{
|
||||
$result = $resultPrestudent;
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function _fillMissingChkboxUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingChkboxUDF = $udfs;
|
||||
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDFLib::CHKBOX_TYPE)
|
||||
@@ -168,17 +141,17 @@ class UDF_model extends DB_Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $_fillMissingChkboxUDF;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function _fillMissingDropdownUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingDropdownUDF = $udfs;
|
||||
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDF_model::UDF_DROPDOWN_TYPE
|
||||
@@ -194,17 +167,17 @@ class UDF_model extends DB_Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $_fillMissingDropdownUDF;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function _fillMissingTextUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingTextUDF = $udfs;
|
||||
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == 'textarea'
|
||||
@@ -220,7 +193,7 @@ class UDF_model extends DB_Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $_fillMissingTextUDF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<div>
|
||||
<?php
|
||||
foreach ($listFields as $key => $value)
|
||||
{
|
||||
echo '<input type="button" value="'.$value.'">';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div>
|
||||
Add:
|
||||
<select>
|
||||
<option value="">Select a field to add..</option>
|
||||
<?php
|
||||
foreach ($listFields as $key => $value)
|
||||
{
|
||||
echo '<option value="'.$value.'">'.$value.'</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
<div>
|
||||
<?php
|
||||
foreach ($metaData as $key => $value)
|
||||
{
|
||||
echo $value->name.' - '.$value->type.'<br>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div>
|
||||
Add filter:
|
||||
<select>
|
||||
<option value="">Select a field to add..</option>
|
||||
<?php
|
||||
foreach ($metaData as $key => $value)
|
||||
{
|
||||
echo '<option value="'.$value->name.'">'.$value->name.'</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
@@ -0,0 +1,9 @@
|
||||
<div>
|
||||
<?php
|
||||
$result = $dataset->retval;
|
||||
foreach ($result as $key => $value)
|
||||
{
|
||||
var_dump($value);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class FilterWidget extends Widget
|
||||
{
|
||||
private $app;
|
||||
private $datasetName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct($name, $args = array())
|
||||
{
|
||||
parent::__construct($name, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function display($widgetData)
|
||||
{
|
||||
$this->load->model('system/Filters_model', 'FiltersModel');
|
||||
|
||||
$this->app = $widgetData['app'];
|
||||
$this->datasetName = $widgetData['datasetName'];
|
||||
|
||||
$dataset = $this->FiltersModel->execReadOnlyQuery($widgetData['query']);
|
||||
|
||||
$this->loadViewSelectFields($this->FiltersModel->getExecutedQueryListFields());
|
||||
|
||||
$this->loadViewSelectFilters($this->FiltersModel->getExecutedQueryMetaData());
|
||||
|
||||
$this->loadViewTableDataset($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function loadViewSelectFields($listFields)
|
||||
{
|
||||
$this->view('widgets/filter/selectFields', array('listFields' => $listFields));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function loadViewSelectFilters($metaData)
|
||||
{
|
||||
$this->view('widgets/filter/selectFilters', array('metaData' => $metaData));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function loadViewTableDataset($result)
|
||||
{
|
||||
$this->view('widgets/filter/tableDataset', array('dataset' => $result));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user