本文整理汇总了PHP中RoleModel::Roles方法的典型用法代码示例。如果您正苦于以下问题:PHP RoleModel::Roles方法的具体用法?PHP RoleModel::Roles怎么用?PHP RoleModel::Roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RoleModel
的用法示例。
在下文中一共展示了RoleModel::Roles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: FixPermissions
/**
* If any role has no permission records, set Member-like permissions on it.
*
* @return array
*/
public function FixPermissions()
{
$Roles = RoleModel::Roles();
$RoleModel = new RoleModel();
$PermissionModel = new PermissionModel();
// Find roles missing permission records
foreach ($Roles as $RoleID => $Role) {
$Permissions = $this->SQL->Select('*')->From('Permission p')->Where('p.RoleID', $RoleID)->Get()->ResultArray();
if (!count($Permissions)) {
// Set basic permission record
$DefaultRecord = array('RoleID' => $RoleID, 'JunctionTable' => null, 'JunctionColumn' => null, 'JunctionID' => null, 'Garden.Email.View' => 1, 'Garden.SignIn.Allow' => 1, 'Garden.Activity.View' => 1, 'Garden.Profiles.View' => 1, 'Garden.Profiles.Edit' => 1, 'Conversations.Conversations.Add' => 1);
$PermissionModel->Save($DefaultRecord);
// Set default category permission
$DefaultCategory = array('RoleID' => $RoleID, 'JunctionTable' => 'Category', 'JunctionColumn' => 'PermissionCategoryID', 'JunctionID' => -1, 'Vanilla.Discussions.View' => 1, 'Vanilla.Discussions.Add' => 1, 'Vanilla.Comments.Add' => 1);
$PermissionModel->Save($DefaultCategory);
}
}
return array('Complete' => TRUE);
}
示例2: Save
/**
* Generic save procedure.
*/
public function Save($FormPostValues, $Settings = FALSE)
{
// See if the user's related roles should be saved or not.
$SaveRoles = GetValue('SaveRoles', $Settings);
// Define the primary key in this model's table.
$this->DefineSchema();
// Custom Rule: This will make sure that at least one role was selected if saving roles for this user.
if ($SaveRoles) {
$this->Validation->AddRule('OneOrMoreArrayItemRequired', 'function:ValidateOneOrMoreArrayItemRequired');
// $this->Validation->AddValidationField('RoleID', $FormPostValues);
$this->Validation->ApplyRule('RoleID', 'OneOrMoreArrayItemRequired');
}
// Make sure that the checkbox val for email is saved as the appropriate enum
if (array_key_exists('ShowEmail', $FormPostValues)) {
$FormPostValues['ShowEmail'] = ForceBool($FormPostValues['ShowEmail'], '0', '1', '0');
}
if (array_key_exists('Banned', $FormPostValues)) {
$FormPostValues['Banned'] = ForceBool($FormPostValues['Banned'], '0', '1', '0');
}
// Validate the form posted values
$UserID = GetValue('UserID', $FormPostValues);
$Insert = $UserID > 0 ? FALSE : TRUE;
if ($Insert) {
$this->AddInsertFields($FormPostValues);
} else {
$this->AddUpdateFields($FormPostValues);
}
$this->EventArguments['FormPostValues'] = $FormPostValues;
$this->FireEvent('BeforeSaveValidation');
$RecordRoleChange = TRUE;
if ($UserID && GetValue('FixUnique', $Settings)) {
$UniqueValid = $this->ValidateUniqueFields(GetValue('Name', $FormPostValues), GetValue('Email', $FormPostValues), $UserID, TRUE);
if (!$UniqueValid['Name']) {
unset($FormPostValues['Name']);
}
if (!$UniqueValid['Email']) {
unset($FormPostValues['Email']);
}
$UniqueValid = TRUE;
} else {
$UniqueValid = $this->ValidateUniqueFields(GetValue('Name', $FormPostValues), GetValue('Email', $FormPostValues), $UserID);
}
// Add & apply any extra validation rules:
if (array_key_exists('Email', $FormPostValues) && GetValue('ValidateEmail', $Settings, TRUE)) {
$this->Validation->ApplyRule('Email', 'Email');
}
if ($this->Validate($FormPostValues, $Insert) && $UniqueValid) {
$Fields = $this->Validation->ValidationFields();
// All fields on the form that need to be validated (including non-schema field rules defined above)
$RoleIDs = GetValue('RoleID', $Fields, 0);
$Username = GetValue('Name', $Fields);
$Email = GetValue('Email', $Fields);
$Fields = $this->Validation->SchemaValidationFields();
// Only fields that are present in the schema
// Remove the primary key from the fields collection before saving
$Fields = RemoveKeyFromArray($Fields, $this->PrimaryKey);
if (in_array('AllIPAddresses', $Fields) && is_array($Fields)) {
$Fields['AllIPAddresses'] = implode(',', $Fields['AllIPAddresses']);
}
if (!$Insert && array_key_exists('Password', $Fields)) {
// Encrypt the password for saving only if it won't be hashed in _Insert()
$PasswordHash = new Gdn_PasswordHash();
$Fields['Password'] = $PasswordHash->HashPassword($Fields['Password']);
$Fields['HashMethod'] = 'Vanilla';
}
// Check for email confirmation.
if (self::RequireConfirmEmail() && !GetValue('NoConfirmEmail', $Settings)) {
if (isset($Fields['Email']) && $UserID == Gdn::Session()->UserID && $Fields['Email'] != Gdn::Session()->User->Email && !Gdn::Session()->CheckPermission('Garden.Users.Edit')) {
$User = Gdn::Session()->User;
$Attributes = Gdn::Session()->User->Attributes;
$ConfirmEmailRoleID = C('Garden.Registration.ConfirmEmailRole');
if (RoleModel::Roles($ConfirmEmailRoleID)) {
// The confirm email role is set and it exists so go ahead with the email confirmation.
$EmailKey = TouchValue('EmailKey', $Attributes, RandomString(8));
if (isset($Attributes['ConfirmedEmailRoles']) && !in_array($ConfirmEmailRoleID, $Attributes['ConfirmedEmailRoles'])) {
$ConfirmedEmailRoles = $Attributes['ConfirmedEmailRoles'];
} elseif ($RoleIDs) {
$ConfirmedEmailRoles = $RoleIDs;
} else {
$ConfirmedEmailRoles = ConsolidateArrayValuesByKey($this->GetRoles($UserID), 'RoleID');
}
$Attributes['ConfirmedEmailRoles'] = $ConfirmedEmailRoles;
$RoleIDs = (array) C('Garden.Registration.ConfirmEmailRole');
$SaveRoles = TRUE;
$Fields['Attributes'] = serialize($Attributes);
}
}
}
$this->EventArguments['Fields'] = $Fields;
$this->FireEvent('BeforeSave');
// Check the validation results again in case something was added during the BeforeSave event.
if (count($this->Validation->Results()) == 0) {
// If the primary key exists in the validated fields and it is a
// numeric value greater than zero, update the related database row.
if ($UserID > 0) {
// If they are changing the username & email, make sure they aren't
// already being used (by someone other than this user)
//.........这里部分代码省略.........
示例3: GetByName
/**
*
* @param array|string $Names
*/
public static function GetByName($Names, &$Missing = NULL)
{
if (is_string($Names)) {
$Names = explode(',', $Names);
$Names = array_map('trim', $Names);
}
// Make a lookup array of the names.
$Names = array_unique($Names);
$Names = array_combine($Names, $Names);
$Names = array_change_key_case($Names);
$Roles = RoleModel::Roles();
$Result = array();
foreach ($Roles as $RoleID => $Role) {
$Name = strtolower($Role['Name']);
if (isset($Names[$Name])) {
$Result[$RoleID] = $Role;
unset($Names[$Name]);
}
}
$Missing = array_values($Names);
return $Result;
}