本文整理汇总了PHP中RoleModel类的典型用法代码示例。如果您正苦于以下问题:PHP RoleModel类的具体用法?PHP RoleModel怎么用?PHP RoleModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RoleModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterCheckAdmin
/**
*
* 过滤器
* @param unknown_type $filterChain
*/
public function filterCheckAdmin($filterChain)
{
//未登录,跳转
if (!($uid = $this->isAdmin())) {
$this->redirect(Yii::app()->baseUrl . "/");
}
//获取用户详细资料
$adminModel = new AdminModel();
$this->_userInfo = $adminModel->getInfoByUid($uid);
$this->username = $this->_userInfo['username'];
$this->hospital = $this->_userInfo['hospital'];
$this->role = $this->_userInfo['role'];
//账号错误
if (!$this->_userInfo) {
$this->_output("302", 'access deny', 'text');
}
$roleModel = new RoleModel();
$role = $roleModel->getInfoByCode($this->_userInfo['role']);
if ($role && $role['permission']) {
$permission = explode(',', $role['permission']);
//生成菜单
$menuModel = new MenuModel();
$this->menus = $menuModel->getInfoByGroup($permission);
foreach ($this->menus as $key => $value) {
$this->menuGroup[$value['group']] = $value['group'];
}
} else {
header("HTTP/1.1 401");
exit;
}
$filterChain->run();
}
示例2: dadosAction
public function dadosAction()
{
$this->_helper->layout->disableLayout();
$page = $this->_request->getParam("page", 1);
$limit = $this->_request->getParam("rows");
$sidx = $this->_request->getParam("sidx", 1);
$sord = $this->_request->getParam("sord");
$roleModel = new RoleModel();
$role = $roleModel->fetchAll();
$count = count($role);
if ($count > 0) {
$total_pages = ceil($count / $limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) {
$page = $total_pages;
}
//$role = $roleModel->fetchAll(null, "$sidx $sord", $limit, ($page*$limit-$limit));
$responce = new stdClass();
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i = 0;
foreach ($role as $row) {
$responce->rows[$i]['cell'] = array($row->cdrole, $row->nmrole);
$i++;
}
$this->view->dados = $responce;
}
示例3: toString
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();
}
示例4: _add
/**
* 添加规则
* @param string $resName
* @param string $privName
*/
protected function _add($resName, $privName)
{
$data = array('res_name' => $resName, 'priv_name' => $privName);
$this->db->insert('acl_rule', $data);
$ruleId = $this->db->lastInsertId();
$roleModel = new RoleModel($this->_modName);
$roleList = $roleModel->getAll();
$data = array();
foreach ($roleList as $role) {
$data = array('rule_id' => $ruleId, 'role_id' => $role['role_id'], 'permit' => 0);
$this->db->insert('acl', $data);
}
}
示例5: updatePermissions
/**
* @param array $input
*
* @return bool
*/
public function updatePermissions(array $input)
{
$roles = $this->getRoles();
$model = new RoleModel($this->db);
foreach ($roles as $role) {
if (isset($input[$role->getId()])) {
$permissions = array_keys($input[$role->getId()]);
$model->updatePermissions($role->getId(), $permissions);
} else {
$model->updatePermissions($role->getId(), array());
}
}
return true;
}
示例6: SelectByRole
/**
* Select content based on author RoleID
*
* @param array $Parameters
* @return boolean
*/
protected function SelectByRole($Parameters)
{
if (!is_array($Parameters)) {
$RoleID = $Parameters;
} else {
$RoleID = GetValue('RoleID', $Parameters, NULL);
}
// Lookup role name -> roleID
if (is_string($RoleID)) {
$RoleModel = new RoleModel();
$Roles = explode(',', $RoleID);
$RoleID = array();
foreach ($Roles as $TestRoleID) {
$TestRoleID = trim($TestRoleID);
$Role = $RoleModel->GetByName($TestRoleID);
if (!$Role) {
continue;
} else {
$Role = array_shift($Role);
$RoleID[] = GetValue('RoleID', $Role);
}
}
}
if (empty($RoleID) || !sizeof($RoleID)) {
return FALSE;
}
// Check cache
$SelectorRoleCacheKey = "modules.promotedcontent.role.{$RoleID}";
$Content = Gdn::Cache()->Get($SelectorRoleCacheKey);
if ($Content == Gdn_Cache::CACHEOP_FAILURE) {
// Get everyone with this Role
$UserIDs = Gdn::SQL()->Select('ur.UserID')->From('UserRole ur')->Where('ur.RoleID', $RoleID)->GroupBy('UserID')->Get()->Result(DATASET_TYPE_ARRAY);
$UserIDs = ConsolidateArrayValuesByKey($UserIDs, 'UserID');
// Get matching Discussions
$Discussions = Gdn::SQL()->Select('d.*')->From('Discussion d')->WhereIn('d.InsertUserID', $UserIDs)->OrderBy('DateInserted', 'DESC')->Limit($this->Limit)->Get()->Result(DATASET_TYPE_ARRAY);
// Get matching Comments
$Comments = Gdn::SQL()->Select('c.*')->From('Comment c')->WhereIn('InsertUserID', $UserIDs)->OrderBy('DateInserted', 'DESC')->Limit($this->Limit)->Get()->Result(DATASET_TYPE_ARRAY);
$this->JoinCategory($Comments);
// Interleave
$Content = $this->Union('DateInserted', array('Discussion' => $Discussions, 'Comment' => $Comments));
$this->Prepare($Content);
// Add result to cache
Gdn::Cache()->Store($SelectorRoleCacheKey, $Content, array(Gdn_Cache::FEATURE_EXPIRY => $this->Expiry));
}
$this->Security($Content);
$this->Condense($Content, $this->Limit);
return $Content;
}
示例7: GetMembersListEnh
public function GetMembersListEnh($Limit = 5, $Offset = 0, $SortOrder, $UserField)
{
$RoleAction = $RoleActionID = "";
$RemoveRoleArray = C('Plugins.MembersListEnh.RoleID');
if (isset($RemoveRoleArray)) {
$RoleAction = $RemoveRoleArray[0];
$RoleActionID = $RemoveRoleArray[1];
}
$MembersListEnhModel = new Gdn_Model('User');
$SQL = $MembersListEnhModel->SQL->Select('*')->From('User u')->LeftJoin('UserRole ur', 'u.UserID = ur.UserID');
if (C('EnabledPlugins.KarmaBank') == TRUE) {
$SQL->LeftJoin('KarmaBankBalance kb', 'u.UserID = kb.UserID');
}
if ($UserField != "Balance") {
$SQL->OrderBy("u.{$UserField}", $SortOrder);
}
if (C('EnabledPlugins.KarmaBank') == TRUE && $UserField == "Balance") {
$SQL->OrderBy("kb.Balance", $SortOrder);
}
$SQL->Where('Deleted', false);
if ($RoleAction == "Exclude") {
$SQL->Where('ur.RoleID<>', $RoleActionID);
}
if ($RoleAction == "Include") {
$SQL->Where('ur.RoleID', $RoleActionID);
}
// Only show user once if in more than one role.
$SQL->GroupBy('ur.UserID');
$Sender->UserData = $SQL->Limit($Limit, $Offset)->Get();
RoleModel::SetUserRoles($Sender->UserData->Result());
return $Sender->UserData;
}
示例8: down
public function down()
{
$role = RoleModel::findBy('first', 'roleDescription', 'Administrators');
if ($role !== null) {
$role->deny('compare');
$role->save();
}
}
示例9: getFormCadastre
public function getFormCadastre()
{
$departmentModel = new DepartmentModel();
$departmentData = $departmentModel->fetchAll($departmentModel->getAllActiveDepartment());
$roleModel = new RoleModel();
$roleData = $roleModel->fetchAll($roleModel->select());
$departmentSupervisorModel = new DepartmentsupervisorModel();
$departmentSupervisorData = $departmentSupervisorModel->fetchAll($departmentSupervisorModel->getAllSupervisor());
$companyModel = new CompanyModel();
$companyData = $companyModel->fetchAll();
$Arraycompany = array();
$Arraycompany['0'] = 'Selecione';
foreach ($companyData as $company) {
$Arraycompany[$company->cdcompany] = $company->nmfantasyname;
}
$this->_nmagenda = new Zend_Form_Element_Text('nmagenda');
$this->_nmagenda->setLabel("Nome da Agenda");
$this->_nmagenda->setRequired(true);
$this->_nmagenda->setDecorators($this->_decoratorsRequired);
$this->_nmagenda->setAttrib("id", "agenda_nmagendas");
$this->_nmagenda->setAttrib("class", "alpha nameagenda");
$this->_nmagenda->setRequired(true);
$this->_cdcompany = new Zend_Form_Element_Select('cdcompany');
$this->_cdcompany->setRegisterInArrayValidator(false);
$this->_cdcompany->addMultiOptions($Arraycompany);
$this->_cdcompany->setLabel("Empresa");
$this->_cdcompany->setDecorators($this->_decoratorsRequired);
$this->_cdcompany->setAttrib("id", "user_cdcompany");
$this->_cdcompany->setAttrib("class", "alpha");
$this->_cdcompany->setRequired(true);
$this->_cdphysicallocation = new Zend_Form_Element_Select('cdphysicallocation');
$this->_cdphysicallocation->setRegisterInArrayValidator(false);
$this->_cdphysicallocation->setLabel("Localização Física");
$this->_cdphysicallocation->addMultiOptions(array('0' => 'Selecione'));
$this->_cdphysicallocation->setDecorators($this->_decoratorsRequired);
$this->_cdphysicallocation->setAttrib("id", "company_physicallocation");
$this->_cdphysicallocation->setAttrib("class", "alpha");
$this->_cdphysicallocation->setRequired(true);
$this->_gridhours = new Zend_Form_Element_Select('gridhours');
$this->_gridhours->setRegisterInArrayValidator(false);
$this->_gridhours->addMultiOptions(array('1' => 'Sim', '2' => 'Não'));
$this->_gridhours->setLabel("Grade de Horário");
$this->_gridhours->setDecorators($this->_decoratorsDefault);
$this->_gridhours->setAttrib("id", "user_gridhours");
$this->_gridhours->setRequired(false);
}
示例10: _permission
/**
* Do permission check.
*
* @since 2.0.0
* @access protected
*/
protected function _permission($RoleID = null)
{
$this->permission(array('Garden.Settings.Manage', 'Garden.Roles.Manage'), false);
if ($RoleID && !checkPermission('Garden.Settings.Manage')) {
// Make sure the user can assign this role.
$Assignable = $this->RoleModel->getAssignable();
if (!isset($Assignable[$RoleID])) {
throw permissionException('@' . t("You don't have permission to modify this role."));
}
}
return true;
}
示例11: Index
public function Index($Keywords = '', $Page = '') {
$this->Permission(
array(
'Garden.Users.Add',
'Garden.Users.Edit',
'Garden.Users.Delete'
),
'',
FALSE
);
$this->AddJsFile('jquery.gardenmorepager.js');
$this->AddJsFile('user.js');
$this->Title(T('Users'));
$this->AddSideMenu('dashboard/user');
$this->Form->Method = 'get';
// Input Validation.
list($Offset, $Limit) = OffsetLimit($Page, PagerModule::$DefaultPageSize);
if (!$Keywords) {
$Keywords = $this->Form->GetFormValue('Keywords');
if ($Keywords)
$Offset = 0;
}
// Put the Keyword back in the form
if ($Keywords)
$this->Form->SetFormValue('Keywords', $Keywords);
$UserModel = new UserModel();
//$Like = trim($Keywords) == '' ? FALSE : array('u.Name' => $Keywords, 'u.Email' => $Keywords);
list($Offset, $Limit) = OffsetLimit($Page, 30);
$Filter = $this->_GetFilter();
if ($Filter)
$Filter['Keywords'] = $Keywords;
else
$Filter = $Keywords;
$this->SetData('RecordCount', $UserModel->SearchCount($Filter));
$this->UserData = $UserModel->Search($Filter, 'u.Name', 'asc', $Limit, $Offset);
RoleModel::SetUserRoles($this->UserData->Result());
// Deliver json data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'users';
}
$this->Render();
}
示例12: up
public function up()
{
$this->createTable('role', array('primary' => 'roleID'), array(array('roleID', 'integer'), array('roleDescription', 'string', array('limit' => 128, 'null' => true)), array('ACLstring', 'text', array('null' => true, 'limit' => '1M'))));
$this->createTable('assignment', array('primary' => 'assignmentID'), array(array('dbUserID', 'integer'), array('roleID', 'integer'), array('assignmentID', 'integer'), array('comments', 'text', array('null' => true))));
$this->createIndex('assignment', array('dbUserID', 'roleID'));
// reset db metadata cache
QFrame_Db_Table::scanDb();
// give the admin user full global rights
$adminRole = RoleModel::create(array('roleDescription' => 'Administrators'));
$adminRole->grant('view');
$adminRole->grant('edit');
$adminRole->grant('approve');
$adminRole->grant('administer');
$adminRole->save();
DbUserModel::findByUsername('admin')->addRole($adminRole)->save();
}
示例13: assignRole
/**
* Assign the given role to the user.
*
* @param string $role
*
* @return mixed
*/
public function assignRole($role, $save = true)
{
// if we passed a role name, find it
if (is_string($role)) {
$role = RoleModel::whereName($role)->first();
}
// if user already has the role, return true.
if ($save and $this->roles()->find([$role->id])->count()) {
return $role;
}
// assign role
if ($save) {
return $this->roles()->save($role);
} else {
return $this->roles()->detach($role);
}
}
示例14: auth
private function auth()
{
// perform mock authentication
$auth_adapter = new QFrame_Auth_Adapter('sample1', 'password');
$auth = Zend_Auth::getInstance();
$auth->authenticate($auth_adapter);
// authorize the sample1 user with the admin role and give the admin role
// all possible global rights
$adminRole = RoleModel::find(4);
$adminRole->grant('view');
$adminRole->grant('edit');
$adminRole->grant('approve');
$adminRole->grant('administer');
$adminRole->save();
$user = new DbUserModel(array('dbUserID' => 1));
$user->addRole($adminRole);
}
示例15: 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();
}