Implementing filters in the generated code
In many AppGini applications, we’d like users to view only a subset of data rather than viewing all the records of a table. For example, in the orders table, we might want users to view the orders as of 1/1/2009 only. To do so, we’d write the PHP code for filtering the orders table by date as follows.

/* filter 1 code*/
/* let’s assume the date field is the fourth field in the orders table*/
addFilter(1, ‘and’, 4, ‘greater-than-or-equal-to’, ‘1/1/2009’);
So, the above code limits the orders table list only orders dating 1/1/2009 or newer. Now, where should this code be placed? It should be placed in the generated “hooks/tablename.php” file inside the tablename_init() function, where tablename is the name of the concerned table. For our example, the file would be named “hooks/orders.php” and the function orders_init(). So, the code in the file would look like this:

function orders_init(&$options, $memberInfo, &$args){
addFilter(1, ‘and’, 4, ‘greater-than-or-equal-to’, ‘1/1/2009’);
return TRUE;
}

 

Using multiple filters
Let’s say we want to filter orders to display only the orders of January 2009. In this case, we’ll add another filter to our code to limit orders to the period from 1/1/2009 to 1/31/2009 [1].

addFilter(1, ‘and’, 4, ‘greater-than-or-equal-to’, ‘1/1/2009’);
addFilter(1, ‘and’, 4, ‘less-than-or-equal-to’, ‘1/31/2009’);
We’ve now finished part 1 of this tutorial. We’ve learnt how to enforce a filter on users when they view a certain table. In the next part of this series, we’ll learn how to further customize the enforced filters.