本文整理汇总了PHP中RoleModel::roles方法的典型用法代码示例。如果您正苦于以下问题:PHP RoleModel::roles方法的具体用法?PHP RoleModel::roles怎么用?PHP RoleModel::roles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RoleModel
的用法示例。
在下文中一共展示了RoleModel::roles方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lookupRoleIDs
/**
*
*
* @param array $Roles
* @return array
*/
protected function lookupRoleIDs($Roles)
{
if (is_string($Roles)) {
$Roles = explode(',', $Roles);
} elseif (!is_array($Roles)) {
$Roles = [];
}
$Roles = array_map('trim', $Roles);
$Roles = array_map('strtolower', $Roles);
$AllRoles = RoleModel::roles();
$RoleIDs = [];
foreach ($AllRoles as $RoleID => $Role) {
$Name = strtolower($Role['Name']);
if (in_array($Name, $Roles) || in_array($RoleID, $Roles)) {
$RoleIDs[] = $RoleID;
}
}
return $RoleIDs;
}
示例2: 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);
}
示例3: getRoles
/**
*
*
* @param $UserID
* @return Gdn_DataSet
*/
public function getRoles($UserID)
{
$UserRolesKey = formatString(self::USERROLES_KEY, array('UserID' => $UserID));
$RolesDataArray = Gdn::cache()->get($UserRolesKey);
if ($RolesDataArray === Gdn_Cache::CACHEOP_FAILURE) {
$RolesDataArray = $this->SQL->getWhere('UserRole', array('UserID' => $UserID))->resultArray();
$RolesDataArray = consolidateArrayValuesByKey($RolesDataArray, 'RoleID');
}
$Result = array();
foreach ($RolesDataArray as $RoleID) {
$Result[] = RoleModel::roles($RoleID, true);
}
return new Gdn_DataSet($Result);
}
示例4: getByName
/**
* Get a role by name.
*
* @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;
}
示例5: settingsController_readOnly_create
/**
* Settings screen for role and restriction choice.
*
* @param object $sender SettingsController.
* @return void.
* @package ReadOnly
* @since 0.1
*/
public function settingsController_readOnly_create($sender)
{
// Define general settings properties.
$sender->permission('Garden.Settings.Manage');
$sender->addSideMenu('/dashboard/settings/plugins');
$sender->setData('Title', t('ReadOnly Settings'));
$sender->setData('Description', t('ReadOnly Settings Description', 'Choose which roles and actions should be restricted.<br/>You
should inform your users about the read only state by ' . anchor('adding a message', '/dashboard/message/add') . ' to the forum.'));
// Consolidate/prepare permissions.
$permissionModel = Gdn::PermissionModel();
$perms = $permissionModel->PermissionColumns();
unset($perms['PermissionID']);
$permissions = array();
foreach ($perms as $key => $value) {
$action = substr($key, strrpos($key, '.') + 1);
$permissions[$action] .= $key . ', ';
}
$permissionItems = array();
foreach ($permissions as $key => $value) {
$text = $key . '<span>' . trim($value, ', ') . '</span>';
$permissionItems[$text] = $key;
}
// Consolidate/prepare roles.
$roleModel = new RoleModel();
$roles = $roleModel->roles();
$roleItems = array();
foreach ($roles as $role) {
$roleItems[$role['Name']] = $role['RoleID'];
}
// Build form info.
$configurationModule = new configurationModule($sender);
$configurationModule->initialize(array('ReadOnly.Restrictions' => array('Control' => 'CheckBoxList', 'Description' => t('ReadOnly Settings Restrictions', 'Choose the actions that should be restricted. Below each action is a list of all the current permissions with that action."Add" and "Edit" is recommended.'), 'Items' => $permissionItems, 'LabelCode' => 'Restrictions'), 'ReadOnly.Roles' => array('Control' => 'CheckBoxList', 'Description' => t('Choose the roles that should <strong>not</strong> be restricted (Admin users will always have all permissions).'), 'Items' => $roleItems, 'LabelCode' => 'Roles'), 'ReadOnly.Message' => array('Control' => 'TextBox', 'LabelCode' => 'Message Text', 'Description' => 'It is a good idea to ' . anchor('inform your users', '/dashboard/message') . ' about the restrictions so that they now what\'s going on...', 'Options' => array('MultiLine' => true)), 'ReadOnly.ShowAlert' => array('Control' => 'Checkbox', 'Description' => 'You can choose show or deactivate the message, however.', 'LabelCode' => 'Show Message')));
// Handle alert message.
if ($sender->Request->isPostBack()) {
$post = $sender->Request->getRequestArguments('post');
$messageModel = new MessageModel();
$messageID = c('ReadOnly.MessageID');
$message = $messageModel->getID($messageID);
if (!$post['ReadOnly-dot-Message']) {
// Delete message when no text is given.
if ($message) {
$messageModel->delete(array('MessageID' => $messageID));
removeFromConfig('ReadOnly.MessageID');
}
} else {
// Check if message already exists.
if ($message) {
// Set MessageID so that existing message gets updated
$formPostValues['MessageID'] = $messageID;
}
$formPostValues['Location'] = '[Base]';
$formPostValues['AssetTarget'] = 'Content';
$formPostValues['Content'] = $post['ReadOnly-dot-Message'];
$formPostValues['CssClass'] = 'AlertMessage';
$formPostValues['Enabled'] = $post['ReadOnly-dot-ShowAlert'];
$formPostValues['AllowDismiss'] = false;
$formPostValues['TransientKey'] = Gdn::session()->transientKey();
saveToConfig('ReadOnly.MessageID', $messageModel->save($formPostValues));
}
}
// Show form.
$configurationModule->renderAll();
}