mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
Now is possible to have more than one FilterWidget in a single page
This commit is contained in:
@@ -12,7 +12,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
*/
|
||||
class Filters extends FHC_Controller
|
||||
{
|
||||
const FILTER_PAGE_PARAM = 'filter_page';
|
||||
const FILTER_UNIQUE_ID = 'filterUniqueId';
|
||||
|
||||
/**
|
||||
* Calls the parent's constructor and loads the FilterWidgetLib
|
||||
@@ -231,31 +231,33 @@ class Filters extends FHC_Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the FilterWidgetLib with the FILTER_PAGE_PARAM parameter
|
||||
* If the parameter FILTER_PAGE_PARAM is not given then the execution of the controller is terminated and
|
||||
* Loads the FilterWidgetLib with the FILTER_UNIQUE_ID parameter
|
||||
* If the parameter FILTER_UNIQUE_ID is not given then the execution of the controller is terminated and
|
||||
* an error message is printed
|
||||
*/
|
||||
private function _loadFilterWidgetLib()
|
||||
{
|
||||
// If the parameter FILTER_PAGE_PARAM is present in the HTTP GET or POST
|
||||
if (isset($_GET[self::FILTER_PAGE_PARAM]) || isset($_POST[self::FILTER_PAGE_PARAM]))
|
||||
// If the parameter FILTER_UNIQUE_ID is present in the HTTP GET or POST
|
||||
if (isset($_GET[self::FILTER_UNIQUE_ID]) || isset($_POST[self::FILTER_UNIQUE_ID]))
|
||||
{
|
||||
// If it is present in the HTTP GET
|
||||
if (isset($_GET[self::FILTER_PAGE_PARAM]))
|
||||
if (isset($_GET[self::FILTER_UNIQUE_ID]))
|
||||
{
|
||||
$filterPage = $this->input->get(self::FILTER_PAGE_PARAM); // is retrieved from the HTTP GET
|
||||
$filterUniqueId = $this->input->get(self::FILTER_UNIQUE_ID); // is retrieved from the HTTP GET
|
||||
}
|
||||
elseif (isset($_POST[self::FILTER_PAGE_PARAM])) // Else if it is present in the HTTP POST
|
||||
elseif (isset($_POST[self::FILTER_UNIQUE_ID])) // Else if it is present in the HTTP POST
|
||||
{
|
||||
$filterPage = $this->input->post(self::FILTER_PAGE_PARAM); // is retrieved from the HTTP POST
|
||||
$filterUniqueId = $this->input->post(self::FILTER_UNIQUE_ID); // is retrieved from the HTTP POST
|
||||
}
|
||||
|
||||
// Loads the FilterWidgetLib that contains all the used logic
|
||||
$this->load->library('FilterWidgetLib', array(self::FILTER_PAGE_PARAM => $filterPage));
|
||||
$this->load->library('FilterWidgetLib');
|
||||
|
||||
$this->filterwidgetlib->setFilterUniqueId($filterUniqueId);
|
||||
}
|
||||
else // Otherwise an error will be written in the output
|
||||
{
|
||||
$this->terminateWithJsonError('Parameter "'.self::FILTER_PAGE_PARAM.'" not provided!');
|
||||
$this->terminateWithJsonError('Parameter "'.self::FILTER_UNIQUE_ID.'" not provided!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class FilterWidgetLib
|
||||
|
||||
const FILTER_PHRASES_CATEGORY = 'FilterWidget'; // The category used to store phrases for the FilterWidget
|
||||
|
||||
const FILTER_PAGE_PARAM = 'filter_page'; // Filter page parameter name
|
||||
const FILTER_UNIQUE_ID = 'filterUniqueId'; // Filter page parameter name
|
||||
|
||||
const PERMISSION_FILTER_METHOD = 'FilterWidget'; // Name for fake method to be checked by the PermissionLib
|
||||
const PERMISSION_TYPE = 'rw';
|
||||
@@ -113,8 +113,6 @@ class FilterWidgetLib
|
||||
public function __construct($params = null)
|
||||
{
|
||||
$this->_ci =& get_instance(); // get code igniter instance
|
||||
|
||||
$this->_filterUniqueId = $this->_getFilterUniqueId($params); // sets the id for the related filter widget
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
@@ -782,14 +780,14 @@ class FilterWidgetLib
|
||||
* NOTE: The default value is the URI where the FilterWidget is called
|
||||
* If the fhc_controller_id is present then is also used
|
||||
*/
|
||||
private function _getFilterUniqueId($params)
|
||||
public function setFilterUniqueIdByParams($params)
|
||||
{
|
||||
if ($params != null
|
||||
&& is_array($params)
|
||||
&& isset($params[self::FILTER_PAGE_PARAM])
|
||||
&& !isEmptyString($params[self::FILTER_PAGE_PARAM]))
|
||||
&& isset($params[self::FILTER_UNIQUE_ID])
|
||||
&& !isEmptyString($params[self::FILTER_UNIQUE_ID]))
|
||||
{
|
||||
$filterUniqueId = $params[self::FILTER_PAGE_PARAM];
|
||||
$filterUniqueId = $params[self::FILTER_UNIQUE_ID];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -797,6 +795,21 @@ class FilterWidgetLib
|
||||
$filterUniqueId = $this->_ci->router->directory.$this->_ci->router->class.'/'.$this->_ci->router->method;
|
||||
}
|
||||
|
||||
if ($params != null
|
||||
&& is_array($params)
|
||||
&& (isset($params[self::APP_PARAMETER]) || isset($params[self::DATASET_NAME_PARAMETER]) || isset($params[self::FILTER_ID])))
|
||||
{
|
||||
$app = '';
|
||||
$dataset = '';
|
||||
$filterid = '';
|
||||
|
||||
if (isset($params[self::APP_PARAMETER])) $app = $params[self::APP_PARAMETER];
|
||||
if (isset($params[self::DATASET_NAME_PARAMETER])) $dataset = $params[self::DATASET_NAME_PARAMETER];
|
||||
if (isset($params[self::FILTER_ID])) $filterid = $params[self::FILTER_ID];
|
||||
|
||||
$filterUniqueId .= '/'.$app.':'.$dataset.':'.$filterid;
|
||||
}
|
||||
|
||||
// If the FHC_CONTROLLER_ID parameter is present in the HTTP GET
|
||||
if (isset($_GET[self::FHC_CONTROLLER_ID]))
|
||||
{
|
||||
@@ -807,7 +820,25 @@ class FilterWidgetLib
|
||||
$filterUniqueId .= '/'.$this->_ci->input->post(self::FHC_CONTROLLER_ID); // then use it
|
||||
}
|
||||
|
||||
return $filterUniqueId;
|
||||
$this->_filterUniqueId = $filterUniqueId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setFilterUniqueId($filterUniqueId)
|
||||
{
|
||||
// If the FHC_CONTROLLER_ID parameter is present in the HTTP GET
|
||||
if (isset($_GET[self::FHC_CONTROLLER_ID]))
|
||||
{
|
||||
$filterUniqueId .= '/'.$this->_ci->input->get(self::FHC_CONTROLLER_ID); // then use it
|
||||
}
|
||||
elseif (isset($_POST[self::FHC_CONTROLLER_ID])) // else if the FHC_CONTROLLER_ID parameter is present in the HTTP POST
|
||||
{
|
||||
$filterUniqueId .= '/'.$this->_ci->input->post(self::FHC_CONTROLLER_ID); // then use it
|
||||
}
|
||||
|
||||
$this->_filterUniqueId = $filterUniqueId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="row" id="divFilterWidgetDataset" app="<?php echo $app; ?>" dataset="<?php echo $dataset; ?>" filterid="<?php echo $filterid; ?>">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<!-- Filter name -->
|
||||
@@ -12,7 +13,7 @@
|
||||
<div id="datasetActionsTop"></div>
|
||||
|
||||
<!-- Filter table -->
|
||||
<div id="divFilterWidgetDataset" app="<?php echo $app; ?>" dataset="<?php echo $dataset; ?>" filterid="<?php echo $filterid; ?>">
|
||||
<div>
|
||||
<?php FilterWidget::loadViewDataset(); ?>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -72,6 +72,8 @@ class FilterWidget extends Widget
|
||||
|
||||
$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->filterwidgetlib->isAllowed($this->_requiredPermissions))
|
||||
|
||||
Reference in New Issue
Block a user