本文整理汇总了PHP中RoleModel::GetByName方法的典型用法代码示例。如果您正苦于以下问题:PHP RoleModel::GetByName方法的具体用法?PHP RoleModel::GetByName怎么用?PHP RoleModel::GetByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RoleModel
的用法示例。
在下文中一共展示了RoleModel::GetByName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SelectByRole
/**
* Select content based on author RoleID
*
* @param array $Parameters
* @return boolean
*/
protected function SelectByRole($Parameters)
{
if (!is_array($Parameters)) {
$RoleID = $Parameters;
} else {
$RoleID = GetValue('RoleID', $Parameters, NULL);
}
// Lookup role name -> roleID
if (is_string($RoleID)) {
$RoleModel = new RoleModel();
$Roles = explode(',', $RoleID);
$RoleID = array();
foreach ($Roles as $TestRoleID) {
$TestRoleID = trim($TestRoleID);
$Role = $RoleModel->GetByName($TestRoleID);
if (!$Role) {
continue;
} else {
$Role = array_shift($Role);
$RoleID[] = GetValue('RoleID', $Role);
}
}
}
if (empty($RoleID) || !sizeof($RoleID)) {
return FALSE;
}
// Check cache
$SelectorRoleCacheKey = "modules.promotedcontent.role.{$RoleID}";
$Content = Gdn::Cache()->Get($SelectorRoleCacheKey);
if ($Content == Gdn_Cache::CACHEOP_FAILURE) {
// Get everyone with this Role
$UserIDs = Gdn::SQL()->Select('ur.UserID')->From('UserRole ur')->Where('ur.RoleID', $RoleID)->GroupBy('UserID')->Get()->Result(DATASET_TYPE_ARRAY);
$UserIDs = ConsolidateArrayValuesByKey($UserIDs, 'UserID');
// Get matching Discussions
$Discussions = Gdn::SQL()->Select('d.*')->From('Discussion d')->WhereIn('d.InsertUserID', $UserIDs)->OrderBy('DateInserted', 'DESC')->Limit($this->Limit)->Get()->Result(DATASET_TYPE_ARRAY);
// Get matching Comments
$Comments = Gdn::SQL()->Select('c.*')->From('Comment c')->WhereIn('InsertUserID', $UserIDs)->OrderBy('DateInserted', 'DESC')->Limit($this->Limit)->Get()->Result(DATASET_TYPE_ARRAY);
$this->JoinCategory($Comments);
// Interleave
$Content = $this->Union('DateInserted', array('Discussion' => $Discussions, 'Comment' => $Comments));
$this->Prepare($Content);
// Add result to cache
Gdn::Cache()->Store($SelectorRoleCacheKey, $Content, array(Gdn_Cache::FEATURE_EXPIRY => $this->Expiry));
}
$this->Security($Content);
$this->Condense($Content, $this->Limit);
return $Content;
}
示例2: Connect
/**
* Connect the user with an external source.
*
* This controller method is meant to be used with plugins that set its data array to work.
* Events: ConnectData
*
* @since 2.0.0
* @access public
*
* @param string $Method Used to register multiple providers on ConnectData event.
*/
public function Connect($Method)
{
$this->AddJsFile('entry.js');
$this->View = 'connect';
$IsPostBack = $this->Form->IsPostBack() && $this->Form->GetFormValue('Connect', NULL) !== NULL;
if (!$IsPostBack) {
// Here are the initial data array values. that can be set by a plugin.
$Data = array('Provider' => '', 'ProviderName' => '', 'UniqueID' => '', 'FullName' => '', 'Name' => '', 'Email' => '', 'Photo' => '', 'Target' => $this->Target());
$this->Form->SetData($Data);
$this->Form->AddHidden('Target', $this->Request->Get('Target', '/'));
}
// The different providers can check to see if they are being used and modify the data array accordingly.
$this->EventArguments = array($Method);
// Fire ConnectData event & error handling.
$CurrentData = $this->Form->FormValues();
try {
$this->FireEvent('ConnectData');
} catch (Gdn_UserException $Ex) {
$this->Form->AddError($Ex);
return $this->Render('ConnectError');
} catch (Exception $Ex) {
if (Debug()) {
$this->Form->AddError($Ex);
} else {
$this->Form->AddError('There was an error fetching the connection data.');
}
return $this->Render('ConnectError');
}
if (!UserModel::NoEmail()) {
if (!$this->Form->GetFormValue('Email') || $this->Form->GetFormValue('EmailVisible')) {
$this->Form->SetFormValue('EmailVisible', TRUE);
$this->Form->AddHidden('EmailVisible', TRUE);
if ($IsPostBack) {
$this->Form->SetFormValue('Email', GetValue('Email', $CurrentData));
}
}
}
$FormData = $this->Form->FormValues();
// debug
// Make sure the minimum required data has been provided to the connect.
if (!$this->Form->GetFormValue('Provider')) {
$this->Form->AddError('ValidateRequired', T('Provider'));
}
if (!$this->Form->GetFormValue('UniqueID')) {
$this->Form->AddError('ValidateRequired', T('UniqueID'));
}
if (!$this->Data('Verified')) {
// Whatever event handler catches this must Set the data 'Verified' to true to prevent a random site from connecting without credentials.
// This must be done EVERY postback and is VERY important.
$this->Form->AddError('The connection data has not been verified.');
}
if ($this->Form->ErrorCount() > 0) {
return $this->Render();
}
$UserModel = Gdn::UserModel();
// Check to see if there is an existing user associated with the information above.
$Auth = $UserModel->GetAuthentication($this->Form->GetFormValue('UniqueID'), $this->Form->GetFormValue('Provider'));
$UserID = GetValue('UserID', $Auth);
// Check to synchronise roles upon connecting.
if (($this->Data('Trusted') || C('Garden.SSO.SynchRoles')) && $this->Form->GetFormValue('Roles', NULL) !== NULL) {
$SaveRoles = TRUE;
// Translate the role names to IDs.
$Roles = $this->Form->GetFormValue('Roles', NULL);
$Roles = RoleModel::GetByName($Roles);
$RoleIDs = array_keys($Roles);
if (empty($RoleIDs)) {
// The user must have at least one role. This protects that.
$RoleIDs = $this->UserModel->NewUserRoleIDs();
}
$this->Form->SetFormValue('RoleID', $RoleIDs);
} else {
$SaveRoles = FALSE;
}
if ($UserID) {
// The user is already connected.
$this->Form->SetFormValue('UserID', $UserID);
if (C('Garden.Registration.ConnectSynchronize', TRUE)) {
$User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
$Data = $this->Form->FormValues();
// Don't overwrite the user photo if the user uploaded a new one.
$Photo = GetValue('Photo', $User);
if (!GetValue('Photo', $Data) || $Photo && !StringBeginsWith($Photo, 'http')) {
unset($Data['Photo']);
}
// Synchronize the user's data.
$UserModel->Save($Data, array('NoConfirmEmail' => TRUE, 'FixUnique' => TRUE, 'SaveRoles' => $SaveRoles));
}
// Always save the attributes because they may contain authorization information.
if ($Attributes = $this->Form->GetFormValue('Attributes')) {
//.........这里部分代码省略.........
示例3: selectByRole
/**
* Select content based on author RoleID.
*
* @param array|int $Parameters
* @return array|false
*/
protected function selectByRole($Parameters)
{
if (!is_array($Parameters)) {
$RoleID = $Parameters;
} else {
$RoleID = val('RoleID', $Parameters, null);
}
// Lookup role name -> roleID
if ($RoleID && is_string($RoleID)) {
$RoleModel = new RoleModel();
$Roles = explode(',', $RoleID);
$RoleID = array();
foreach ($Roles as $TestRoleID) {
$TestRoleID = trim($TestRoleID);
$Role = $RoleModel->GetByName($TestRoleID);
if (!$Role) {
continue;
} else {
$Role = array_shift($Role);
$RoleID[] = val('RoleID', $Role);
}
}
}
if (empty($RoleID) || !sizeof($RoleID)) {
return false;
}
// Check cache
sort($RoleID);
$RoleIDKey = implode('-', $RoleID);
$SelectorRoleCacheKey = "modules.promotedcontent.role.{$RoleIDKey}";
$Content = Gdn::cache()->get($SelectorRoleCacheKey);
if ($Content == Gdn_Cache::CACHEOP_FAILURE) {
// Get everyone with this Role
$UserIDs = Gdn::sql()->select('ur.UserID')->from('UserRole ur')->where('ur.RoleID', $RoleID)->groupBy('UserID')->get()->result(DATASET_TYPE_ARRAY);
$UserIDs = array_column($UserIDs, 'UserID');
// Get matching Discussions
$Discussions = array();
if ($this->ShowDiscussions()) {
$Discussions = Gdn::sql()->select('d.*')->from('Discussion d')->whereIn('d.InsertUserID', $UserIDs)->orderBy('DateInserted', 'DESC')->limit($this->Limit)->get()->result(DATASET_TYPE_ARRAY);
}
// Get matching Comments
$Comments = array();
if ($this->ShowComments()) {
$Comments = Gdn::sql()->select('c.*')->from('Comment c')->whereIn('InsertUserID', $UserIDs)->orderBy('DateInserted', 'DESC')->limit($this->Limit)->get()->result(DATASET_TYPE_ARRAY);
$this->JoinCategory($Comments);
}
// Interleave
$Content = $this->Union('DateInserted', array('Discussion' => $Discussions, 'Comment' => $Comments));
$this->processContent($Content);
// Add result to cache
Gdn::cache()->store($SelectorRoleCacheKey, $Content, array(Gdn_Cache::FEATURE_EXPIRY => $this->Expiry));
}
$this->Security($Content);
$this->Condense($Content, $this->Limit);
return $Content;
}