more minor fixes, heading for the big files now
extraneous brackets
$linkID is never used. Also - might want to consider some kind of reset() function

...that takes care of the ->withSql, ->withParams reset
again - a ->clear() method might make sense here to reset the SQL/Params
pretty sure this variable isn't needed
a tiny bit more concise
avoiding an indent level
testing filters on every single foreach run can be rather wasteful ;-)