• Resolved ranone

    (@ranone)


    Hi, I’m trying to make the export csv data as readable as possible…

    I have 2 questions:

    1) is there the possibility to put the complete url instead of just the name for the file upload fields? (for example https://domain.com/location-to-pdb-upload-dir/filename.ext)

    2) is there the possibility of using the ‘title’ instead of the ‘name’ as the headers of the CSV file?

    Thanks a lot

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author xnau webdesign

    (@xnau)

    Yes, it’s possible, but it is important to understand that doing either of these things will result in a CSV that cannot be imported back in to Participants Database because it breaks the expected format.

    It is possible to add custom code that modifies the exported value using the pdb-csv_export_value filter. That filter gets two arguments: the value that is getting exported and the PDb_Field_Item object for the exporting field. The filter expects in return the value to be exported. You can use that filter to convert the filename to the complete URL on export.

    For the field titles, there is a checkbox in the Export CSV interface to include the field titles in the exported CSV.

    If you want to import this back in to Participants Database, you’ll need to make sure the row with the field titles is not included.

    Thread Starter ranone

    (@ranone)

    Tks @xnau for your reply..

    For the CSV Export I pass in the frontend template with csv_export_form() function, is there a possibility to write something here? (Not in back office interface)

    Then I have another connected question…

    In the csv_export_form() function I really need to pass groups names instead of fields names (for example export_groups instead of export_fields).

    Is it possible to do a hack?

    Listing all the fields is impossible for me because I have available only a variable that I can use which is the group name…

    Tks a lot

    Plugin Author xnau webdesign

    (@xnau)

    The frontend CSV export passes through the same filter, so the same code will work there too.

    Groups? No, not possible, the export goes field by field, it ignores groups entirely.

    Thread Starter ranone

    (@ranone)

    Hi,
    is there a method that gives me the names of all the fields of a group in a simple way?

    Plugin Author xnau webdesign

    (@xnau)

    There is no public method specifically for this, but you can use a function like this:

    <?php
    function pdb_get_group_fields( $name ) {
      global $wpdb;
      $result = $wpdb->get_col( $wpdb->prepare( 'SELECT f.name FROM ' . Participants_Db::$fields_table . ' f WHERE f.group = %s', $name ) );
      
      return $result;
    }
    ?>

    That will give you an array of field names.

    Thread Starter ranone

    (@ranone)

    I’m sorry, but the $fields_table variable what should it be?

    In the CSV export I have fields that seems to be cached from previous queries… Is there any way to reset and perform a new query?

    Tks a lot

    • This reply was modified 3 years ago by ranone.
    Plugin Author xnau webdesign

    (@xnau)

    You don’t need to set the $fields_table variable, just use Participants_Db::$fields_table the plugin provides the value.

    The CSV export uses the last query use to generate the list, so you just need to redisplay the list. Of course, make sure there is no page caching if you are on the frontend.

    Thread Starter ranone

    (@ranone)

    From a further check I have found that the result of the query on the database is correct.

    The problem is when I pass this result to the csv_export_form() function in the export_fields parameter.

    The result in the CSV strangely includes other fields from other groups … I am doing some further testing, but it’s very strange…

    Is there a way to clean cache in pdb-list template before include csv_export_form() function?

    Tks

    • This reply was modified 3 years ago by ranone.
    Plugin Author xnau webdesign

    (@xnau)

    Make sure you’re providing the data to the function in the correct format.

    Thread Starter ranone

    (@ranone)

    I pass the result of the pdb_get_group_fields() function which I have verified to be an array…

    This array is correct as result extrapolated from database.

    The file CSV returned by csv_export_form() function is however incorrect because it shows fields not passed to the export_fields parameter..

    • This reply was modified 3 years ago by ranone.
    Plugin Author xnau webdesign

    (@xnau)

    Make sure it’s just an array of field names.

    This is working here, so we need to make sure it’s getting configured correctly.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘CSV export customization’ is closed to new replies.