@@ -457,10 +457,12 @@ function filter_offset( $p_page_number, $p_per_page ) {
457
457
* Make sure that our filters are entirely correct and complete (it is possible that they are not).
458
458
* We need to do this to cover cases where we don't have complete control over the filters given.s
459
459
* @param array $p_filter_arr
460
+ * @param int $p_user_id Optional user id to verify current filter against (normally current user)
461
+ * @param int $p_project_id Optional project id to verify current filter against (normally current project)
460
462
* @return mixed
461
463
* @todo function needs to be abstracted
462
464
*/
463
- function filter_ensure_valid_filter ( $ p_filter_arr ) {
465
+ function filter_ensure_valid_filter ( $ p_filter_arr, $ p_user_id = null , $ p_project_id = null ) {
464
466
# extend current filter to add information passed via POST
465
467
if ( !isset ( $ p_filter_arr ['_version ' ] ) ) {
466
468
$ p_filter_arr ['_version ' ] = config_get_global ( 'cookie_version ' );
@@ -474,45 +476,32 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
474
476
$ p_filter_arr ['_view_type ' ] = gpc_get_string ( 'view_type ' , 'simple ' );
475
477
}
476
478
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_ISSUES_PER_PAGE ] ) ) {
477
- $ p_filter_arr [FILTER_PROPERTY_ISSUES_PER_PAGE ] = gpc_get_int ( FILTER_PROPERTY_ISSUES_PER_PAGE , config_get ( 'default_limit_view ' ) );
479
+ $ p_filter_arr [FILTER_PROPERTY_ISSUES_PER_PAGE ] = gpc_get_int ( FILTER_PROPERTY_ISSUES_PER_PAGE , config_get ( 'default_limit_view ' , null , $ p_user_id , $ p_project_id ) );
478
480
}
479
481
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_HIGHLIGHT_CHANGED ] ) ) {
480
- $ p_filter_arr [FILTER_PROPERTY_HIGHLIGHT_CHANGED ] = config_get ( 'default_show_changed ' );
482
+ $ p_filter_arr [FILTER_PROPERTY_HIGHLIGHT_CHANGED ] = config_get ( 'default_show_changed ' , null , $ p_user_id , $ p_project_id );
481
483
}
482
484
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_STICKY ] ) ) {
483
- $ p_filter_arr [FILTER_PROPERTY_STICKY ] = gpc_string_to_bool ( config_get ( 'show_sticky_issues ' ) );
485
+ $ p_filter_arr [FILTER_PROPERTY_STICKY ] = gpc_string_to_bool ( config_get ( 'show_sticky_issues ' , null , $ p_user_id , $ p_project_id ) );
484
486
}
485
487
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_SORT_FIELD_NAME ] ) ) {
486
488
$ p_filter_arr [FILTER_PROPERTY_SORT_FIELD_NAME ] = "last_updated " ;
487
489
}
488
490
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_SORT_DIRECTION ] ) ) {
489
491
$ p_filter_arr [FILTER_PROPERTY_SORT_DIRECTION ] = "DESC " ;
490
492
}
491
-
492
493
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_PLATFORM ] ) ) {
493
- $ p_filter_arr [FILTER_PROPERTY_PLATFORM ] = array (
494
- 0 => META_FILTER_ANY ,
495
- );
494
+ $ p_filter_arr [FILTER_PROPERTY_PLATFORM ] = array ( 0 => META_FILTER_ANY , );
496
495
}
497
-
498
496
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_OS ] ) ) {
499
- $ p_filter_arr [FILTER_PROPERTY_OS ] = array (
500
- 0 => META_FILTER_ANY ,
501
- );
497
+ $ p_filter_arr [FILTER_PROPERTY_OS ] = array ( 0 => META_FILTER_ANY , );
502
498
}
503
-
504
499
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_OS_BUILD ] ) ) {
505
- $ p_filter_arr [FILTER_PROPERTY_OS_BUILD ] = array (
506
- 0 => META_FILTER_ANY ,
507
- );
500
+ $ p_filter_arr [FILTER_PROPERTY_OS_BUILD ] = array ( 0 => META_FILTER_ANY , );
508
501
}
509
-
510
502
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_PROJECT_ID ] ) ) {
511
- $ p_filter_arr [FILTER_PROPERTY_PROJECT_ID ] = array (
512
- 0 => META_FILTER_CURRENT ,
513
- );
503
+ $ p_filter_arr [FILTER_PROPERTY_PROJECT_ID ] = array ( 0 => META_FILTER_CURRENT , );
514
504
}
515
-
516
505
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_START_MONTH ] ) ) {
517
506
$ p_filter_arr [FILTER_PROPERTY_START_MONTH ] = gpc_get_string ( FILTER_PROPERTY_START_MONTH , date ( 'm ' ) );
518
507
}
@@ -612,7 +601,7 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
612
601
}
613
602
614
603
# validate sorting
615
- $ t_fields = helper_get_columns_to_view ();
604
+ $ t_fields = helper_get_columns_to_view ( COLUMNS_TARGET_VIEW_PAGE , true , $ p_user_id , $ p_project_id );
616
605
$ t_n_fields = count ( $ t_fields );
617
606
for ( $ i = 0 ;$ i < $ t_n_fields ;$ i ++ ) {
618
607
if ( isset ( $ t_fields [$ i ] ) && in_array ( $ t_fields [$ i ], array ( 'selection ' , 'edit ' , 'attachment ' ) ) ) {
@@ -673,23 +662,17 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
673
662
if ( !isset ( $ p_filter_arr [$ t_multi_field_name ] ) ) {
674
663
if ( FILTER_PROPERTY_HIDE_STATUS == $ t_multi_field_name ) {
675
664
$ p_filter_arr [$ t_multi_field_name ] = array (
676
- config_get ( 'hide_status_default ' ),
665
+ config_get ( 'hide_status_default ' , null , $ p_user_id , $ p_project_id ),
677
666
);
678
667
}
679
668
else if ( 'custom_fields ' == $ t_multi_field_name ) {
680
- $ p_filter_arr [$ t_multi_field_name ] = array (
681
- $ f_custom_fields_data ,
682
- );
669
+ $ p_filter_arr [$ t_multi_field_name ] = array ( $ f_custom_fields_data , );
683
670
} else {
684
- $ p_filter_arr [$ t_multi_field_name ] = array (
685
- META_FILTER_ANY ,
686
- );
671
+ $ p_filter_arr [$ t_multi_field_name ] = array ( META_FILTER_ANY , );
687
672
}
688
673
} else {
689
674
if ( !is_array ( $ p_filter_arr [$ t_multi_field_name ] ) ) {
690
- $ p_filter_arr [$ t_multi_field_name ] = array (
691
- $ p_filter_arr [$ t_multi_field_name ],
692
- );
675
+ $ p_filter_arr [$ t_multi_field_name ] = array ( $ p_filter_arr [$ t_multi_field_name ], );
693
676
}
694
677
$ t_checked_array = array ();
695
678
foreach ( $ p_filter_arr [$ t_multi_field_name ] as $ t_filter_value ) {
@@ -754,40 +737,18 @@ function filter_get_default() {
754
737
$ t_default_show_changed = config_get ( 'default_show_changed ' );
755
738
756
739
$ t_filter = array (
757
- FILTER_PROPERTY_CATEGORY_ID => array (
758
- '0 ' => META_FILTER_ANY ,
759
- ),
760
- FILTER_PROPERTY_SEVERITY => array (
761
- '0 ' => META_FILTER_ANY ,
762
- ),
763
- FILTER_PROPERTY_STATUS => array (
764
- '0 ' => META_FILTER_ANY ,
765
- ),
740
+ FILTER_PROPERTY_CATEGORY_ID => array ( '0 ' => META_FILTER_ANY , ),
741
+ FILTER_PROPERTY_SEVERITY => array ( '0 ' => META_FILTER_ANY , ),
742
+ FILTER_PROPERTY_STATUS => array ( '0 ' => META_FILTER_ANY , ),
766
743
FILTER_PROPERTY_HIGHLIGHT_CHANGED => $ t_default_show_changed ,
767
- FILTER_PROPERTY_REPORTER_ID => array (
768
- '0 ' => META_FILTER_ANY ,
769
- ),
770
- FILTER_PROPERTY_HANDLER_ID => array (
771
- '0 ' => META_FILTER_ANY ,
772
- ),
773
- FILTER_PROPERTY_PROJECT_ID => array (
774
- '0 ' => META_FILTER_CURRENT ,
775
- ),
776
- FILTER_PROPERTY_RESOLUTION => array (
777
- '0 ' => META_FILTER_ANY ,
778
- ),
779
- FILTER_PROPERTY_BUILD => array (
780
- '0 ' => META_FILTER_ANY ,
781
- ),
782
- FILTER_PROPERTY_VERSION => array (
783
- '0 ' => META_FILTER_ANY ,
784
- ),
785
- FILTER_PROPERTY_HIDE_STATUS => array (
786
- '0 ' => $ t_hide_status_default ,
787
- ),
788
- FILTER_PROPERTY_MONITOR_USER_ID => array (
789
- '0 ' => META_FILTER_ANY ,
790
- ),
744
+ FILTER_PROPERTY_REPORTER_ID => array ( '0 ' => META_FILTER_ANY , ),
745
+ FILTER_PROPERTY_HANDLER_ID => array ( '0 ' => META_FILTER_ANY , ),
746
+ FILTER_PROPERTY_PROJECT_ID => array ( '0 ' => META_FILTER_CURRENT , ),
747
+ FILTER_PROPERTY_RESOLUTION => array ( '0 ' => META_FILTER_ANY , ),
748
+ FILTER_PROPERTY_BUILD => array ( '0 ' => META_FILTER_ANY , ),
749
+ FILTER_PROPERTY_VERSION => array ( '0 ' => META_FILTER_ANY , ),
750
+ FILTER_PROPERTY_HIDE_STATUS => array ( '0 ' => $ t_hide_status_default , ),
751
+ FILTER_PROPERTY_MONITOR_USER_ID => array ( '0 ' => META_FILTER_ANY , ),
791
752
FILTER_PROPERTY_SORT_FIELD_NAME => 'last_updated ' ,
792
753
FILTER_PROPERTY_SORT_DIRECTION => 'DESC ' ,
793
754
FILTER_PROPERTY_ISSUES_PER_PAGE => config_get ( 'default_limit_view ' ),
@@ -799,10 +760,12 @@ function filter_get_default() {
799
760
/**
800
761
* De-serialize filter string
801
762
* @param string $p_serialized_filter serialized filter
763
+ * @param int $p_user_id user id
764
+ * @param int $p_project_id project id
802
765
* @return mixed filter array
803
766
* @see filter_ensure_valid_filter
804
767
*/
805
- function filter_deserialize ( $ p_serialized_filter ) {
768
+ function filter_deserialize ( $ p_serialized_filter, $ p_user_id = null , $ p_project_id = null ) {
806
769
if ( is_blank ( $ p_serialized_filter ) ) {
807
770
return false ;
808
771
}
@@ -826,7 +789,7 @@ function filter_deserialize( $p_serialized_filter ) {
826
789
if ( $ t_filter_array ['_version ' ] != config_get_global ( 'cookie_version ' ) ) {
827
790
828
791
# if the version is not new enough, update it using defaults
829
- return filter_ensure_valid_filter ( $ t_filter_array );
792
+ return filter_ensure_valid_filter ( $ t_filter_array, $ p_user_id , $ p_project_id );
830
793
}
831
794
832
795
return $ t_filter_array ;
1 commit comments
atrol commentedon Apr 8, 2013
For a better performance you might consider calling the changed functions with parameters whenever the needed values are already available.
e.g. instead of calling columns_get_all() in config_columns_set.php call columns_get_all( $t_project_id, $t_user_id );
This will avoid double calls of helper_get_current_project() and auth_get_current_user_id().
If there remain only calls with all parameters, the === null stuff can be removed.