This topic is locked

How to show user's own data until search

5/2/2017 11:47:29 AM
PHPRunner Tips and Tricks
admin

Q: Instead of 'Hide Data until search' I would like to see a feature of 'Show user owned data, hide all other data until search'.
A: This is useful in applications where people can see everyone's data but only edit their own. When they first get to the list page they see their own data and can run a search to see more data.
This code needs to be added to AfterTableInit event of Orders table.

if( !SearchClause::getSearchObject($table)->isUsedSrch() ) {

$query->addWhere("CustomerID = '" . $_SESSION["UserID"] . "'");

}


Here we use Search API to figure out if search was executed. If there were no search yet we mimic 'Users can see and edit their own data only' behavior.
In this example we assume that CustomerID field in Orders table defines who this record belongs to.


In this example Customers is the login table and Orders is the table where this functionality is implemented.