getArray() public method

Returns an array of RoleID => RoleName pairs.
public getArray ( ) : array
return array
示例#1
0
 public function toString()
 {
     $Form = $this->_Sender->Form;
     $this->_Sender->addJsFile('condition.js');
     if ($Form->authenticatedPostBack()) {
         // Grab the conditions from the form and convert them to the conditions array.
         $this->Conditions($this->_FromForm());
     } else {
     }
     $this->Types = array_merge(array('' => '(' . sprintf(t('Select a %s'), t('Condition Type', 'Type')) . ')'), Gdn_Condition::AllTypes());
     //die(print_r($this->Types));
     // Get all of the permissions that are valid for the permissions dropdown.
     $PermissionModel = new PermissionModel();
     $Permissions = $PermissionModel->GetGlobalPermissions(0);
     $Permissions = array_keys($Permissions);
     sort($Permissions);
     $Permissions = array_combine($Permissions, $Permissions);
     $Permissions = array_merge(array('' => '(' . sprintf(t('Select a %s'), t('Permission')) . ')'), $Permissions);
     $this->Permissions = $Permissions;
     // Get all of the roles.
     $RoleModel = new RoleModel();
     $Roles = $RoleModel->getArray();
     $Roles = array_merge(array('-' => '(' . sprintf(t('Select a %s'), t('Role')) . ')'), $Roles);
     $this->Roles = $Roles;
     $this->Form = $Form;
     return parent::ToString();
 }
 /**
  * Edit a user account.
  *
  * @since 2.0.0
  * @access public
  * @param int $UserID Unique ID.
  */
 public function edit($UserID)
 {
     $this->permission('Garden.Users.Edit');
     // Page setup
     $this->addJsFile('user.js');
     $this->title(t('Edit User'));
     $this->addSideMenu('dashboard/user');
     // Only admins can reassign roles
     $RoleModel = new RoleModel();
     $AllRoles = $RoleModel->getArray();
     $RoleData = $RoleModel->getAssignable();
     $UserModel = new UserModel();
     $User = $UserModel->getID($UserID, DATASET_TYPE_ARRAY);
     // Determine if username can be edited
     $CanEditUsername = (bool) c("Garden.Profile.EditUsernames") || Gdn::session()->checkPermission('Garden.Users.Edit');
     $this->setData('_CanEditUsername', $CanEditUsername);
     // Determine if emails can be edited
     $CanEditEmail = Gdn::session()->checkPermission('Garden.Users.Edit');
     $this->setData('_CanEditEmail', $CanEditEmail);
     // Decide if they have ability to confirm users
     $Confirmed = (bool) valr('Confirmed', $User);
     $CanConfirmEmail = UserModel::RequireConfirmEmail() && Gdn::session()->checkPermission('Garden.Users.Edit');
     $this->setData('_CanConfirmEmail', $CanConfirmEmail);
     $this->setData('_EmailConfirmed', $Confirmed);
     $User['ConfirmEmail'] = (int) $Confirmed;
     // Determine whether user being edited is privileged (can escalate permissions)
     $UserModel = new UserModel();
     $EditingPrivilegedUser = $UserModel->checkPermission($User, 'Garden.Settings.Manage');
     // Determine our password reset options
     // Anyone with user editing my force reset over email
     $this->ResetOptions = array(0 => t('Keep current password.'), 'Auto' => t('Force user to reset their password and send email notification.'));
     // Only admins may manually reset passwords for other admins
     if (checkPermission('Garden.Settings.Manage') || !$EditingPrivilegedUser) {
         $this->ResetOptions['Manual'] = t('Manually set user password. No email notification.');
     }
     // Set the model on the form.
     $this->Form->setModel($UserModel);
     // Make sure the form knows which item we are editing.
     $this->Form->addHidden('UserID', $UserID);
     try {
         $AllowEditing = true;
         $this->EventArguments['AllowEditing'] =& $AllowEditing;
         $this->EventArguments['TargetUser'] =& $User;
         // These are all the 'effective' roles for this edit action. This list can
         // be trimmed down from the real list to allow subsets of roles to be
         // edited.
         $this->EventArguments['RoleData'] =& $RoleData;
         $UserRoleData = $UserModel->getRoles($UserID)->resultArray();
         $RoleIDs = array_column($UserRoleData, 'RoleID');
         $RoleNames = array_column($UserRoleData, 'Name');
         $UserRoleData = arrayCombine($RoleIDs, $RoleNames);
         $this->EventArguments['UserRoleData'] =& $UserRoleData;
         $this->fireEvent("BeforeUserEdit");
         $this->setData('AllowEditing', $AllowEditing);
         $this->Form->setData($User);
         if ($this->Form->authenticatedPostBack()) {
             if (!$CanEditUsername) {
                 $this->Form->setFormValue("Name", $User['Name']);
             }
             // Allow mods to confirm/unconfirm emails
             $this->Form->removeFormValue('Confirmed');
             $Confirmation = $this->Form->getFormValue('ConfirmEmail', null);
             $Confirmation = !is_null($Confirmation) ? (bool) $Confirmation : null;
             if ($CanConfirmEmail && is_bool($Confirmation)) {
                 $this->Form->setFormValue('Confirmed', (int) $Confirmation);
             }
             $ResetPassword = $this->Form->getValue('ResetPassword', false);
             // If we're an admin or this isn't a privileged user, allow manual setting of password
             $AllowManualReset = checkPermission('Garden.Settings.Manage') || !$EditingPrivilegedUser;
             if ($ResetPassword == 'Manual' && $AllowManualReset) {
                 // If a new password was specified, add it to the form's collection
                 $NewPassword = $this->Form->getValue('NewPassword', '');
                 $this->Form->setFormValue('Password', $NewPassword);
             }
             // Role changes
             // These are the new roles the editing user wishes to apply to the target
             // user, adjusted for his ability to affect those roles
             $RequestedRoles = $this->Form->getFormValue('RoleID');
             if (!is_array($RequestedRoles)) {
                 $RequestedRoles = array();
             }
             $RequestedRoles = array_flip($RequestedRoles);
             $UserNewRoles = array_intersect_key($RoleData, $RequestedRoles);
             // These roles will stay turned on regardless of the form submission contents
             // because the editing user does not have permission to modify them
             $ImmutableRoles = array_diff_key($AllRoles, $RoleData);
             $UserImmutableRoles = array_intersect_key($ImmutableRoles, $UserRoleData);
             // Apply immutable roles
             foreach ($UserImmutableRoles as $IMRoleID => $IMRoleName) {
                 $UserNewRoles[$IMRoleID] = $IMRoleName;
             }
             // Put the data back into the forum object as if the user had submitted
             // this themselves
             $this->Form->setFormValue('RoleID', array_keys($UserNewRoles));
             if ($this->Form->save(array('SaveRoles' => true)) !== false) {
                 if ($this->Form->getValue('ResetPassword', '') == 'Auto') {
                     $UserModel->PasswordRequest($User['Email']);
                     $UserModel->setField($UserID, 'HashMethod', 'Reset');
                 }
                 $this->informMessage(t('Your changes have been saved.'));
             }
             $UserRoleData = $UserNewRoles;
         }
     } catch (Exception $Ex) {
         $this->Form->addError($Ex);
     }
     $this->setData('User', $User);
     $this->setData('Roles', $RoleData);
     $this->setData('UserRoles', $UserRoleData);
     $this->render();
 }
