Adldap2 / Adldap2-Laravel

LDAP Authentication & Management for Laravel
MIT License
911 stars 185 forks source link

Pagniate works irrespective of the limit params #333

Open raghul-selvakumar opened 7 years ago

raghul-selvakumar commented 7 years ago

Description:

The paginate function works irrespective of the records per page and current page params. I have made the records per page and current page params as dynamic and following is the code,

$ad = new \Adldap\Adldap();

if ($offset==0) {
    $currentPage = 1;
} else {
    $offset = ($offset/$limit);
    $currentPage = $offset+1;
}

$ad->addProvider($config);

$provider = $ad->connect();

$search = $provider->search();

$recordsPerPage = $limit;

$adUsers = $search->users()->sortBy('cn', 'asc')
                        ->paginate($recordsPerPage, $currentPage)
                        ->getResults();

For example, if the records per page is 50 and current page is 1, it should return me only 50 records from the beginning, but the above code returns me all the records, exactly 874 records in the AD.

Help will be really appreciated. Thanks

stevebauman commented 7 years ago

Hi @raghul-selvakumar,

Unfortunately PHP doesn't support LDAP server side sorting at the moment, so we actually retrieve the entire result set to allow sorting since it was a requested feature.

If we sort a result set of returned results from the first paged request, it won't be sorted properly since the entire resulting records haven't been retrieved yet, which will contain out of order results.

If we perform this the other way, we'll need to store the cookie somehow inside the users session to be able to request the next resulting set of LDAP records. This opens a can of worms since users may be using other frameworks for managing sessions instead of PHP's sessions. We would have to create some sort of 'driver' based cookie implementation for each type of implementation that the dev is working with.

We also can't create cookies without devs knowing since this could infringe upon their countries rights (the EU for example).

The current pagination implementation is meant to correct the PHP LDAP sorting issue and bypass max result limits on LDAP servers to be able to retrieve all records instead of being limited to your servers maximum (usually 500 or 1000).

I'm completely open to PR's and talks about implementation of pagination that requests only the requested page of data, but it could be difficult.

raghul-selvakumar commented 7 years ago

Hi @stevebauman

That makes sense. Thank you for your reply steve.