• Resolved robinjohnson

    (@robinjohnson)


    Hello! I was just wondering if it is possible to attach variables to the downloaded url – such as only download form entries from a certain date field in the form, or submission date, or download entries from a certain user, etc.

    Thanks for such a helpful plugin!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Doeke Norg

    (@doekenorg)

    Hi Robin,

    As of this moment the plugin does not support that type of filtering. But you could use the gfexcel_output_rows hook to filter down the array of results before it is rendered. Just filter out the results you don’t want using array_filter.

    And you can make the hook respond to a request parameter. So in theory it is possible to build your own.

    If you need I could whip up an example. But that will have to wait till tomorrow.

    Please let me know if this helps you out.

    Thread Starter robinjohnson

    (@robinjohnson)

    Hi Doeke,

    Thanks so much for the info. I will definitely have a look into that – thanks for pointing me in the right direction!

    Plugin Author Doeke Norg

    (@doekenorg)

    I had some time on my hands to provide you; and any of you who is wondering how to do something similar, an example.

    I’m aware the code quite verbose; but I’m trying to illustrate how stuff works. So I added some comments, and nested if’s.

    You can set a date to filter against, by adding ?from_date={date} where {date} is something like 2018-02-14.

    Hope this helps someone out.

    <?php
    // functions.php
    
    /**
     * Filtering rows example
     * Include row by default, but exclude based on a certain condition
     * In this case we exclude every row before $from_date
     * And we take $from_date as a query_string parameter
     */
    add_filter('gfexcel_output_rows', function ($rows) {
        if (!array_key_exists('from_date', $_GET)) {
            return true; // nothing to filter
        }
    
        $from_date = DateTime::createFromFormat('Y-m-d', $_GET['from_date'])->setTime(0, 0); //2018-07-10 00:00:00
    
        return array_filter($rows, function ($row) use ($from_date) {
            foreach ($row as $i => $field) {
                // $field can either be a string, or an (extended) BaseValue-class.
                // lets say column 2 is a date, and we only want rows after a given date
                if ($i === 1) {
                    // column 2, because the array starts at 0
                    if ($date = DateTime::createFromFormat('Y-m-d H:i:s', (string) $field)) {
                        /**
                         * Note the '(string) $field' ! This is necessary, because it might be a BaseValue-class. 
                         * This converts that class to a string version of the actual value.
                         */
                        
                        if ($date < $from_date) {
                            return false; //exclude, because date is earlier than we want
                        }
                    }
                }
            }
    
            return true; //include this row by default
        });
    });
    Plugin Author Doeke Norg

    (@doekenorg)

    Just found a major bug in the code above. It should read:
    return $rows; // nothing to filter
    instead of
    return true; // nothing to filter

    ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘URL Variables’ is closed to new replies.