From 40813ab951edc6aa9e0492bea46b9ba01bfcb4dd Mon Sep 17 00:00:00 2001 From: corsacca Date: Mon, 16 Dec 2024 08:58:45 +0100 Subject: [PATCH] Metrics: Prune files and hide sections when fields disabled * Remove Metric Pages no longer used * Allow metrics to be used with groups disabled or some fields no available --- dt-groups/groups.php | 2 +- dt-mapping/mapping.php | 2 +- dt-metrics/combined/hover-map.php | 8 +- dt-metrics/combined/locations-list.php | 7 +- dt-metrics/combined/site-links.php | 12 +- dt-metrics/contacts/baptism-tree.js | 36 --- dt-metrics/contacts/baptism-tree.php | 142 ----------- dt-metrics/contacts/coaching-tree.js | 35 --- dt-metrics/contacts/coaching-tree.php | 143 ----------- dt-metrics/contacts/milestones-map.php | 237 ------------------- dt-metrics/contacts/milestones.js | 66 ------ dt-metrics/contacts/milestones.php | 163 ------------- dt-metrics/contacts/milestones_map.js | 16 -- dt-metrics/contacts/seeker-path.js | 60 ----- dt-metrics/contacts/seeker-path.php | 125 ---------- dt-metrics/groups/tree.js | 128 ---------- dt-metrics/groups/tree.php | 150 ------------ dt-metrics/metrics.php | 12 - dt-metrics/personal/activity-highlights.js | 88 +++++-- dt-metrics/personal/activity-highlights.php | 47 ++-- dt-metrics/personal/baptism-tree.js | 34 --- dt-metrics/personal/baptism-tree.php | 171 ------------- dt-metrics/personal/coaching-tree.js | 33 --- dt-metrics/personal/coaching-tree.php | 175 -------------- dt-metrics/personal/group-tree.js | 124 ---------- dt-metrics/personal/group-tree.php | 177 -------------- dt-metrics/personal/mapbox-contacts-maps.php | 190 --------------- dt-metrics/personal/mapbox-groups-maps.php | 184 -------------- dt-metrics/personal/overview.js | 33 ++- dt-metrics/personal/overview.php | 8 +- dt-metrics/records/genmap.php | 2 +- dt-posts/dt-posts.php | 2 +- 32 files changed, 153 insertions(+), 2459 deletions(-) delete mode 100644 dt-metrics/contacts/baptism-tree.js delete mode 100644 dt-metrics/contacts/baptism-tree.php delete mode 100644 dt-metrics/contacts/coaching-tree.js delete mode 100644 dt-metrics/contacts/coaching-tree.php delete mode 100644 dt-metrics/contacts/milestones-map.php delete mode 100644 dt-metrics/contacts/milestones.js delete mode 100644 dt-metrics/contacts/milestones.php delete mode 100644 dt-metrics/contacts/milestones_map.js delete mode 100644 dt-metrics/contacts/seeker-path.js delete mode 100644 dt-metrics/contacts/seeker-path.php delete mode 100644 dt-metrics/groups/tree.js delete mode 100644 dt-metrics/groups/tree.php delete mode 100644 dt-metrics/personal/baptism-tree.js delete mode 100644 dt-metrics/personal/baptism-tree.php delete mode 100644 dt-metrics/personal/coaching-tree.js delete mode 100644 dt-metrics/personal/coaching-tree.php delete mode 100644 dt-metrics/personal/group-tree.js delete mode 100644 dt-metrics/personal/group-tree.php delete mode 100644 dt-metrics/personal/mapbox-contacts-maps.php delete mode 100644 dt-metrics/personal/mapbox-groups-maps.php diff --git a/dt-groups/groups.php b/dt-groups/groups.php index 22f04cd8ff..9ba708d5d3 100644 --- a/dt-groups/groups.php +++ b/dt-groups/groups.php @@ -4,7 +4,7 @@ $modules['groups_base'] = [ 'name' => 'Groups', 'enabled' => true, - 'locked' => true, + 'locked' => false, 'prerequisites' => [ 'contacts_base' ], 'post_type' => 'groups', 'description' => 'Default group functionality' diff --git a/dt-mapping/mapping.php b/dt-mapping/mapping.php index e44698c7db..29c2f8ce46 100644 --- a/dt-mapping/mapping.php +++ b/dt-mapping/mapping.php @@ -1074,7 +1074,7 @@ public function map_level_by_grid_id( $grid_id ) { $results['children'][$index]['id'] = (int) $child['id']; $results['children'][$index]['grid_id'] = (int) $child['grid_id']; $results['children'][$index]['population'] = (int) $child['population']; - $results['children'][$index]['population_formatted'] = number_format( $child['population'] ); + $results['children'][$index]['population_formatted'] = number_format( $child['population'] ?? 0 ); $results['children'][$index]['latitude'] = (float) $child['latitude']; $results['children'][$index]['longitude'] = (float) $child['longitude']; $results['children'][$index]['parent_id'] = empty( $child['parent_id'] ) ? null : (int) $child['parent_id']; diff --git a/dt-metrics/combined/hover-map.php b/dt-metrics/combined/hover-map.php index 4fa35651ab..973a19229f 100644 --- a/dt-metrics/combined/hover-map.php +++ b/dt-metrics/combined/hover-map.php @@ -77,9 +77,13 @@ public function data( $force_refresh = false ) { //get initial data $data = DT_Mapping_Module::instance()->data(); + $post_types = DT_Posts::get_post_types(); + $data = $this->add_contacts_column( $data ); - $data = $this->add_groups_column( $data ); - $data = $this->add_churches_column( $data ); + if ( in_array( 'groups', $post_types ) ) { + $data = $this->add_groups_column( $data ); + $data = $this->add_churches_column( $data ); + } $data = $this->add_users_column( $data ); return $data; diff --git a/dt-metrics/combined/locations-list.php b/dt-metrics/combined/locations-list.php index 00cc8a19e8..a34fcdad04 100644 --- a/dt-metrics/combined/locations-list.php +++ b/dt-metrics/combined/locations-list.php @@ -73,10 +73,13 @@ public function list_scripts() { public function data( $force_refresh = false ) { //get initial data $data = DT_Mapping_Module::instance()->data(); + $post_types = DT_Posts::get_post_types(); $data = $this->add_contacts_column( $data ); - $data = $this->add_groups_column( $data ); - $data = $this->add_churches_column( $data ); + if ( !empty( $post_types['groups'] ) ) { + $data = $this->add_groups_column( $data ); + $data = $this->add_churches_column( $data ); + } $data = $this->add_users_column( $data ); return $data; diff --git a/dt-metrics/combined/site-links.php b/dt-metrics/combined/site-links.php index b3880cc45c..b5fd6b0b31 100644 --- a/dt-metrics/combined/site-links.php +++ b/dt-metrics/combined/site-links.php @@ -75,12 +75,12 @@ public function scripts() { 'site_links_header' => __( 'Site Links', 'disciple_tools' ), 'site_links_none_header' => __( 'None Set', 'disciple_tools' ), 'totals_header' => _x( 'Contacts transferred during date range', 'Contacts transferred during date range', 'disciple_tools' ), - 'status_created_header' => sprintf( _x( '%s of contacts created in date range', 'Seeker Path of contacts created in date range', 'disciple_tools' ), $field_settings['overall_status']['name'] ), - 'seeker_path_created_header' => sprintf( _x( '%s of contacts created in date range', 'Seeker Path of contacts created in date range', 'disciple_tools' ), $field_settings['seeker_path']['name'] ), - 'milestones_created_header' => sprintf( _x( '%s of contacts created in date range', 'Seeker Path of contacts created in date range', 'disciple_tools' ), $field_settings['milestones']['name'] ), - 'status_changes_header' => sprintf( _x( '%s changes during date range', 'Seeker Path changes during date range', 'disciple_tools' ), $field_settings['overall_status']['name'] ), - 'seeker_path_changes_header' => sprintf( _x( '%s changes during date range', 'Seeker Path changes during date range', 'disciple_tools' ), $field_settings['seeker_path']['name'] ), - 'milestones_changes_header' => sprintf( _x( '%s changes during date range', 'Seeker Path changes during date range', 'disciple_tools' ), $field_settings['milestones']['name'] ), + 'status_created_header' => sprintf( _x( '%s of contacts created in date range', 'Seeker Path of contacts created in date range', 'disciple_tools' ), $field_settings['overall_status']['name'] ?? __( 'Contact Status', 'disciple_tools' ) ), + 'seeker_path_created_header' => sprintf( _x( '%s of contacts created in date range', 'Seeker Path of contacts created in date range', 'disciple_tools' ), $field_settings['seeker_path']['name'] ?? __( 'Seeker Path', 'disciple_tools' ) ), + 'milestones_created_header' => sprintf( _x( '%s of contacts created in date range', 'Seeker Path of contacts created in date range', 'disciple_tools' ), $field_settings['milestones']['name'] ?? __( 'Faith Milestones', 'disciple_tools' ) ), + 'status_changes_header' => sprintf( _x( '%s changes during date range', 'Seeker Path changes during date range', 'disciple_tools' ), $field_settings['overall_status']['name'] ?? __( 'Contact Status', 'disciple_tools' ) ), + 'seeker_path_changes_header' => sprintf( _x( '%s changes during date range', 'Seeker Path changes during date range', 'disciple_tools' ), $field_settings['seeker_path']['name'] ?? __( 'Seeker Path', 'disciple_tools' ) ), + 'milestones_changes_header' => sprintf( _x( '%s changes during date range', 'Seeker Path changes during date range', 'disciple_tools' ), $field_settings['milestones']['name'] ?? __( 'Faith Milestones', 'disciple_tools' ) ), ], 'general' => [ 'no_data_msg' => __( 'No Data Available', 'disciple_tools' ) diff --git a/dt-metrics/contacts/baptism-tree.js b/dt-metrics/contacts/baptism-tree.js deleted file mode 100644 index cdd0e859eb..0000000000 --- a/dt-metrics/contacts/baptism-tree.js +++ /dev/null @@ -1,36 +0,0 @@ -jQuery(document).ready(function () { - if (window.wpApiShare.url_path.startsWith('metrics/contacts/baptism-tree')) { - project_baptism_tree(); - } - - function project_baptism_tree() { - 'use strict'; - let chart = jQuery('#chart'); - let spinner = ' '; - - chart.empty().html(spinner); - jQuery('#metrics-sidemenu').foundation('down', jQuery('#contacts-menu')); - - let translations = window.dtMetricsProject.data.translations; - - chart.empty().html(` - ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_baptism_tree)}
-
-
-
${spinner}
-
-
- -

- `); - - window - .makeRequest('POST', 'metrics/contacts/baptism_tree') - .then((response) => { - // console.log(response) - jQuery('#generation_map').empty().html(response); - jQuery('#generation_map li:last-child').addClass('last'); - new window.Foundation.Reveal(jQuery('#modal')); - }); - } -}); diff --git a/dt-metrics/contacts/baptism-tree.php b/dt-metrics/contacts/baptism-tree.php deleted file mode 100644 index 7eb013ae7f..0000000000 --- a/dt-metrics/contacts/baptism-tree.php +++ /dev/null @@ -1,142 +0,0 @@ -has_permission() ){ - return; - } - $this->title = __( 'Baptism Tree', 'disciple_tools' ); - $this->base_title = __( 'Contacts', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - $this->namespace = "dt-metrics/$this->base_slug/$this->slug"; - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function scripts() { - wp_enqueue_script( 'dt_metrics_project_script', get_template_directory_uri() . $this->js_file_name, [ - 'jquery', - 'lodash' - ], filemtime( get_theme_file_path() . $this->js_file_name ), true ); - - wp_localize_script( - 'dt_metrics_project_script', 'dtMetricsProject', [ - 'root' => esc_url_raw( rest_url() ), - 'theme_uri' => get_template_directory_uri(), - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'current_user_login' => wp_get_current_user()->user_login, - 'current_user_id' => get_current_user_id(), - 'data' => $this->data(), - ] - ); - } - - public function data() { - return [ - 'translations' => [ - 'title_baptism_tree' => __( 'Baptism Generation Tree', 'disciple_tools' ), - ], - ]; - } - - public function add_api_routes() { - $version = '1'; - $namespace = 'dt/v' . $version; - register_rest_route( - $namespace, '/metrics/contacts/baptism_tree', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'tree' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function tree( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - return $this->get_baptism_generations_tree(); - } - - public function get_baptism_generations_tree(){ - $query = dt_queries()->tree( 'multiplying_baptisms_only' ); - if ( is_wp_error( $query ) ){ - return $this->_circular_structure_error( $query ); - } - if ( empty( $query ) ) { - return $this->_no_results(); - } - $menu_data = $this->prepare_menu_array( $query ); - return $this->build_menu( 0, $menu_data, -1 ); - } - - public function build_menu( $parent_id, $menu_data, $gen, $unique_check = [] ) { - $html = ''; - - if ( isset( $menu_data['parents'][$parent_id] ) ) - { - $gen++; - - $first_section = ''; - if ( $gen === 0 ) { - $first_section = 'first-section'; - } - - $html = ''; - - } - return $html; - } - - public function prepare_menu_array( $query ) { - // prepare special array with parent-child relations - $menu_data = array( - 'items' => array(), - 'parents' => array() - ); - - foreach ( $query as $menu_item ) - { - $menu_data['items'][$menu_item['id']] = $menu_item; - $menu_data['parents'][$menu_item['parent_id']][] = $menu_item['id']; - } - return $menu_data; - } -} -new DT_Metrics_Contacts_Baptism_Tree(); diff --git a/dt-metrics/contacts/coaching-tree.js b/dt-metrics/contacts/coaching-tree.js deleted file mode 100644 index 2bcc1b60f1..0000000000 --- a/dt-metrics/contacts/coaching-tree.js +++ /dev/null @@ -1,35 +0,0 @@ -jQuery(document).ready(function () { - if (window.wpApiShare.url_path.startsWith('metrics/contacts/coaching-tree')) { - coaching_tree(); - } - - function coaching_tree() { - 'use strict'; - let chart = jQuery('#chart'); - let spinner = ' '; - chart.empty().html(spinner); - jQuery('#metrics-sidemenu').foundation('down', jQuery('#contacts-menu')); - - let translations = window.dtMetricsProject.data.translations; - - chart.empty().html(` - ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_coaching_tree)}
-
-
-
${spinner}
-
-
- -

- `); - - window - .makeRequest('POST', 'metrics/contacts/coaching_tree') - .then((response) => { - // console.log(response) - jQuery('#generation_map').empty().html(response); - jQuery('#generation_map li:last-child').addClass('last'); - new window.Foundation.Reveal(jQuery('#modal')); - }); - } -}); diff --git a/dt-metrics/contacts/coaching-tree.php b/dt-metrics/contacts/coaching-tree.php deleted file mode 100644 index 781cd0c944..0000000000 --- a/dt-metrics/contacts/coaching-tree.php +++ /dev/null @@ -1,143 +0,0 @@ -has_permission() ){ - return; - } - $this->title = __( 'Coaching Tree', 'disciple_tools' ); - $this->base_title = __( 'Contacts', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - - $this->namespace = "dt-metrics/$this->base_slug/$this->slug"; - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function scripts() { - wp_enqueue_script( 'dt_metrics_project_script', get_template_directory_uri() . $this->js_file_name, [ - 'jquery', - 'lodash' - ], filemtime( get_theme_file_path() . $this->js_file_name ), true ); - - wp_localize_script( - 'dt_metrics_project_script', 'dtMetricsProject', [ - 'root' => esc_url_raw( rest_url() ), - 'theme_uri' => get_template_directory_uri(), - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'current_user_login' => wp_get_current_user()->user_login, - 'current_user_id' => get_current_user_id(), - 'data' => $this->data(), - ] - ); - } - - public function data() { - return [ - 'translations' => [ - 'title_coaching_tree' => __( 'Coaching Generation Tree', 'disciple_tools' ), - ], - ]; - } - - public function add_api_routes() { - $version = '1'; - $namespace = 'dt/v' . $version; - register_rest_route( - $namespace, '/metrics/contacts/coaching_tree', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'tree' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function tree( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - return $this->get_baptism_generations_tree(); - } - - public function get_baptism_generations_tree(){ - $query = dt_queries()->tree( 'multiplying_coaching_only' ); - if ( is_wp_error( $query ) ){ - return $this->_circular_structure_error( $query ); - } - if ( empty( $query ) ) { - return $this->_no_results(); - } - $menu_data = $this->prepare_menu_array( $query ); - return $this->build_menu( 0, $menu_data, -1 ); - } - - public function build_menu( $parent_id, $menu_data, $gen, $unique_check = [] ) { - $html = ''; - - if ( isset( $menu_data['parents'][$parent_id] ) ) - { - $gen++; - - $first_section = ''; - if ( $gen === 0 ) { - $first_section = 'first-section'; - } - - $html = ''; - - } - return $html; - } - - public function prepare_menu_array( $query ) { - // prepare special array with parent-child relations - $menu_data = array( - 'items' => array(), - 'parents' => array() - ); - - foreach ( $query as $menu_item ) - { - $menu_data['items'][$menu_item['id']] = $menu_item; - $menu_data['parents'][$menu_item['parent_id']][] = $menu_item['id']; - } - return $menu_data; - } -} -new DT_Metrics_Coaching_Tree(); diff --git a/dt-metrics/contacts/milestones-map.php b/dt-metrics/contacts/milestones-map.php deleted file mode 100644 index da3752715f..0000000000 --- a/dt-metrics/contacts/milestones-map.php +++ /dev/null @@ -1,237 +0,0 @@ -has_permission() ){ - return; - } - $this->title = __( 'Milestones Map', 'disciple_tools' ); - $this->base_title = __( 'Contacts', 'disciple_tools' ); - - $this->namespace = "dt-metrics/$this->base_slug/$this->slug"; - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - - add_action( 'wp_enqueue_scripts', [ $this, 'mapping_scripts' ], 89 ); - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - - } - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - - public function scripts() { - $this->title = __( 'Milestones Map', 'disciple_tools' ); - DT_Mapping_Module::instance()->scripts(); - global $dt_mapping; - - // Milestones Script - wp_enqueue_script( 'dt_'.$this->slug.'_script', - get_template_directory_uri() . '/dt-metrics/contacts/' . $this->js_file_name, - [ - 'jquery', - 'dt_mapping_js', - 'lodash' - ], - filemtime( get_theme_file_path() . '/dt-metrics/contacts/' . $this->js_file_name ), - true - ); - wp_localize_script( - 'dt_'.$this->slug.'_script', $this->js_object_name, [ - 'rest_endpoints_base' => esc_url_raw( rest_url() ) . "dt-metrics/$this->base_slug/$this->slug", - 'base_slug' => $this->base_slug, - 'root' => esc_url_raw( rest_url() ), - 'uri' => $dt_mapping['url'], - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'current_user_login' => wp_get_current_user()->user_login, - 'current_user_id' => get_current_user_id(), - 'translations' => [ - 'title' => __( 'Milestones', 'disciple_tools' ) - ] - ] - ); - } - - public function mapping_scripts() { - //Drilldown and map - DT_Mapping_Module::instance()->scripts(); - } - - - public function data( $force_refresh = false ) { - //get initial data - $data = DT_Mapping_Module::instance()->data(); - - $data = $this->add_milestones_data( $data, $force_refresh ); - - return $data; - } - - public function translations() { - $translations = []; - return $translations; - } - - public function add_api_routes() { - register_rest_route( - $this->namespace, '/data', [ - [ - 'methods' => 'GET', - 'callback' => [ $this, 'milestones_map_endpoint' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function milestones_map_endpoint( WP_REST_Request $request ){ - if ( !$this->has_permission() ) { - return new WP_Error( 'milestones_map', 'Missing Permissions', [ 'status' => 400 ] ); - } - $params = $request->get_params(); - - return $this->data( isset( $params['refresh'] ) && $params['refresh'] === 'true' ); - } - - - public function add_milestones_data( $data, $force_refresh = false ) { - - - if ( isset( $_SERVER['SERVER_NAME'] ) ) { - $url = ( !isset( $_SERVER['HTTPS'] ) || @( $_SERVER['HTTPS'] != 'on' ) ) - ? 'http://'. sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) - : 'https://'. sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ); - if ( isset( $_SERVER['REQUEST_URI'] ) ) { - $url .= sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ); - } - } - $url_path = trim( str_replace( get_site_url(), '', $url ), '/' ); - - /** - * Step 1 - * Extract the labels and data from the data section of the filter - * - * @note No modification to this section needed. - */ - $column_labels = $data['custom_column_labels'] ?? []; - $column_data = $data['custom_column_data'] ?? []; - - /** - * Step 2 - * Get the next index/column to add - * This will add this new column of data to the end of the list. - * - * @note No modification to this section needed. - * @note To modify the order of the columns use the filter order - * found in the add_filters() function. - * @example Current load level 10 - * add_filter( 'dt_mapping_module_data', 'dt_mm_add_contacts_column', 10, 1 ); - * Change to load level 50 and thus move it down the column list. Which means it - * will load after 0-49, and in front of 51-1000+ - * add_filter( 'dt_mapping_module_data', 'dt_mm_add_contacts_column', 50, 1 ); - */ - if ( empty( $column_labels ) ) { - $next_column_number = 0; - } else if ( count( $column_labels ) === 1 ) { - $next_column_number = 1; - } else { - $next_column_number = count( $column_labels ); - } - - /** - * Step 3 - * Add new label - * - * @note Modify this! Add your column name and key. - */ - // $column_labels[ $next_column_number ] = [ - // 'key' => 'churches', - // 'label' => __( 'Churches', 'disciple_tools' ) - // ]; - $field_settings = DT_Posts::get_post_field_settings( 'contacts' ); - $milestones_options = $field_settings['milestones']['default']; - foreach ( $milestones_options as $option_key => $option_value ){ - $column_labels[] = [ - 'key' => $option_key, - 'label' => $option_value['label'] - ]; - } - $next_column_number = count( $column_labels ); - - - - /** - * Step 4 - * Add new column to existing data - * - * @note No modification to this section needed. - */ - if ( ! empty( $column_data ) ) { - foreach ( $column_data as $key => $value ) { - $column_data[$key][$next_column_number] = 0; - } - } - - /** - * Step 5 - * Add new label and data column - * This is the section you can loop through any content type - * and add a new column of data for it. You want to only add grid_ids - * that have a positive count value. - * - * @note Modify this section! - * @note Don't add 0 values, or you might create unnecessary array and - * transfer weight to the mapping javascript file. - */ - $results = Disciple_Tools_Mapping_Queries::get_location_grid_totals_on_field( 'contacts', 'milestones', $force_refresh ); - $keys = array_column( $column_labels, 'key' ); - if ( ! empty( $results ) ) { - foreach ( $results as $result ) { - if ( $result['type'] && $result['count'] > 0 && in_array( $result['type'], $keys ) ) { // filter for only contact and positive counts - $grid_id = $result['grid_id']; - - // test if grid_id exists, else prepare it with 0 values - if ( ! isset( $column_data[ $grid_id ] ) ) { - $column_data[$grid_id] = []; - $i = 0; - while ( $i <= $next_column_number ) { - $column_data[$grid_id][$i] = 0; - $i++; - } - } - - // add new record to column - $column_data[$grid_id][array_search( $result['type'], $keys )] = (int) $result['count'] ?? 0; // must be string - } - } - } - - /** - * Step 6 - * Put back the modified labels and column data and return everything to the filter. - * - * @note No modification to this section needed. - */ - $data['custom_column_labels'] = $column_labels; - $data['custom_column_data'] = $column_data; - - return $data; - } -} -new DT_Metrics_Milestones_Map_Chart(); diff --git a/dt-metrics/contacts/milestones.js b/dt-metrics/contacts/milestones.js deleted file mode 100644 index 22a496c891..0000000000 --- a/dt-metrics/contacts/milestones.js +++ /dev/null @@ -1,66 +0,0 @@ -jQuery(document).ready(function ($) { - if (window.wpApiShare.url_path.startsWith('metrics/contacts/milestones')) { - get_milestones(); - } - - function get_milestones() { - jQuery('#metrics-sidemenu').foundation('down', jQuery('#contacts-menu')); - - let chartDiv = jQuery('#chart'); - let sourceData = window.wp_js_object.data; - - chartDiv.empty().html(` -
${window.SHAREDFUNCTIONS.escapeHTML(window.wp_js_object.translations.milestones)}
-
${window.SHAREDFUNCTIONS.escapeHTML(window.wp_js_object.translations.filter_to_date_range)}:
-
-   - ${window.SHAREDFUNCTIONS.escapeHTML(window.wp_js_object.translations.all_time)} - -
-
-
-
- `); - - let chart = window.am4core.create('chartdiv', window.am4charts.XYChart); - - chart.data = sourceData.milestones; - let categoryAxis = chart.xAxes.push(new window.am4charts.CategoryAxis()); - categoryAxis.dataFields.category = 'milestones'; - categoryAxis.renderer.grid.template.location = 0; - categoryAxis.renderer.minGridDistance = 30; - categoryAxis.renderer.labels.template.adapter.add( - 'dy', - function (dy, target) { - if (target.dataItem && target.dataItem.index & (2 == 2)) { - return dy + 25; - } - return dy; - }, - ); - - let valueAxis = chart.yAxes.push(new window.am4charts.ValueAxis()); - - // Create series - let series = chart.series.push(new window.am4charts.ColumnSeries()); - series.dataFields.valueY = 'value'; - series.dataFields.categoryX = 'milestones'; - series.name = 'Visits'; - series.columns.template.tooltipText = '{categoryX}: [bold]{valueY}[/]'; - series.columns.template.fillOpacity = 0.8; - - let columnTemplate = series.columns.template; - columnTemplate.strokeWidth = 2; - columnTemplate.strokeOpacity = 1; - - window.METRICS.setupDatePicker( - `${window.wp_js_object.rest_endpoints_base}/milestones/`, - function (data, label) { - if (data) { - $('.date_range_picker span').html(label); - chart.data = data; - } - }, - ); - } -}); diff --git a/dt-metrics/contacts/milestones.php b/dt-metrics/contacts/milestones.php deleted file mode 100644 index 3aae8b8578..0000000000 --- a/dt-metrics/contacts/milestones.php +++ /dev/null @@ -1,163 +0,0 @@ -has_permission() ){ - return; - } - $this->title = __( 'Milestones Chart', 'disciple_tools' ); - $this->base_title = __( 'Contacts', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - /** - * Load scripts for the plugin - */ - public function scripts() { - - wp_register_script( 'datepicker', 'https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js', false ); - wp_enqueue_style( 'datepicker-css', 'https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css', array() ); - - wp_register_script( 'amcharts-core', 'https://www.amcharts.com/lib/4/core.js', false, '4' ); - wp_register_script( 'amcharts-charts', 'https://www.amcharts.com/lib/4/charts.js', false, '4' ); - - - wp_enqueue_script( 'dt_' . $this->slug . '_script', - get_template_directory_uri() . $this->js_file_name, - [ - 'moment', - 'jquery', - 'jquery-ui-core', - 'datepicker', - 'amcharts-core', - 'amcharts-charts', - ], - filemtime( get_theme_file_path() . $this->js_file_name ) - ); - - // Localize script with array data - wp_localize_script( - 'dt_'.$this->slug.'_script', $this->js_object_name, [ - 'rest_endpoints_base' => esc_url_raw( rest_url() ) . "dt-metrics/$this->base_slug/$this->slug", - 'data' => [ - 'milestones' => $this->milestones() - ], - 'translations' => [ - 'milestones' => __( 'Milestones', 'disciple_tools' ), - 'filter_contacts_to_date_range' => __( 'Filter contacts to date range:', 'disciple_tools' ), - 'all_time' => __( 'All Time', 'disciple_tools' ), - 'filter_to_date_range' => __( 'Filter to date range', 'disciple_tools' ), - ] - ] - ); - } - - public function add_api_routes() { - $namespace = "dt-metrics/$this->base_slug/$this->slug"; - register_rest_route( - $namespace, '/milestones/', [ - [ - 'methods' => WP_REST_Server::READABLE, - 'callback' => [ $this, 'milestones_endpoint' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function milestones_endpoint( WP_REST_Request $request ){ - if ( !$this->has_permission() ) { - return new WP_Error( 'milestones', 'Missing Permissions', [ 'status' => 400 ] ); - } - $params = $request->get_params(); - if ( isset( $params['start'], $params['end'] ) ){ - $start = strtotime( $params['start'] ); - $end = strtotime( $params['end'] ) + DAY_IN_SECONDS; - $result = $this->milestones( $start, $end ); - if ( is_wp_error( $result ) ) { - return $result; - } else { - return new WP_REST_Response( $result ); - } - } else { - return new WP_Error( 'milestones', 'Missing a valid values', [ 'status' => 400 ] ); - } - } - - - public function milestones( $start = null, $end = null ){ - global $wpdb; - if ( empty( $start ) ){ - $start = 0; - } - if ( empty( $end ) ){ - $end = time(); - } - - $res = $wpdb->get_results( $wpdb->prepare( " - SELECT COUNT( DISTINCT(log.object_id) ) as `value`, log.meta_value as milestones - FROM $wpdb->dt_activity_log log - INNER JOIN $wpdb->postmeta as type ON ( log.object_id = type.post_id AND type.meta_key = 'type' AND type.meta_value != 'user' ) - INNER JOIN $wpdb->posts post - ON ( - post.ID = log.object_id - AND post.post_type = 'contacts' - AND post.post_status = 'publish' - ) - INNER JOIN $wpdb->postmeta pm - ON ( - pm.post_id = post.ID - AND pm.meta_key = 'milestones' - AND pm.meta_value = log.meta_value - ) - WHERE log.meta_key = 'milestones' - AND log.object_type = 'contacts' - AND log.hist_time > %s - AND log.hist_time < %s - GROUP BY log.meta_value - ", $start, $end ), ARRAY_A ); - - $field_settings = DT_Posts::get_post_field_settings( 'contacts' ); - $milestones_options = $field_settings['milestones']['default']; - $milestones_data = []; - - foreach ( $milestones_options as $option_key => $option_value ){ - $milestones_data[$option_value['label']] = 0; - foreach ( $res as $r ){ - if ( $r['milestones'] === $option_key ){ - $milestones_data[$option_value['label']] = $r['value']; - } - } - } - $return = []; - foreach ( $milestones_data as $k => $v ){ - $return[] = [ - 'milestones' => $k, - 'value' => (int) $v - ]; - } - - return $return; - } -} -new DT_Metrics_Milestones_Chart(); diff --git a/dt-metrics/contacts/milestones_map.js b/dt-metrics/contacts/milestones_map.js deleted file mode 100644 index 948f238a90..0000000000 --- a/dt-metrics/contacts/milestones_map.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -jQuery(document).ready(function () { - jQuery('#metrics-sidemenu').foundation( - 'down', - jQuery(`#${window.wp_js_object.base_slug}-menu`), - ); - - let chartDiv = jQuery('#chart'); - chartDiv.empty().html(` - ${window.wp_js_object.translations.title} -
- `); - - window.page_mapping_view(window.wp_js_object.rest_endpoints_base); -}); diff --git a/dt-metrics/contacts/seeker-path.js b/dt-metrics/contacts/seeker-path.js deleted file mode 100644 index 5418c0f7d1..0000000000 --- a/dt-metrics/contacts/seeker-path.js +++ /dev/null @@ -1,60 +0,0 @@ -jQuery(document).ready(function ($) { - jQuery('#metrics-sidemenu').foundation('down', jQuery('#contacts-menu')); - - let chartDiv = jQuery('#chart'); - let sourceData = window.wp_js_object.data; - - chartDiv.empty().html(` -
${window.SHAREDFUNCTIONS.escapeHTML(window.wp_js_object.translations.seeker_path)}
-
${window.SHAREDFUNCTIONS.escapeHTML(window.wp_js_object.translations.filter_contacts_to_date_range)}
-
-   - ${window.escape(window.wp_js_object.translations.all_time)} - -
-
-
-
- `); - - let chart = window.am4core.create('chartdiv', window.am4charts.XYChart); - - chart.data = sourceData.seeker_path; - let categoryAxis = chart.xAxes.push(new window.am4charts.CategoryAxis()); - categoryAxis.dataFields.category = 'seeker_path'; - categoryAxis.renderer.grid.template.location = 0; - categoryAxis.renderer.minGridDistance = 30; - categoryAxis.renderer.labels.template.adapter.add( - 'dy', - function (dy, target) { - if (target.dataItem && target.dataItem.index & (2 == 2)) { - return dy + 25; - } - return dy; - }, - ); - - let valueAxis = chart.yAxes.push(new window.am4charts.ValueAxis()); - - // Create series - let series = chart.series.push(new window.am4charts.ColumnSeries()); - series.dataFields.valueY = 'value'; - series.dataFields.categoryX = 'seeker_path'; - series.name = 'Visits'; - series.columns.template.tooltipText = '{categoryX}: [bold]{valueY}[/]'; - series.columns.template.fillOpacity = 0.8; - - let columnTemplate = series.columns.template; - columnTemplate.strokeWidth = 2; - columnTemplate.strokeOpacity = 1; - - window.METRICS.setupDatePicker( - `${window.wp_js_object.rest_endpoints_base}/seeker_path/`, - function (data, label, start, end) { - if (data) { - $('.date_range_picker span').html(label); - chart.data = data; - } - }, - ); -}); diff --git a/dt-metrics/contacts/seeker-path.php b/dt-metrics/contacts/seeker-path.php deleted file mode 100644 index cfd0e12542..0000000000 --- a/dt-metrics/contacts/seeker-path.php +++ /dev/null @@ -1,125 +0,0 @@ -has_permission() ){ - return; - } - $url_path = dt_get_url_path( true ); - $this->title = __( 'Seeker Path', 'disciple_tools' ); - $this->base_title = __( 'Contacts', 'disciple_tools' ); - - // only load scripts if exact url - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - /** - * Load scripts for the plugin - */ - public function scripts() { - - wp_enqueue_script( 'dt_' . $this->slug . '_script', - get_template_directory_uri() . $this->js_file_name, - [ - 'moment', - 'jquery', - 'jquery-ui-core', - 'datepicker', - 'amcharts-core', - 'amcharts-charts', - 'lodash' - ], - filemtime( get_theme_file_path() . $this->js_file_name ) - ); - - // Localize script with array data - wp_localize_script( - 'dt_'.$this->slug.'_script', $this->js_object_name, [ - 'rest_endpoints_base' => esc_url_raw( rest_url() ) . "dt-metrics/$this->base_slug/$this->slug", - 'data' => [ - 'seeker_path' => $this->seeker_path() - ], - 'translations' => [ - 'seeker_path' => __( 'Seeker Path', 'disciple_tools' ), - 'filter_contacts_to_date_range' => __( 'Filter contacts to date range:', 'disciple_tools' ), - 'all_time' => __( 'All Time', 'disciple_tools' ), - 'filter_to_date_range' => __( 'Filter to date range', 'disciple_tools' ), - ] - ] - ); - } - - public function add_api_routes() { - $namespace = "dt-metrics/$this->base_slug/$this->slug"; - register_rest_route( - $namespace, '/seeker_path/', [ - [ - 'methods' => WP_REST_Server::READABLE, - 'callback' => [ $this, 'seeker_path_endpoint' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function seeker_path_endpoint( WP_REST_Request $request ){ - if ( !$this->has_permission() ) { - return new WP_Error( 'seeker_path_endpoint', 'Missing Permissions', [ 'status' => 400 ] ); - } - $params = $request->get_params(); - if ( isset( $params['start'], $params['end'] ) ){ - $start = strtotime( $params['start'] ); - $end = strtotime( $params['end'] ); - $result = $this->seeker_path( $start, $end ); - if ( is_wp_error( $result ) ) { - return $result; - } else { - return new WP_REST_Response( $result ); - } - } else { - return new WP_Error( 'seeker_path_endpoint', 'Missing a valid values', [ 'status' => 400 ] ); - } - } - - public function seeker_path( $start = null, $end = null ){ - if ( empty( $start ) ){ - $start = 0; - } - if ( empty( $end ) ){ - $end = time(); - } - - $seeker_path_activity = Disciple_Tools_Counter_Contacts::seeker_path_activity( $start, $end ); - $return = []; - foreach ( $seeker_path_activity as $key => $value ){ - if ( $key != 'none' ){ - $return[] = [ - 'seeker_path' => $value['label'], - 'value' => (int) $value['value'] - ]; - } - } - - return $return; - } -} -new DT_Metrics_Seeker_Path_Chart(); diff --git a/dt-metrics/groups/tree.js b/dt-metrics/groups/tree.js deleted file mode 100644 index 531e23d7a8..0000000000 --- a/dt-metrics/groups/tree.js +++ /dev/null @@ -1,128 +0,0 @@ -jQuery(document).ready(function () { - if (window.wpApiShare.url_path.startsWith('metrics/groups/tree')) { - project_group_tree(); - } - - function project_group_tree() { - 'use strict'; - let chart = jQuery('#chart'); - let spinner = ' '; - - chart.empty().html(spinner); - jQuery('#metrics-sidemenu').foundation('down', jQuery('#groups-menu')); - - let translations = window.dtMetricsProject.data.translations; - - chart.empty().html(` - ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_group_tree)}
-
-
- - - - - - -
-
-
-
-
- -

