-
Notifications
You must be signed in to change notification settings - Fork 65
#2498 - Metrics - Personal Layers Map #2542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
fb97a60
805aee9
1debcc0
0a95051
7488015
85d1b03
1fdfafd
64c397d
51ffd8a
be8905f
9fd2f94
1cacd6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1301,34 +1301,72 @@ public static function post_type_geojson( $post_type, $args = [], $offset = 0, $ | |
global $wpdb; | ||
|
||
//phpcs:disable | ||
// Determine if post id filtering should take place. | ||
$post_id_filter_sql = ''; | ||
$shared_user_join_sql = ''; | ||
$shared_user_condition_sql = ''; | ||
if ( isset( $args['list_all'], $args['list_all_by_user_id'] ) && !$args['list_all'] ) { | ||
$post_id_filter_sql = $wpdb->prepare( " | ||
SELECT * FROM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this outer layer is needed |
||
( | ||
SELECT api_p.ID | ||
FROM $wpdb->posts api_p | ||
LEFT JOIN $wpdb->postmeta as field_type ON ( field_type.post_id = api_p.ID AND field_type.meta_key = 'type' ) | ||
WHERE (field_type.meta_value = 'access' OR field_type.meta_value = 'user' OR field_type.meta_value = 'access_placeholder') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This keeps groups from showing. |
||
AND (api_p.post_status = 'publish') | ||
AND api_p.post_type = %s | ||
GROUP BY api_p.ID | ||
LIMIT 0, 50000 | ||
) AS assigned_post_ids | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused at this whole section. It says assigned_post_ids, but no sql to to with assignment? |
||
", ( ( $post_type === 'system-users' ) ? 'contacts' : $post_type ) ); | ||
|
||
if ( isset( $args['field_type'] ) && $args['field_type'] == 'user_select' ) { | ||
$shared_user_join_sql = "LEFT JOIN $wpdb->dt_share as field_shared_with ON ( field_shared_with.post_id = um.meta_value )"; | ||
$post_id_filter_sql = 'AND (um.meta_value IN ('. $post_id_filter_sql .'))'; | ||
} else { | ||
$shared_user_join_sql = "LEFT JOIN $wpdb->dt_share as field_shared_with ON ( field_shared_with.post_id = p.ID )"; | ||
$post_id_filter_sql = 'AND (p.ID IN ('. $post_id_filter_sql .'))'; | ||
} | ||
$shared_user_condition_sql = "AND (field_shared_with.user_id = ". $args['list_all_by_user_id'] .")"; | ||
} | ||
|
||
if ( isset( $args['field_key'], $args['field_type'] ) && in_array( $args['field_type'], [ 'key_select', 'multi_select' ] ) ){ | ||
$prepared_query = $wpdb->prepare( " | ||
SELECT p.post_title AS name, lgm.post_id, lgm.lng, lgm.lat | ||
SELECT DISTINCT p.post_title AS name, lgm.post_id, lgm.lng, lgm.lat | ||
FROM $wpdb->dt_location_grid_meta AS lgm | ||
JOIN $wpdb->posts AS p ON ( p.ID = lgm.post_id ) | ||
LEFT JOIN $wpdb->postmeta AS pm ON ( p.ID = pm.post_id ) | ||
". $shared_user_join_sql ." | ||
WHERE lgm.post_type = %s | ||
". $shared_user_condition_sql ." | ||
AND (pm.meta_key = %s)" . ( !empty( $args['field_values'] ) ? " AND (pm.meta_value IN (" . dt_array_to_sql( $args['field_values'] ) . "))" : '' ) ." | ||
". $post_id_filter_sql ." | ||
LIMIT %d, %d; | ||
", $post_type, $args['field_key'], $offset, $limit ); | ||
|
||
} elseif ( isset( $args['field_type'] ) && $args['field_type'] == 'user_select' ){ | ||
$prepared_query = $wpdb->prepare(" | ||
SELECT u.display_name AS name, um.meta_value AS post_id, lgm.lng, lgm.lat | ||
SELECT DISTINCT u.display_name AS name, um.meta_value AS post_id, lgm.lng, lgm.lat | ||
FROM $wpdb->dt_location_grid_meta AS lgm | ||
JOIN $wpdb->users AS u ON ( u.ID = lgm.post_id ) | ||
LEFT JOIN $wpdb->usermeta AS um ON ( u.ID = um.user_id AND um.meta_key = %s ) | ||
INNER JOIN $wpdb->usermeta AS um_cap ON ( u.ID = um_cap.user_id AND um_cap.meta_key = %s ) | ||
". $shared_user_join_sql ." | ||
WHERE lgm.post_type = %s | ||
". $shared_user_condition_sql ." | ||
". $post_id_filter_sql ." | ||
LIMIT %d, %d; | ||
", ( $wpdb->prefix . 'corresponds_to_contact' ), ( $wpdb->prefix . 'capabilities' ), 'users', $offset, $limit ); | ||
|
||
} else { | ||
$prepared_query = $wpdb->prepare( " | ||
SELECT p.post_title AS name, lgm.post_id, lgm.lng, lgm.lat | ||
SELECT DISTINCT p.post_title AS name, lgm.post_id, lgm.lng, lgm.lat | ||
FROM $wpdb->dt_location_grid_meta AS lgm | ||
JOIN $wpdb->posts AS p ON ( p.ID = lgm.post_id ) | ||
". $shared_user_join_sql ." | ||
WHERE lgm.post_type = %s | ||
". $shared_user_condition_sql ." | ||
". $post_id_filter_sql ." | ||
LIMIT %d, %d; | ||
", $post_type, $offset, $limit ); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list_all
seems to be set by the browser.Consider checking if the user can actually list all. the new genmapper should have code to copy.