本文整理汇总了PHP中ArrayCombine函数的典型用法代码示例。如果您正苦于以下问题:PHP ArrayCombine函数的具体用法?PHP ArrayCombine怎么用?PHP ArrayCombine使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayCombine函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetArray
/**
* Returns an array of RoleID => RoleName pairs.
*
* @return array
*/
public function GetArray() {
// $RoleData = $this->GetEditablePermissions();
$RoleData = $this->Get();
$RoleIDs = ConsolidateArrayValuesByKey($RoleData->ResultArray(), 'RoleID');
$RoleNames = ConsolidateArrayValuesByKey($RoleData->ResultArray(), 'Name');
return ArrayCombine($RoleIDs, $RoleNames);
}
示例2: Registration
/**
* Configuration of registration settings.
*/
public function Registration($RedirectUrl = '')
{
$this->Permission('Garden.Registration.Manage');
if (!C('Garden.Registration.Manage', TRUE)) {
return Gdn::Dispatcher()->Dispatch('Default404');
}
$this->AddSideMenu('dashboard/settings/registration');
$this->AddJsFile('registration.js');
$this->Title(T('Registration'));
// Create a model to save configuration settings
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array('Garden.Registration.Method' => 'Captcha', 'Garden.Registration.CaptchaPrivateKey', 'Garden.Registration.CaptchaPublicKey', 'Garden.Registration.InviteExpiration'));
// Set the model on the forms.
$this->Form->SetModel($ConfigurationModel);
// Load roles with sign-in permission
$RoleModel = new RoleModel();
$this->RoleData = $RoleModel->GetByPermission('Garden.SignIn.Allow');
// Get the currently selected default roles
// $this->ExistingRoleData = Gdn::Config('Garden.Registration.DefaultRoles');
// if (is_array($this->ExistingRoleData) === FALSE)
// $this->ExistingRoleData = array();
// Get currently selected InvitationOptions
$this->ExistingRoleInvitations = Gdn::Config('Garden.Registration.InviteRoles');
if (is_array($this->ExistingRoleInvitations) === FALSE) {
$this->ExistingRoleInvitations = array();
}
// Get the currently selected Expiration Length
$this->InviteExpiration = Gdn::Config('Garden.Registration.InviteExpiration', '');
// Registration methods.
$this->RegistrationMethods = array('Captcha' => "New users fill out a simple form and are granted access immediately.", 'Approval' => "New users are reviewed and approved by an administrator (that's you!).", 'Invitation' => "Existing members send invitations to new members.");
// Options for how many invitations a role can send out per month.
$this->InvitationOptions = array('0' => T('None'), '1' => '1', '2' => '2', '5' => '5', '-1' => T('Unlimited'));
// Options for when invitations should expire.
$this->InviteExpirationOptions = array('-1 week' => T('1 week after being sent'), '-2 weeks' => T('2 weeks after being sent'), '-1 month' => T('1 month after being sent'), 'FALSE' => T('never'));
if ($this->Form->AuthenticatedPostBack() === FALSE) {
$this->Form->SetData($ConfigurationModel->Data);
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->ApplyRule('Garden.Registration.Method', 'Required');
// if($this->Form->GetValue('Garden.Registration.Method') != 'Closed')
// $ConfigurationModel->Validation->ApplyRule('Garden.Registration.DefaultRoles', 'RequiredArray');
// Define the Garden.Registration.RoleInvitations setting based on the postback values
$InvitationRoleIDs = $this->Form->GetValue('InvitationRoleID');
$InvitationCounts = $this->Form->GetValue('InvitationCount');
$this->ExistingRoleInvitations = ArrayCombine($InvitationRoleIDs, $InvitationCounts);
$ConfigurationModel->ForceSetting('Garden.Registration.InviteRoles', $this->ExistingRoleInvitations);
// Save!
if ($this->Form->Save() !== FALSE) {
$this->StatusMessage = T("Your settings have been saved.");
if ($RedirectUrl != '') {
$this->RedirectUrl = $RedirectUrl;
}
}
}
$this->Render();
}
示例3: delete
/**
* Delete a user account.
*
* @since 2.0.0
* @access public
* @param int $UserID Unique ID.
* @param string $Method Type of deletion to do (delete, keep, or wipe).
*/
public function delete($UserID = '', $Method = '')
{
$this->permission('Garden.Users.Delete');
$Session = Gdn::session();
if ($Session->User->UserID == $UserID) {
trigger_error(errorMessage("You cannot delete the user you are logged in as.", $this->ClassName, 'FetchViewLocation'), E_USER_ERROR);
}
$this->addSideMenu('dashboard/user');
$this->title(t('Delete User'));
$RoleModel = new RoleModel();
$AllRoles = $RoleModel->getArray();
// By default, people with access here can freely assign all roles
$this->RoleData = $AllRoles;
$UserModel = new UserModel();
$this->User = $UserModel->getID($UserID);
try {
$CanDelete = true;
$this->EventArguments['CanDelete'] =& $CanDelete;
$this->EventArguments['TargetUser'] =& $this->User;
// These are all the 'effective' roles for this delete action. This list can
// be trimmed down from the real list to allow subsets of roles to be
// edited.
$this->EventArguments['RoleData'] =& $this->RoleData;
$UserRoleData = $UserModel->getRoles($UserID)->resultArray();
$RoleIDs = array_column($UserRoleData, 'RoleID');
$RoleNames = array_column($UserRoleData, 'Name');
$this->UserRoleData = ArrayCombine($RoleIDs, $RoleNames);
$this->EventArguments['UserRoleData'] =& $this->UserRoleData;
$this->fireEvent("BeforeUserDelete");
$this->setData('CanDelete', $CanDelete);
$Method = in_array($Method, array('delete', 'keep', 'wipe')) ? $Method : '';
$this->Method = $Method;
if ($Method != '') {
$this->View = 'deleteconfirm';
}
if ($this->Form->authenticatedPostBack() && $Method != '') {
$UserModel->delete($UserID, array('DeleteMethod' => $Method));
$this->View = 'deletecomplete';
}
} catch (Exception $Ex) {
$this->Form->addError($Ex);
}
$this->render();
}
示例4: array
<?php
if (!defined('APPLICATION')) {
exit;
}
$Count = array(1, 2, 3, 4, 5, 10, 15, 20, 25, 30);
$Time = array(30, 60, 90, 120, 240);
$Lock = array(30, 60, 90, 120, 240);
$SpamCount = ArrayCombine($Count, $Count);
$SpamTime = ArrayCombine($Time, $Time);
$SpamLock = ArrayCombine(array(60, 120, 180, 240, 300, 600), array(1, 2, 3, 4, 5, 10));
echo $this->Form->Open();
echo $this->Form->Errors();
?>
<h1><?php
echo Gdn::Translate('Manage Spam');
?>
</h1>
<div class="Info"><?php
echo Gdn::Translate('Prevent spam on your forum by limiting the number of discussions & comments that users can post within a given period of time.');
?>
</div>
<table class="AltColumns">
<thead>
<tr>
<th><?php
echo Gdn::Translate('Only Allow');
?>
</th>
<th class="Alt"><?php
echo Gdn::Translate('Within');
示例5: Registration
/**
* Configuration of registration settings.
*/
public function Registration($RedirectUrl = '')
{
$this->Permission('Garden.Registration.Manage');
$this->AddSideMenu('garden/settings/registration');
$this->AddJsFile('registration.js');
$this->Title(Translate('Registration'));
// Create a model to save configuration settings
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array('Garden.Registration.Method', 'Garden.Registration.DefaultRoles', 'Garden.Registration.CaptchaPrivateKey', 'Garden.Registration.CaptchaPublicKey', 'Garden.Registration.InviteExpiration'));
// Set the model on the forms.
$this->Form->SetModel($ConfigurationModel);
// Load roles with sign-in permission
$RoleModel = new Gdn_RoleModel();
$this->RoleData = $RoleModel->GetByPermission('Garden.SignIn.Allow');
// Get the currently selected default roles
$this->ExistingRoleData = Gdn::Config('Garden.Registration.DefaultRoles');
if (is_array($this->ExistingRoleData) === FALSE) {
$this->ExistingRoleData = array();
}
// Get currently selected InvitationOptions
$this->ExistingRoleInvitations = Gdn::Config('Garden.Registration.InviteRoles');
if (is_array($this->ExistingRoleInvitations) === FALSE) {
$this->ExistingRoleInvitations = array();
}
// Get the currently selected Expiration Length
$this->InviteExpiration = Gdn::Config('Garden.Registration.InviteExpiration', '');
// Registration methods.
$this->RegistrationMethods = array('Closed' => "Registration is closed.", 'Basic' => "The applicants are granted access immediately.", 'Captcha' => "The applicants must copy the text from a captcha image, proving that they are not a robot.", 'Approval' => "The applicants must be approved by an administrator before they are granted access.", 'Invitation' => "Existing members send out invitations to new members. Any person who receives an invitation is granted access immediately. Invitations are permission-based (defined below). Monthly invitations are NOT cumulative.");
// Options for how many invitations a role can send out per month.
$this->InvitationOptions = array('0' => Gdn::Translate('None'), '1' => '1', '2' => '2', '5' => '5', '-1' => Gdn::Translate('Unlimited'));
// Options for when invitations should expire.
$this->InviteExpirationOptions = array('-1 week' => Gdn::Translate('1 week after being sent'), '-2 weeks' => Gdn::Translate('2 weeks after being sent'), '-1 month' => Gdn::Translate('1 month after being sent'), 'FALSE' => Gdn::Translate('never'));
if ($this->Form->AuthenticatedPostBack() === FALSE) {
$this->Form->SetData($ConfigurationModel->Data);
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->ApplyRule('Garden.Registration.Method', 'Required');
if ($this->Form->GetValue('Garden.Registration.Method') != 'Closed') {
$ConfigurationModel->Validation->ApplyRule('Garden.Registration.DefaultRoles', 'RequiredArray');
}
// Define the Garden.Registration.RoleInvitations setting based on the postback values
$InvitationRoleIDs = $this->Form->GetValue('InvitationRoleID');
$InvitationCounts = $this->Form->GetValue('InvitationCount');
$this->ExistingRoleInvitations = ArrayCombine($InvitationRoleIDs, $InvitationCounts);
$ConfigurationModel->ForceSetting('Garden.Registration.InviteRoles', $this->ExistingRoleInvitations);
// Save!
if ($this->Form->Save() !== FALSE) {
$this->StatusMessage = Translate("Your settings have been saved.");
if ($RedirectUrl != '') {
$this->RedirectUrl = $RedirectUrl;
}
}
}
$this->Render();
}
示例6: Edit
/**
* 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 = CheckPermission('Garden.Settings.Manage') ? $AllRoles : array();
$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) GetValueR('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 = ConsolidateArrayValuesByKey($UserRoleData, 'RoleID');
$RoleNames = ConsolidateArrayValuesByKey($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
//.........这里部分代码省略.........
示例7: hash_algos
echo $this->Form->CheckBox('Trusted', 'This is trusted connection and can sync roles & permissions.');
?>
</li>
<li>
<?php
echo $this->Form->CheckBox('IsDefault', 'Make this connection your default signin method.');
?>
</li>
<li>
<h2>Advanced</h2>
</li>
<li>
<?php
$HashAlgos = hash_algos();
$HashAlgos = ArrayCombine($HashAlgos, $HashAlgos);
echo $this->Form->Label('Hash Algorithm', 'HashType'), '<div class="Info">' . T("Choose md5 if you're not sure what to choose.", "You can select a custom hash algorithm to sign your requests. The hash algorithm must also be used in your client library. Choose md5 if you're not sure what to choose.") . '</div>', $this->Form->DropDown('HashType', $HashAlgos, array('Default' => 'md5'));
?>
</li>
<li>
<?php
echo $this->Form->CheckBox('TestMode', 'This connection is in test-mode.');
?>
</li>
</ul>
<?php
echo '<div class="Buttons">';
echo $this->Form->Button('Save');
echo $this->Form->Button('Generate Client ID and Secret', array('Name' => 'Generate'));
示例8: Edit
/**
* 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');
// Determine if username can be edited
$this->CanEditUsername = TRUE;
$this->CanEditUsername = $this->CanEditUsername & Gdn::Config("Garden.Profile.EditUsernames");
$this->CanEditUsername = $this->CanEditUsername | Gdn::Session()->CheckPermission('Garden.Users.Edit');
$RoleModel = new RoleModel();
$AllRoles = $RoleModel->GetArray();
// By default, people with access here can freely assign all roles
$this->RoleData = $AllRoles;
$UserModel = new UserModel();
$this->User = $UserModel->GetID($UserID);
// 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'] =& $this->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'] =& $this->RoleData;
$UserRoleData = $UserModel->GetRoles($UserID)->ResultArray();
$RoleIDs = ConsolidateArrayValuesByKey($UserRoleData, 'RoleID');
$RoleNames = ConsolidateArrayValuesByKey($UserRoleData, 'Name');
$this->UserRoleData = ArrayCombine($RoleIDs, $RoleNames);
$this->EventArguments['UserRoleData'] =& $this->UserRoleData;
$this->FireEvent("BeforeUserEdit");
$this->SetData('AllowEditing', $AllowEditing);
if (!$this->Form->AuthenticatedPostBack()) {
$this->Form->SetData($this->User);
} else {
if (!$this->CanEditUsername) {
$this->Form->SetFormValue("Name", $this->User->Name);
}
// If a new password was specified, add it to the form's collection
$ResetPassword = $this->Form->GetValue('ResetPassword', FALSE);
$NewPassword = $this->Form->GetValue('NewPassword', '');
if ($ResetPassword !== FALSE) {
$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($this->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, $this->RoleData);
$UserImmutableRoles = array_intersect_key($ImmutableRoles, $this->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('Password', '') != '') {
$UserModel->SendPasswordEmail($UserID, $NewPassword);
}
$this->InformMessage(T('Your changes have been saved.'));
}
$this->UserRoleData = $UserNewRoles;
}
} catch (Exception $Ex) {
$this->Form->AddError($Ex);
}
$this->Render();
}