New way to initialize and modify filter parameters

This commit is contained in:
Manuel Cillero 2017-09-18 03:00:12 +02:00
parent ce5f89b38f
commit 6b9f1ad9d5
14 changed files with 541 additions and 526 deletions

View file

@ -11,7 +11,7 @@ function stormorganization_list() {
if (array_key_exists('name', $_GET)) {
if ($_SESSION['stormorganization_list_filter']['name'] != $_GET['name']) {
$_SESSION['stormorganization_list_filter']['name'] = $_GET['name'];
_storm_set_filter_param('organization', 'name', $_GET['name']);
}
}
@ -35,63 +35,56 @@ function stormorganization_list() {
),
);
$where = array();
$args = array();
$filterfields = array();
$s = "SELECT n.*, sor.*, nre.format FROM {node} AS n
INNER JOIN {stormorganization} AS sor ON n.vid=sor.vid
INNER JOIN {node_revisions} AS nre ON n.vid = nre.vid
WHERE n.status=1 AND n.type='stormorganization'";
$where = array();
$args = array();
$filterfields = array();
$country = isset($_SESSION['stormorganization_list_filter']['country']) ? $_SESSION['stormorganization_list_filter']['country'] : '-';
if ($country != '-') {
if (_storm_isset_filter_param('organization', 'country', '-')) {
$where[] = "sor.country='%s'";
$args[] = $_SESSION['stormorganization_list_filter']['country'];
$filterfields[] = t('Country');
}
if (isset($_SESSION['stormorganization_list_filter']['name']) && $_SESSION['stormorganization_list_filter']['name'] != '') {
if (_storm_isset_filter_param('organization', 'name', '')) {
$where[] = "LOWER(n.title) LIKE LOWER('%s')";
$args[] = $_SESSION['stormorganization_list_filter']['name'];
$filterfields[] = t('Name');
}
$iscustomer = isset($_SESSION['stormorganization_list_filter']['iscustomer']) ? $_SESSION['stormorganization_list_filter']['iscustomer'] : '-';
if ($iscustomer != '-') {
if ($iscustomer == 'yes') {
if (_storm_isset_filter_param('organization', 'iscustomer', NULL, '-')) {
if ($_SESSION['stormorganization_list_filter']['iscustomer'] == 'yes') {
$where[] = "sor.iscustomer=1";
}
elseif ($iscustomer == 'no') {
elseif ($_SESSION['stormorganization_list_filter']['iscustomer'] == 'no') {
$where[] = "sor.iscustomer=0";
}
$filterfields[] = t('Customer');
}
$isprovider = isset($_SESSION['stormorganization_list_filter']['isprovider']) ? $_SESSION['stormorganization_list_filter']['isprovider'] : '-';
if ($isprovider != '-') {
if ($isprovider == 'yes') {
if (_storm_isset_filter_param('organization', 'isprovider', NULL, '-')) {
if ($_SESSION['stormorganization_list_filter']['isprovider'] == 'yes') {
$where[] = "sor.isprovider=1";
}
elseif ($isprovider == 'no') {
elseif ($_SESSION['stormorganization_list_filter']['isprovider'] == 'no') {
$where[] = "sor.isprovider=0";
}
$filterfields[] = t('Provider');
}
$isactive = isset($_SESSION['stormorganization_list_filter']['isactive']) ? $_SESSION['stormorganization_list_filter']['isactive'] : '-';
if ($isactive != '-') {
if ($isactive == 'yes') {
if (_storm_isset_filter_param('organization', 'isactive', 'yes', '-')) {
if ($_SESSION['stormorganization_list_filter']['isactive'] == 'yes') {
$where[] = "sor.isactive=1";
}
elseif ($isactive == 'no') {
elseif ($_SESSION['stormorganization_list_filter']['isactive'] == 'no') {
$where[] = "sor.isactive=0";
}
$filterfields[] = t('Active');
}
// Sets value for fieldset label, does not affect filter itself.
$itemsperpage = isset($_SESSION['stormorganization_list_filter']['itemsperpage']) ? $_SESSION['stormorganization_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
$itemsperpage = _storm_get_filter_param('organization', 'itemsperpage', variable_get('storm_default_items_per_page', 10));
if (count($filterfields) == 0) {
$filterdesc = t('Not filtered');
@ -120,18 +113,16 @@ function stormorganization_list() {
function stormorganization_list_filter(&$form_state, $filterdesc = 'Filter') {
$country_list = storm_attributes_bydomain('Country');
$country = isset($_SESSION['stormorganization_list_filter']['country']) ? $_SESSION['stormorganization_list_filter']['country'] : '-';
$_SESSION['stormorganization_list_filter']['country'] = $country;
$country = _storm_get_filter_param('organization', 'country', '-');
$name = isset($_SESSION['stormorganization_list_filter']['name']) ? $_SESSION['stormorganization_list_filter']['name'] : '';
$iscustomer = isset($_SESSION['stormorganization_list_filter']['iscustomer']) ? $_SESSION['stormorganization_list_filter']['iscustomer'] : NULL;
$isprovider = isset($_SESSION['stormorganization_list_filter']['isprovider']) ? $_SESSION['stormorganization_list_filter']['isprovider'] : NULL;
$name = _storm_get_filter_param('organization', 'name', '');
$isactive = isset($_SESSION['stormorganization_list_filter']['isactive']) ? $_SESSION['stormorganization_list_filter']['isactive'] : 'yes';
$_SESSION['stormorganization_list_filter']['isactive'] = $isactive;
$iscustomer = _storm_get_filter_param('organization', 'iscustomer');
$isprovider = _storm_get_filter_param('organization', 'isprovider');
$isactive = _storm_get_filter_param('organization', 'isactive', 'yes');
$itemsperpage = _storm_get_filter_param('organization', 'itemsperpage', variable_get('storm_default_items_per_page', 10));
$itemsperpage = isset($_SESSION['stormorganization_list_filter']['itemsperpage']) ? $_SESSION['stormorganization_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
$_SESSION['stormorganization_list_filter']['itemsperpage'] = $itemsperpage;
$form = array();