Skip to content

Commit

Permalink
Merge pull request #553 from alicolville/evolve
Browse files Browse the repository at this point in the history
10.3.8
  • Loading branch information
alicolville authored May 20, 2023
2 parents cc67e55 + 076a58c commit 797941d
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 93 deletions.
3 changes: 2 additions & 1 deletion assets/js/data.footable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jQuery( document ).ready(function ( $, undefined ) {
'table_id': table_id,
'week': $( this ).data( 'week' ),
'bmi-format': $( this ).data( 'bmi-format' ),
'uikit': $( this ).data( 'uikit' )
'uikit': $( this ).data( 'uikit' ),
'name': $( this ).data( 'name' )
};

ws_ls_post_data_to_WP( 'table_data', data, ws_ls_callback_setup_table )
Expand Down
2 changes: 1 addition & 1 deletion assets/js/data.footable.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions includes/admin-pages/settings/page-settings-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ function ws_ls_settings_page_group() {
<input type="submit" value="<?php echo __('Add', WE_LS_SLUG); ?>" class="button" <?php if ( false === WS_LS_IS_PRO ) { echo ' disabled'; } ?> />
</form>

<?php

do_action( 'wlt-hook-custom-group-table' );

$enable_table = apply_filters( 'wlt-filters-admin-group-view-enabled', true );

if ( true === $enable_table ) { ?>
<h4><?php echo __('Existing groups', WE_LS_SLUG); ?></h4>

<table class="ws-ls-settings-groups-list-ajax table ws-ls-loading-table" id="groups-list"
Expand All @@ -55,7 +62,9 @@ function ws_ls_settings_page_group() {
data-toggle="true"
data-use-parent-width="true">
</table>
<?php }

?>
</div>
</div>

Expand Down
9 changes: 8 additions & 1 deletion includes/admin-pages/user-data/data-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ function ws_ls_admin_page_group_view() {
<input type="submit" value="<?php echo __('Edit', WE_LS_SLUG); ?>" class="button" <?php if ( false === WS_LS_IS_PRO ) { echo ' disabled'; } ?> />
</form>
<br />
<?php echo ws_ls_component_group_view_entries( [ 'group-id' => $group_id, 'enable-group-select' => false, 'uikit' => false ]); ;?>
<?php
do_action( 'wlt-hook-custom-user-entries-for-group-table' );

if ( true === (bool) apply_filters( 'wlt-filters-admin-entries-per-group-view-enabled', true ) ) {
echo ws_ls_component_group_view_entries( [ 'group-id' => $group_id, 'enable-group-select' => false, 'uikit' => false ]);
}

;?>
<p>
<a class="button-secondary" href="<?php echo admin_url( 'admin.php?page=ws-ls-settings&mode=groups' ); ?>">
<i class="fa fa-arrow-left"></i>
Expand Down
13 changes: 11 additions & 2 deletions includes/admin-pages/user-data/data-summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function ws_ls_admin_page_data_summary() {
do_action( 'wlt-hook-data-all-deleted' );
}

ws_ls_data_table_enqueue_scripts();
?>
<div class="wrap ws-ls-user-data ws-ls-admin-page">
<h1><?php echo __('Summary', WE_LS_SLUG); ?></h1>
Expand All @@ -29,6 +30,8 @@ function ws_ls_admin_page_data_summary() {

$user_summary_order = get_option( 'ws-ls-postbox-order-ws-ls-user-summary-one', [ 'league-table', 'weight-change-by-group', 'summary-entries' ] );

$user_summary_order = apply_filters( 'wlt-filters-postbox-order-ws-ls-user-summary-one', $user_summary_order );

foreach ( $user_summary_order as $postbox ) {

if ( 'league-table' === $postbox ) {
Expand All @@ -37,6 +40,10 @@ function ws_ls_admin_page_data_summary() {
ws_ls_postbox_change_by_groups();
} elseif ( 'summary-entries' === $postbox ) {
ws_ls_postbox_latest_entries();
} else {
if ( true === function_exists( 'ws_ls_postbox_' . $postbox ) ) {
call_user_func( 'ws_ls_postbox_' . $postbox ) ;
}
}
}
?>
Expand All @@ -48,6 +55,8 @@ function ws_ls_admin_page_data_summary() {

$user_summary_order = get_option( 'ws-ls-postbox-order-ws-ls-user-summary-two', [ 'user-search', 'quick-stats', 'view-all', 'export', 'delete-data' ] );

$user_summary_order = apply_filters( 'wlt-filters-postbox-order-ws-ls-user-summary-two', $user_summary_order );

foreach ( $user_summary_order as $postbox ) {

if ( 'user-search' === $postbox ) {
Expand Down Expand Up @@ -139,11 +148,11 @@ function ws_ls_postbox_export() {
<div class="postbox <?php ws_ls_postbox_classes( 'export', 'ws-ls-user-summary-two' ); ?>" id="export">
<?php ws_ls_postbox_header( [ 'title' => __( 'Export all data', WE_LS_SLUG ), 'postbox-id' => 'export', 'postbox-col' => 'ws-ls-user-summary-two' ] ); ?>
<div class="inside">
<a class="button-secondary" href="<?php echo ws_ls_export_link('new', [ 'format' => 'csv', 'title' => __( 'All Data', WE_LS_SLUG ) ] ); ?>">
<a class="button-secondary button-wt-to-excel" href="<?php echo ws_ls_export_link('new', [ 'format' => 'csv', 'title' => __( 'All Data', WE_LS_SLUG ) ] ); ?>">
<i class="fa fa-file-excel-o"></i>
<?php echo __('To CSV', WE_LS_SLUG); ?>
</a>
<a class="button-secondary" href="<?php echo ws_ls_export_link('new', [ 'format' => 'json', 'title' => __( 'All Data', WE_LS_SLUG ) ] ); ?>">
<a class="button-secondary button-wt-to-json" href="<?php echo ws_ls_export_link('new', [ 'format' => 'json', 'title' => __( 'All Data', WE_LS_SLUG ) ] ); ?>">
<i class="fa fa-file-code-o"></i>
<?php echo __('To JSON', WE_LS_SLUG); ?>
</a>
Expand Down
24 changes: 21 additions & 3 deletions includes/admin-pages/user-data/data-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function ws_ls_admin_page_data_user() {
unset( $user_order[ 'photos' ] );
}

$user_order = apply_filters( 'wlt-filters-postbox-order-ws-ls-user-data-one', $user_order );

foreach ( $user_order as $postbox ) {

if ( 'chart' === $postbox ) {
Expand All @@ -74,14 +76,24 @@ function ws_ls_admin_page_data_user() {
ws_ls_postbox_awards( $user_id );
} elseif ( 'user-entries' === $postbox ) {
ws_ls_postbox_user_entries( $user_id );
}
} else {
if ( true === function_exists( 'ws_ls_postbox_' . $postbox ) ) {
call_user_func( 'ws_ls_postbox_' . $postbox ) ;
}
}
}

?>
</div>
</div>
<div id="postbox-container-1" class="postbox-container">
<?php ws_ls_user_side_bar( $user_id ); ?>
<?php
if ( true === (bool) apply_filters( 'wlt-filters-admin-show-standard-sidebar', true ) ) {
ws_ls_user_side_bar( $user_id );
}

do_action( 'wlt-actions-admin-sidebar' );
?>
</div>
</div>
<br class="clear">
Expand Down Expand Up @@ -292,7 +304,13 @@ function ws_ls_postbox_user_entries( $user_id ) {
<div class="postbox <?php ws_ls_postbox_classes( 'user-entries', 'ws-ls-user-data-one' ); ?>" id="user-entries">
<?php ws_ls_postbox_header( [ 'title' => __( 'Entries for this user', WE_LS_SLUG ), 'postbox-id' => 'user-entries', 'postbox-col' => 'ws-ls-user-data-one' ] ); ?>
<div class="inside">
<?php echo ws_ls_data_table_render( [ 'smaller-width' => true, 'user-id' => $user_id, 'bmi-format' => 'both' ] ); ?>
<?php

$bmi_enabled = apply_filters( 'wlt-filter-admin-user-entries-enable-bmi', true );

echo ws_ls_data_table_render( [ 'smaller-width' => true, 'user-id' => $user_id, 'bmi-format' => 'both', 'enable-bmi' => $bmi_enabled, 'name' => 'user-entries-data-home' ] );

?>
</div>
</div>
<?php
Expand Down
107 changes: 56 additions & 51 deletions includes/admin-pages/user-data/data-view-all.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ function ws_ls_admin_page_view_all() {

ws_ls_permission_check_message();

?>
$title = apply_filters( 'wlt-filter-view-all-title', __( 'View All Data', WE_LS_SLUG ) );
?>
<div class="wrap ws-ls-user-data ws-ls-admin-page">
<h1><?php echo __('View All Data', WE_LS_SLUG); ?></h1>
<h1><?php echo $title; ?></h1>
<div id="poststuff">
<div id="post-body" class="metabox-holder">
<div id="post-body-content">
Expand All @@ -20,57 +21,61 @@ function ws_ls_admin_page_view_all() {
?>
<div class="postbox">

<h2 class="hndle"><span><?php echo __('View All Data', WE_LS_SLUG); ?></span></h2>
<h2 class="hndle"><span><?php echo $title; ?></span></h2>

<div class="inside">
<?php

$entry_counts = ws_ls_db_entries_count();

if(false === empty($entry_counts)) {

echo sprintf('
<p>
<strong>%s:</strong> %s | <strong>%s:</strong> %s | <strong>%s:</strong> %s |
<a href="%s">%s</a> | <a href="%s">%s</a>
</p>',
__('Number of WordPress users', WE_LS_SLUG),
ws_ls_round_number( $entry_counts['number-of-users'] ),
__('Number of weight entries', WE_LS_SLUG),
ws_ls_round_number( $entry_counts['number-of-entries'] ),
__('Number of targets entered', WE_LS_SLUG),
ws_ls_round_number( $entry_counts['number-of-targets'] ),
ws_ls_get_link_to_export(),
__('Export to CSV', WE_LS_SLUG),
ws_ls_get_link_to_export('json'),
__('Export to JSON', WE_LS_SLUG)
);
}

if ( $entry_counts['number-of-entries'] > 5000 ) {
printf( '<p class="ws-ls-validation-error"><strong>%s</strong></p>', __( 'For performance reasons, the following table shall be restricted to a maximum of 5000 entries. For more data, please view individual user records.' ) );
}

// Show meta data?
if( false === empty( $_GET['show-meta'] ) ) {
$value = ( 'y' === $_GET['show-meta'] ) ? true : false;
update_option('ws-ls-show-meta', $value );
}

$show_meta = get_option( 'ws-ls-show-meta' ) ? true : false;

echo ws_ls_data_table_render( [ 'limit' => 5000, 'enable-meta-fields' => $show_meta ] );

if ( ws_ls_meta_fields_number_of_enabled() > 0 ) {

echo sprintf(
'&nbsp;<a class="btn button-secondary" href="%s"><i class="fas fa-book-reader"></i> %s</a>',
admin_url( 'admin.php?page=ws-ls-data-home&mode=all&show-meta=' ) . ( ( false === $show_meta ) ? 'y' : 'n'),
( false === $show_meta ) ? __( 'Include Custom Fields (Slower)', WE_LS_SLUG ) : __( 'Hide Custom Fields (Quicker)', WE_LS_SLUG )
);

}

<?php

do_action( 'wlt-hook-view-all-table' );

if( true=== (bool) apply_filters( 'wlt-filters-admin-view-all-enabled', true ) ) {

$entry_counts = ws_ls_db_entries_count();

if ( false === empty( $entry_counts ) ) {

echo sprintf( '
<p>
<strong>%s:</strong> %s | <strong>%s:</strong> %s | <strong>%s:</strong> %s |
<a href="%s">%s</a> | <a href="%s">%s</a>
</p>',
__( 'Number of WordPress users', WE_LS_SLUG ),
ws_ls_round_number( $entry_counts['number-of-users'] ),
__( 'Number of weight entries', WE_LS_SLUG ),
ws_ls_round_number( $entry_counts['number-of-entries'] ),
__( 'Number of targets entered', WE_LS_SLUG ),
ws_ls_round_number( $entry_counts['number-of-targets'] ),
ws_ls_get_link_to_export(),
__( 'Export to CSV', WE_LS_SLUG ),
ws_ls_get_link_to_export( 'json' ),
__( 'Export to JSON', WE_LS_SLUG )
);
}

if ( $entry_counts['number-of-entries'] > 5000 ) {
printf( '<p class="ws-ls-validation-error"><strong>%s</strong></p>', __( 'For performance reasons, the following table shall be restricted to a maximum of 5000 entries. For more data, please view individual user records.' ) );
}

// Show meta data?
if ( false === empty( $_GET['show-meta'] ) ) {
$value = ( 'y' === $_GET['show-meta'] ) ? true : false;
update_option( 'ws-ls-show-meta', $value );
}

$show_meta = get_option( 'ws-ls-show-meta' ) ? true : false;

echo ws_ls_data_table_render( [ 'limit' => 5000, 'enable-meta-fields' => $show_meta ] );

if ( ws_ls_meta_fields_number_of_enabled() > 0 ) {

echo sprintf(
'&nbsp;<a class="btn button-secondary" href="%s"><i class="fas fa-book-reader"></i> %s</a>',
admin_url( 'admin.php?page=ws-ls-data-home&mode=all&show-meta=' ) . ( ( false === $show_meta ) ? 'y' : 'n' ),
( false === $show_meta ) ? __( 'Include Custom Fields (Slower)', WE_LS_SLUG ) : __( 'Hide Custom Fields (Quicker)', WE_LS_SLUG )
);

}
}
?>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions includes/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ function ws_ls_get_table_data() {
'table_id' => $table_id
];

$data = apply_filters( 'wlt-filter-user-table-data', $data, $front_end );

wp_send_json( $data );
}
add_action( 'wp_ajax_table_data', 'ws_ls_get_table_data' );
Expand Down
5 changes: 5 additions & 0 deletions includes/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,14 @@ function ws_ls_db_create_core_tables() {

$sql = "CREATE TABLE $table_name (
user_id integer NOT NULL,
group_id integer NULL,
week_count integer NULL,
start_weight float DEFAULT 0 NULL,
previous_weight float DEFAULT 0 NULL,
recent_weight float DEFAULT 0 NULL,
recent_weight_date datetime NULL,
weight_difference float DEFAULT 0 NULL,
weight_difference_previous float DEFAULT 0 NULL,
sum_of_weights float DEFAULT 0 NULL,
no_entries integer DEFAULT 0 NULL,
target_added integer DEFAULT 0 NULL,
Expand Down
2 changes: 2 additions & 0 deletions includes/form-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function ws_ls_form_post_handler_target( $user_id ) {

do_action( 'wlt-hook-data-added-edited', [ 'user-id' => $user_id, 'type' => 'target', 'mode' => 'update' ], [ 'kg' => $kg ] );

ws_ls_stats_update_for_user( $user_id );

return ( false !== ws_ls_db_target_set( $user_id, $kg ) );
}

Expand Down
23 changes: 21 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,35 @@ function ws_ls_entry_get_latest_kg( $user_id = NULL ) {
*/
function ws_ls_entry_get_previous( $arguments = [] ) {

$arguments = wp_parse_args( $arguments, [ 'user-id' => get_current_user_id(), 'meta' => true ] );
$arguments = wp_parse_args( $arguments, [ 'user-id' => get_current_user_id(), 'meta' => true, 'kg-only' => false ] );
$arguments[ 'id' ] = ws_ls_db_entry_previous( $arguments );

if ( true === empty( $arguments[ 'id' ] ) ) {
return NULL;
}

return ws_ls_entry_get( $arguments );
$previous_entry = ws_ls_entry_get( $arguments );

return ( true === $arguments[ 'kg-only'] &&
false === empty( $previous_entry[ 'kg' ] ) ) ?
$previous_entry[ 'kg' ] :
$previous_entry;
}

/**
* Return Kg for previous weight
* @param $user_id
*
* @return string|null
*/
function ws_ls_entry_get_previous_kg( $user_id = NULL ) {

$user_id = ( NULL === $user_id ) ? get_current_user_id() : $user_id;

return ws_ls_entry_get_previous( [ 'user-id' => $user_id, 'meta' => false, 'kg-only' => true ] );
}


/**
* DEPRECATED: replace with ws_ls_to_bool()
*
Expand Down
Loading

0 comments on commit 797941d

Please sign in to comment.