- `); - - window.makeRequest('POST', 'metrics/group/tree').then((response) => { - // console.log(response) - jQuery('#generation_map').empty().html(response); - jQuery('#generation_map li:last-child').addClass('last'); - new window.Foundation.Reveal(jQuery('#modal')); - }); - } -}); - -function open_modal_details(id) { - let modal = jQuery('#modal'); - let spinner = ' '; - let translations = window.dtMetricsProject.data.translations; - - modal.empty().html(spinner).foundation('open'); - - window - .makeRequest( - 'GET', - 'groups/' + window.SHAREDFUNCTIONS.escapeHTML(id), - null, - 'dt-posts/v2/', - ) - .then((data) => { - // console.log(data) - if (data) { - let list = - '
' + - window.SHAREDFUNCTIONS.escapeHTML(translations.members) + - '
'; - modal.empty().append(` -
-
${window.SHAREDFUNCTIONS.escapeHTML(data.title)}
-
-
-
${window.SHAREDFUNCTIONS.escapeHTML(translations.status) /*Status*/}: ${window.SHAREDFUNCTIONS.escapeHTML(data.group_status.label)}
-
${window.SHAREDFUNCTIONS.escapeHTML(translations.assigned_to) /*Assigned to*/}: ${window.SHAREDFUNCTIONS.escapeHTML(assigned_to)}
-
${window.SHAREDFUNCTIONS.escapeHTML(translations.total_members) /*Total Members*/}: ${window.SHAREDFUNCTIONS.escapeHTML(data.member_count)}
- ${list} -
-
- -
- - `); - } - }); -} - -function toggle_multiplying_only() { - let list = jQuery('#generation_map .li-gen-1:not(:has(li.li-gen-2))'); - let button = jQuery('#multiplying-only'); - if (button.hasClass('hollow')) { - list.hide(); - button.removeClass('hollow'); - } else { - button.addClass('hollow'); - list.show(); - } -} - -function highlight_active() { - let list = jQuery('.inactive'); - let button = jQuery('#highlight-active'); - if (button.hasClass('hollow')) { - list.addClass('inactive-gray'); - button.removeClass('hollow'); - } else { - button.addClass('hollow'); - list.removeClass('inactive-gray'); - } -} - -function highlight_churches() { - let list = jQuery('#generation_map span:not(.church)'); - let button = jQuery('#highlight-churches'); - if (button.hasClass('hollow')) { - list.addClass('not-church-gray'); - button.removeClass('hollow'); - } else { - button.addClass('hollow'); - list.removeClass('not-church-gray'); - } -} diff --git a/dt-metrics/groups/tree.php b/dt-metrics/groups/tree.php deleted file mode 100644 index ac44d28608..0000000000 --- a/dt-metrics/groups/tree.php +++ /dev/null @@ -1,150 +0,0 @@ -has_permission() ){ - return; - } - $this->base_title = __( 'Groups', 'disciple_tools' ); - $this->title = __( 'Groups Tree', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - - $this->namespace = "dt-metrics/$this->base_slug/$this->slug"; - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function add_api_routes() { - - $version = '1'; - $namespace = 'dt/v' . $version; - register_rest_route( - $namespace, '/metrics/group/tree', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'tree' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function tree( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - return $this->get_group_generations_tree(); - } - - public function scripts() { - wp_enqueue_script( 'dt_metrics_project_script', get_template_directory_uri() . $this->js_file_name, [ - 'jquery', - 'lodash' - ], filemtime( get_theme_file_path() . $this->js_file_name ), true ); - - wp_localize_script( - 'dt_metrics_project_script', 'dtMetricsProject', [ - 'root' => esc_url_raw( rest_url() ), - 'theme_uri' => get_template_directory_uri(), - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'current_user_login' => wp_get_current_user()->user_login, - 'current_user_id' => get_current_user_id(), - 'map_key' => empty( DT_Mapbox_API::get_key() ) ? '' : DT_Mapbox_API::get_key(), - 'data' => $this->data(), - ] - ); - } - - public function data() { - return [ - 'translations' => [ - 'title_group_tree' => __( 'Group Generation Tree', 'disciple_tools' ), - 'highlight_active' => __( 'Highlight Active', 'disciple_tools' ), - 'highlight_churches' => __( 'Highlight Churches', 'disciple_tools' ), - 'members' => __( 'Members', 'disciple_tools' ), - 'view_record' => __( 'View Record', 'disciple_tools' ), - 'assigned_to' => __( 'Assigned To', 'disciple_tools' ), - 'status' => __( 'Status', 'disciple_tools' ), - 'total_members' => __( 'Total Members', 'disciple_tools' ), - 'view_group' => __( 'View Group', 'disciple_tools' ), - - ], - 'group_generation_tree' => $this->get_group_generations_tree(), - ]; - } - - public function get_group_generations_tree(){ - $query = dt_queries()->tree( 'multiplying_groups_only' ); - if ( is_wp_error( $query ) ){ - return $this->_circular_structure_error( $query ); - } - if ( empty( $query ) ) { - return $this->_no_results(); - } - $menu_data = $this->prepare_menu_array( $query ); - return $this->build_group_tree( 0, $menu_data, 0 ); - } - - public function prepare_menu_array( $query ) { - // prepare special array with parent-child relations - $menu_data = array( - 'items' => array(), - 'parents' => array() - ); - - foreach ( $query as $menu_item ) - { - $menu_data['items'][$menu_item['id']] = $menu_item; - $menu_data['parents'][$menu_item['parent_id']][] = $menu_item['id']; - } - return $menu_data; - } - - public function build_group_tree( $parent_id, $menu_data, $gen ) { - $html = ''; - - if ( isset( $menu_data['parents'][$parent_id] ) ) - { - $first_section = ''; - if ( $gen === 0 ) { - $first_section = 'first-section'; - } - - $html = ''; - - } - return $html; - } -} -new DT_Metrics_Groups_Tree(); diff --git a/dt-metrics/metrics.php b/dt-metrics/metrics.php index 164e8b158b..7e60394d4f 100644 --- a/dt-metrics/metrics.php +++ b/dt-metrics/metrics.php @@ -56,13 +56,6 @@ public function __construct(){ require_once( get_template_directory() . '/dt-metrics/records/records-endpoints.php' ); if ( dt_has_permissions( [ 'dt_all_access_contacts', 'view_project_metrics' ] ) ){ // tests if project level permissions - /* Contacts */ - // if ( !empty( $modules['dmm_module']['enabled'] ) ){ - //...require_once( get_template_directory() . '/dt-metrics/contacts/baptism-tree.php' ); - //...require_once( get_template_directory() . '/dt-metrics/contacts/coaching-tree.php' ); - // require_once( get_template_directory() . '/dt-metrics/contacts/milestones.php' ); - // ...require_once( get_template_directory() . '/dt-metrics/contacts/milestones-map.php' ); - // } if ( !empty( $modules['access_module']['enabled'] ) ){ //...require_once( get_template_directory() . '/dt-metrics/contacts/mapbox-maps.php' ); require_once( get_template_directory() . '/dt-metrics/contacts/sources.php' ); @@ -102,11 +95,6 @@ public function __construct(){ '; if ( dt_has_permissions( [ 'dt_all_access_contacts', 'view_project_metrics' ] ) ){ - //if ( !empty( $modules['dmm_module']['enabled'] ) ){ - // $content .= '
  • ' . __( 'Contacts', 'disciple_tools' ) . ' - // - //
  • '; - //ß} $content .= '
  • ' . __( 'Project', 'disciple_tools' ) . '
  • '; diff --git a/dt-metrics/personal/activity-highlights.js b/dt-metrics/personal/activity-highlights.js index 2739245ed0..358a191f1f 100644 --- a/dt-metrics/personal/activity-highlights.js +++ b/dt-metrics/personal/activity-highlights.js @@ -91,43 +91,103 @@ function buildHighlights(data, label = 'all time') { ${makeRecordsCreatedSection(contacts_created)} -

    ${makeTitle(quick_actions_done, field_I_changed)}

    - ${makeDataTable(quick_actions_done)} - + ${ + quick_actions_done + ? ` +

    ${makeTitle(quick_actions_done, field_I_changed)}

    + ${makeDataTable(quick_actions_done)}` + : `` + } + + ${ + milestones_added + ? `

    ${makeTitle(milestones_added, field_I_changed)}

    - ${makeDataTable(milestones_added)} + ${makeDataTable(milestones_added)}` + : `` + } + ${ + milestones_added_by_others + ? `

    ${makeTitle(milestones_added_by_others, field_others_changed)}

    - ${makeDataTable(milestones_added_by_others)} + ${makeDataTable(milestones_added_by_others)}` + : `` + } + ${ + seeker_path_changed + ? `

    ${makeTitle(seeker_path_changed, field_I_changed)}

    - ${makeDataTable(seeker_path_changed)} + ${makeDataTable(seeker_path_changed)}` + : `` + } + ${ + seeker_path_changed_by_others + ? `

    ${makeTitle(seeker_path_changed_by_others, field_others_changed)}

    - ${makeDataTable(seeker_path_changed_by_others)} + ${makeDataTable(seeker_path_changed_by_others)}` + : `` + } + ${ + baptisms + ? `

    ${baptism_by_me}

    - ${makeBaptismsSection(baptisms)} + ${makeBaptismsSection(baptisms)}` + : `` + } + ${ + baptisms_by_others + ? `

    ${baptism_by_others}

    - ${makeBaptismsByOthersSection(baptisms_by_others)} + ${makeBaptismsByOthersSection(baptisms_by_others)}` + : `` + } + ${ + groups_created + ? `

    ${makeTitle(groups_created, field_I_made)}

    ${makeRecordsCreatedSection(groups_created)} -
    + ` + : `` + } + ${ + group_type_changed + ? `

    ${makeTitle(group_type_changed, field_I_changed)}

    - ${makeDataTable(group_type_changed)} + ${makeDataTable(group_type_changed)}` + : `` + } + ${ + group_type_changed_by_others + ? `

    ${makeTitle(group_type_changed_by_others, field_others_changed)}

    - ${makeDataTable(group_type_changed_by_others)} + ${makeDataTable(group_type_changed_by_others)}` + : `` + } + ${ + health_metrics_added + ? `

    ${makeTitle(health_metrics_added, field_I_changed)}

    - ${makeDataTable(health_metrics_added)} + ${makeDataTable(health_metrics_added)}` + : `` + } + ${ + health_metrics_added_by_others + ? `

    ${makeTitle(health_metrics_added_by_others, field_others_changed)}

    - ${makeDataTable(health_metrics_added_by_others)} + ${makeDataTable(health_metrics_added_by_others)}` + : `` + }
    diff --git a/dt-metrics/personal/activity-highlights.php b/dt-metrics/personal/activity-highlights.php index bf49ed23c6..eeb53d9ae3 100644 --- a/dt-metrics/personal/activity-highlights.php +++ b/dt-metrics/personal/activity-highlights.php @@ -109,30 +109,45 @@ private static function check_date_string( string $str ) { private static function get_user_highlights( $from = null, $to = null ) { + $post_types = DT_Posts::get_post_types(); + $contact_field_settings = DT_Posts::get_post_field_settings( 'contacts' ); $data = []; $data['contacts_created'] = self::get_records_created( $from, $to, 'contacts' ); - $data['quick_actions_done'] = self::get_quick_actions_done( $from, $to, $contact_field_settings ); - $data['seeker_path_changed'] = self::get_info_added( $from, $to, 'contacts', 'seeker_path', '%', $contact_field_settings ); - $data['milestones_added'] = self::get_info_added( $from, $to, 'contacts', 'milestones', 'milestone_%', $contact_field_settings ); - $data['milestones_added_by_others'] = self::get_info_added_by_others( $from, $to, 'contacts', 'milestones', 'milestone_', $contact_field_settings ); - $data['seeker_path_changed_by_others'] = self::get_info_added_by_others( $from, $to, 'contacts', 'seeker_path', '', $contact_field_settings ); + if ( isset( $contact_field_settings['quick_button_no_answer'] ) ){ + $data['quick_actions_done'] = self::get_quick_actions_done( $from, $to, $contact_field_settings ); + } - $data['baptisms'] = self::get_baptisms( $from, $to ); - $data['baptisms_by_others'] = self::get_baptisms_by_others( $from, $to ); + if ( isset( $contact_field_settings['milestones'] ) ){ + $data['milestones_added'] = self::get_info_added( $from, $to, 'contacts', 'milestones', 'milestone_%', $contact_field_settings ); + $data['milestones_added_by_others'] = self::get_info_added_by_others( $from, $to, 'contacts', 'milestones', 'milestone_', $contact_field_settings ); + } + + if ( isset( $contact_field_settings['seeker_path'] ) ){ + $data['seeker_path_changed_by_others'] = self::get_info_added_by_others( $from, $to, 'contacts', 'seeker_path', '', $contact_field_settings ); + $data['seeker_path_changed'] = self::get_info_added( $from, $to, 'contacts', 'seeker_path', '%', $contact_field_settings ); + } + + if ( isset( $contact_field_settings['baptized'] ) ){ + $data['baptisms'] = self::get_baptisms( $from, $to ); + $data['baptisms_by_others'] = self::get_baptisms_by_others( $from, $to ); + } $data['comments_posted'] = self::get_comments_posted( $from, $to ); $data['comments_liked'] = self::get_comments_liked( $from, $to ); - $group_field_settings = DT_Posts::get_post_field_settings( 'groups' ); - $data['groups_created'] = self::get_records_created( $from, $to, 'groups' ); - $data['health_metrics_added'] = self::get_info_added( $from, $to, 'groups', 'health_metrics', 'church_%', $group_field_settings ); - $data['group_type_changed'] = self::get_info_added( $from, $to, 'groups', 'group_type', '%', $group_field_settings ); + if ( in_array( 'groups', $post_types ) ) { + $group_field_settings = DT_Posts::get_post_field_settings( 'groups' ); + $data['groups_created'] = self::get_records_created( $from, $to, 'groups' ); + $data['health_metrics_added'] = self::get_info_added( $from, $to, 'groups', 'health_metrics', 'church_%', $group_field_settings ); + $data['group_type_changed'] = self::get_info_added( $from, $to, 'groups', 'group_type', '%', $group_field_settings ); + + $data['health_metrics_added_by_others'] = self::get_info_added_by_others( $from, $to, 'groups', 'health_metrics', 'church_', $group_field_settings ); + $data['group_type_changed_by_others'] = self::get_info_added_by_others( $from, $to, 'groups', 'group_type', '', $group_field_settings ); + } - $data['health_metrics_added_by_others'] = self::get_info_added_by_others( $from, $to, 'groups', 'health_metrics', 'church_', $group_field_settings ); - $data['group_type_changed_by_others'] = self::get_info_added_by_others( $from, $to, 'groups', 'group_type', '', $group_field_settings ); return $data; } @@ -171,7 +186,7 @@ private static function get_records_created( $from, $to, $post_type = 'contacts' $records_created = empty( $rows ) ? 0 : $rows[0]['records_created']; return [ - 'field_label' => $post_settings['label_plural'], + 'field_label' => $post_settings['label_plural'] ?? $post_type, 'count' => $records_created, 'label' => sprintf( esc_html__( '%1$d %2$s created', 'disciple_tools' ), $records_created, $records_created === 1 ? $post_settings['label_singular'] : $post_settings['label_plural'] ), ]; @@ -258,7 +273,7 @@ private static function get_info_added( $from, $to, $post_type, $subtype, $meta_ $rows = self::insert_labels( $rows, $subtype, $field_settings ); return [ - 'field_label' => $field_settings[$subtype]['name'], + 'field_label' => $field_settings[$subtype]['name'] ?? $subtype, 'rows' => $rows, ]; } @@ -307,7 +322,7 @@ private static function get_info_added_by_others( $from, $to, $post_type, $subty $post_settings = apply_filters( 'dt_get_post_type_settings', [], $post_type ); return [ - 'field_label' => $field_settings[$subtype]['name'], + 'field_label' => $field_settings[$subtype]['name'] ?? $subtype, 'post_type_label' => $post_settings['label_plural'], 'rows' => $rows, ]; diff --git a/dt-metrics/personal/baptism-tree.js b/dt-metrics/personal/baptism-tree.js deleted file mode 100644 index f82fcb2ee1..0000000000 --- a/dt-metrics/personal/baptism-tree.js +++ /dev/null @@ -1,34 +0,0 @@ -jQuery(document).ready(function () { - if (window.wpApiShare.url_path.startsWith('metrics/personal/baptism-tree')) { - baptism_tree(); - } - - function baptism_tree() { - 'use strict'; - let chart = jQuery('#chart'); - let spinner = ' '; - - chart.empty().html(spinner); - jQuery('#metrics-sidemenu').foundation('down', jQuery('#personal-menu')); - - let translations = window.dtMetricsProject.data.translations; - - chart.empty().html(` - ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_baptism_tree)}
    -
    -
    -
    ${spinner}
    -
    -
    - -

    - `); - - window.makeRequest('POST', 'metrics/my/baptism_tree').then((response) => { - // console.log(response) - jQuery('#generation_map').empty().html(response); - jQuery('#generation_map li:last-child').addClass('last'); - new window.Foundation.Reveal(jQuery('#modal')); - }); - } -}); diff --git a/dt-metrics/personal/baptism-tree.php b/dt-metrics/personal/baptism-tree.php deleted file mode 100644 index f5db13f840..0000000000 --- a/dt-metrics/personal/baptism-tree.php +++ /dev/null @@ -1,171 +0,0 @@ -has_permission() ){ - return; - } - $this->title = __( 'My Baptism Tree', 'disciple_tools' ); - $this->base_title = __( 'Personal', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - $this->namespace = "dt-metrics/$this->base_slug/$this->slug"; - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function scripts() { - wp_enqueue_script( 'dt_metrics_project_script', get_template_directory_uri() . $this->js_file_name, [ - 'jquery', - 'lodash' - ], filemtime( get_theme_file_path() . $this->js_file_name ), true ); - - wp_localize_script( - 'dt_metrics_project_script', 'dtMetricsProject', [ - 'root' => esc_url_raw( rest_url() ), - 'theme_uri' => get_template_directory_uri(), - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'current_user_login' => wp_get_current_user()->user_login, - 'current_user_id' => get_current_user_id(), - 'data' => $this->data(), - ] - ); - } - - public function data() { - return [ - 'translations' => [ - 'title_baptism_tree' => __( 'My Baptism Generation Tree', 'disciple_tools' ), - ], - ]; - } - - public function add_api_routes() { - $version = '1'; - $namespace = 'dt/v' . $version; - register_rest_route( - $namespace, '/metrics/my/baptism_tree', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'tree' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function tree( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - return $this->get_baptism_generations_tree(); - } - - public function get_baptism_generations_tree(){ - global $wpdb; - $user = wp_get_current_user(); - $baptized_contacts_shared_with_me = $wpdb->get_results( $wpdb->prepare( " - SELECT s.post_id FROM $wpdb->p2p p2p - INNER JOIN $wpdb->dt_share s ON ( s.post_id = p2p.p2p_from && s.user_id = %s ) - WHERE p2p.p2p_type = 'baptizer_to_baptized' - ", $user->ID ), ARRAY_A - ); - foreach ( $baptized_contacts_shared_with_me as $l ){ - $this->my_list[] = (int) $l['post_id']; - } - - $query = dt_queries()->tree( 'multiplying_baptisms_only' ); - if ( is_wp_error( $query ) ){ - return $this->_circular_structure_error( $query ); - } - $contact_id = Disciple_Tools_Users::get_contact_for_user( get_current_user_id() ); - $this->my_list[] = $contact_id; - $node = [ - 'parent_id' => 0, - 'id' => $contact_id, - 'name' => $user->display_name - ]; - //Stream of baptisms starting with me. - $query = array_merge( [ $node ], dt_queries()->get_node_descendants( $query, [ $contact_id ] ) ); - - $menu_data = $this->prepare_menu_array( $query ); - - if ( count( $menu_data['parents'] ) === 0 ) { - return $this->_no_results(); - } - - return $this->build_menu( 0, $menu_data, -1 ); - } - - public function build_menu( $parent_id, $menu_data, $gen, $unique_check = [] ) { - $html = ''; - - if ( isset( $menu_data['parents'][$parent_id] ) ) - { - $gen++; - - $first_section = ''; - if ( $gen === 0 ) { - $first_section = 'first-section'; - } - - $html = ''; - - } - return $html; - } - - public function prepare_menu_array( $query ) { - // prepare special array with parent-child relations - $menu_data = array( - 'items' => array(), - 'parents' => array() - ); - - foreach ( $query as $menu_item ) - { - $menu_data['items'][$menu_item['id']] = $menu_item; - $menu_data['parents'][$menu_item['parent_id']][] = $menu_item['id']; - } - return $menu_data; - } -} -new DT_Metrics_Personal_Baptism_Tree(); diff --git a/dt-metrics/personal/coaching-tree.js b/dt-metrics/personal/coaching-tree.js deleted file mode 100644 index 8d86978ab5..0000000000 --- a/dt-metrics/personal/coaching-tree.js +++ /dev/null @@ -1,33 +0,0 @@ -jQuery(document).ready(function () { - if (window.wpApiShare.url_path.startsWith('metrics/personal/coaching-tree')) { - coaching_tree(); - } - - function coaching_tree() { - 'use strict'; - let chart = jQuery('#chart'); - let spinner = ' '; - chart.empty().html(spinner); - jQuery('#metrics-sidemenu').foundation('down', jQuery('#personal-menu')); - - let translations = window.dtMetricsProject.data.translations; - - chart.empty().html(` - ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_coaching_tree)}
    -
    -
    -
    ${spinner}
    -
    -
    - -

    - `); - - window.makeRequest('POST', 'metrics/my/coaching_tree').then((response) => { - // console.log(response) - jQuery('#generation_map').empty().html(response); - jQuery('#generation_map li:last-child').addClass('last'); - new window.Foundation.Reveal(jQuery('#modal')); - }); - } -}); diff --git a/dt-metrics/personal/coaching-tree.php b/dt-metrics/personal/coaching-tree.php deleted file mode 100644 index 28926bd6de..0000000000 --- a/dt-metrics/personal/coaching-tree.php +++ /dev/null @@ -1,175 +0,0 @@ -has_permission() ){ - return; - } - $this->title = __( 'My Coaching Tree', 'disciple_tools' ); - $this->base_title = __( 'Personal', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - - $this->namespace = "dt-metrics/$this->base_slug/$this->slug"; - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function scripts() { - wp_enqueue_script( 'dt_metrics_project_script', get_template_directory_uri() . $this->js_file_name, [ - 'jquery', - 'lodash' - ], filemtime( get_theme_file_path() . $this->js_file_name ), true ); - - wp_localize_script( - 'dt_metrics_project_script', 'dtMetricsProject', [ - 'root' => esc_url_raw( rest_url() ), - 'theme_uri' => get_template_directory_uri(), - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'current_user_login' => wp_get_current_user()->user_login, - 'current_user_id' => get_current_user_id(), - 'data' => $this->data(), - ] - ); - } - - public function data() { - return [ - 'translations' => [ - 'title_coaching_tree' => __( 'My Coaching Generation Tree', 'disciple_tools' ), - ], - ]; - } - - public function add_api_routes() { - $version = '1'; - $namespace = 'dt/v' . $version; - register_rest_route( - $namespace, '/metrics/my/coaching_tree', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'tree' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function tree( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - return $this->get_baptism_generations_tree(); - } - - public function get_baptism_generations_tree(){ - global $wpdb; - $user = wp_get_current_user(); - $coached_contacts_shared_with_me = $wpdb->get_results( $wpdb->prepare( " - SELECT s.post_id FROM $wpdb->p2p p2p - INNER JOIN $wpdb->dt_share s ON ( s.post_id = p2p.p2p_from && s.user_id = %s ) - WHERE p2p.p2p_type = 'contacts_to_contacts' - ", $user->ID ), ARRAY_A - ); - - foreach ( $coached_contacts_shared_with_me as $l ){ - $this->my_list[] = (int) $l['post_id']; - } - - $query = dt_queries()->tree( 'multiplying_coaching_only' ); - if ( is_wp_error( $query ) ){ - return $this->_circular_structure_error( $query ); - } - if ( empty( $query ) ) { - return $this->_no_results(); - } - $contact_id = Disciple_Tools_Users::get_contact_for_user( get_current_user_id() ); - $this->my_list[] = $contact_id; - $node = [ - 'parent_id' => 0, - 'id' => $contact_id, - 'name' => $user->display_name - ]; - //Stream of baptisms starting with me. - $query = array_merge( [ $node ], dt_queries()->get_node_descendants( $query, [ $contact_id ] ) ); - $menu_data = $this->prepare_menu_array( $query ); - - if ( count( $menu_data['parents'] ) <= 1 ) { - return $this->_no_results(); - } - - return $this->build_menu( 0, $menu_data, -1 ); - } - - public function build_menu( $parent_id, $menu_data, $gen, $unique_check = [] ) { - $html = ''; - - if ( isset( $menu_data['parents'][$parent_id] ) ) - { - $gen++; - - $first_section = ''; - if ( $gen === 0 ) { - $first_section = 'first-section'; - } - - $html = ''; - - } - return $html; - } - - public function prepare_menu_array( $query ) { - // prepare special array with parent-child relations - $menu_data = array( - 'items' => array(), - 'parents' => array() - ); - - foreach ( $query as $menu_item ) - { - $menu_data['items'][$menu_item['id']] = $menu_item; - $menu_data['parents'][$menu_item['parent_id']][] = $menu_item['id']; - } - return $menu_data; - } -} -new DT_Metrics_Personal_Coaching_Tree(); diff --git a/dt-metrics/personal/group-tree.js b/dt-metrics/personal/group-tree.js deleted file mode 100644 index 9c412b3958..0000000000 --- a/dt-metrics/personal/group-tree.js +++ /dev/null @@ -1,124 +0,0 @@ -'use strict'; -jQuery(document).ready(function () { - if (window.wpApiShare.url_path.startsWith('metrics/personal/group-tree')) { - group_tree(); - } - - function group_tree() { - let chart = jQuery('#chart'); - let spinner = ' '; - - chart.empty().html(spinner); - jQuery('#metrics-sidemenu').foundation('down', jQuery('#personal-menu')); - - let translations = window.dtMetricsProject.data.translations; - - chart.empty().html(` - ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_group_tree)}
    -
    -
    - - - - - - -
    -
    -
    -
    -
    - -

    - `); - - window.makeRequest('POST', 'metrics/my/group_tree').then((response) => { - // console.log(response) - jQuery('#generation_map').empty().html(response); - jQuery('#generation_map li:last-child').addClass('last'); - new window.Foundation.Reveal(jQuery('#modal')); - }); - } -}); - -function open_modal_details(id) { - let modal = jQuery('#modal'); - let spinner = ' '; - let translations = window.dtMetricsProject.data.translations; - - modal.empty().html(spinner).foundation('open'); - - window - .makeRequest('GET', 'groups/' + id, null, 'dt-posts/v2/') - .then((data) => { - // console.log(data) - if (data) { - let list = - '
    ' + - window.SHAREDFUNCTIONS.escapeHTML(translations.members) + - '
    '; - let content = ` -
    -
    ${window.SHAREDFUNCTIONS.escapeHTML(data.title)}
    -
    -
    -
    ${window.SHAREDFUNCTIONS.escapeHTML(translations.status) /*Status*/}: ${window.SHAREDFUNCTIONS.escapeHTML(data.group_status.label)}
    -
    ${window.SHAREDFUNCTIONS.escapeHTML(translations.assigned_to) /*Assigned to*/}: ${window.SHAREDFUNCTIONS.escapeHTML(assigned_to)}
    -
    ${window.SHAREDFUNCTIONS.escapeHTML(translations.total_members) /*Total Members*/}: ${window.SHAREDFUNCTIONS.escapeHTML(data.member_count)}
    - ${list} -
    -
    - -
    - - `; - modal.empty().html(content); - } - }); -} - -function toggle_multiplying_only() { - let list = jQuery('#generation_map .li-gen-1:not(:has(li.li-gen-2))'); - let button = jQuery('#multiplying-only'); - if (button.hasClass('hollow')) { - list.hide(); - button.removeClass('hollow'); - } else { - button.addClass('hollow'); - list.show(); - } -} - -function highlight_active() { - let list = jQuery('.inactive'); - let button = jQuery('#highlight-active'); - if (button.hasClass('hollow')) { - list.addClass('inactive-gray'); - button.removeClass('hollow'); - } else { - button.addClass('hollow'); - list.removeClass('inactive-gray'); - } -} - -function highlight_churches() { - let list = jQuery('#generation_map span:not(.church)'); - let button = jQuery('#highlight-churches'); - if (button.hasClass('hollow')) { - list.addClass('not-church-gray'); - button.removeClass('hollow'); - } else { - button.addClass('hollow'); - list.removeClass('not-church-gray'); - } -} diff --git a/dt-metrics/personal/group-tree.php b/dt-metrics/personal/group-tree.php deleted file mode 100644 index 4ed2aee007..0000000000 --- a/dt-metrics/personal/group-tree.php +++ /dev/null @@ -1,177 +0,0 @@ -has_permission() ){ - return; - } - $this->base_title = __( 'Personal', 'disciple_tools' ); - $this->title = __( 'My Groups Tree', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - - $this->namespace = "dt-metrics/$this->base_slug/$this->slug"; - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function add_api_routes() { - - $version = '1'; - $namespace = 'dt/v' . $version; - register_rest_route( - $namespace, '/metrics/my/group_tree', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'tree' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function tree( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - return $this->get_group_generations_tree(); - } - - public function scripts() { - wp_enqueue_script( 'dt_metrics_project_script', get_template_directory_uri() . $this->js_file_name, [ - 'jquery', - 'lodash' - ], filemtime( get_theme_file_path() . $this->js_file_name ), true ); - - wp_localize_script( - 'dt_metrics_project_script', 'dtMetricsProject', [ - 'root' => esc_url_raw( rest_url() ), - 'theme_uri' => get_template_directory_uri(), - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'current_user_login' => wp_get_current_user()->user_login, - 'current_user_id' => get_current_user_id(), - 'map_key' => empty( DT_Mapbox_API::get_key() ) ? '' : DT_Mapbox_API::get_key(), - 'data' => $this->data(), - ] - ); - } - - public function data() { - return [ - 'translations' => [ - 'title_group_tree' => __( 'My Group Generation Tree', 'disciple_tools' ), - 'highlight_active' => __( 'Highlight Active', 'disciple_tools' ), - 'highlight_churches' => __( 'Highlight Churches', 'disciple_tools' ), - 'members' => __( 'Members', 'disciple_tools' ), - 'view_record' => __( 'View Record', 'disciple_tools' ), - 'assigned_to' => __( 'Assigned To', 'disciple_tools' ), - 'status' => __( 'Status', 'disciple_tools' ), - 'total_members' => __( 'Total Members', 'disciple_tools' ), - 'view_group' => __( 'View Group', 'disciple_tools' ), - ], - ]; - } - - public function get_group_generations_tree(){ - global $wpdb; - $user = wp_get_current_user(); - $generational_groups_shared_with_me = $wpdb->get_results( $wpdb->prepare( " - SELECT s.post_id FROM $wpdb->p2p p2p - INNER JOIN $wpdb->dt_share s ON ( ( s.post_id = p2p.p2p_from OR s.post_id = p2p.p2p_to ) && s.user_id = %s ) - WHERE p2p.p2p_type = 'groups_to_groups' - ", $user->ID ), ARRAY_A - ); - - foreach ( $generational_groups_shared_with_me as $l ){ - $this->my_list[] = (int) $l['post_id']; - } - - $query = dt_queries()->tree( 'multiplying_groups_only' ); - if ( is_wp_error( $query ) ){ - return $this->_circular_structure_error( $query ); - } - if ( empty( $query ) ) { - return $this->_no_results(); - } - $menu_data = $this->prepare_menu_array( $query ); - - foreach ( $menu_data['parents'] as $parent_id => $parent ) { - if ( !in_array( $parent_id, $this->my_list ) && 0 !== $parent_id ) { - unset( $menu_data['parents'][$parent_id] ); - unset( $menu_data['parents'][0][array_search( $parent_id, $menu_data['parents'][0] )] ); - } - } - if ( count( $menu_data['parents'] ) <= 1 ) { - return $this->_no_results(); - } - - return $this->build_group_tree( 0, $menu_data, 0 ); - } - - public function prepare_menu_array( $query ) { - // prepare special array with parent-child relations - $menu_data = array( - 'items' => array(), - 'parents' => array() - ); - - foreach ( $query as $menu_item ) - { - $menu_data['items'][$menu_item['id']] = $menu_item; - $menu_data['parents'][$menu_item['parent_id']][] = $menu_item['id']; - } - return $menu_data; - } - - public function build_group_tree( $parent_id, $menu_data, $gen ) { - $html = ''; - - if ( isset( $menu_data['parents'][$parent_id] ) ) - { - $first_section = ''; - if ( $gen === 0 ) { - $first_section = 'first-section'; - } - - $html = ''; - - } - return $html; - } -} -new DT_Metrics_Personal_Groups_Tree(); diff --git a/dt-metrics/personal/mapbox-contacts-maps.php b/dt-metrics/personal/mapbox-contacts-maps.php deleted file mode 100644 index 36c2a59ab7..0000000000 --- a/dt-metrics/personal/mapbox-contacts-maps.php +++ /dev/null @@ -1,190 +0,0 @@ - [ 'me' ] ]; - - public function __construct() { - parent::__construct(); - if ( !$this->has_permission() ){ - return; - } - $this->title = __( 'Contacts Maps', 'disciple_tools' ); - $this->base_title = __( 'Contacts', 'disciple_tools' ); - - $modules = dt_get_option( 'dt_post_type_modules' ); - - if ( !empty( $modules['access_module']['enabled'] ) ){ - $this->base_filter = [ [ [ 'type' => [ 'access' ], 'assigned_to' => [ 'me' ], 'overall_status' => [ '-closed' ] ], [ 'type' => [ 'connection', 'personal' ], 'shared_with' => [ 'me' ] ] ] ]; - } - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function scripts() { - DT_Mapbox_API::load_mapbox_header_scripts(); - // Map starter Script - wp_enqueue_script( 'dt_mapbox_script', - get_template_directory_uri() . $this->js_file_name, - [ - 'jquery', - 'lodash' - ], - filemtime( get_theme_file_path() . $this->js_file_name ), - true - ); - wp_localize_script( - 'dt_mapbox_script', 'dt_mapbox_metrics', [ - 'translations' => [], - 'settings' => [ - 'map_key' => DT_Mapbox_API::get_key(), - 'no_map_key_msg' => _x( 'To view this map, a mapbox key is needed; click here to add.', 'install mapbox key to view map', 'disciple_tools' ), - 'map_mirror' => dt_get_location_grid_mirror( true ), - 'menu_slug' => $this->base_slug, - 'post_type' => $this->post_type, - 'title' => $this->title, - 'geocoder_url' => trailingslashit( get_stylesheet_directory_uri() ), - 'geocoder_nonce' => wp_create_nonce( 'wp_rest' ), - 'rest_base_url' => $this->namespace, - 'rest_url' => 'cluster_geojson', - 'totals_rest_url' => 'get_grid_totals', - 'list_by_grid_rest_url' => 'get_list_by_grid_id', - 'points_rest_url' => 'points_geojson', - ], - ] - ); - } - - public function add_api_routes() { - register_rest_route( - $this->namespace, '/cluster_geojson', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'cluster_geojson' ], - 'permission_callback' => '__return_true', - ], - ] - ); - register_rest_route( - $this->namespace, '/get_grid_totals', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'get_grid_totals' ], - 'permission_callback' => '__return_true', - ], - ] - ); - register_rest_route( - $this->namespace, '/get_list_by_grid_id', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'get_list_by_grid_id' ], - 'permission_callback' => '__return_true', - ], - ] - ); - register_rest_route( - $this->namespace, '/points_geojson', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'points_geojson' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function cluster_geojson( WP_REST_Request $request ) { - if ( ! $this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['post_type'] ) || empty( $params['post_type'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - $offset = !empty( $params['offset'] ) ? $params['offset'] : 0; - $limit = !empty( $params['limit'] ) ? $params['limit'] : 50000; - - return Disciple_Tools_Mapping_Queries::cluster_geojson( $post_type, $query, $offset, $limit ); - } - - - - public function get_grid_totals( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['post_type'] ) || empty( $params['post_type'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - $results = Disciple_Tools_Mapping_Queries::query_location_grid_meta_totals( $post_type, $query ); - - $list = []; - foreach ( $results as $result ) { - $list[$result['grid_id']] = $result; - } - - return $list; - } - - public function get_list_by_grid_id( WP_REST_Request $request ) { - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['grid_id'] ) || empty( $params['grid_id'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $grid_id = sanitize_text_field( wp_unslash( $params['grid_id'] ) ); - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - - return Disciple_Tools_Mapping_Queries::query_under_location_grid_meta_id( $post_type, $grid_id, $query ); - } - - - /** - * Points - */ - public function points_geojson( WP_REST_Request $request ) { - if ( ! $this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['post_type'] ) || empty( $params['post_type'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - - return Disciple_Tools_Mapping_Queries::points_geojson( $post_type, $query ); - } -} -new DT_Metrics_Mapbox_Personal_Contacts_Maps(); diff --git a/dt-metrics/personal/mapbox-groups-maps.php b/dt-metrics/personal/mapbox-groups-maps.php deleted file mode 100644 index 7b88a8a13c..0000000000 --- a/dt-metrics/personal/mapbox-groups-maps.php +++ /dev/null @@ -1,184 +0,0 @@ - [ 'me' ] ]; - - public function __construct() { - parent::__construct(); - if ( !$this->has_permission() ){ - return; - } - $this->title = __( 'Groups Maps', 'disciple_tools' ); - $this->base_title = __( 'Groups', 'disciple_tools' ); - - $url_path = dt_get_url_path( true ); - if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { - add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); - } - add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); - } - - public function scripts() { - DT_Mapbox_API::load_mapbox_header_scripts(); - // Map starter Script - wp_enqueue_script( 'dt_mapbox_script', - get_template_directory_uri() . $this->js_file_name, - [ - 'jquery', - 'lodash' - ], - filemtime( get_theme_file_path() . $this->js_file_name ), - true - ); - wp_localize_script( - 'dt_mapbox_script', 'dt_mapbox_metrics', [ - 'translations' => [], - 'settings' => [ - 'map_key' => DT_Mapbox_API::get_key(), - 'no_map_key_msg' => _x( 'To view this map, a mapbox key is needed; click here to add.', 'install mapbox key to view map', 'disciple_tools' ), - 'map_mirror' => dt_get_location_grid_mirror( true ), - 'menu_slug' => $this->base_slug, - 'post_type' => $this->post_type, - 'title' => $this->title, - 'geocoder_url' => trailingslashit( get_stylesheet_directory_uri() ), - 'geocoder_nonce' => wp_create_nonce( 'wp_rest' ), - 'rest_base_url' => $this->namespace, - 'rest_url' => 'cluster_geojson', - 'totals_rest_url' => 'get_grid_totals', - 'list_by_grid_rest_url' => 'get_list_by_grid_id', - 'points_rest_url' => 'points_geojson', - ], - ] - ); - } - - public function add_api_routes() { - register_rest_route( - $this->namespace, '/cluster_geojson', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'cluster_geojson' ], - 'permission_callback' => '__return_true', - ], - ] - ); - register_rest_route( - $this->namespace, '/get_grid_totals', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'get_grid_totals' ], - 'permission_callback' => '__return_true', - ], - ] - ); - register_rest_route( - $this->namespace, '/get_list_by_grid_id', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'get_list_by_grid_id' ], - 'permission_callback' => '__return_true', - ], - ] - ); - register_rest_route( - $this->namespace, '/points_geojson', [ - [ - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => [ $this, 'points_geojson' ], - 'permission_callback' => '__return_true', - ], - ] - ); - } - - public function cluster_geojson( WP_REST_Request $request ) { - if ( ! $this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['post_type'] ) || empty( $params['post_type'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - $offset = !empty( $params['offset'] ) ? $params['offset'] : 0; - $limit = !empty( $params['limit'] ) ? $params['limit'] : 50000; - - return Disciple_Tools_Mapping_Queries::cluster_geojson( $post_type, $query, $offset, $limit ); - } - - - - public function get_grid_totals( WP_REST_Request $request ) { - if ( !$this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['post_type'] ) || empty( $params['post_type'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - $results = Disciple_Tools_Mapping_Queries::query_location_grid_meta_totals( $post_type, $query ); - - $list = []; - foreach ( $results as $result ) { - $list[$result['grid_id']] = $result; - } - - return $list; - } - - public function get_list_by_grid_id( WP_REST_Request $request ) { - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['grid_id'] ) || empty( $params['grid_id'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $grid_id = sanitize_text_field( wp_unslash( $params['grid_id'] ) ); - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - - return Disciple_Tools_Mapping_Queries::query_under_location_grid_meta_id( $post_type, $grid_id, $query ); - } - - - /** - * Points - */ - public function points_geojson( WP_REST_Request $request ) { - if ( ! $this->has_permission() ){ - return new WP_Error( __METHOD__, 'Missing Permissions', [ 'status' => 400 ] ); - } - - $params = $request->get_json_params() ?? $request->get_body_params(); - if ( ! isset( $params['post_type'] ) || empty( $params['post_type'] ) ) { - return new WP_Error( __METHOD__, 'Missing Post Types', [ 'status' => 400 ] ); - } - $post_type = $params['post_type']; - $query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; - $query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); - - return Disciple_Tools_Mapping_Queries::points_geojson( $post_type, $query ); - } -} -new DT_Metrics_Mapbox_Personal_Groups_Maps(); diff --git a/dt-metrics/personal/overview.js b/dt-metrics/personal/overview.js index 2d10b46fc5..8bbe8deef2 100644 --- a/dt-metrics/personal/overview.js +++ b/dt-metrics/personal/overview.js @@ -45,7 +45,8 @@ jQuery(function () {
    `; } - html += `

    ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_groups)}

    + if (sourceData.hero_stats) + html += `

    ${window.SHAREDFUNCTIONS.escapeHTML(translations.title_groups)}

    @@ -57,12 +58,16 @@ jQuery(function () {
    - - + `; + if (sourceData.group_types) { + html += `

    -
    + `; + } + if (sourceData.group_health && sourceData.group_generations) { + html += `
    @@ -72,8 +77,9 @@ jQuery(function () {
    -
    - `; + `; + } + html += ``; chartDiv.empty().html(html); @@ -89,13 +95,18 @@ jQuery(function () { // build charts drawMyContactsProgress(); } - if (sourceData.preferences.groups.church_metrics) { + if ( + sourceData.preferences.groups.church_metrics && + sourceData.group_health + ) { drawMyGroupHealth(); - } else { - jQuery('#my_groups_health_container').remove(); } - drawGroupTypes(); - drawGroupGenerations(); + if (sourceData.group_types) { + drawGroupTypes(); + } + if (sourceData.group_generations) { + drawGroupGenerations(); + } function drawMyContactsProgress() { let chart = window.am4core.create( diff --git a/dt-metrics/personal/overview.php b/dt-metrics/personal/overview.php index 2cc947c7ef..3ff4f4b681 100644 --- a/dt-metrics/personal/overview.php +++ b/dt-metrics/personal/overview.php @@ -88,14 +88,16 @@ public function overview() { $data = [ 'preferences' => $this->preferences(), 'hero_stats' => $this->chart_my_hero_stats(), - 'group_types' => $this->chart_group_types(), - 'group_health' => $this->chart_group_health(), - 'group_generations' => $this->chart_group_generations(), ]; $modules = dt_get_option( 'dt_post_type_modules' ); if ( !empty( $modules['access_module']['enabled'] ) ){ $data['contacts_progress'] = $this->chart_contacts_progress(); } + if ( !empty( $modules['groups_base']['enabled'] ) ){ + $data['group_types'] = $this->chart_group_types(); + $data['group_health'] = $this->chart_group_health(); + $data['group_generations'] = $this->chart_group_generations(); + } return apply_filters( 'dt_my_metrics', $data ); } diff --git a/dt-metrics/records/genmap.php b/dt-metrics/records/genmap.php index 98b5e594b1..bbade50529 100644 --- a/dt-metrics/records/genmap.php +++ b/dt-metrics/records/genmap.php @@ -259,7 +259,7 @@ public function get_genmap( $query, $depth_limit, $focus_id, $filters = [], $can return $this->_circular_structure_error( $query ); } if ( empty( $query ) ) { - return $this->_no_results(); + return []; } $menu_data = $this->prepare_menu_array( $query ); diff --git a/dt-posts/dt-posts.php b/dt-posts/dt-posts.php index eabf8b8c9c..80fa36443c 100644 --- a/dt-posts/dt-posts.php +++ b/dt-posts/dt-posts.php @@ -22,7 +22,7 @@ public function __construct() { ); public static function get_post_types(){ - return array_unique( apply_filters( 'dt_registered_post_types', [ 'contacts', 'groups' ] ) ); + return array_unique( apply_filters( 'dt_registered_post_types', [ 'contacts' ] ) ); } /**