This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

slipgrom3145
slipgrom3145

How get filter values before list render in backend? I want to recalculate values of the scoreboard depending on the selected filter values.

PS. Pls help and sorry for my bad english

dragontree
dragontree

Did you find a solution?

SergeyKasyanov
SergeyKasyanov

my solution

function getCurrentFilters()
{
    $filters = [];
    foreach (\Session::get('widget', []) as $name => $item) {
        if (str_contains($name, 'Filter')) {
            $filter = @unserialize(@base64_decode($item));
            if ($filter) {
                $filters[] = $filter;
            }
        }
    }

    return $filters;
}
jvanremoortere
jvanremoortere

I think this is an issue. After wanting to achieve the same thing (recalculating values for scoreboard) I checked (almost) every plugin using scoreboards and found that not one plugin updates it's scoreboard on list update (filter, update of record, ...). You always have to refresh te page to get an updated scoreboards...

Anyone an idea on best practice?

Last updated

milos.stanic
milos.stanic

@sk Thanks for the solution. I found the filters were kept in the session, however, I wasn't able to find a way to decode them.

One thing, though, I had to change your code:

function getCurrentFilters() {
        $filters = [];
        foreach (\Session::get('widget', []) as $name => $item) {
            if (str_contains($name, 'Filter')) {
                $filter = @unserialize(@base64_decode($item));
                if ($filter) {
                    //$filters[] = $filter;
                    array_push($filters, $filter);
                }
            }
        }

        return $filters;
    }

See the commented out line and the array_push line below. In the original code it was getting only one filter, with this correction it gets all the filters on page.

Thanks again!

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.