Forum Replies Created

Viewing 15 replies - 76 through 90 (of 274 total)
  • Plugin Author ka2

    (@ka2)

    Thank you for your inquiry.

    Yes, your hope can be achieved in this plugin.
    As an example, I will propose the structure, such as the following.

    Table for multiusers:

    CREATE TABLE user_data (
      ID bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
      user_id bigint(20) unsigned NOT NULL,
      username varchar(100) NOT NULL,
      profile text,
      created datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Created Datetime',
      updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated Datetime',
      PRIMARY KEY (<code>ID</code>)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

    Shortcode to entry data page:

    [cdbt-entry table="user_data" bootstrap_style="true" display_title="true" hidden_cols="created"]

    Filter for entry forms:

    function my_shortcode_custom_forms( $elements_options, $shortcode_name, $table ){
      if ( ! is_admin() && 'cdbt-entry' === $shortcode_name && 'user_data' === $table ) {
        $_current_user_id = 0; // For guest user
        if ( is_user_logged_in() ) {
          $current_user = wp_get_current_user();
          $_current_user_id = $current_user->ID;
        }
        foreach ( $elements_options as $_i => $_option ) {
          if ( 'user_id' === $_option['elementName'] ) {
            $elements_options[$_i]['elementType'] = 'hidden';
            $elements_options[$_i]['defaultValue'] = $_current_user_id;
          }
        }
      }
      return $elements_options;
    }
    add_filter( 'cdbt_shortcode_custom_forms', 'my_shortcode_custom_forms', 10, 3 );

    Shortcode of viewing only data of specific user:

    [cdbt-view table="user_data" exclude_cols="ID,user_id,created,updated"]

    Filter for viewing specific user data only:

    function custom_filter_get_data_sql( $sql, $table_name, $sql_clauses ) {
      if ( ! is_admin() && 'user_data' === $table_name ) {
        $_current_user_id = 0; // For guest user
        if ( is_user_logged_in() ) {
          $current_user = wp_get_current_user();
          $_current_user_id = $current_user->ID;
        }
        $_new_sql = <<<SQL
    SELECT %s
    FROM %s
    WHERE user_id=%s
    %s %s
    SQL;
    	$sql = sprintf( $_new_sql, $sql_clauses[0], $table_name, $_current_user_id, $sql_clauses[2], $sql_clauses[3] );
      }
      return $sql;
    }
    add_filter( 'cdbt_crud_get_data_sql', 'custom_filter_get_data_sql', 10, 3 );

    Please try to refer.

    Thank you,

    Plugin Author ka2

    (@ka2)

    Yes, please make new issue about photo link.

    Plugin Author ka2

    (@ka2)

    Thank you for your inquiry.

    You will be able to allow specific user to any shortcode if you use a “cdbt_after_shortcode_permit” filter. The describe of that filter is here (for Japanese only, sorry).

    For example, if you want to allow access to any shortcode to the only logged in user (ex. user ID is “2”), it is as following:

    shortcode on the post:

    [cdbt-view table="prefix_table"]

    added filter:

    function my_after_shortcode_permit( $result_permit, $shortcode_name, $table ){
      if ( 'cdbt-view' === $shortcode_name && 'prefix_table' === $table ) {
        if ( is_user_logged_in() ) {
          $current_user = wp_get_current_user();
          if ( $current_user->ID == 2 ) {
            $result_permit = true;
          } else {
            $result_permit = false;
          }
        }
    
      }
      return $result_permit;
    }
    add_filter( 'cdbt_after_shortcode_permit', 'my_after_shortcode_permit', 10, 3 );

    Thank you,

    Plugin Author ka2

    (@ka2)

    I am very sorry, “sort_order” in the attributes of the shortcode to filter had leaked. Correct shortcode is as follows:

    [cdbt-view table="wp_tips" display_title="false" order_cols="ID" sort_order="ID:asc"]

    I could finally confirm the operating by configuration of the table, the shortcode and the filters such as the following.

    Table structure:

    CREATE TABLE wp_tips (
      ID bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
      username varchar(100) NOT NULL,
      date_time datetime DEFAULT NULL,
      league varchar(255) DEFAULT NULL,
      match varchar(255) DEFAULT NULL,
      tip varchar(10) DEFAULT NULL,
      odds float(6,2) DEFAULT NULL,
      book varchar(10) DEFAULT NULL,
      win_loss varchar(4) DEFAULT NULL,
      PRIMARY KEY (ID)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4

    Display table in main page:

    [cdbt-view table="wp_tips" display_title="false" exclude_cols="ID,username"]

    Display table in other page (post id = 23):

    [cdbt-view table="wp_tips" display_title="false" order_cols="ID" sort_order="ID:asc"]

    Code of filter hooks into the “functions.php” at the theme:

    if ( ! is_admin() ) :
    
    function wp_tips_get_data_sql( $sql, $table_name, $sql_clauses ) {
      if ( get_post()->ID === 23 && 'wp_tips' === $table_name ) {
        $_overwrite_sql = <<< SQL
    SELECT
        count(id) AS BETS,
        Sum(IF(win_loss = 'win', 1, 0)) As Wins,
        Sum(IF(win_loss = 'loss', 1, 0)) As Looses,
        Sum(IF(win_loss = 'void',1, 0)) AS Void
    FROM %s ;
    SQL;
    
    $sql = sprintf( $_overwrite_sql, $table_name );
      }
      return $sql;
    }
    add_filter( 'cdbt_crud_get_data_sql', 'wp_tips_get_data_sql', 10, 3 );
    
    function wp_tips_shortcode_custom_columns( $columns, $shortcode_name, $table ){
      if ( get_post()->ID === 23 && 'cdbt-view' === $shortcode_name && 'wp_tips' === $table ) {
        $columns = [];
        $columns[] = [
          'label' => 'BETS',
          'property' => 'BETS',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
        $columns[] = [
          'label' => 'Wins',
          'property' => 'Wins',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
         $columns[] = [
          'label' => 'Looses',
          'property' => 'Looses',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
         $columns[] = [
          'label' => 'Void',
          'property' => 'Void',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
      }
      return $columns;
    }
    add_filter( 'cdbt_shortcode_custom_columns', 'wp_tips_shortcode_custom_columns', 10, 3 );
    
    endif;

    Thank you,

    Plugin Author ka2

    (@ka2)

    Thank you for providing a code, however I could not found a problem in your code.

    Please try to change as following. Then you still will not display the original table structure in the table management screen?

    function wp_tips_get_data_sql( $sql, $table_name, $sql_clauses ) {
      if ( ! is_admin() && 'wp_tips' === $table_name ) {
        $_overwrite_sql = <<< SQL
    SELECT
        count(id) AS BETS,
        Sum(IF(win_loss = 'win', 1, 0)) As Wins,
        Sum(IF(win_loss = 'loss', 1, 0)) As Looses,
        Sum(IF(win_loss = 'void',1, 0)) AS Void
    
    FROM %s ;
    SQL;
    
    $sql = sprintf( $_overwrite_sql, $table_name );
      }
      return $sql;
    }
    add_filter( 'cdbt_crud_get_data_sql', 'wp_tips_get_data_sql', 10, 3 );
    
    function wp_tips_shortcode_custom_columns( $columns, $shortcode_name, $table ){
      if ( ! is_admin() && 'cdbt-view' === $shortcode_name && 'wp_tips' === $table ) {
        $columns = [];
        $columns[] = [
          'label' => 'BETS',
          'property' => 'BETS',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
        $columns[] = [
          'label' => 'Wins',
          'property' => 'Wins',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
         $columns[] = [
          'label' => 'Looses',
          'property' => 'Looses',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
         $columns[] = [
          'label' => 'Void',
          'property' => 'Void',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
      }
      return $columns;
    }
    add_filter( 'cdbt_shortcode_custom_columns', 'wp_tips_shortcode_custom_columns', 10, 3 );

    Thank you,

    Plugin Author ka2

    (@ka2)

    Hmm…
    Please show me source code that you have added in the “functions.php”.

    Thank you for taking care of it.

    Plugin Author ka2

    (@ka2)

    I’m glad to carry out a your wishes.

    Please enclose the filter hook by the conditional statement as shown below to disable the customization of the table output on the management screen:

    if ( ! is_admin() ) :
    
    function bc_tips_get_data_sql( $sql, $table_name, $sql_clauses ) {
    
    omission ...
    
    }
    add_filter( 'cdbt_crud_get_data_sql', 'bc_tips_get_data_sql', 10, 3 );
    
    function bc_tips_shortcode_custom_columns( $columns, $shortcode_name, $table ){
    
    omission ...
    
    }
    add_filter( 'cdbt_shortcode_custom_columns', 'bc_tips_shortcode_custom_columns', 10, 3 );
    
    endif;

    Thank you,

    Plugin Author ka2

    (@ka2)

    I tried the coexistence of “Relevanssi” plugin and “Custom DataBase Tables” plugin.
    As you say, it occurred an error of “header already sent” when I updated the post that contains the shortcodes of “Custom DataBase Tables” plugin.

    To avoid this problem, I unchecked of the “Expand shortcodes in post content” at the “Relevanssi Search Options” of the “Relevanssi” plugin, then I could be successfully updated without error.

    Thank you,

    Plugin Author ka2

    (@ka2)

    Your code has been leaked to add a function “custom_update_wpdt_stockmgmt” to the filter.
    Please add the following code to the end.

    add_filter( 'cdbt_before_update_data', 'custom_update_wpdt_stockmgmt', 10, 3 );

    Thank you,

    Plugin Author ka2

    (@ka2)

    I’m very sorry, it was a bug in plugin.

    It was a problem that can not be successfully retrieved data when hide the primary key column (such as “ID”) at “cdbt-edit”.

    I will release a modified plugin in the next version. Please wait.

    Thank you for taking the time to this matter.

    Plugin Author ka2

    (@ka2)

    Thank you very much for your prompt reply.

    Your trouble is there does not set current values to the entry forms that pop out by shortcode “cdbt-edit”? My this recognition is wrong?
    If my above recognition was right, please try to confirm of whether occurred JavaScript errors on your page.

    Thank you for providing the URL. But, I could not see the page because I did not have authority, unfortunately.

    Thank you,

    Plugin Author ka2

    (@ka2)

    Sorry for my late reply.

    I do not understand yet the automatic update mechanism that you want.
    Sorry to trouble you, please tell me the more detailed specifications.

    thank you,

    Plugin Author ka2

    (@ka2)

    This ticket was closed to have corresponded already.

    Plugin Author ka2

    (@ka2)

    This ticket was closed to have corresponded already.

    Plugin Author ka2

    (@ka2)

    This ticket was closed to have corresponded already.

Viewing 15 replies - 76 through 90 (of 274 total)