SQL and argument review.

This PR is a review of all doctrine queries and a quicker review of input arguments to API's. There's one conceptual decision. In the current codebase we have two styles of doctrine usage; direct sql via entity manager and sql built via query builder. 

With respect to the referenced issue (#1340) it seems that, at expense of a minor performance hit when using a builder class, that the use of query builder as standard would prevent the building of such insecure queries

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #1340
| Refs tickets  | 
| License       | MIT
| Doc PR        |