Well - there is the API documentation for both classes (
CriteriaCompo and
Criteria). But they take a little getting used to. Their purpose is to handle everything after the 'WHERE' in a SQL Query.
Lets say you want to retrieve every user in XOOPS with an email ending in xoops.org, with a post count of 0, listed by date of user registration (oldest to newest).
Here's what I do:
Start with the full SQL query to retrieve the records you want.
SELECT * FROM xoops_users WHERE [b]email LIKE '%xoops.org' AND posts=0 ORDER BY user_regdate ASC[/b]
The
criteria for your records is displayed in bold, above.
The CriteriaCompo is a container to hold all the different pieces of the criteria. In our query the pieces are:
email LIKE '%xoops.org'
posts=0
First we create a new CriteriaCompo to hold our Criteria(s)
$crit = new CriteriaCompo();
Next we create a Criteria object for each piece:
$email = new Criteria('email', '%xoops.org', 'LIKE');
$posts = new Criteria('posts', 0, '=');
Then we add them to the container:
$crit->add($email);
$crit->add($posts);
To adjust the sorting and the order, both CriteriaCompo and Criteria have the setSort and setOrder functions.
$crit->setSort('user_regdate');
$crit->setSort('ASC');
To get the resulting WHERE text, use the renderWhere function
$WHERE = $crit->renderWhere();
$WHERE should be 'WHERE (email LIKE '%xoops.org') AND (posts = 0)'
For an example of how to use these objects in your own SQL queries, I recommend looking at the GetObjects function in any of the files in the /kernel directory