Completed
Push — develop ( 22119f...118b22 )
by Gennady
16:37
created
future/includes/class-gv-view.php 1 patch
Spacing   +54 added lines, -55 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		$supports = array( 'title', 'revisions' );
126 126
 
127 127
 		if ( $is_hierarchical ) {
128
-			$supports[] = 'page-attributes';
128
+			$supports[ ] = 'page-attributes';
129 129
 		}
130 130
 
131 131
 		/**
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 		$rule = array( sprintf( '%s/([^/]+)/csv/?', $slug ), 'index.php?gravityview=$matches[1]&csv=1', 'top' );
228 228
 
229 229
 		add_filter( 'query_vars', function( $query_vars ) { 
230
-			$query_vars[] = 'csv';
230
+			$query_vars[ ] = 'csv';
231 231
 			return $query_vars;
232 232
 		} );
233 233
 
234
-		if ( ! isset( $wp_rewrite->extra_rules_top[ $rule[0] ] ) ) {
234
+		if ( ! isset( $wp_rewrite->extra_rules_top[ $rule[ 0 ] ] ) ) {
235 235
 			call_user_func_array( 'add_rewrite_rule', $rule );
236 236
 		}
237 237
 	}
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
300 300
 			return $content;
301 301
 		}
302 302
 
303
-		$is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID );
303
+		$is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap( 'gravityview_moderate_entries', $view->ID );
304 304
 
305 305
 		/**
306 306
 		 * Editing a single entry.
307 307
 		 */
308 308
 		if ( $entry = $request->is_edit_entry( $view->form ? $view->form->ID : 0 ) ) {
309
-			if ( $entry['status'] != 'active' ) {
309
+			if ( $entry[ 'status' ] != 'active' ) {
310 310
 				gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $entry->ID ) );
311 311
 				return __( 'You are not allowed to view this content.', 'gravityview' );
312 312
 			}
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 			}
318 318
 
319 319
 			if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) {
320
-				if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) )  ) {
320
+				if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) {
321 321
 					gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $entry->ID ) );
322 322
 					return __( 'You are not allowed to view this content.', 'gravityview' );
323 323
 				}
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 
341 341
 			foreach ( $entryset as $e ) {
342 342
 
343
-				if ( 'active' !== $e['status'] ) {
343
+				if ( 'active' !== $e[ 'status' ] ) {
344 344
 					gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $e->ID ) );
345 345
 					return __( 'You are not allowed to view this content.', 'gravityview' );
346 346
 				}
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 				}
352 352
 
353 353
 				if ( $show_only_approved && ! $is_admin_and_can_view ) {
354
-					if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $e->ID, \GravityView_Entry_Approval::meta_key ) )  ) {
354
+					if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $e->ID, \GravityView_Entry_Approval::meta_key ) ) ) {
355 355
 						gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $e->ID ) );
356 356
 						return __( 'You are not allowed to view this content.', 'gravityview' );
357 357
 					}
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 			$join_column    = is_numeric( $join_column ) ? GF_Field::by_id( $join, $join_column ) : Internal_Field::by_id( $join_column );
527 527
 			$join_on_column = is_numeric( $join_on_column ) ? GF_Field::by_id( $join_on, $join_on_column ) : Internal_Field::by_id( $join_on_column );
528 528
 
529
-			$joins [] = new Join( $join, $join_column, $join_on, $join_on_column );
529
+			$joins [ ] = new Join( $join, $join_column, $join_on, $join_on_column );
530 530
 		}
531 531
 
532 532
 		return $joins;
@@ -621,13 +621,13 @@  discard block
 block discarded – undo
621 621
 			}
622 622
 
