Show results based on Session data
Show results based on Session data

I am trying to figure out how to show results based on session data IE: User = Location2 show locations 2 only results.
I have it working except that everyone sees everything. I am trying to get it so that users only see their data.
I normally do this with a where function in SQL but am unsure how to get it to work in datatables editor.
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
Editor::inst( $db, 'pending_dpa' )
->fields(
Field::inst( 'pending_dpa.ID' ),
Field::inst( 'pending_dpa.added' )
->validator( Validate::dateFormat( 'Y-m-d H:i' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) )
->setFormatter( Format::dateFormatToSql('Y-m-d H:i:s' ) ),
Field::inst( 'pending_dpa.location_id' ),
Field::inst( 'pending_dpa.location_name' ),
Field::inst( 'pending_dpa.date' ),
Field::inst( 'pending_dpa.acct_num' ),
Field::inst( 'pending_dpa.mobile_num' ),
Field::inst( 'pending_dpa.customer' ),
Field::inst( 'pending_dpa.status' ),
Field::inst( 'pending_dpa.amount' ),
Field::inst( 'pending_dpa.type' ),
Field::inst( 'pending_dpa.note' ),
Field::inst( 'pending_dpa.modified' )
->validator( Validate::dateFormat( 'Y-m-d H:i' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) )
->setFormatter( Format::dateFormatToSql('Y-m-d H:i:s' ) ),
Field::inst( 'locations.district' ),
Field::inst( 'pending_dpa.corrected' )
->setFormatter( function ( $val, $data, $opts ) {
return ! $val ? 0 : 1;
} )
)
->where( 'pending_dpa.corrected', 0, '=' )
->leftJoin( 'locations', 'locations.Outlet_ID', '=', 'pending_dpa.location_id' )
->debug( true )
->process( $_POST )
->json();
The session data would be like this $_SESSION['location'] = "District 2"
Any help is much appreciated.
This question has an accepted answers - jump to answer
Answers
And here is my JS file.
Hi @davidjmorin
Perhaps something like
see here
@Lapointe Thank you for your post. I did look over that helpfile but couldn't figure that out. With your example I get an ajax error.
If I remove this
->where( 'pending_dpa.corrected', 0, '=' )
->where( function ( $q ) (use $location) {
$q->where( 'locations.district', $location);
} );
It works fine. So its something with this query.
ok i see my error lol. I did not start the session in this PHP file.
I got this to work with the following.
If ok mark the question as answered please