当前位置: 首页>>代码示例>>PHP>>正文


PHP RoleModel::Roles方法代码示例

本文整理汇总了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);
 }
开发者ID:3marproof,项目名称:vanilla,代码行数:24,代码来源:class.dbamodel.php

示例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)
//.........这里部分代码省略.........
开发者ID:statico,项目名称:openshift-origin-vanillaforums,代码行数:101,代码来源:class.usermodel.php

示例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;
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:26,代码来源:class.rolemodel.php


注:本文中的RoleModel::Roles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。