looks fine and works for me OK Lets break this down
The new code generated in the where clauses allows specific access overrides such as core.edit.state and core.delete.own
// ACCESS - View Level Access
$whereAccess = '1';
if (!$this->canAdmin())
{
$groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels());
$whereAccess = 'a.access IN ('.$groups.')';
}
if admin no need to check
if not admin check view level access
admin can see all same as
SELECT a.* FROM atable WHERE 1
NOT admin only see allowed items
SELECT a.* FROM atable WHERE a.access IN ('.$groups.')
PUBLISHED
show where published =1 or null but allow core edit state
//Allow some users to access (core.edit.state)
if ($acl->get('core.edit.state'))
$wherePublished = '1'; //Do not filter
core edit state = need to see all records
//same as
SELECT a.* FROM atable WHERE 1
Apply filters as needed...
// FILTER - Published state
$published = $this->getState('filter.published');
if (is_numeric($published))
{
//Limit to publish state when filter is applied
$wherePublished = 'a.published = ' . (int)$published;
//Does not apply the author condition when filter is defined
$allowAuthor = '0';
}
And finally
$query->where("$whereAccess AND $wherePublished");
// if admin show all
SELECT a.* FROM atable WHERE 1 AND 1
// if not Admin but can edit state
SELECT a.* FROM atable WHERE a.access IN ('.$groups.') and 1 // because user can edit state
// if not admin and not core edit state apply normal access controls
// allow access based on view level and show published or null
SELECT a.* FROM atable WHERE a.access IN ('.$groups.') AND (published =1 or published = null)
// if filters applied
// admin
SELECT a.* FROM atable WHERE 1 AND a.published = Filter State
// not admin but core.edit.state permission
SELECT a.* FROM atable WHERE a.access IN ('.$groups.') AND a.published = Filter State
// not admin and not core edit state
SELECT a.* FROM atable WHERE a.access IN ('.$groups.') AND a.published = Filter State
Hope it helps understand it a little better