Change the dataset based on a seession variable

Change the dataset based on a seession variable

whitbaconwhitbacon Posts: 40Questions: 2Answers: 0
edited April 2013 in Editor
Hello,
I am trying to change the records a user sees based on a session variable. In my case the session variable is auth level. Here is a generic sampl that does not work.
[code]
Editor::inst( $db, 'caseinfo' )
->fields(
Field::inst( 'casename' ),
Field::inst( 'factsnum' ),
Field::inst( 'socialsecurity' ),
Field::inst( 'primdob' )
->validator( 'Validate::dateFormat', 'D, j M y' )
->getFormatter( 'Format::date_sql_to_format', 'D, j M y' )
->setFormatter( 'Format::date_format_to_sql', 'D, j M y' ),
Field::inst( 'id' )
)

switch ($_SESSION['auth_level']) {
case 2:
->where( 'userid', 2, '=' );
break;
case 4:
->where( 'agencyid', 2, '=' );
break;

}

->process( $_POST )
->json();
[/code]

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    The code above is invalid PHP which is why it isn't working. There are a couple of syntax errors. Try this instead:

    [code]
    $editor = Editor::inst( $db, 'caseinfo' )
    ->fields(
    Field::inst( 'casename' ),
    Field::inst( 'factsnum' ),
    Field::inst( 'socialsecurity' ),
    Field::inst( 'primdob' )
    ->validator( 'Validate::dateFormat', 'D, j M y' )
    ->getFormatter( 'Format::date_sql_to_format', 'D, j M y' )
    ->setFormatter( 'Format::date_format_to_sql', 'D, j M y' ),
    Field::inst( 'id' )
    );

    switch ($_SESSION['auth_level']) {
    case 2:
    $editor->where( 'userid', 2, '=' );
    break;
    case 4:
    $editor->where( 'agencyid', 2, '=' );
    break;
    }

    $editor
    ->process( $_POST )
    ->json();
    [/code]

    Allan
This discussion has been closed.