623 623
 			foreach ( $_fields as $field ) {
624
-				if ( ! empty( $field['unions'] ) ) {
625
-					foreach ( $field['unions'] as $form_id => $field_id ) {
624
+				if ( ! empty( $field[ 'unions' ] ) ) {
625
+					foreach ( $field[ 'unions' ] as $form_id => $field_id ) {
626 626
 						if ( ! isset( $unions[ $form_id ] ) ) {
627 627
 							$unions[ $form_id ] = array();
628 628
 						}
629 629
 
630
-						$unions[ $form_id ][ $field['id'] ] =
630
+						$unions[ $form_id ][ $field[ 'id' ] ] =
631 631
 							is_numeric( $field_id ) ? \GV\GF_Field::by_id( \GV\GF_Form::by_id( $form_id ), $field_id ) : \GV\Internal_Field::by_id( $field_id );
632 632
 					}
633 633
 				}
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 		if ( ! $view->form ) {
677 677
 			gravityview()->log->error( 'View #{view_id} tried attaching non-existent Form #{form_id} to it.', array(
678 678
 				'view_id' => $view->ID,
679
-				'form_id' => $view->_gravityview_form_id ? : 0,
679
+				'form_id' => $view->_gravityview_form_id ?: 0,
680 680
 			) );
681 681
 		}
682 682
 
@@ -911,43 +911,42 @@  discard block
 block discarded – undo
911 911
 			 * @todo: Stop using _frontend and use something like $request->get_search_criteria() instead
912 912
 			 */
913 913
 			$parameters = \GravityView_frontend::get_view_entries_parameters( $this->settings->as_atts(), $this->form->ID );
914
-			$parameters['context_view_id'] = $this->ID;
914
+			$parameters[ 'context_view_id' ] = $this->ID;
915 915
 			$parameters = \GVCommon::calculate_get_entries_criteria( $parameters, $this->form->ID );
916 916
 
917 917
 			if ( $request instanceof REST\Request ) {
918 918
 				$atts = $this->settings->as_atts();
919 919
 				$paging_parameters = wp_parse_args( $request->get_paging(), array(
920
-						'paging' => array( 'page_size' => $atts['page_size'] ),
920
+						'paging' => array( 'page_size' => $atts[ 'page_size' ] ),
921 921
 					) );
922
-				$parameters['paging'] = $paging_parameters['paging'];
922
+				$parameters[ 'paging' ] = $paging_parameters[ 'paging' ];
923 923
 			}
924 924
 
925
-			$page = Utils::get( $parameters['paging'], 'current_page' ) ?
926
-				: ( ( ( $parameters['paging']['offset'] - $this->settings->get( 'offset' ) ) / $parameters['paging']['page_size'] ) + 1 );
925
+			$page = Utils::get( $parameters[ 'paging' ], 'current_page' ) ?: ( ( ( $parameters[ 'paging' ][ 'offset' ] - $this->settings->get( 'offset' ) ) / $parameters[ 'paging' ][ 'page_size' ] ) + 1 );
927 926
 
928 927
 			/**
929 928
 			 * Cleanup duplicate field_filter parameters to simplify the query.
930 929
 			 */
931 930
 			$unique_field_filters = array();
932
-			foreach ( $parameters['search_criteria']['field_filters'] as $key => $filter ) {
931
+			foreach ( $parameters[ 'search_criteria' ][ 'field_filters' ] as $key => $filter ) {
933 932
 				if ( 'mode' === $key ) {
934
-					$unique_field_filters['mode'] = $filter;
933
+					$unique_field_filters[ 'mode' ] = $filter;
935 934
 				} else if ( ! in_array( $filter, $unique_field_filters ) ) {
936
-					$unique_field_filters[] = $filter;
935
+					$unique_field_filters[ ] = $filter;
937 936
 				}
938 937
 			}
939
-			$parameters['search_criteria']['field_filters'] = $unique_field_filters;
938
+			$parameters[ 'search_criteria' ][ 'field_filters' ] = $unique_field_filters;
940 939
 
941
-			if ( ! empty( $parameters['search_criteria']['field_filters'] ) ) {
940
+			if ( ! empty( $parameters[ 'search_criteria' ][ 'field_filters' ] ) ) {
942 941
 				gravityview()->log->notice( 'search_criteria/field_filters is not empty, third-party code may be using legacy search_criteria filters.' );
943 942
 			}
944 943
 
945 944
 			if ( gravityview()->plugin->supports( Plugin::FEATURE_GFQUERY ) ) {
946 945
 				$query_class = $this->get_query_class();
947
-				$query = new $query_class( $this->form->ID, $parameters['search_criteria'], $parameters['sorting'] );
946
+				$query = new $query_class( $this->form->ID, $parameters[ 'search_criteria' ], $parameters[ 'sorting' ] );
948 947
 
949
-				$query->limit( $parameters['paging']['page_size'] )
950
-					->offset( ( ( $page - 1 ) * $parameters['paging']['page_size'] ) + $this->settings->get( 'offset' ) );
948
+				$query->limit( $parameters[ 'paging' ][ 'page_size' ] )
949
+					->offset( ( ( $page - 1 ) * $parameters[ 'paging' ][ 'page_size' ] ) + $this->settings->get( 'offset' ) );
951 950
 
952 951
 				/**
953 952
 				 * Any joins?
@@ -970,7 +969,7 @@  discard block
 block discarded – undo
970 969
 
971 970
 							$query_parameters = $query->_introspect();
972 971
 
973
-							$query->where( \GF_Query_Condition::_and( $query_parameters['where'], $condition ) );
972
+							$query->where( \GF_Query_Condition::_and( $query_parameters[ 'where' ], $condition ) );
974 973
 						}
975 974
 
976 975
 
@@ -985,7 +984,7 @@  discard block
 block discarded – undo
985 984
 
986 985
 							$query_parameters = $query->_introspect();
987 986
 
988
-							$query->where( \GF_Query_Condition::_and( $query_parameters['where'], $condition ) );
987
+							$query->where( \GF_Query_Condition::_and( $query_parameters[ 'where' ], $condition ) );
989 988
 						}
990 989
 					}
991 990
 				
@@ -1009,7 +1008,7 @@  discard block
 block discarded – undo
1009 1008
 							$conditions = array();
1010 1009
 
1011 1010
 							foreach ( $condition->expressions as $_condition ) {
1012
-								$conditions[] = $recurse( $_condition, $fields, $recurse );
1011
+								$conditions[ ] = $recurse( $_condition, $fields, $recurse );
1013 1012
 							}
1014 1013
 
1015 1014
 							return call_user_func_array(
@@ -1038,10 +1037,10 @@  discard block
 block discarded – undo
1038 1037
 						$q = new $query_class( $form_id );
1039 1038
 
1040 1039
 						// Copy the WHERE clauses but substitute the field_ids to the respective ones
1041
-						$q->where( $where_union_substitute( $query_parameters['where'], $fields, $where_union_substitute ) );
1040
+						$q->where( $where_union_substitute( $query_parameters[ 'where' ], $fields, $where_union_substitute ) );
1042 1041
 
1043 1042
 						// Copy the ORDER clause and substitute the field_ids to the respective ones
1044
-						foreach ( $query_parameters['order'] as $order ) {
1043
+						foreach ( $query_parameters[ 'order' ] as $order ) {
1045 1044
 							list( $column, $_order ) = $order;
1046 1045
 
1047 1046
 							if ( $column && $column instanceof \GF_Query_Column ) {
@@ -1055,15 +1054,15 @@  discard block
 block discarded – undo
1055 1054
 
1056 1055
 						add_filter( 'gform_gf_query_sql', $gf_query_sql_callback = function( $sql ) use ( &$unions_sql ) {
1057 1056
 							// Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses
1058
-							$select = 'UNION ALL ' . str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql['select'] );
1057
+							$select = 'UNION ALL ' . str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql[ 'select' ] );
1059 1058
 
1060 1059
 							// Record the SQL
1061
-							$unions_sql[] = array(
1060
+							$unions_sql[ ] = array(
1062 1061
 								// Remove columns, we'll rebuild them
1063 1062
 								'select'  => preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $select ),
1064
-								'from'    => $sql['from'],
1065
-								'join'    => $sql['join'],
1066
-								'where'   => $sql['where'],
1063
+								'from'    => $sql[ 'from' ],
1064
+								'join'    => $sql[ 'join' ],
1065
+								'where'   => $sql[ 'where' ],
1067 1066
 								// Remove order and limit
1068 1067
 							);
1069 1068
 
@@ -1080,11 +1079,11 @@  discard block
 block discarded – undo
1080 1079
 
1081 1080
 					add_filter( 'gform_gf_query_sql', $gf_query_sql_callback = function( $sql ) use ( $unions_sql ) {
1082 1081
 						// Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses
1083
-						$sql['select'] = str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql['select'] );
1082
+						$sql[ 'select' ] = str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql[ 'select' ] );
1084 1083
 
1085 1084
 						// Remove columns, we'll rebuild them
1086
-						preg_match( '#DISTINCT (`[motc]\d+`.`.*?`)#', $sql['select'], $select_match );
1087
-						$sql['select'] = preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $sql['select'] );
1085
+						preg_match( '#DISTINCT (`[motc]\d+`.`.*?`)#', $sql[ 'select' ], $select_match );
1086
+						$sql[ 'select' ] = preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $sql[ 'select' ] );
1088 1087
 
1089 1088
 						$unions = array();
1090 1089
 
@@ -1095,30 +1094,30 @@  discard block
 block discarded – undo
1095 1094
 						};
1096 1095
 
1097 1096
 						// Add all the order columns into the selects, so we can order by the whole union group
1098
-						preg_match_all( '#(`[motc]\d+`.`.*?`)#', $sql['order'], $order_matches );
1097
+						preg_match_all( '#(`[motc]\d+`.`.*?`)#', $sql[ 'order' ], $order_matches );
1099 1098
 						
1100 1099
 						$columns = array(
1101
-							sprintf( '%s AS %s', $select_match[1], $column_to_alias( $select_match[1] ) )
1100
+							sprintf( '%s AS %s', $select_match[ 1 ], $column_to_alias( $select_match[ 1 ] ) )
1102 1101
 						);
1103 1102
 
1104 1103
 						foreach ( array_slice( $order_matches, 1 ) as $match ) {
1105
-							$columns[] = sprintf( '%s AS %s', $match[0], $column_to_alias( $match[0] ) );
1104
+							$columns[ ] = sprintf( '%s AS %s', $match[ 0 ], $column_to_alias( $match[ 0 ] ) );
1106 1105
 
1107 1106
 							// Rewrite the order columns to the shared aliases
1108
-							$sql['order'] = str_replace( $match[0], $column_to_alias( $match[0] ), $sql['order'] );
1107
+							$sql[ 'order' ] = str_replace( $match[ 0 ], $column_to_alias( $match[ 0 ] ), $sql[ 'order' ] );
1109 1108
 						}
1110 1109
 
1111 1110
 						$columns = array_unique( $columns );
1112 1111
 
1113 1112
 						// Add the columns to every UNION
1114 1113
 						foreach ( $unions_sql as $union_sql ) {
1115
-							$union_sql['select'] .= implode( ', ', $columns );
1116
-							$unions []= implode( ' ', $union_sql );
1114
+							$union_sql[ 'select' ] .= implode( ', ', $columns );
1115
+							$unions [ ] = implode( ' ', $union_sql );
1117 1116
 						}
1118 1117
 
1119 1118
 						// Add the columns to the main SELECT, but only grab the entry id column
1120
-						$sql['select'] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM (' . $sql['select'] . implode( ', ', $columns );
1121
-						$sql['order'] = implode( ' ', $unions ) . ') AS u ' . $sql['order'];
1119
+						$sql[ 'select' ] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM (' . $sql[ 'select' ] . implode( ', ', $columns );
1120
+						$sql[ 'order' ] = implode( ' ', $unions ) . ') AS u ' . $sql[ 'order' ];
1122 1121
 
1123 1122
 						return $sql;
1124 1123
 					} );
@@ -1159,15 +1158,15 @@  discard block
 block discarded – undo
1159 1158
 				} );
1160 1159
 			} else {
1161 1160
 				$entries = $this->form->entries
1162
-					->filter( \GV\GF_Entry_Filter::from_search_criteria( $parameters['search_criteria'] ) )
1161
+					->filter( \GV\GF_Entry_Filter::from_search_criteria( $parameters[ 'search_criteria' ] ) )
1163 1162
 					->offset( $this->settings->get( 'offset' ) )
1164
-					->limit( $parameters['paging']['page_size'] )
1163
+					->limit( $parameters[ 'paging' ][ 'page_size' ] )
1165 1164
 					->page( $page );
1166 1165
 
1167
-				if ( ! empty( $parameters['sorting'] ) && ! empty( $parameters['sorting']['key'] ) ) {
1166
+				if ( ! empty( $parameters[ 'sorting' ] ) && ! empty( $parameters[ 'sorting' ][ 'key' ] ) ) {
1168 1167
 					$field = new \GV\Field();
1169
-					$field->ID = $parameters['sorting']['key'];
1170
-					$direction = strtolower( $parameters['sorting']['direction'] ) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC;
1168
+					$field->ID = $parameters[ 'sorting' ][ 'key' ];
1169
+					$direction = strtolower( $parameters[ 'sorting' ][ 'direction' ] ) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC;
1171 1170
 					$entries = $entries->sort( new \GV\Entry_Sort( $field, $direction ) );
1172 1171
 				}
1173 1172
 			}
@@ -1238,7 +1237,7 @@  discard block
 block discarded – undo
1238 1237
 		$allowed = $headers = array();
1239 1238
 
1240 1239
 		foreach ( $view->fields->by_position( "directory_*" )->by_visible()->all() as $id => $field ) {
1241
-			$allowed[] = $field;
1240
+			$allowed[ ] = $field;
1242 1241
 		}
1243 1242
 
1244 1243
 		$renderer = new Field_Renderer();
@@ -1262,11 +1261,11 @@  discard block
 block discarded – undo
1262 1261
 			foreach ( $allowed as $field ) {
1263 1262
 				$source = is_numeric( $field->ID ) ? $view->form : new \GV\Internal_Source();
1264 1263
 
1265
-				$return[] = $renderer->render( $field, $view, $source, $entry, gravityview()->request, '\GV\Field_CSV_Template' );
1264
+				$return[ ] = $renderer->render( $field, $view, $source, $entry, gravityview()->request, '\GV\Field_CSV_Template' );
1266 1265
 
1267 1266
 				if ( ! $headers_done ) {
1268 1267
 					$label = $field->get_label( $view, $source, $entry );
1269
-					$headers[] = $label ? $label : $field->ID;
1268
+					$headers[ ] = $label ? $label : $field->ID;
1270 1269
 				}
1271 1270
 			}
1272 1271
 
Please login to merge, or discard this patch.