本文整理匯總了PHP中UserQuery::findOneByNetid方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserQuery::findOneByNetid方法的具體用法?PHP UserQuery::findOneByNetid怎麽用?PHP UserQuery::findOneByNetid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserQuery
的用法示例。
在下文中一共展示了UserQuery::findOneByNetid方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_user
function get_user($netid)
{
$q = new UserQuery();
$user = $q->findOneByNetid($netid);
// The user exists in the database
if ($user) {
return $user;
} else {
// We need to build it.
$netid_info = netid_info($netid);
if ($netid_info) {
if (array_key_exists("givenname", $netid_info)) {
$name = $netid_info["givenname"]["0"] . " " . $netid_info["sn"]["0"];
} else {
// User has no name in LDAP, set their name to their netid.
$name = $netid;
}
$year = array_key_exists("ou", $netid_info) ? $netid_info["ou"]["0"] : false;
$user = new User();
$user->setNetid($netid);
if ($year) {
$user->setYear($year);
}
if ($name) {
$user->setName($name);
}
$user->save();
return $user;
} else {
// User doesn't exist in ldap either
return false;
}
}
}