mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
Merge branch 'master' into feature-3716/Messaging_inbox_outbox_user
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class Ausbildungssemester_widget extends DropdownWidget
|
||||
{
|
||||
public function display($widgetData)
|
||||
{
|
||||
$ausbildungssemester_arr = array();
|
||||
|
||||
// Set max number of ausbildungssemester
|
||||
if (isset($widgetData['studiengang']) && is_numeric($widgetData['studiengang'])) // max semester for given studiengang
|
||||
{
|
||||
// to be done
|
||||
}
|
||||
elseif (isset($widgetData['number_semester']) && is_numeric($widgetData['number_semester'])) // custom number of semester
|
||||
{
|
||||
$number_semester = $widgetData['number_semester']; // max semester for bachelor
|
||||
}
|
||||
else
|
||||
{
|
||||
$number_semester = 10; // default
|
||||
}
|
||||
|
||||
|
||||
// Generate number series
|
||||
for ($i = 1; $i <= $number_semester; $i++)
|
||||
{
|
||||
$ausbildungssemester_obj = new StdClass();
|
||||
$ausbildungssemester_obj->id = $i;
|
||||
$ausbildungssemester_obj->description = $i;
|
||||
|
||||
$ausbildungssemester_arr []= $ausbildungssemester_obj;
|
||||
}
|
||||
|
||||
$this->setElementsArray(
|
||||
success($ausbildungssemester_arr),
|
||||
true,
|
||||
$this->p->t('lehre', 'ausbildungssemester'),
|
||||
'No Ausbildungssemester found'
|
||||
);
|
||||
|
||||
$this->loadDropDownView($widgetData);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,11 @@ class FilterWidget extends Widget
|
||||
{
|
||||
// Paths of the views
|
||||
const WIDGET_URL_FILTER = 'widgets/filter/filter';
|
||||
const WIDGET_URL_FILTER_OPTIONS = 'widgets/filter/filterOptions';
|
||||
const WIDGET_URL_SELECT_FIELDS = 'widgets/filter/selectFields';
|
||||
const WIDGET_URL_DATASET_TABLESORTER = 'widgets/filter/tableDataset';
|
||||
const WIDGET_URL_DATASET_PIVOTUI = 'widgets/filter/pivotUIDataset';
|
||||
const WIDGET_URL_DATASET_TABULATOR = 'widgets/filter/tabulatorDataset';
|
||||
const WIDGET_URL_SELECT_FILTERS = 'widgets/filter/selectFilters';
|
||||
const WIDGET_URL_SAVE_FILTER = 'widgets/filter/saveFilter';
|
||||
|
||||
@@ -40,16 +42,23 @@ class FilterWidget extends Widget
|
||||
// To have a column in the GUI with checkboxes to select rows in the table
|
||||
private $_checkboxes;
|
||||
|
||||
// To hide the GUI to operate or save the filter widget
|
||||
private $_hideHeader;
|
||||
private $_hideSave;
|
||||
// To hide the GUI to operate with the filter widget or to save a custom filter
|
||||
private $_hideOptions; // if true hides all the options
|
||||
private $_hideSelectFields; // if true hides the fields selection
|
||||
private $_hideSelectFilters; // if true hides the filters selections
|
||||
private $_hideSave; // if true hides the GUI to save a custom filter
|
||||
|
||||
private $_hideMenu; // if true then the menu is not shown
|
||||
private $_customMenu; // if true then method _setFilterMenu is NOT called
|
||||
|
||||
private $_datasetRepresentation; // dataset representation (ex: tablesorter, pivotUI, ...)
|
||||
private $_datasetRepresentationOptions; // dataset representation options for tablesorter, pivotUI, ...
|
||||
private $_datasetRepFieldsDefs; // dataset representation attributes for each record field
|
||||
|
||||
private $_reloadDataset; // Force Reload of Dataset
|
||||
|
||||
private $_sessionTimeout; // session expiring time
|
||||
|
||||
private static $_FilterWidgetInstance; // static property that contains the instance of itself
|
||||
|
||||
/**
|
||||
@@ -61,18 +70,20 @@ class FilterWidget extends Widget
|
||||
|
||||
self::$_FilterWidgetInstance = $this; // set static property $_FilterWidgetInstance with this instance
|
||||
|
||||
$this->load->library('FiltersLib'); // Loads the FiltersLib that contains all the used logic
|
||||
$this->load->library('FilterWidgetLib'); // Loads the FilterWidgetLib that contains all the used logic
|
||||
|
||||
$this->_initFilterWidget($args); // checks parameters and initialize properties
|
||||
|
||||
$this->filterwidgetlib->setFilterUniqueIdByParams($args);
|
||||
|
||||
// Let's start if it's allowed
|
||||
// NOTE: If it is NOT allowed then no data are loaded
|
||||
if ($this->filterslib->isAllowed($this->_requiredPermissions))
|
||||
if ($this->filterwidgetlib->isAllowed($this->_requiredPermissions))
|
||||
{
|
||||
$this->_startFilterWidget();
|
||||
|
||||
// If a custom menu is not used, then default menu is used
|
||||
if ($this->_customMenu != true) $this->_setFilterMenu();
|
||||
if ($this->_hideMenu != true && $this->_customMenu != true) $this->_setFilterMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,18 +95,33 @@ class FilterWidget extends Widget
|
||||
*/
|
||||
public function display($widgetData)
|
||||
{
|
||||
$this->view(self::WIDGET_URL_FILTER); // GUI starts here
|
||||
$this->view(self::WIDGET_URL_FILTER, array(
|
||||
'app' => $this->_app,
|
||||
'dataset' => $this->_datasetName,
|
||||
'filterid' => $this->_filterId
|
||||
)); // GUI starts here
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public static methods used to load views and to access statically to some properies of the FilterWidget
|
||||
|
||||
/**
|
||||
* Loads the view related to the filter options
|
||||
*/
|
||||
public static function loadViewFilterOptions()
|
||||
{
|
||||
if (self::$_FilterWidgetInstance->_hideOptions != true)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_FILTER_OPTIONS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the view related to the selected fields
|
||||
*/
|
||||
public static function loadViewSelectFields()
|
||||
{
|
||||
if (self::$_FilterWidgetInstance->_hideHeader != true)
|
||||
if (self::$_FilterWidgetInstance->_hideSelectFields != true)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_SELECT_FIELDS);
|
||||
}
|
||||
@@ -106,7 +132,7 @@ class FilterWidget extends Widget
|
||||
*/
|
||||
public static function loadViewSelectFilters()
|
||||
{
|
||||
if (self::$_FilterWidgetInstance->_hideHeader != true)
|
||||
if (self::$_FilterWidgetInstance->_hideSelectFilters != true)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_SELECT_FILTERS);
|
||||
}
|
||||
@@ -128,15 +154,20 @@ class FilterWidget extends Widget
|
||||
*/
|
||||
public static function loadViewDataset()
|
||||
{
|
||||
if (self::$_FilterWidgetInstance->_datasetRepresentation == FiltersLib::DATASET_REP_TABLESORTER)
|
||||
if (self::$_FilterWidgetInstance->_datasetRepresentation == FilterWidgetLib::DATASET_REP_TABLESORTER)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_DATASET_TABLESORTER);
|
||||
}
|
||||
|
||||
if (self::$_FilterWidgetInstance->_datasetRepresentation == FiltersLib::DATASET_REP_PIVOTUI)
|
||||
if (self::$_FilterWidgetInstance->_datasetRepresentation == FilterWidgetLib::DATASET_REP_PIVOTUI)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_DATASET_PIVOTUI);
|
||||
}
|
||||
|
||||
if (self::$_FilterWidgetInstance->_datasetRepresentation == FilterWidgetLib::DATASET_REP_TABULATOR)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_DATASET_TABULATOR);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
@@ -157,122 +188,158 @@ class FilterWidget extends Widget
|
||||
$this->_datasetName = null;
|
||||
$this->_filterKurzbz = null;
|
||||
$this->_filterId = null;
|
||||
$this->_reloadDataset = null;
|
||||
$this->_reloadDataset = true; // by default the dataset is NOT cached in session
|
||||
$this->_query = null;
|
||||
$this->_additionalColumns = null;
|
||||
$this->_columnsAliases = null;
|
||||
$this->_formatRow = null;
|
||||
$this->_markRow = null;
|
||||
$this->_checkboxes = null;
|
||||
$this->_hideHeader = null;
|
||||
$this->_hideOptions = null;
|
||||
$this->_hideSelectFields = null;
|
||||
$this->_hideSelectFilters = null;
|
||||
$this->_hideSave = null;
|
||||
$this->_hideMenu = null;
|
||||
$this->_customMenu = null;
|
||||
$this->_datasetRepresentation = null;
|
||||
$this->_datasetRepresentationOptions = null;
|
||||
$this->_datasetRepFieldsDefs = null;
|
||||
$this->_sessionTimeout = FilterWidgetLib::SESSION_DEFAULT_TIMEOUT;
|
||||
|
||||
// Retrieved the required permissions parameter if present
|
||||
if (isset($args[FiltersLib::REQUIRED_PERMISSIONS_PARAMETER]))
|
||||
if (isset($args[FilterWidgetLib::REQUIRED_PERMISSIONS]))
|
||||
{
|
||||
$this->_requiredPermissions = $args[FiltersLib::REQUIRED_PERMISSIONS_PARAMETER];
|
||||
$this->_requiredPermissions = $args[FilterWidgetLib::REQUIRED_PERMISSIONS];
|
||||
}
|
||||
|
||||
// Parameters needed to retrieve univocally a filter from DB
|
||||
if (isset($args[FiltersLib::APP_PARAMETER]))
|
||||
if (isset($args[FilterWidgetLib::APP]))
|
||||
{
|
||||
$this->_app = $args[FiltersLib::APP_PARAMETER];
|
||||
$this->_app = $args[FilterWidgetLib::APP];
|
||||
}
|
||||
|
||||
if (isset($args[FiltersLib::DATASET_NAME_PARAMETER]))
|
||||
if (isset($args[FilterWidgetLib::DATASET_NAME]))
|
||||
{
|
||||
$this->_datasetName = $args[FiltersLib::DATASET_NAME_PARAMETER];
|
||||
$this->_datasetName = $args[FilterWidgetLib::DATASET_NAME];
|
||||
}
|
||||
|
||||
if (isset($args[FiltersLib::FILTER_KURZBZ_PARAMETER]))
|
||||
if (isset($args[FilterWidgetLib::FILTER_KURZBZ]))
|
||||
{
|
||||
$this->_filterKurzbz = $args[FiltersLib::FILTER_KURZBZ_PARAMETER];
|
||||
$this->_filterKurzbz = $args[FilterWidgetLib::FILTER_KURZBZ];
|
||||
}
|
||||
|
||||
if (isset($args[FiltersLib::FILTER_ID]))
|
||||
if (isset($args[FilterWidgetLib::FILTER_ID]))
|
||||
{
|
||||
$this->_filterId = $args[FiltersLib::FILTER_ID];
|
||||
$this->_filterId = $args[FilterWidgetLib::FILTER_ID];
|
||||
}
|
||||
|
||||
// How to retrieve data for the filter: SQL statement or a result from DB
|
||||
if (isset($args[FiltersLib::QUERY_PARAMETER]))
|
||||
if (isset($args[FilterWidgetLib::QUERY]))
|
||||
{
|
||||
$this->_query = $args[FiltersLib::QUERY_PARAMETER];
|
||||
$this->_query = $args[FilterWidgetLib::QUERY];
|
||||
}
|
||||
|
||||
if (isset($args[FiltersLib::DATASET_RELOAD_PARAMETER]))
|
||||
if (isset($args[FilterWidgetLib::DATASET_RELOAD]))
|
||||
{
|
||||
$this->_reloadDataset = $args[FiltersLib::DATASET_RELOAD_PARAMETER];
|
||||
$this->_reloadDataset = $args[FilterWidgetLib::DATASET_RELOAD];
|
||||
}
|
||||
|
||||
// Parameter is used to add extra columns to the dataset
|
||||
if (isset($args[FiltersLib::ADDITIONAL_COLUMNS])
|
||||
&& is_array($args[FiltersLib::ADDITIONAL_COLUMNS])
|
||||
&& count($args[FiltersLib::ADDITIONAL_COLUMNS]) > 0)
|
||||
if (isset($args[FilterWidgetLib::ADDITIONAL_COLUMNS])
|
||||
&& is_array($args[FilterWidgetLib::ADDITIONAL_COLUMNS])
|
||||
&& count($args[FilterWidgetLib::ADDITIONAL_COLUMNS]) > 0)
|
||||
{
|
||||
$this->_additionalColumns = $args[FiltersLib::ADDITIONAL_COLUMNS];
|
||||
$this->_additionalColumns = $args[FilterWidgetLib::ADDITIONAL_COLUMNS];
|
||||
}
|
||||
|
||||
// Parameter is used to add use aliases for the columns fo the dataset
|
||||
if (isset($args[FiltersLib::COLUMNS_ALIASES])
|
||||
&& is_array($args[FiltersLib::COLUMNS_ALIASES])
|
||||
&& count($args[FiltersLib::COLUMNS_ALIASES]) > 0)
|
||||
if (isset($args[FilterWidgetLib::COLUMNS_ALIASES])
|
||||
&& is_array($args[FilterWidgetLib::COLUMNS_ALIASES])
|
||||
&& count($args[FilterWidgetLib::COLUMNS_ALIASES]) > 0)
|
||||
{
|
||||
$this->_columnsAliases = $args[FiltersLib::COLUMNS_ALIASES];
|
||||
$this->_columnsAliases = $args[FilterWidgetLib::COLUMNS_ALIASES];
|
||||
}
|
||||
|
||||
// Parameter that contains a function to format the rows of the dataset
|
||||
if (isset($args[FiltersLib::FORMAT_ROW]) && is_callable($args[FiltersLib::FORMAT_ROW]))
|
||||
if (isset($args[FilterWidgetLib::FORMAT_ROW]) && is_callable($args[FilterWidgetLib::FORMAT_ROW]))
|
||||
{
|
||||
$this->_formatRow = $args[FiltersLib::FORMAT_ROW];
|
||||
$this->_formatRow = $args[FilterWidgetLib::FORMAT_ROW];
|
||||
}
|
||||
|
||||
// Parameter that contains a function to mark in the GUI the rows of the dataset
|
||||
if (isset($args[FiltersLib::MARK_ROW]) && is_callable($args[FiltersLib::MARK_ROW]))
|
||||
if (isset($args[FilterWidgetLib::MARK_ROW]) && is_callable($args[FilterWidgetLib::MARK_ROW]))
|
||||
{
|
||||
$this->_markRow = $args[FiltersLib::MARK_ROW];
|
||||
$this->_markRow = $args[FilterWidgetLib::MARK_ROW];
|
||||
}
|
||||
|
||||
// Parameter used to specify the column of the dataset that will be used
|
||||
// as id of the checkboxes column in the GUI
|
||||
if (isset($args[FiltersLib::CHECKBOXES]))
|
||||
if (isset($args[FilterWidgetLib::CHECKBOXES]))
|
||||
{
|
||||
$this->_checkboxes = $args[FiltersLib::CHECKBOXES];
|
||||
$this->_checkboxes = $args[FilterWidgetLib::CHECKBOXES];
|
||||
}
|
||||
|
||||
// To specify if the header to operate with the FilterWidget is shown or not
|
||||
if (isset($args[FiltersLib::HIDE_HEADER]) && is_bool($args[FiltersLib::HIDE_HEADER]))
|
||||
// To specify if the filter options are shown ot not
|
||||
if (isset($args[FilterWidgetLib::HIDE_OPTIONS]) && is_bool($args[FilterWidgetLib::HIDE_OPTIONS]))
|
||||
{
|
||||
$this->_hideHeader = $args[FiltersLib::HIDE_HEADER];
|
||||
$this->_hideOptions = $args[FilterWidgetLib::HIDE_OPTIONS];
|
||||
}
|
||||
|
||||
// To specify if the form to select fields is shown or not
|
||||
if (isset($args[FilterWidgetLib::HIDE_SELECT_FIELDS]) && is_bool($args[FilterWidgetLib::HIDE_SELECT_FIELDS]))
|
||||
{
|
||||
$this->_hideSelectFields = $args[FilterWidgetLib::HIDE_SELECT_FIELDS];
|
||||
}
|
||||
|
||||
// To specify if the form to select filters is shown or not
|
||||
if (isset($args[FilterWidgetLib::HIDE_SELECT_FILTERS]) && is_bool($args[FilterWidgetLib::HIDE_SELECT_FILTERS]))
|
||||
{
|
||||
$this->_hideSelectFilters = $args[FilterWidgetLib::HIDE_SELECT_FILTERS];
|
||||
}
|
||||
|
||||
// To specify if the form to save a custom FilterWidget is shown or not
|
||||
if (isset($args[FiltersLib::HIDE_SAVE]) && is_bool($args[FiltersLib::HIDE_SAVE]))
|
||||
if (isset($args[FilterWidgetLib::HIDE_SAVE]) && is_bool($args[FilterWidgetLib::HIDE_SAVE]))
|
||||
{
|
||||
$this->_hideSave = $args[FiltersLib::HIDE_SAVE];
|
||||
$this->_hideSave = $args[FilterWidgetLib::HIDE_SAVE];
|
||||
}
|
||||
|
||||
// If the menu should be shown or not
|
||||
if (isset($args[FilterWidgetLib::HIDE_MENU]) && is_bool($args[FilterWidgetLib::HIDE_MENU]))
|
||||
{
|
||||
$this->_hideMenu = $args[FilterWidgetLib::HIDE_MENU];
|
||||
}
|
||||
|
||||
// If a custom menu is set
|
||||
if (isset($args[FiltersLib::CUSTOM_MENU]) && is_bool($args[FiltersLib::CUSTOM_MENU]))
|
||||
if (isset($args[FilterWidgetLib::CUSTOM_MENU]) && is_bool($args[FilterWidgetLib::CUSTOM_MENU]))
|
||||
{
|
||||
$this->_customMenu = $args[FiltersLib::CUSTOM_MENU];
|
||||
$this->_customMenu = $args[FilterWidgetLib::CUSTOM_MENU];
|
||||
}
|
||||
|
||||
// To specify how to represent the dataset (ex: tablesorter, pivotUI, ...)
|
||||
if (isset($args[FiltersLib::DATASET_REPRESENTATION])
|
||||
&& ($args[FiltersLib::DATASET_REPRESENTATION] == FiltersLib::DATASET_REP_TABLESORTER
|
||||
|| $args[FiltersLib::DATASET_REPRESENTATION] == FiltersLib::DATASET_REP_PIVOTUI))
|
||||
if (isset($args[FilterWidgetLib::DATASET_REPRESENTATION])
|
||||
&& ($args[FilterWidgetLib::DATASET_REPRESENTATION] == FilterWidgetLib::DATASET_REP_TABLESORTER
|
||||
|| $args[FilterWidgetLib::DATASET_REPRESENTATION] == FilterWidgetLib::DATASET_REP_PIVOTUI
|
||||
|| $args[FilterWidgetLib::DATASET_REPRESENTATION] == FilterWidgetLib::DATASET_REP_TABULATOR))
|
||||
{
|
||||
$this->_datasetRepresentation = $args[FiltersLib::DATASET_REPRESENTATION];
|
||||
$this->_datasetRepresentation = $args[FilterWidgetLib::DATASET_REPRESENTATION];
|
||||
}
|
||||
|
||||
// To specify options for the dataset representation (ex: tablesorter, pivotUI, ...)
|
||||
if (isset($args[FiltersLib::DATASET_REP_OPTIONS]) && !isEmptyString($args[FiltersLib::DATASET_REP_OPTIONS]))
|
||||
if (isset($args[FilterWidgetLib::DATASET_REP_OPTIONS]) && !isEmptyString($args[FilterWidgetLib::DATASET_REP_OPTIONS]))
|
||||
{
|
||||
$this->_datasetRepresentationOptions = $args[FiltersLib::DATASET_REP_OPTIONS];
|
||||
$this->_datasetRepresentationOptions = $args[FilterWidgetLib::DATASET_REP_OPTIONS];
|
||||
}
|
||||
|
||||
// To specify how to represent each record field
|
||||
if (isset($args[FilterWidgetLib::DATASET_REP_FIELDS_DEFS]) && !isEmptyString($args[FilterWidgetLib::DATASET_REP_FIELDS_DEFS]))
|
||||
{
|
||||
$this->_datasetRepFieldsDefs = $args[FilterWidgetLib::DATASET_REP_FIELDS_DEFS];
|
||||
}
|
||||
|
||||
// To specify the expiring session time
|
||||
if (isset($args[FilterWidgetLib::SESSION_TIMEOUT]) && is_numeric($args[FilterWidgetLib::SESSION_TIMEOUT]))
|
||||
{
|
||||
$this->_sessionTimeout = $args[FilterWidgetLib::SESSION_TIMEOUT];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,40 +348,55 @@ class FilterWidget extends Widget
|
||||
*/
|
||||
private function _checkParameters($args)
|
||||
{
|
||||
// If no options are given to this widget...
|
||||
if (!is_array($args) || (is_array($args) && count($args) == 0))
|
||||
{
|
||||
show_error('Second parameter of the widget call must be a NOT empty associative array');
|
||||
}
|
||||
else
|
||||
else // ...otherwise
|
||||
{
|
||||
if ((!isset($args[FiltersLib::APP_PARAMETER]) && !isset($args[FiltersLib::DATASET_NAME_PARAMETER]))
|
||||
&& !isset($args[FiltersLib::FILTER_ID]))
|
||||
// Parameters (app AND dataset name) OR filter id are mandatory
|
||||
if ((!isset($args[FilterWidgetLib::APP]) && !isset($args[FilterWidgetLib::DATASET_NAME]))
|
||||
&& !isset($args[FilterWidgetLib::FILTER_ID]))
|
||||
{
|
||||
show_error(
|
||||
'The parameters ("'.FiltersLib::APP_PARAMETER.'" and "'.FiltersLib::DATASET_NAME_PARAMETER.') OR "'.
|
||||
FiltersLib::FILTER_ID.'" must be specified'
|
||||
'The parameters ("'.FilterWidgetLib::APP.'" AND "'.FilterWidgetLib::DATASET_NAME.') OR "'.
|
||||
FilterWidgetLib::FILTER_ID.'" must be specified'
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset($args[FiltersLib::QUERY_PARAMETER]))
|
||||
// The query parameter is mandatory
|
||||
if (!isset($args[FilterWidgetLib::QUERY]))
|
||||
{
|
||||
show_error('The parameters "'.FiltersLib::QUERY_PARAMETER.'" must be specified');
|
||||
show_error('The parameter "'.FilterWidgetLib::QUERY.'" must be specified');
|
||||
}
|
||||
|
||||
if (!isset($args[FiltersLib::DATASET_REPRESENTATION]))
|
||||
// The dataset representation parameter is mandatory
|
||||
if (!isset($args[FilterWidgetLib::DATASET_REPRESENTATION]))
|
||||
{
|
||||
show_error('The parameter "'.FiltersLib::DATASET_REPRESENTATION.'" must be specified');
|
||||
show_error('The parameter "'.FilterWidgetLib::DATASET_REPRESENTATION.'" must be specified');
|
||||
}
|
||||
|
||||
if (isset($args[FiltersLib::DATASET_REPRESENTATION])
|
||||
&& $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_TABLESORTER
|
||||
&& $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_PIVOTUI)
|
||||
// Checks if the dataset representation parameter is valid
|
||||
if (isset($args[FilterWidgetLib::DATASET_REPRESENTATION])
|
||||
&& $args[FilterWidgetLib::DATASET_REPRESENTATION] != FilterWidgetLib::DATASET_REP_TABLESORTER
|
||||
&& $args[FilterWidgetLib::DATASET_REPRESENTATION] != FilterWidgetLib::DATASET_REP_PIVOTUI
|
||||
&& $args[FilterWidgetLib::DATASET_REPRESENTATION] != FilterWidgetLib::DATASET_REP_TABULATOR)
|
||||
{
|
||||
show_error(
|
||||
'The parameter "'.FiltersLib::DATASET_REPRESENTATION.
|
||||
'" must be IN ("'.FiltersLib::DATASET_REP_TABLESORTER.'", "'.FiltersLib::DATASET_REP_PIVOTUI.'")'
|
||||
'The parameter "'.FilterWidgetLib::DATASET_REPRESENTATION.
|
||||
'" must be IN ("'
|
||||
.FilterWidgetLib::DATASET_REP_TABLESORTER.'", "'
|
||||
.FilterWidgetLib::DATASET_REP_PIVOTUI.'", "'
|
||||
.FilterWidgetLib::DATASET_REP_TABULATOR.'")'
|
||||
);
|
||||
}
|
||||
|
||||
// If given the session timeout parameter must be a number
|
||||
if (isset($args[FilterWidgetLib::SESSION_TIMEOUT]) && !is_numeric($args[FilterWidgetLib::SESSION_TIMEOUT]))
|
||||
{
|
||||
show_error('The parameter "'.FilterWidgetLib::SESSION_TIMEOUT.'" must be a number');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,52 +405,53 @@ class FilterWidget extends Widget
|
||||
*/
|
||||
private function _startFilterWidget()
|
||||
{
|
||||
// Looks for expired filter widgets in session and drops them
|
||||
$this->filterwidgetlib->dropExpiredFilterWidgets();
|
||||
|
||||
// Read the all session for this filter widget
|
||||
$session = $this->filterslib->getSession();
|
||||
$session = $this->filterwidgetlib->getSession();
|
||||
|
||||
// If session is NOT empty -> a filter was already loaded
|
||||
if ($session != null)
|
||||
{
|
||||
// Retrieve the filterId stored in the session
|
||||
$sessionFilterId = $this->filterslib->getSessionElement(FiltersLib::FILTER_ID);
|
||||
$sessionFilterId = $this->filterwidgetlib->getSessionElement(FilterWidgetLib::FILTER_ID);
|
||||
|
||||
// If the filter loaded in session is NOT the same that is being requested then empty the session
|
||||
if ($this->_filterId != $sessionFilterId)
|
||||
{
|
||||
$this->filterslib->setSession(null);
|
||||
$this->filterwidgetlib->setSession(null);
|
||||
$session = null;
|
||||
}
|
||||
else // else if the filter loaded in session is the same that is being requested
|
||||
{
|
||||
// Get SESSION_RELOAD_DATASET from the session
|
||||
$sessionReloadDataset = $this->filterslib->getSessionElement(FiltersLib::SESSION_RELOAD_DATASET);
|
||||
// Get SESSION_DATASET_RELOAD from the session
|
||||
$sessionReloadDataset = $this->filterwidgetlib->getSessionElement(FilterWidgetLib::SESSION_DATASET_RELOAD);
|
||||
|
||||
// if Filter changed or reload is forced by parameter then reload the Dataset
|
||||
if ($this->_reloadDataset === true || $sessionReloadDataset === true)
|
||||
{
|
||||
// Set as false to stop changing the dataset
|
||||
$this->filterslib->setSessionElement(FiltersLib::SESSION_RELOAD_DATASET, false);
|
||||
$this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_DATASET_RELOAD, false);
|
||||
|
||||
// Generate dataset query using filters from the session
|
||||
$datasetQuery = $this->filterslib->generateDatasetQuery(
|
||||
$datasetQuery = $this->filterwidgetlib->generateDatasetQuery(
|
||||
$this->_query,
|
||||
$this->filterslib->getSessionElement(FiltersLib::SESSION_FILTERS)
|
||||
$this->filterwidgetlib->getSessionElement(FilterWidgetLib::SESSION_FILTERS)
|
||||
);
|
||||
|
||||
// Then retrieve dataset from DB
|
||||
$dataset = $this->filterslib->getDataset($datasetQuery);
|
||||
$dataset = $this->filterwidgetlib->getDataset($datasetQuery);
|
||||
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow
|
||||
|
||||
$this->load->model('system/Filters_model', 'FiltersModel');
|
||||
|
||||
// Set the new dataset and its attributes in the session
|
||||
$this->filterslib->setSessionElement(FiltersLib::SESSION_METADATA, $this->FiltersModel->getExecutedQueryMetaData());
|
||||
$this->filterslib->setSessionElement(FiltersLib::SESSION_ROW_NUMBER, count($dataset->retval));
|
||||
$this->filterslib->setSessionElement(FiltersLib::SESSION_DATASET, $dataset->retval);
|
||||
$this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_METADATA, $this->FiltersModel->getExecutedQueryMetaData());
|
||||
$this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_ROW_NUMBER, count($dataset->retval));
|
||||
$this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_DATASET, $dataset->retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -378,7 +461,7 @@ class FilterWidget extends Widget
|
||||
if ($session == null)
|
||||
{
|
||||
// Load filter definition data from DB
|
||||
$definition = $this->filterslib->loadDefinition(
|
||||
$definition = $this->filterwidgetlib->loadDefinition(
|
||||
$this->_filterId,
|
||||
$this->_app,
|
||||
$this->_datasetName,
|
||||
@@ -386,53 +469,54 @@ class FilterWidget extends Widget
|
||||
);
|
||||
|
||||
// Checks and parse json present into the definition
|
||||
$parsedFilterJson = $this->filterslib->parseFilterJson($definition);
|
||||
$parsedFilterJson = $this->filterwidgetlib->parseFilterJson($definition);
|
||||
if ($parsedFilterJson != null) // if the json is valid
|
||||
{
|
||||
// Generate dataset query
|
||||
$datasetQuery = $this->filterslib->generateDatasetQuery($this->_query, $parsedFilterJson->filters);
|
||||
$datasetQuery = $this->filterwidgetlib->generateDatasetQuery($this->_query, $parsedFilterJson->filters);
|
||||
|
||||
// Then retrieve dataset from DB
|
||||
$dataset = $this->filterslib->getDataset($datasetQuery);
|
||||
$dataset = $this->filterwidgetlib->getDataset($datasetQuery);
|
||||
|
||||
// Try to load the name of the filter using the PhrasesLib
|
||||
$filterName = $this->filterslib->getFilterName($parsedFilterJson);
|
||||
$filterName = $this->filterwidgetlib->getFilterName($parsedFilterJson);
|
||||
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow
|
||||
|
||||
$this->load->model('system/Filters_model', 'FiltersModel');
|
||||
|
||||
// Stores an array that contains all the data useful for
|
||||
$this->filterslib->setSession(
|
||||
$this->filterwidgetlib->setSession(
|
||||
array(
|
||||
FiltersLib::FILTER_ID => $this->_filterId, // the current filter id
|
||||
FiltersLib::APP_PARAMETER => $this->_app, // the current app parameter
|
||||
FiltersLib::DATASET_NAME_PARAMETER => $this->_datasetName, // the carrent dataset name
|
||||
FiltersLib::SESSION_FILTER_NAME => $filterName, // the current filter name
|
||||
FiltersLib::SESSION_FIELDS => $this->FiltersModel->getExecutedQueryListFields(), // all the fields of the dataset
|
||||
FiltersLib::SESSION_SELECTED_FIELDS => $this->_getColumnsNames($parsedFilterJson->columns), // all the selected fields
|
||||
FiltersLib::SESSION_COLUMNS_ALIASES => $this->_columnsAliases, // all the fields aliases
|
||||
FiltersLib::SESSION_ADDITIONAL_COLUMNS => $this->_additionalColumns, // additional columns
|
||||
FiltersLib::SESSION_CHECKBOXES => $this->_checkboxes, // the name of the field used to build the checkboxes column
|
||||
FiltersLib::SESSION_FILTERS => $parsedFilterJson->filters, // all the filters used to filter the dataset
|
||||
FiltersLib::SESSION_METADATA => $this->FiltersModel->getExecutedQueryMetaData(), // the metadata of the dataset
|
||||
FiltersLib::SESSION_ROW_NUMBER => count($dataset->retval), // the number of loaded rows by this filter
|
||||
FiltersLib::SESSION_DATASET => $dataset->retval, // the entire dataset
|
||||
FiltersLib::SESSION_RELOAD_DATASET => false, // if the dataset must be reloaded, not needed the first time
|
||||
FiltersLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation
|
||||
FiltersLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions // the choosen dataset representation options
|
||||
FilterWidgetLib::FILTER_ID => $this->_filterId, // the current filter id
|
||||
FilterWidgetLib::APP => $this->_app, // the current app parameter
|
||||
FilterWidgetLib::DATASET_NAME => $this->_datasetName, // the carrent dataset name
|
||||
FilterWidgetLib::SESSION_FILTER_NAME => $filterName, // the current filter name
|
||||
FilterWidgetLib::SESSION_FIELDS => $this->FiltersModel->getExecutedQueryListFields(), // all the fields of the dataset
|
||||
FilterWidgetLib::SESSION_SELECTED_FIELDS => $this->_getColumnsNames($parsedFilterJson->columns), // all the selected fields
|
||||
FilterWidgetLib::SESSION_COLUMNS_ALIASES => $this->_columnsAliases, // all the fields aliases
|
||||
FilterWidgetLib::SESSION_ADDITIONAL_COLUMNS => $this->_additionalColumns, // additional columns
|
||||
FilterWidgetLib::SESSION_CHECKBOXES => $this->_checkboxes, // the name of the field used to build the checkboxes column
|
||||
FilterWidgetLib::SESSION_FILTERS => $parsedFilterJson->filters, // all the filters used to filter the dataset
|
||||
FilterWidgetLib::SESSION_METADATA => $this->FiltersModel->getExecutedQueryMetaData(), // the metadata of the dataset
|
||||
FilterWidgetLib::SESSION_ROW_NUMBER => count($dataset->retval), // the number of loaded rows by this filter
|
||||
FilterWidgetLib::SESSION_DATASET => $dataset->retval, // the entire dataset
|
||||
FilterWidgetLib::SESSION_DATASET_RELOAD => false, // if the dataset must be reloaded, not needed the first time
|
||||
FilterWidgetLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation
|
||||
FilterWidgetLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, // the choosen dataset representation options
|
||||
FilterWidgetLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs // the choosen dataset representation record fields definition
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: latest operations to be performed in the session to be shure that they are always present
|
||||
// To be always stored in the session, otherwise is not possible to load data from Filters controller
|
||||
// NOTE: must the latest operation to be performed in the session to be shure that is always present
|
||||
$this->filterslib->setSessionElement(FiltersLib::REQUIRED_PERMISSIONS_PARAMETER, $this->_requiredPermissions);
|
||||
$this->filterwidgetlib->setSessionElement(FilterWidgetLib::REQUIRED_PERMISSIONS, $this->_requiredPermissions);
|
||||
// Renew or set the session expiring time
|
||||
$this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_TIMEOUT, strtotime('+'.$this->_sessionTimeout.' minutes', time()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,7 +525,7 @@ class FilterWidget extends Widget
|
||||
private function _setFilterMenu()
|
||||
{
|
||||
// Generates the filters structure array
|
||||
$filterMenu = $this->filterslib->generateFilterMenu(
|
||||
$filterMenu = $this->filterwidgetlib->generateFilterMenu(
|
||||
$this->router->directory.$this->router->class.'/'.$this->router->method
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,34 @@ class Organisationseinheit_widget extends DropdownWidget
|
||||
public function display($widgetData)
|
||||
{
|
||||
$this->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel');
|
||||
|
||||
|
||||
if (isset($widgetData['typ']))
|
||||
$typ = $widgetData['typ'];
|
||||
{
|
||||
$this->setElementsArray($this->OrganisationseinheitModel->getRecursiveList($widgetData['typ']));
|
||||
}
|
||||
// If 'organisationseinheit' (array of specific oe_kurzbz) is given, retrieve these organisational units only
|
||||
elseif (isset($widgetData['organisationseinheit']) && !empty($widgetData['organisationseinheit']))
|
||||
{
|
||||
$condition = '
|
||||
oe_kurzbz IN (\''. implode('\',\'', $widgetData['organisationseinheit']) . '\') AND
|
||||
aktiv = TRUE
|
||||
';
|
||||
$this->addSelectToModel($this->OrganisationseinheitModel, 'oe_kurzbz', 'organisationseinheittyp_kurzbz || \' \' || bezeichnung');
|
||||
$this->OrganisationseinheitModel->addOrder('organisationseinheittyp_kurzbz', 'ASC');
|
||||
$this->setElementsArray(
|
||||
$this->OrganisationseinheitModel->loadWhere($condition),
|
||||
true,
|
||||
$this->p->t('lehre', 'organisationseinheit'),
|
||||
'No organisational units found'
|
||||
);
|
||||
}
|
||||
// Default: retrieve tree of all organisational units
|
||||
else
|
||||
$typ = null;
|
||||
|
||||
// NOTE: no need to call addSelectToModel because getRecursiveList already returns
|
||||
// the correct names of the fields
|
||||
|
||||
$this->setElementsArray($this->OrganisationseinheitModel->getRecursiveList($typ));
|
||||
{
|
||||
// NOTE: no need to call addSelectToModel because getRecursiveList already returns
|
||||
// the correct names of the fields
|
||||
$this->setElementsArray($this->OrganisationseinheitModel->getRecursiveList());
|
||||
}
|
||||
|
||||
$this->loadDropDownView($widgetData);
|
||||
}
|
||||
|
||||
@@ -8,15 +8,29 @@ class Studiengang_widget extends DropdownWidget
|
||||
$this->load->model('organisation/Studiengang_model', 'StudiengangModel');
|
||||
$this->StudiengangModel->addOrder('kurzbzlang');
|
||||
|
||||
$this->addSelectToModel($this->StudiengangModel, 'studiengang_kz', '\'(\' || kurzbzlang || \') \' || bezeichnung');
|
||||
|
||||
$this->setElementsArray(
|
||||
$this->StudiengangModel->loadWhere(array('aktiv' => true)),
|
||||
true,
|
||||
'Select a studiengang...',
|
||||
'No studiengaenge found'
|
||||
);
|
||||
|
||||
$this->addSelectToModel($this->StudiengangModel, 'studiengang_kz', '\'(\' || upper(typ||kurzbz) || \') \' || tbl_studiengang.bezeichnung');
|
||||
|
||||
// If 'studiengang' (array of specific studiengaenge) is given, retrieve these studiengaenge only
|
||||
if (isset($widgetData['studiengang']) && !empty($widgetData['studiengang']))
|
||||
{
|
||||
$condition = '
|
||||
studiengang_kz IN ('. implode(',', $widgetData['studiengang']) . ') AND
|
||||
aktiv = true
|
||||
';
|
||||
}
|
||||
// Default: retrieve all studiengaenge
|
||||
else
|
||||
{
|
||||
$condition = array('aktiv' => true);
|
||||
}
|
||||
|
||||
$this->setElementsArray(
|
||||
$this->StudiengangModel->loadWhere($condition),
|
||||
true,
|
||||
$this->p->t('lehre', 'studiengang'),
|
||||
'No studiengaenge found'
|
||||
);
|
||||
|
||||
$this->loadDropDownView();
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,14 @@ class Studiensemester_widget extends DropdownWidget
|
||||
{
|
||||
// Studiensemester
|
||||
$this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel');
|
||||
$this->StudiensemesterModel->addOrder('studiensemester_kurzbz', 'DESC');
|
||||
$this->StudiensemesterModel->addOrder('start', 'DESC');
|
||||
|
||||
$this->addSelectToModel($this->StudiensemesterModel, 'studiensemester_kurzbz', 'studiensemester_kurzbz');
|
||||
|
||||
$this->setElementsArray(
|
||||
$this->StudiensemesterModel->load(),
|
||||
true,
|
||||
'Select a studiensemester...',
|
||||
$this->p->t('lehre', 'studiensemester'),
|
||||
'No studiensemester found'
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,440 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* To display a table that shows data retriev by a SQL statement
|
||||
*/
|
||||
class TableWidget extends Widget
|
||||
{
|
||||
// Paths of the views
|
||||
const WIDGET_URL_TABLE = 'widgets/table/table';
|
||||
const WIDGET_URL_DATASET_TABLESORTER = 'widgets/table/tableDataset';
|
||||
const WIDGET_URL_DATASET_PIVOTUI = 'widgets/table/pivotUIDataset';
|
||||
const WIDGET_URL_DATASET_TABULATOR = 'widgets/table/tabulatorDataset';
|
||||
|
||||
// Default formats
|
||||
const DEFAULT_DATE_FORMAT = 'd.m.Y H:i:s';
|
||||
const DEFAULT_MARK_ROW_CLASS = 'text-danger';
|
||||
|
||||
// Required permissions to use this TableWidget
|
||||
private $_requiredPermissions;
|
||||
|
||||
// SQL statement
|
||||
private $_query;
|
||||
|
||||
// Additional columns to add to the dataset or aliases to be used to rename columns of the dataset
|
||||
private $_additionalColumns;
|
||||
private $_columnsAliases;
|
||||
|
||||
// To format or mark rows of the dataset
|
||||
private $_formatRow;
|
||||
private $_markRow;
|
||||
|
||||
// To have a column in the GUI with checkboxes to select rows in the table
|
||||
private $_checkboxes;
|
||||
|
||||
private $_datasetRepresentation; // dataset representation (ex: tablesorter, pivotUI, ...)
|
||||
private $_datasetRepresentationOptions; // dataset representation options for tablesorter, pivotUI, ...
|
||||
private $_datasetRepFieldsDefs; // dataset representation attributes for each record field
|
||||
|
||||
private $_reloadDataset; // Force Reload of Dataset
|
||||
|
||||
private $_sessionTimeout; // session expiring time
|
||||
|
||||
private static $_TableWidgetInstance; // static property that contains the instance of itself
|
||||
|
||||
/**
|
||||
* Initialize the TableWidget and starts the execution of the logic
|
||||
*/
|
||||
public function __construct($name, $args = array())
|
||||
{
|
||||
parent::__construct($name, $args); // calls the parent's constructor
|
||||
|
||||
self::$_TableWidgetInstance = $this; // set static property $_TableWidgetInstance with this instance
|
||||
|
||||
$this->load->library('TableWidgetLib'); // Loads the TableWidgetLib that contains all the used logic
|
||||
|
||||
$this->_initTableWidget($args); // checks parameters and initialize properties
|
||||
|
||||
$this->tablewidgetlib->setTableUniqueIdByParams($args);
|
||||
|
||||
// Let's start if it's allowed
|
||||
// NOTE: If it is NOT allowed then no data are loaded
|
||||
if ($this->tablewidgetlib->isAllowed($this->_requiredPermissions))
|
||||
{
|
||||
$this->_startTableWidget($args[TableWidgetLib::TABLE_UNIQUE_ID]);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* Called when echoing the table widget call
|
||||
*/
|
||||
public function display($widgetData)
|
||||
{
|
||||
$this->view(self::WIDGET_URL_TABLE, array(
|
||||
'tableUniqueId' => $widgetData[TableWidgetLib::TABLE_UNIQUE_ID]
|
||||
)); // GUI starts here
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public static methods used to load views and to access statically to some properies of the TableWidget
|
||||
|
||||
/**
|
||||
* Loads the view related to the dataset, here is decided how to represent the dataset (ex: tablesorter, pivotUI, ...)
|
||||
*/
|
||||
public static function loadViewDataset()
|
||||
{
|
||||
if (self::$_TableWidgetInstance->_datasetRepresentation == TableWidgetLib::DATASET_REP_TABLESORTER)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_DATASET_TABLESORTER);
|
||||
}
|
||||
|
||||
if (self::$_TableWidgetInstance->_datasetRepresentation == TableWidgetLib::DATASET_REP_PIVOTUI)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_DATASET_PIVOTUI);
|
||||
}
|
||||
|
||||
if (self::$_TableWidgetInstance->_datasetRepresentation == TableWidgetLib::DATASET_REP_TABULATOR)
|
||||
{
|
||||
self::_loadView(self::WIDGET_URL_DATASET_TABULATOR);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Checks parameters and initialize all the properties of this TableWidget
|
||||
*/
|
||||
private function _initTableWidget($args)
|
||||
{
|
||||
$this->_checkParameters($args);
|
||||
|
||||
// If here then everything is ok
|
||||
|
||||
// Initialize class properties
|
||||
$this->_requiredPermissions = null;
|
||||
$this->_reloadDataset = true; // by default the dataset is NOT cached in session
|
||||
$this->_query = null;
|
||||
$this->_additionalColumns = null;
|
||||
$this->_columnsAliases = null;
|
||||
$this->_formatRow = null;
|
||||
$this->_markRow = null;
|
||||
$this->_checkboxes = null;
|
||||
$this->_datasetRepresentation = null;
|
||||
$this->_datasetRepresentationOptions = null;
|
||||
$this->_datasetRepFieldsDefs = null;
|
||||
$this->_sessionTimeout = TableWidgetLib::SESSION_DEFAULT_TIMEOUT;
|
||||
|
||||
// Retrieved the required permissions parameter if present
|
||||
if (isset($args[TableWidgetLib::REQUIRED_PERMISSIONS]))
|
||||
{
|
||||
$this->_requiredPermissions = $args[TableWidgetLib::REQUIRED_PERMISSIONS];
|
||||
}
|
||||
|
||||
// How to retrieve data for the table: SQL statement or a result from DB
|
||||
if (isset($args[TableWidgetLib::QUERY]))
|
||||
{
|
||||
$this->_query = $args[TableWidgetLib::QUERY];
|
||||
}
|
||||
|
||||
if (isset($args[TableWidgetLib::DATASET_RELOAD]))
|
||||
{
|
||||
$this->_reloadDataset = $args[TableWidgetLib::DATASET_RELOAD];
|
||||
}
|
||||
|
||||
// Parameter is used to add extra columns to the dataset
|
||||
if (isset($args[TableWidgetLib::ADDITIONAL_COLUMNS])
|
||||
&& is_array($args[TableWidgetLib::ADDITIONAL_COLUMNS])
|
||||
&& count($args[TableWidgetLib::ADDITIONAL_COLUMNS]) > 0)
|
||||
{
|
||||
$this->_additionalColumns = $args[TableWidgetLib::ADDITIONAL_COLUMNS];
|
||||
}
|
||||
|
||||
// Parameter is used to add use aliases for the columns fo the dataset
|
||||
if (isset($args[TableWidgetLib::COLUMNS_ALIASES])
|
||||
&& is_array($args[TableWidgetLib::COLUMNS_ALIASES])
|
||||
&& count($args[TableWidgetLib::COLUMNS_ALIASES]) > 0)
|
||||
{
|
||||
$this->_columnsAliases = $args[TableWidgetLib::COLUMNS_ALIASES];
|
||||
}
|
||||
|
||||
// Parameter that contains a function to format the rows of the dataset
|
||||
if (isset($args[TableWidgetLib::FORMAT_ROW]) && is_callable($args[TableWidgetLib::FORMAT_ROW]))
|
||||
{
|
||||
$this->_formatRow = $args[TableWidgetLib::FORMAT_ROW];
|
||||
}
|
||||
|
||||
// Parameter that contains a function to mark in the GUI the rows of the dataset
|
||||
if (isset($args[TableWidgetLib::MARK_ROW]) && is_callable($args[TableWidgetLib::MARK_ROW]))
|
||||
{
|
||||
$this->_markRow = $args[TableWidgetLib::MARK_ROW];
|
||||
}
|
||||
|
||||
// Parameter used to specify the column of the dataset that will be used
|
||||
// as id of the checkboxes column in the GUI
|
||||
if (isset($args[TableWidgetLib::CHECKBOXES]))
|
||||
{
|
||||
$this->_checkboxes = $args[TableWidgetLib::CHECKBOXES];
|
||||
}
|
||||
|
||||
// To specify how to represent the dataset (ex: tablesorter, pivotUI, ...)
|
||||
if (isset($args[TableWidgetLib::DATASET_REPRESENTATION])
|
||||
&& ($args[TableWidgetLib::DATASET_REPRESENTATION] == TableWidgetLib::DATASET_REP_TABLESORTER
|
||||
|| $args[TableWidgetLib::DATASET_REPRESENTATION] == TableWidgetLib::DATASET_REP_PIVOTUI
|
||||
|| $args[TableWidgetLib::DATASET_REPRESENTATION] == TableWidgetLib::DATASET_REP_TABULATOR))
|
||||
{
|
||||
$this->_datasetRepresentation = $args[TableWidgetLib::DATASET_REPRESENTATION];
|
||||
}
|
||||
|
||||
// To specify options for the dataset representation (ex: tablesorter, pivotUI, ...)
|
||||
if (isset($args[TableWidgetLib::DATASET_REP_OPTIONS]) && !isEmptyString($args[TableWidgetLib::DATASET_REP_OPTIONS]))
|
||||
{
|
||||
$this->_datasetRepresentationOptions = $args[TableWidgetLib::DATASET_REP_OPTIONS];
|
||||
}
|
||||
|
||||
// To specify how to represent each record field
|
||||
if (isset($args[TableWidgetLib::DATASET_REP_FIELDS_DEFS]) && !isEmptyString($args[TableWidgetLib::DATASET_REP_FIELDS_DEFS]))
|
||||
{
|
||||
$this->_datasetRepFieldsDefs = $args[TableWidgetLib::DATASET_REP_FIELDS_DEFS];
|
||||
}
|
||||
|
||||
// To specify the expiring session time
|
||||
if (isset($args[TableWidgetLib::SESSION_TIMEOUT]) && is_numeric($args[TableWidgetLib::SESSION_TIMEOUT]))
|
||||
{
|
||||
$this->_sessionTimeout = $args[TableWidgetLib::SESSION_TIMEOUT];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the required parameters used to call this TableWidget
|
||||
*/
|
||||
private function _checkParameters($args)
|
||||
{
|
||||
// If no options are given to this widget...
|
||||
if (!is_array($args) || (is_array($args) && count($args) == 0))
|
||||
{
|
||||
show_error('Second parameter of the widget call must be a NOT empty associative array');
|
||||
}
|
||||
else // ...otherwise
|
||||
{
|
||||
// The unique id parameter is mandatory
|
||||
if (!isset($args[TableWidgetLib::TABLE_UNIQUE_ID]))
|
||||
{
|
||||
show_error('The parameter "'.TableWidgetLib::TABLE_UNIQUE_ID.'" must be specified');
|
||||
}
|
||||
|
||||
// The query parameter is mandatory
|
||||
if (!isset($args[TableWidgetLib::QUERY]))
|
||||
{
|
||||
show_error('The parameter "'.TableWidgetLib::QUERY.'" must be specified');
|
||||
}
|
||||
|
||||
// The dataset representation parameter is mandatory
|
||||
if (!isset($args[TableWidgetLib::DATASET_REPRESENTATION]))
|
||||
{
|
||||
show_error('The parameter "'.TableWidgetLib::DATASET_REPRESENTATION.'" must be specified');
|
||||
}
|
||||
|
||||
// Checks if the dataset representation parameter is valid
|
||||
if (isset($args[TableWidgetLib::DATASET_REPRESENTATION])
|
||||
&& $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_TABLESORTER
|
||||
&& $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_PIVOTUI
|
||||
&& $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_TABULATOR)
|
||||
{
|
||||
show_error(
|
||||
'The parameter "'.TableWidgetLib::DATASET_REPRESENTATION.
|
||||
'" must be IN ("'
|
||||
.TableWidgetLib::DATASET_REP_TABLESORTER.'", "'
|
||||
.TableWidgetLib::DATASET_REP_PIVOTUI.'", "'
|
||||
.TableWidgetLib::DATASET_REP_TABULATOR.'")'
|
||||
);
|
||||
}
|
||||
|
||||
// If given the session timeout parameter must be a number
|
||||
if (isset($args[TableWidgetLib::SESSION_TIMEOUT]) && !is_numeric($args[TableWidgetLib::SESSION_TIMEOUT]))
|
||||
{
|
||||
show_error('The parameter "'.TableWidgetLib::SESSION_TIMEOUT.'" must be a number');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains all the logic used to load all the data needed to the TableWidget
|
||||
*/
|
||||
private function _startTableWidget($tableUniqueId)
|
||||
{
|
||||
// Looks for expired table widgets in session and drops them
|
||||
$this->tablewidgetlib->dropExpiredTableWidgets();
|
||||
|
||||
// Read the all session for this table widget
|
||||
$session = $this->tablewidgetlib->getSession();
|
||||
|
||||
// If session is NOT empty -> a table was already loaded
|
||||
if ($session != null)
|
||||
{
|
||||
// Get SESSION_DATASET_RELOAD from the session
|
||||
$sessionReloadDataset = $this->tablewidgetlib->getSessionElement(TableWidgetLib::SESSION_DATASET_RELOAD);
|
||||
|
||||
// if Filter changed or reload is forced by parameter then reload the Dataset
|
||||
if ($this->_reloadDataset === true || $sessionReloadDataset === true)
|
||||
{
|
||||
// Set as false to stop changing the dataset
|
||||
$this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_DATASET_RELOAD, false);
|
||||
|
||||
// Generate dataset query using tables from the session
|
||||
$datasetQuery = $this->tablewidgetlib->generateDatasetQuery($this->_query);
|
||||
|
||||
// Then retrieve dataset from DB
|
||||
$dataset = $this->tablewidgetlib->getDataset($datasetQuery);
|
||||
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow
|
||||
|
||||
// Set the new dataset and its attributes in the session
|
||||
$this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_METADATA, $this->tablewidgetlib->getExecutedQueryMetaData());
|
||||
$this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_ROW_NUMBER, count($dataset->retval));
|
||||
$this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_DATASET, $dataset->retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the session is empty -> first time that this table is loaded
|
||||
if ($session == null)
|
||||
{
|
||||
// Generate dataset query
|
||||
$datasetQuery = $this->tablewidgetlib->generateDatasetQuery($this->_query);
|
||||
|
||||
// Then retrieve dataset from DB
|
||||
$dataset = $this->tablewidgetlib->getDataset($datasetQuery);
|
||||
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow
|
||||
|
||||
// Stores an array that contains all the data useful for
|
||||
$this->tablewidgetlib->setSession(
|
||||
array(
|
||||
TableWidgetLib::TABLE_UNIQUE_ID => $tableUniqueId, // table unique id
|
||||
TableWidgetLib::SESSION_FIELDS => $this->tablewidgetlib->getExecutedQueryListFields(), // all the fields of the dataset
|
||||
TableWidgetLib::SESSION_COLUMNS_ALIASES => $this->_columnsAliases, // all the fields aliases
|
||||
TableWidgetLib::SESSION_ADDITIONAL_COLUMNS => $this->_additionalColumns, // additional columns
|
||||
TableWidgetLib::SESSION_CHECKBOXES => $this->_checkboxes, // the name of the field used to build the checkboxes column
|
||||
TableWidgetLib::SESSION_METADATA => $this->tablewidgetlib->getExecutedQueryMetaData(), // the metadata of the dataset
|
||||
TableWidgetLib::SESSION_ROW_NUMBER => count($dataset->retval), // the number of loaded rows by this table
|
||||
TableWidgetLib::SESSION_DATASET => $dataset->retval, // the entire dataset
|
||||
TableWidgetLib::SESSION_DATASET_RELOAD => false, // if the dataset must be reloaded, not needed the first time
|
||||
TableWidgetLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation
|
||||
TableWidgetLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, // the choosen dataset representation options
|
||||
TableWidgetLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs // the choosen dataset representation record fields definition
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: must the latest operation to be performed in the session to be shure that is always present
|
||||
// To be always stored in the session, otherwise is not possible to load data from Filters controller
|
||||
$this->tablewidgetlib->setSessionElement(TableWidgetLib::REQUIRED_PERMISSIONS, $this->_requiredPermissions);
|
||||
// Renew or set the session expiring time
|
||||
$this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_TIMEOUT, strtotime('+'.$this->_sessionTimeout.' minutes', time()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the method _markRow and _formatRow to marks rows using markRow and format rowns using formatRow
|
||||
* NOTE: this method operates directly on the retrieved dataset: parameter passed by reference
|
||||
*/
|
||||
private function _formatDataset(&$rawDataset)
|
||||
{
|
||||
if (hasData($rawDataset) && is_array($rawDataset->retval))
|
||||
{
|
||||
// For each row of the data set
|
||||
for ($rowCounter = 0; $rowCounter < count($rawDataset->retval); $rowCounter++)
|
||||
{
|
||||
// Calls the methods to mark and to format a row
|
||||
// NOTE: keep this order! the markRow function given as parameter is supposing to work
|
||||
// on a raw dataset, NOT on a formatted one
|
||||
$rawDataset->retval[$rowCounter]->MARK_ROW_CLASS = $this->_markRow($rawDataset->retval[$rowCounter]);
|
||||
$this->_formatRow($rawDataset->retval[$rowCounter]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the columns of all the rows of the entire dataset
|
||||
* - converts booleans into strings "true" and "false"
|
||||
* - format dates using the format string defined in DEFAULT_DATE_FORMAT
|
||||
* Calls the parameter formatRow if it was given and if it is a valid funtion
|
||||
* NOTE: this method operates directly on the retrieved dataset: parameter passed by reference
|
||||
*/
|
||||
private function _formatRow(&$rawDatasetRow)
|
||||
{
|
||||
// For each column of the row
|
||||
foreach ($rawDatasetRow as $columnName => $columnValue)
|
||||
{
|
||||
// Basic conversions
|
||||
if (is_bool($columnValue))
|
||||
{
|
||||
$rawDatasetRow->{$columnName} = ($columnValue === true ? 'true' : 'false');
|
||||
}
|
||||
elseif (DateTime::createFromFormat('Y-m-d H:i:s', $columnValue) !== false)
|
||||
{
|
||||
$rawDatasetRow->{$columnName} = date(self::DEFAULT_DATE_FORMAT, strtotime($columnValue));
|
||||
}
|
||||
}
|
||||
|
||||
// If a valid function call the given formatRow
|
||||
if ($this->_formatRow != null && is_callable($this->_formatRow))
|
||||
{
|
||||
$formatRowFunction = $this->_formatRow;
|
||||
$rawDatasetRow = $formatRowFunction($rawDatasetRow);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that contains a class name used to mark rows in the dataset table
|
||||
* Calls the parameter markRow if it was given and if it is a valid funtion
|
||||
*/
|
||||
private function _markRow($rawDatasetRow)
|
||||
{
|
||||
// If a valid function call the given markRow
|
||||
if ($this->_markRow != null && is_callable($this->_markRow))
|
||||
{
|
||||
$markRowFunction = $this->_markRow;
|
||||
$class = $markRowFunction($rawDatasetRow);
|
||||
}
|
||||
|
||||
return !isset($class) ? '' : $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that retrieves the name of the columns present in a table JSON definition
|
||||
*/
|
||||
private function _getColumnsNames($columns)
|
||||
{
|
||||
$columnsNames = array();
|
||||
|
||||
foreach ($columns as $key => $obj)
|
||||
{
|
||||
if (isset($obj->name))
|
||||
{
|
||||
$columnsNames[] = $obj->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $columnsNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a view using the given viewName and eventually other parameters
|
||||
*/
|
||||
private static function _loadView($viewName, $parameters = null)
|
||||
{
|
||||
$ci =& get_instance();
|
||||
$ci->load->view($viewName, $parameters);
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class DropdownWidget extends HTMLWidget
|
||||
{
|
||||
if (is_object($elements) && isset($elements->retval))
|
||||
{
|
||||
show_error($elements->retval);
|
||||
show_error(getError($elements));
|
||||
}
|
||||
else if (is_string($elements))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user