spatie / opening-hours

Query and format a set of opening hours

Home Page:https://freek.dev/595-managing-opening-hours-with-php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to use this package for filtering only online users along with pagination ?

hazem-taha opened this issue · comments

Hello,

I was wondering if there is a way to use this package for filtering only online users along with pagination / query builders ?

commented

Sorry I don't see the relation with this package.

Purpose is:

A helper to query and format a set of opening hours

Basically none of the notion of "user", "pagination" nor "query builder" belongs to this package scope.

Can you elaborate on why you're expecting an online user filter for opening-hours?

Thanks.

Hello,

I have a page with a list of paginated users, each user has his own working hours. and I'm trying to add a filter from which I can list only currently online users OR users who are available tomorrow OR at specific date.

I know this package is not built for that use case, but I was wondering if there is a workaround to accomplish this ?

commented

OK, I see; so "online" in you app = "open business" in the lib terminology.

By the library design, you'll have to iterate over each users to check if they are online at each specific dates, so you get a filtered list and paginate the result only once filtered.

If you have millions of users, that won't be an option to do it each time, you will have to cache the result and possibly preload results for next days.

With the day-granularity (checking if a user is only at least 1 minute in a day) you probably can afford a cached value for each day. For currently online which is a second-precise notion you can't but you could have a cronjob running each minute, selecting all the user that have the current time as a open or close time in their schedule and then refresh for each of them an "online" boolean flag in your users table.

If you don't use exceptions, filters or overflow (e.g. only have week days in your config arrays, without any kind of holidays, special time or dynamic calculation) then you can predict the "online" in a more performant way using only SQL if you split data accordingly (a table with 1 row per time-range which would have day, start time, end time in separated columns), but in this case, this library will have no particular helper to craft the query you need for that.

Perfect, Thanks for these great details, I think I will go with the last option by utilizing the stored opening hours array in the DB since I'm not using exceptions.

Thanks again @kylekatarnls