示例#3
0
 /**
  * Get users by role.
  *
  * @param int|string $Role The ID or name of the role.
  * @return Gdn_DataSet Returns the users with the given role.
  */
 public function getByRole($Role)
 {
     $RoleID = $Role;
     // Optimistic
     if (is_string($Role)) {
         $RoleModel = new RoleModel();
         $Roles = $RoleModel->getArray();
         $RolesByName = array_flip($Roles);
         $RoleID = val($Role, $RolesByName, null);
         // No such role
         if (is_null($RoleID)) {
             return new Gdn_DataSet();
         }
     }
     return $this->SQL->select('u.*')->from('User u')->join('UserRole ur', 'u.UserID = ur.UserID')->where('ur.RoleID', $RoleID, true, false)->orderBy('DateInserted', 'desc')->get();
 }
 /**
  * Edit user account.
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Username or User ID.
  */
 public function edit($UserReference = '', $Username = '', $UserID = '')
 {
     $this->permission('Garden.SignIn.Allow');
     $this->getUserInfo($UserReference, $Username, $UserID, true);
     $UserID = valr('User.UserID', $this);
     $Settings = array();
     // Set up form
     $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY);
     $this->Form->setModel(Gdn::userModel());
     $this->Form->setData($User);
     // Decide if they have ability to edit the username
     $CanEditUsername = (bool) c("Garden.Profile.EditUsernames") || Gdn::session()->checkPermission('Garden.Users.Edit');
     $this->setData('_CanEditUsername', $CanEditUsername);
     // Decide if they have ability to edit the email
     $EmailEnabled = (bool) c('Garden.Profile.EditEmails', true) && !UserModel::noEmail();
     $CanEditEmail = $EmailEnabled && $UserID == Gdn::session()->UserID || checkPermission('Garden.Users.Edit');
     $this->setData('_CanEditEmail', $CanEditEmail);
     // Decide if they have ability to confirm users
     $Confirmed = (bool) valr('User.Confirmed', $this);
     $CanConfirmEmail = UserModel::requireConfirmEmail() && checkPermission('Garden.Users.Edit');
     $this->setData('_CanConfirmEmail', $CanConfirmEmail);
     $this->setData('_EmailConfirmed', $Confirmed);
     $this->Form->setValue('ConfirmEmail', (int) $Confirmed);
     // Decide if we can *see* email
     $this->setData('_CanViewPersonalInfo', Gdn::session()->UserID == val('UserID', $User) || checkPermission('Garden.PersonalInfo.View') || checkPermission('Garden.Users.Edit'));
     // Define gender dropdown options
     $this->GenderOptions = array('u' => t('Unspecified'), 'm' => t('Male'), 'f' => t('Female'));
     $this->fireEvent('BeforeEdit');
     // If seeing the form for the first time...
     if ($this->Form->authenticatedPostBack()) {
         $this->Form->setFormValue('UserID', $UserID);
         if (!$CanEditUsername) {
             $this->Form->setFormValue("Name", $User['Name']);
         } else {
             $UsernameError = t('UsernameError', 'Username can only contain letters, numbers, underscores, and must be between 3 and 20 characters long.');
             Gdn::userModel()->Validation->applyRule('Name', 'Username', $UsernameError);
         }
         // API
         // These options become available when POSTing as a user with Garden.Settings.Manage permissions
         if (Gdn::session()->checkPermission('Garden.Settings.Manage')) {
             // Role change
             $RequestedRoles = $this->Form->getFormValue('RoleID', null);
             if (!is_null($RequestedRoles)) {
                 $RoleModel = new RoleModel();
                 $AllRoles = $RoleModel->getArray();
                 if (!is_array($RequestedRoles)) {
                     $RequestedRoles = is_numeric($RequestedRoles) ? array($RequestedRoles) : array();
                 }
                 $RequestedRoles = array_flip($RequestedRoles);
                 $UserNewRoles = array_intersect_key($AllRoles, $RequestedRoles);
                 // Put the data back into the forum object as if the user had submitted
                 // this themselves
                 $this->Form->setFormValue('RoleID', array_keys($UserNewRoles));
                 // Allow saving roles
                 $Settings['SaveRoles'] = true;
             }
             // Password change
             $NewPassword = $this->Form->getFormValue('Password', null);
             if (!is_null($NewPassword)) {
             }
         }
         // Allow mods to confirm emails
         $this->Form->removeFormValue('Confirmed');
         $Confirmation = $this->Form->getFormValue('ConfirmEmail', null);
         $Confirmation = !is_null($Confirmation) ? (bool) $Confirmation : null;
         if ($CanConfirmEmail && is_bool($Confirmation)) {
             $this->Form->setFormValue('Confirmed', (int) $Confirmation);
         }
         if ($this->Form->save($Settings) !== false) {
             $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY);
             $this->setData('Profile', $User);
             $this->informMessage(sprite('Check', 'InformSprite') . t('Your changes have been saved.'), 'Dismissable AutoDismiss HasSprite');
         }
         if (!$CanEditEmail) {
             $this->Form->setFormValue("Email", $User['Email']);
         }
     }
     $this->title(t('Edit Profile'));
     $this->_setBreadcrumbs(t('Edit Profile'), '/profile/edit');
     $this->render();
 }
 /**
  * Reset permissions for all roles, based on the value in their Type column.
  *
  * @param string $Type Role type to limit the updates to.
  */
 public static function resetAllRoles($Type = null)
 {
     // Retrieve an array containing all available roles.
     $RoleModel = new RoleModel();
     if ($Type) {
         $Result = $RoleModel->getByType($Type)->resultArray();
         $Roles = array_column($Result, 'Name', 'RoleID');
     } else {
         $Roles = $RoleModel->getArray();
     }
     // Iterate through our roles and reset their permissions.
     $Permissions = Gdn::permissionModel();
     foreach ($Roles as $RoleID => $Role) {
         $Permissions->resetRole($RoleID);
     }
 }
 /**
  * Editing a category.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $CategoryID Unique ID of the category to be updated.
  */
 public function editCategory($CategoryID = '')
 {
     // Check permission
     $this->permission('Garden.Community.Manage');
     // Set up models
     $RoleModel = new RoleModel();
     $PermissionModel = Gdn::permissionModel();
     $this->Form->setModel($this->CategoryModel);
     if (!$CategoryID && $this->Form->authenticatedPostBack()) {
         if ($ID = $this->Form->getFormValue('CategoryID')) {
             $CategoryID = $ID;
         }
     }
     // Get category data
     $this->Category = $this->CategoryModel->getID($CategoryID);
     if (!$this->Category) {
         throw notFoundException('Category');
     }
     $this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
     // Set up head
     $this->addJsFile('jquery.alphanumeric.js');
     $this->addJsFile('categories.js');
     $this->addJsFile('jquery.gardencheckboxgrid.js');
     $this->title(t('Edit Category'));
     $this->addSideMenu('vanilla/settings/managecategories');
     // Make sure the form knows which item we are editing.
     $this->Form->addHidden('CategoryID', $CategoryID);
     $this->setData('CategoryID', $CategoryID);
     // Load all roles with editable permissions
     $this->RoleArray = $RoleModel->getArray();
     $this->fireEvent('AddEditCategory');
     if ($this->Form->authenticatedPostBack()) {
         $this->setupDiscussionTypes($this->Category);
         $Upload = new Gdn_Upload();
         $TmpImage = $Upload->validateUpload('PhotoUpload', false);
         if ($TmpImage) {
             // Generate the target image name
             $TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image
             $Parts = $Upload->saveAs($TmpImage, $ImageBaseName);
             $this->Form->setFormValue('Photo', $Parts['SaveName']);
         }
         $this->Form->setFormValue('CustomPoints', (bool) $this->Form->getFormValue('CustomPoints'));
         if ($this->Form->save()) {
             $Category = CategoryModel::categories($CategoryID);
             $this->setData('Category', $Category);
             if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
                 redirect('vanilla/settings/managecategories');
             }
         }
     } else {
         $this->Form->setData($this->Category);
         $this->setupDiscussionTypes($this->Category);
         $this->Form->setValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
     }
     // Get all of the currently selected role/permission combinations for this junction.
     $Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
     $Permissions = $PermissionModel->unpivotPermissions($Permissions, true);
     if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
         $this->setData('PermissionData', $Permissions, true);
     }
     // Render default view
     $this->render();
 }
 /**
  * Editing a category.
  *
  * @since 2.0.0
  * @param int|string $CategoryID Unique ID of the category to be updated.
  * @throws Exception when category cannot be found.
  */
 public function editCategory($CategoryID = '')
 {
     // Check permission
     $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
     // Set up models
     $RoleModel = new RoleModel();
     $PermissionModel = Gdn::permissionModel();
     $this->Form->setModel($this->CategoryModel);
     if (!$CategoryID && $this->Form->authenticatedPostBack()) {
         if ($ID = $this->Form->getFormValue('CategoryID')) {
             $CategoryID = $ID;
         }
     }
     // Get category data
     $this->Category = CategoryModel::categories($CategoryID);
     if (!$this->Category) {
         throw notFoundException('Category');
     }
     // Category data is expected to be in the form of an object.
     $this->Category = (object) $this->Category;
     $this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
     $displayAsOptions = categoryModel::getDisplayAsOptions();
     // Restrict "Display As" types based on parent.
     $parentCategory = $this->CategoryModel->getID($this->Category->ParentCategoryID);
     $parentDisplay = val('DisplayAs', $parentCategory);
     if ($parentDisplay === 'Flat') {
         unset($displayAsOptions['Heading']);
     }
     // Set up head
     $this->addJsFile('jquery.alphanumeric.js');
     $this->addJsFile('manage-categories.js');
     $this->addJsFile('jquery.gardencheckboxgrid.js');
     $this->title(t('Edit Category'));
     $this->setHighlightRoute('vanilla/settings/categories');
     // Make sure the form knows which item we are editing.
     $this->Form->addHidden('CategoryID', $CategoryID);
     $this->setData('CategoryID', $CategoryID);
     // Load all roles with editable permissions
     $this->RoleArray = $RoleModel->getArray();
     $this->fireAs('SettingsController');
     $this->fireEvent('AddEditCategory');
     if ($this->Form->authenticatedPostBack()) {
         $this->setupDiscussionTypes($this->Category);
         $Upload = new Gdn_Upload();
         $TmpImage = $Upload->validateUpload('PhotoUpload', false);
         if ($TmpImage) {
             // Generate the target image name
             $TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image
             $Parts = $Upload->saveAs($TmpImage, $ImageBaseName);
             $this->Form->setFormValue('Photo', $Parts['SaveName']);
         }
         $this->Form->setFormValue('CustomPoints', (bool) $this->Form->getFormValue('CustomPoints'));
         // Enforces tinyint values on boolean fields to comply with strict mode
         $this->Form->setFormValue('HideAllDiscussions', forceBool($this->Form->getFormValue('HideAllDiscussions'), '0', '1', '0'));
         $this->Form->setFormValue('Archived', forceBool($this->Form->getFormValue('Archived'), '0', '1', '0'));
         $this->Form->setFormValue('AllowFileUploads', forceBool($this->Form->getFormValue('AllowFileUploads'), '0', '1', '0'));
         if ($parentDisplay === 'Flat' && $this->Form->getFormValue('DisplayAs') === 'Heading') {
             $this->Form->addError('Cannot display as a heading when your parent category is displayed flat.', 'DisplayAs');
         }
         if ($this->Form->save()) {
             $Category = CategoryModel::categories($CategoryID);
             $this->setData('Category', $Category);
             if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
                 $destination = $this->categoryPageByParent($parentCategory);
                 redirect($destination);
             } elseif ($this->deliveryType() === DELIVERY_TYPE_DATA && method_exists($this, 'getCategory')) {
                 $this->Data = [];
                 $this->getCategory($CategoryID);
                 return;
             }
         }
     } else {
         $this->Form->setData($this->Category);
         $this->setupDiscussionTypes($this->Category);
         $this->Form->setValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
     }
     // Get all of the currently selected role/permission combinations for this junction.
     $Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
     $Permissions = $PermissionModel->unpivotPermissions($Permissions, true);
     if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
         $this->setData('PermissionData', $Permissions, true);
     }
     // Render default view
     $this->setData('Operation', 'Edit');
     $this->setData('DisplayAsOptions', $displayAsOptions);
     $this->render();
 }
 /**
  * Create settings screen for plugin.
  *
  * @param $sender SettingsController.
  * @return void.
  * @package TwitterBot
  * @since 0.1
  */
 public function settingsController_twitterBot_create($sender)
 {
     $sender->permission('Garden.Settings.Manage');
     $sender->addSideMenu('dashboard/settings/plugins');
     $categories = CategoryModel::categories();
     unset($categories[-1]);
     $roleModel = new RoleModel();
     $userRoles = $roleModel->getArray();
     $configurationModule = new ConfigurationModule($sender);
     $configurationModule->initialize(array('TwitterBot.ConsumerKey' => array('LabelCode' => 'Your applications consumer key', 'Options' => array('class' => 'InputBox BigInput')), 'TwitterBot.ConsumerSecret' => array('LabelCode' => 'The secret for your consumer key', 'Options' => array('class' => 'InputBox BigInput')), 'TwitterBot.OAuthAccessToken' => array('LabelCode' => 'Your oAuth access token', 'Options' => array('class' => 'InputBox BigInput')), 'TwitterBot.OAuthAccessTokenSecret' => array('LabelCode' => 'The secret for your oAuth access token', 'Options' => array('class' => 'InputBox BigInput')), 'TwitterBot.CategoryIDs' => array('Control' => 'CheckBoxList', 'LabelCode' => 'Categories', 'Items' => $categories, 'Description' => 'Tweet discussions from this categories', 'Options' => array('ValueField' => 'CategoryID', 'TextField' => 'Name')), 'TwitterBot.RoleIDs' => array('Control' => 'CheckBoxList', 'LabelCode' => 'User roles', 'Items' => $userRoles, 'Description' => 'Only discussions of this user roles will be published on Twitter', 'Options' => array('ValueField' => 'RoleID', 'TextField' => 'Name')), 'TwitterBot.AnnouncementsOnly' => array('Control' => 'CheckBox', 'LabelCode' => 'Only tweet announcements', 'Default' => true), 'TwitterBot.ShowCheckbox' => array('Control' => 'CheckBox', 'LabelCode' => 'Show checkbox below new discussions', 'Default' => true)));
     $sender->setData('Title', t('TwitterBot Settings'));
     $sender->setData('Description', t('New discussions will automatically appear on your Twitter account. You have to <a href="https://apps.twitter.com/app/new">create a new app</a> and fill the credentials in her to make it work.'));
     $configurationModule->renderAll();
 }