New FAPI function: getContentObjects()

There are a couple of dopplegangers for this functionality in core, buried in FourQ and the database gateways. Both are awkward, and offer little more than arguments for the where and order by clauses. All are about to be deprecated and replaced with getContentObjects() in FarCry 6.0.1.

application.fapi.getContentObjects() massively improves on older methods by:
- using dynamic arguments for filtering
- handling filters on date columns that can have null values
- automatically filtering results by their status
- using cfqueryparam for all filter values

The arguments are:
- typename (req)
- lProperties (default=objectid)
- status (default=request.mode.
lValidStatus)
- orderBy (default=unordered)
- [property filters]*

Property filters are arguments in the form propertyname_comparison=value. Supported comparisons are:
- eq, neq (equality filters)
- in, notin (list filters)
- like (standard DB like comparison)
- isnull (boolean value to specify whether to return null properties or not)
- gt, gte, lt, lte (standard comparisons, null dates always pass these filters)

Examples:
qLatestNews = application.fapi.getContentObjects(typename="dmNews",lProperties="objectid,title",publishDate_lt=now(),expiryDate_gt=now(),orderBy="publishDate desc")
qLockedHTML = application.fapi.getContentObjects(typename="dmHTML",locked_eq=1)
qNotActiveUsers = application.fapi.getContentObjects(typename="dmUser",userstatus_in="inactive,pending")

This FAPI function is only intended to replace the 90% of queries we use the most in webskins. Other functionality like filters on related tables, grouping, and aggregates will still be handled in custom SQL.

Cheers, Blair

2358 views and 0 responses