webCOMAND

repo::switch_user()

Switch the repository "user of record".  All subsequent queries performed on this repository will apply the new user's authorizations until pop_user() is called.

Prototype

integer switch_user(Object $user)

Parameter

  • user - A User Object that represents the new "user of record".

Return

If successful, the number of users on the user stack is returned.  Otherwise FALSE is returned.  The number of users on the stack is incremented each time switch_user() or push_user() is called successfully and decremented each time pop_user() is called.

Example

$user = $repo->get_first("FROM User WHERE OID=123");

// switch the "user of record" to user with OID 123
$index = $repo->switch_user($user);
if($index == FALSE) {
    exit("Could not switch user.");
}

// get all contacts user with OID 123 can view
$contacts = $repo->get("SELECT Name FROM Contact");
foreach($contacts as $contact) {
	echo($contact->Name . "\n");
}

// return to previous "user of record"
$repo->pop_user($index);

See Also

push_user(), peek_user(), pop_user(), push_super_user()