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

@ -5,27 +5,30 @@
*/
function stormproject_list() {
global $user;
$breadcrumb = array();
$breadcrumb[] = l(t('Home'), '<front>');
drupal_set_breadcrumb($breadcrumb);
if (array_key_exists('organization_nid', $_GET)) {
if ($_SESSION['stormproject_list_filter']['organization_nid'] != $_GET['organization_nid']) {
$_SESSION['stormproject_list_filter']['organization_nid'] = $_GET['organization_nid'];
_storm_set_filter_param('project', 'organization_nid', $_GET['organization_nid']);
}
if (array_key_exists('view', $_GET) && $_GET['view'] == 'all') {
$_SESSION['stormproject_list_filter']['projectcategory'] = '-';
$_SESSION['stormproject_list_filter']['projectstatus'] = '-';
$_SESSION['stormproject_list_filter']['projectpriority'] = '-';
_storm_set_filter_param('project', 'projectcategory', '-');
_storm_set_filter_param('project', 'projectstatus', '-');
_storm_set_filter_param('project', 'projectpriority', '-');
unset($_SESSION['stormproject_list_filter']['datebeginfrom']);
unset($_SESSION['stormproject_list_filter']['datebeginto']);
unset($_SESSION['stormproject_list_filter']['dateendfrom']);
unset($_SESSION['stormproject_list_filter']['dateendto']);
unset($_SESSION['stormproject_list_filter']['assigned_to']);
_storm_set_filter_param('project', 'datebeginfrom');
_storm_set_filter_param('project', 'datebeginto');
_storm_set_filter_param('project', 'dateendfrom');
_storm_set_filter_param('project', 'dateendto');
$_SESSION['stormproject_list_filter']['billable'] = '-';
$_SESSION['stormproject_list_filter']['billed'] = '-';
_storm_set_filter_param('project', 'assigned_to');
_storm_set_filter_param('project', 'billable', '-');
_storm_set_filter_param('project', 'billed', '-');
}
}
@ -70,37 +73,35 @@ function stormproject_list() {
),
);
$s = "SELECT n.*, spr.*, nre.format FROM {node} AS n
INNER JOIN {stormproject} AS spr ON n.vid=spr.vid
INNER JOIN {node_revisions} AS nre ON n.vid = nre.vid
WHERE n.status=1 AND n.type='stormproject'";
$where = array();
$args = array();
$filterfields = array();
if (isset($_SESSION['stormproject_list_filter']['organization_nid']) && ($_SESSION['stormproject_list_filter']['organization_nid'] != 0)) {
$s = "SELECT n.*, spr.*, nre.format FROM {node} AS n
INNER JOIN {stormproject} AS spr ON n.vid=spr.vid
INNER JOIN {node_revisions} AS nre ON n.vid = nre.vid
WHERE n.status=1 AND n.type='stormproject'";
if (_storm_isset_filter_param('project', 'organization_nid', 0)) {
$where[] = 'spr.organization_nid=%d';
$args[] = $_SESSION['stormproject_list_filter']['organization_nid'];
$filterfields[] = t('Organization');
}
$category_list = storm_attributes_bydomain('project category search');
$projectcategory = isset($_SESSION['stormproject_list_filter']['projectcategory']) ? $_SESSION['stormproject_list_filter']['projectcategory'] : $category_list['default'];
$_SESSION['stormproject_list_filter']['projectcategory'] = $projectcategory;
if ($projectcategory != '-') {
$where[] = "spr.projectcategory='%s'";
$args[] = $projectcategory;
$category_list = storm_attributes_bydomain('Project category search');
if (_storm_isset_filter_param('project', 'projectcategory', $category_list['default'], '-')) {
$category = split(',', $_SESSION['stormproject_list_filter']['projectcategory']);
$v = array();
foreach ($category as $item) $v[] = '%s';
$where[] = "spr.projectcategory IN ('". implode("','", $v) ."')";
foreach ($category as $key => $value) {
$args[] = $value;
}
$filterfields[] = t('Category');
}
$status_list = storm_attributes_bydomain('project status search');
$projectstatus = isset($_SESSION['stormproject_list_filter']['projectstatus']) ? $_SESSION['stormproject_list_filter']['projectstatus'] : $status_list['default'];
$_SESSION['stormproject_list_filter']['projectstatus'] = $projectstatus;
if ($projectstatus != '-') {
$status = split(',', $projectstatus);
$status_list = storm_attributes_bydomain('Project status search');
if (_storm_isset_filter_param('project', 'projectstatus', $status_list['default'], '-')) {
$status = split(',', $_SESSION['stormproject_list_filter']['projectstatus']);
$v = array();
foreach ($status as $item) $v[] = '%s';
$where[] = "spr.projectstatus IN ('". implode("','", $v) ."')";
@ -109,18 +110,19 @@ function stormproject_list() {
}
$filterfields[] = t('Status');
}
$priority_list = storm_attributes_bydomain('project priority search');
$projectpriority = isset($_SESSION['stormproject_list_filter']['projectpriority']) ? $_SESSION['stormproject_list_filter']['projectpriority'] : $priority_list['default'];
$_SESSION['stormproject_list_filter']['projectpriority'] = $projectpriority;
if ($projectpriority != '-') {
$where[] = "spr.projectpriority='%s'";
$args[] = $projectpriority;
$priority_list = storm_attributes_bydomain('Project priority search');
if (_storm_isset_filter_param('project', 'projectpriority', $priority_list['default'], '-')) {
$priority = split(',', $_SESSION['stormproject_list_filter']['projectpriority']);
$v = array();
foreach ($priority as $item) $v[] = '%s';
$where[] = "spr.projectpriority IN ('". implode("','", $v) ."')";
foreach ($priority as $key => $value) {
$args[] = $value;
}
$filterfields[] = t('Priority');
}
if (isset($_SESSION['stormproject_list_filter']['datebeginfrom'])) {
if (_storm_isset_filter_param('project', 'datebeginfrom')) {
$datebeginfrom = $_SESSION['stormproject_list_filter']['datebeginfrom'];
$datebeginfrom['hour'] = 0;
$datebeginfrom['minute'] = 0;
@ -131,8 +133,7 @@ function stormproject_list() {
$filterfields[] = t('Date');
}
}
if (isset($_SESSION['stormproject_list_filter']['datebeginto'])) {
if (_storm_isset_filter_param('project', 'datebeginto')) {
$datebeginto = $_SESSION['stormproject_list_filter']['datebeginto'];
$datebeginto['hour'] = 23;
$datebeginto['minute'] = 59;
@ -143,8 +144,7 @@ function stormproject_list() {
$filterfields[] = t('Date');
}
}
if (isset($_SESSION['stormproject_list_filter']['dateendfrom'])) {
if (_storm_isset_filter_param('project', 'dateendfrom')) {
$dateendfrom = $_SESSION['stormproject_list_filter']['dateendfrom'];
$dateendfrom['hour'] = 0;
$dateendfrom['minute'] = 0;
@ -155,8 +155,7 @@ function stormproject_list() {
$filterfields[] = t('Date');
}
}
if (isset($_SESSION['stormproject_list_filter']['dateendto'])) {
if (_storm_isset_filter_param('project', 'dateendto')) {
$dateendto = $_SESSION['stormproject_list_filter']['dateendto'];
$dateendto['hour'] = 23;
$dateendto['minute'] = 59;
@ -168,21 +167,25 @@ function stormproject_list() {
}
}
if (isset($_SESSION['stormproject_list_filter']['assigned_to'])) {
if (_storm_isset_filter_param('project', 'assigned_to')) {
if (!is_numeric($_SESSION['stormproject_list_filter']['assigned_to'])) {
switch ($_SESSION['stormproject_list_filter']['assigned_to']) {
case 'all':
// NO FILTER
break;
case 'mine':
// CURRENT USER
if (!empty($user->stormperson_nid) && is_numeric($user->stormperson_nid)) {
$assigned_to_nid = $user->stormperson_nid;
}
break;
case 'none':
$where[] = '(spr.assigned_nid IS NULL OR spr.assigned_nid = 0) ';
break;
}
}
else {
@ -195,19 +198,18 @@ function stormproject_list() {
}
}
if (isset($_SESSION['stormproject_list_filter']['billable']) && $_SESSION['stormproject_list_filter']['billable'] != '-') {
if (_storm_isset_filter_param('project', 'billable', '-')) {
$where[] = 'spr.billable=%d';
$args[] = $_SESSION['stormproject_list_filter']['billable'];
$filterfields[] = t('Billable');
}
if (isset($_SESSION['stormproject_list_filter']['billed']) && $_SESSION['stormproject_list_filter']['billed'] != '-') {
if (_storm_isset_filter_param('project', 'billed', '-')) {
$where[] = 'spr.billed=%d';
$args[] = $_SESSION['stormproject_list_filter']['billed'];
$filterfields[] = t('Billed');
}
$itemsperpage = isset($_SESSION['stormproject_list_filter']['itemsperpage']) ? $_SESSION['stormproject_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
$itemsperpage = _storm_get_filter_param('project', 'itemsperpage', variable_get('storm_default_items_per_page', 10));
if (count($filterfields) == 0) {
$filterdesc = t('Not filtered');
@ -236,26 +238,29 @@ function stormproject_list() {
}
function stormproject_list_filter(&$form_state, $filterdesc = 'Filter') {
$organization_nid = isset($_SESSION['stormproject_list_filter']['organization_nid']) ? $_SESSION['stormproject_list_filter']['organization_nid'] : 0;
$organization_nid = _storm_get_filter_param('project', 'organization_nid', 0);
$category_list = storm_attributes_bydomain('project category search');
$projectcategory = isset($_SESSION['stormproject_list_filter']['projectcategory']) ? $_SESSION['stormproject_list_filter']['projectcategory'] : $category_list['default'];
$category_list = storm_attributes_bydomain('Project category search');
$projectcategory = _storm_get_filter_param('project', 'projectcategory', $category_list['default']);
$status_list = storm_attributes_bydomain('project status search');
$projectstatus = isset($_SESSION['stormproject_list_filter']['projectstatus']) ? $_SESSION['stormproject_list_filter']['projectstatus'] : $status_list['default'];
$status_list = storm_attributes_bydomain('Project status search');
$projectstatus = _storm_get_filter_param('project', 'projectstatus', $status_list['default']);
$priority_list = storm_attributes_bydomain('project priority search');
$projectpriority = isset($_SESSION['stormproject_list_filter']['projectpriority']) ? $_SESSION['stormproject_list_filter']['projectpriority'] : $priority_list['default'];
$priority_list = storm_attributes_bydomain('Project priority search');
$projectpriority = _storm_get_filter_param('project', 'projectpriority', $priority_list['default']);
$datebeginfrom = isset($_SESSION['stormproject_list_filter']['datebeginfrom']) ? $_SESSION['stormproject_list_filter']['datebeginfrom'] : NULL;
$datebeginto = isset($_SESSION['stormproject_list_filter']['datebeginto']) ? $_SESSION['stormproject_list_filter']['datebeginto'] : NULL;
$dateendfrom = isset($_SESSION['stormproject_list_filter']['dateendfrom']) ? $_SESSION['stormproject_list_filter']['dateendfrom'] : NULL;
$dateendto = isset($_SESSION['stormproject_list_filter']['dateendto']) ? $_SESSION['stormproject_list_filter']['dateendto'] : NULL;
$datebeginfrom = _storm_get_filter_param('project', 'datebeginfrom');
$datebeginto = _storm_get_filter_param('project', 'datebeginto');
$dateendfrom = _storm_get_filter_param('project', 'dateendfrom');
$dateendto = _storm_get_filter_param('project', 'dateendto');
$assigned_to = isset($_SESSION['stormproject_list_filter']['assigned_to']) ? $_SESSION['stormproject_list_filter']['assigned_to'] : NULL;
$assigned_to = _storm_get_filter_param('project', 'assigned_to');
$billable = _storm_get_filter_param('project', 'billable', '-');
$billed = _storm_get_filter_param('project', 'billed', '-');
$itemsperpage = _storm_get_filter_param('project', 'itemsperpage', variable_get('storm_default_items_per_page', 10));
$itemsperpage = isset($_SESSION['stormproject_list_filter']['itemsperpage']) ? $_SESSION['stormproject_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
$_SESSION['stormproject_list_filter']['itemsperpage'] = $itemsperpage;
$form = array();
@ -275,11 +280,12 @@ function stormproject_list_filter(&$form_state, $filterdesc = 'Filter') {
while ($organization = db_fetch_object($r)) {
$organizations[$organization->nid] = $organization->title;
}
$organizations = array(0 => t('All')) + $organizations;
$form['filter']['organization_nid'] = array(
'#type' => 'select',
'#title' => t('Organization'),
'#default_value' => $organization_nid,
'#options' => array(0 => t('All')) + $organizations,
'#options' => $organizations,
);
$form['filter']['group1'] = array(
@ -364,14 +370,14 @@ function stormproject_list_filter(&$form_state, $filterdesc = 'Filter') {
'#type' => 'select',
'#title' => t('Billable'),
'#options' => array('-' => t('all'), '1' => t('billable'), '0' => t('not billable')),
'#default_value' => isset($_SESSION['stormproject_list_filter']['billable']) ? $_SESSION['stormproject_list_filter']['billable'] : '-',
'#default_value' => $billable,
);
$form['filter']['group4']['billed'] = array(
'#type' => 'select',
'#title' => t('Billed'),
'#options' => array('-' => t('all'), '1' => t('billed'), '0' => t('not billed')),
'#default_value' => isset($_SESSION['stormproject_list_filter']['billed']) ? $_SESSION['stormproject_list_filter']['billed'] : '-',
'#default_value' => $billed,
);
$form['filter']['group5'] = array(