Feed Bean
The feed
bean/object allows developers to programmatically query Mura for other beans/objects. Initially, many developers query for content
beans/objects. In essence, when you search for content items using this method, you're creating a Collection dynamically. However, you may also query for user
beans/objects, and as you'll see in the Custom Objects section, any other kind of Mura object or custom object you wish.
In short, the feed
bean/object to obtains a collection of beans/objects, based on desired filters/criteria.
Note: Once the feed
bean/object has been populated, most developers will call either the getIterator
or getQuery
methods to work with the collection of beans/objects. See the Key Methods area below for details. Please visit the Mura Iterators section, for more information on iterators.
Syntax
There are a couple of ways to obtain a feed
bean/object, and each of those are described below.
loadBy
The first way for obtaining a feed
bean/object is by using the common loadBy
method. When loading it this way, keep in mind you will only be working with content
beans/objects.
If you wish to load an existing Collection created via Mura's Admin UI, you can load a feed
bean/object by any of the following attributes:
- feedid
- name
- remoteid
<cfset feedBean = m.getBean('feed').loadBy(name='{Collection Name Goes Here}')>
getFeed
The primary method for obtaining a feed
bean/object, is to use your desired bean's/object's getFeed
method. You can either call getFeed
on your desired bean/object itself, or pass in the name of the bean as an argument to the getFeed
method, as shown in the examples below.
Content Feed
feedBean = m.getBean('content').getFeed(); // or feedBean = m.getFeed('content');
User Feed
feedBean = m.getBean('user').getFeed(); // or feedBean = m.getFeed('user');
Custom Object
feedBean = m.getBean('yourCustomObject').getFeed(); // or feedBean = m.getFeed('yourCustomObject');
Usage
Use the feed
bean/object to create, access, and/or manipulate a collection of beans/objects.
Key Methods
Since a feed
bean/object is essentially an easy way to query Mura for objects, the key methods for working with feeds share a similarity with conventional SQL syntax, but in a way that's more comfortable for developers. Also, as shown in the examples below, Mura allows for method chaining. The methods below also apply to Mura ORM Feeds, and are also exposed via the Mura.js API.
Method | Parameter | Description |
---|---|---|
where | property | Analogous to SQL "WHERE" clause. If property parameter is empty, the method is used for readability purposes only. You may optionally provide a property argument, in which case Mura will treat it as andProp . |
prop | property | Analogous to SQL "AND" clause. The property argument is the attribute to use as the left operand value of a SQL WHERE condition. |
andProp | property | Analogous to SQL "AND" clause. The property argument is the attribute to use as the left operand value of a SQL WHERE condition. |
orProp | property | Analogous to SQL "OR" clause. The property argument is the attribute to use as the left operand value of a SQL WHERE condition. |
null | n/a | Analogous to SQL "IS NULL" operator. Checks if the preceding property value is null . |
isEQ | criteria | Analogous to SQL "=" comparison operator. Checks if the preceding property value is "equal to" the criteria argument. |
isNEQ | criteria | Analogous to SQL "<>" or "!=" comparison operator. Checks if the preceding property value is "not equal to" the criteria argument. |
isLT | criteria | Analogous to SQL "<" comparison operator. Checks if the preceding property value is "less than" the criteria argument. |
isLTE | criteria | Analogous to SQL "<=" comparison operator. Checks if the preceding property value is "less than or equal to" the criteria argument. |
isGT | criteria | Analogous to SQL ">" comparison operator. Checks if the preceding property value is "greater than" the criteria argument. |
isGTE | criteria | Analogous to SQL ">=" comparison operator. Checks if the preceding property value is "greater than or equal to" the criteria argument. |
isIn | criteria | Analogous to SQL "WHERE IN" clause. Checks if the preceding property value is in the list of literal values that have been specified as the criteria argument. Shorthand for multiple OR conditions. |
isNotIn | criteria | Similar to the isIn method. Checks if the preceding property value is NOT in the list of literal values that have been specified as the criteria argument. Shorthand for multiple AND x NEQ conditions. |
containsValue | criteria | Analogous to SQL "CONTAINS" comparison operator. Checks if the preceding property value "contains" the criteria argument. |
beginsWith | criteria | Analogous to SQL "LIKE" comparison operator. Checks if the preceding property value "begins with" the criteria argument. May use wildcards (e.g., % or _ , etc.) |
endsWith | criteria | Analogous to SQL "LIKE" operator. Checks if the preceding property value "ends with" the criteria argument. May use wildcards (e.g., % or _ , etc.) |
openGrouping | n/a | Analogous to SQL "AND (" logical operator. Creates an "AND" with a parenthesis to form complex expressions. See grouping example below. |
andOpenGrouping | n/a | Analogous to SQL "AND (" logical operator. Creates an "AND" with a parenthesis to form complex expressions. See grouping example below. |
orOpenGrouping | n/a | Analogous to SQL "OR (" logical operator. Creates an "OR" with a parenthesis to form complex expressions. See grouping example below. |
closeGrouping | n/a | Analogous to SQL ")" logical operator. Creates a closing parenthesis to preceding "opening" statements for complex expressions. See grouping example below. |
sort | property, direction | Analogous to SQL "ORDER BY" clause. Allows sorting by one or more properties, and may be returned in ascending (asc ) or descending (desc ) order. |
itemsPerPage | itemsPerPage | Expects a number to set the NextN attribute of the recordset. Set to zero (0) to include all items on one page. |
maxItems | maxItems | Analogous to SQL "TOP" or "LIMIT" clause. Used to limit the number of records to retrieve. Set to zero (0) to retrieve all records. The default setting is twenty (20) for content beans/objects. |
includeHomePage | boolean | *Only applies to Mura content. Set to true to include the Home Page. |
showNavOnly | boolean | *Only applies to Mura content. Set to true to include only content items flagged as "Include in Site Navigation". |
showExcludeSearch | boolean | *Only applies to Mura content. Set to true to include content items flagged as "Exclude from Site Search". |
isFeaturesOnly | boolean | *Only applies to Mura content. Set to true to only search for content items flagged as "Feature in this section?". |
contentPools | criteria | *Only applies to Mura content. A comma-delimited list of SiteIDs to search for content items. |
getIterator | Returns an iterator object. Please visit the Mura Iterators section, for more information on iterators. Note: This method is not exposed or available via the Mura.js API. Use
getQuery instead. |
|
getQuery | countOnly | Returns a query object. Optionally pass in the countOnly argument, to obtain only a count of the records that match your filter criteria. |
Examples
Note: When using m.getFeed('content')
, unless you specify otherwise, Mura will only search for content items that are active, approved, set to appear in navigation, not excluded from search results, currently on display, exclude the home page, and limited to the top 20 records.
Also, when using m.getFeed('user')
, by default, Mura will only search for Site Members (isPublic=1
). To search for System Users, add .setIsPublic(0)
to your method chain.
prop & andProp
This example demonstrates the use of the prop
and andProp
methods.
feedBean = m.getFeed('content') .where() .prop('title') .isEQ('About Us') .andProp('siteid') .isEQ('default'); // Analogous SQL SELECT * FROM tcontent WHERE title = 'About Us' AND siteid = 'default';
orProp
This example demonstrates the use of the prop
method.
feedBean = m.getFeed('content') .where() .prop('title') .isEQ('About Us') .orProp('title') .isEQ('News'); // Analogous SQL SELECT * FROM tcontent WHERE title = 'About Us' OR title = 'News';
Sort
This example demonstrates how to obtain a feed
bean/object of Mura content items. It is searching for any content where the "title" attribute is equal to "News" or "Blog" and will sort the results by title, descending.
contentFeed = m.getFeed('content') .where() .prop('title') .isEQ('News') .orProp('title') .isEQ('Blog') .sort('title', 'desc'); // Analogous SQL SELECT * FROM tcontent WHERE title = 'News' OR title = 'Blog' ORDER BY title DESC;
getIterator
Returns an iterator object.
<cfset it = feedBean.getIterator()> <!--- Loop over the iterator ---> <cfif it.hasNext()> <ul> <cfloop condition="it.hasNext()"> <cfset item = it.next()> <li> <cfdump var="#item.getAllValues()#"> </li> </cfloop> </ul> <cfelse> <!--- Feed has no items ---> </cfif>
getQuery
Returns a query object.
rsObjects = feedBean.getQuery();
contentPools
This example demonstrates how to search more than one site for content items, under the same instance of Mura.
feedBean = m.getFeed('content') .where() .prop('credits') .containsValue('Steve') .contentPools('site1,site2,site3'); // Analogous SQL SELECT * FROM tcontent WHERE credits LIKE '%Steve%' AND siteid IN ('site1','site2','site3');
Grouping Example
This example demonstrates how to use the openGrouping
, orOpenGrouping
, and closeGrouping
methods.
feedBean = m.getFeed('content') .where() .prop('credits') .containsValue('Steve') .openGrouping() .prop('title') .beginsWith('Why') .closeGrouping() .orOpenGrouping() .prop('title') .isEQ('News') .closeGrouping(); // Analogous SQL SELECT * FROM tcontent WHERE credits LIKE '%Steve%' AND ( title LIKE 'Why%' ) OR ( title = 'News' );
Searching for Super Users
This example demonstrates how to search for "super" users. Remember, Mura only searches Site Members by default, so we have to use .setIsPublic(0
) to search for System Users.
feedBean = m.getFeed('user') .where() .prop('s2') // if s2=1, then they're a super user .isEQ(1) .setIsPublic(0); // Analogous SQL SELECT * FROM tusers WHERE s2 = 1 AND ispublic = 0;
Searching for Custom Objects
This example demonstrates how to search for a custom object. See the Custom Objects section for more information.
feedBean = m.getFeed('yourCustomObject') .where() .prop('someProperty') .isEQ('someValue'); // Analogous SQL SELECT * FROM yourCustomObjectTable WHERE someProperty = 'someValue';