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


PHP UserRole类代码示例

本文整理汇总了PHP中UserRole的典型用法代码示例。如果您正苦于以下问题:PHP UserRole类的具体用法?PHP UserRole怎么用?PHP UserRole使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserRole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setAdmin

 /**
  * @description Set the an user as administrator.
  * @param mail Mail of the user.
  */
 public function setAdmin($mail)
 {
     $this->output->writeln(sprintf('Set user <info>%s</info> as Administrator', $mail));
     $admin_role = Role::get(1);
     if (empty($admin_role)) {
         $this->output->writeln('No Administrator role is in the database!');
         return FALSE;
     }
     $user = new User();
     $user->mail = $mail;
     $user->fetch('mail');
     if (empty($user->getId())) {
         $this->output->writeln(sprintf('User with the mail address <info>%s</info> not found in in the database!', $mail));
         return FALSE;
     }
     $ur = new UserRole();
     $ur->user = $user;
     $ur->role = $admin_role;
     if (!$ur->save()) {
         $this->output->writeln('Unable to associate the administrator role!');
         $this->output->writeln(print_r($ur->getErrors(), TRUE));
         return FALSE;
     }
     $this->output->writeln('User associated!');
     return TRUE;
 }
开发者ID:mermetbt,项目名称:biome,代码行数:30,代码来源:RightsCommand.php

示例2: createUserRole

 /**
  * @param int $id
  * @param string $roleName
  * @return UserRole
  */
 public static function createUserRole($id, $roleName)
 {
     $useRole = new UserRole();
     $useRole->setId($id);
     $useRole->setName($roleName);
     return $useRole;
 }
开发者ID:euBatham,项目名称:javacature,代码行数:12,代码来源:UserRoleFactory.class.php

示例3: mapDtoToUserRole

 public function mapDtoToUserRole(RoleDto $roleDto)
 {
     $userRole = new UserRole();
     $userRole->setId($roleDto->getId());
     $userRole->setName($roleDto->getName());
     return $userRole;
 }
开发者ID:euBatham,项目名称:javacature,代码行数:7,代码来源:UserRoleMapper.class.php

示例4: testCreate

 public function testCreate()
 {
     $userRole = new UserRole();
     $userRole->setName('Administrator');
     $userRole->setDescription('Admin account with access to everything.');
     $this->assertSame('Administrator', $userRole->getName());
     $this->assertSame('Admin account with access to everything.', $userRole->getDescription());
 }
开发者ID:pdt256,项目名称:truecar,代码行数:8,代码来源:UserRoleTest.php

示例5: setRoles

 /**
  * @param $oRole
  */
 public function setRoles($oRole)
 {
     $oUserRoles = new UserRole();
     $oUserRoles->setRole($oRole);
     $oUserRoles->setUser($this);
     $aCollection = new \PropelCollection();
     $aCollection->append($oUserRoles);
     $this->setUserRoles($aCollection);
 }
开发者ID:slashworks,项目名称:control-bundle,代码行数:12,代码来源:User.php

示例6: testHasRoles

 public function testHasRoles()
 {
     $adminRole = new UserRole();
     $adminRole->setName('admin');
     $user = new User();
     $user->addRole($adminRole);
     $this->assertTrue($user->hasRoles(['admin']));
     $this->assertFalse($user->hasRoles(['developer']));
 }
开发者ID:pdt256,项目名称:truecar,代码行数:9,代码来源:UserTest.php

示例7: createOrFind

 public function createOrFind(User $oUser, Role $oRole)
 {
     $oUserRole = $this->filterByUser($oUser)->filterByRole($oRole)->findOne();
     if (!$oUserRole) {
         $oUserRole = new UserRole();
         $oUserRole->setRole($oRole);
         $oUserRole->setUser($oUser);
         $oUserRole->save();
     }
     return $oUserRole;
 }
开发者ID:rapila,项目名称:cms-base,代码行数:11,代码来源:UserRoleQuery.php

示例8: selectAllByUserId

 public function selectAllByUserId($id)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'user_id=:id';
     $criteria->params = array(':id' => $id);
     return UserRole::model()->findAll($criteria);
 }
开发者ID:vasia-ostapchuk,项目名称:source,代码行数:7,代码来源:UserRole.php

示例9: select_html

 public static function select_html($selected = 0, $name = "userrole_id", $class = "select", $template = '%name%')
 {
     $roles = new UserRole();
     $roles->get_iterated();
     echo "<select name='{$name}' class='{$class}'>";
     foreach ($roles as $role) {
         if ($selected == $role->id) {
             $selstr = " selected='selected'";
         } else {
             $selstr = "";
         }
         $format = parse_template($template, $role->stored);
         echo "<option value='{$role->id}' class='user_select'{$selstr}>" . $format . "</option>\n";
     }
     echo "</select>";
 }
开发者ID:jotavejv,项目名称:CMS,代码行数:16,代码来源:userrole.php

示例10: edit

 public function edit($cid, $title)
 {
     $cid = (int) $cid;
     $content = Content::factory($cid);
     if (!$this->user->can_edit_content($content)) {
         $this->templatemanager->notify_next("You don't have enough permissions to edit this content!", 'failure');
         redirect('administration/dashboard');
     }
     $page = $content->page->limit(1)->get();
     $roles = UserRole::factory()->get();
     $ctypes = ContentType::factory()->get();
     if (!$page->exists()) {
         show_error("No page exists!");
     }
     /*if (!$content->exists())
     		{
     			$html = $page->body()->find('div[id='.trim($title).']', 0)->innertext;
     			//var_dump($html); die;
     			$content->div = $title;
     			$content->contents = $html;
     			$content->editor_id = $this->user->id;
     			$content->save(array($page));
     		}//*/
     $divs = $page->get_div_ids();
     //$this->templatemanager->assign("css_file", $css_file);
     $this->templatemanager->assign("content", $content);
     $this->templatemanager->assign("divs", $divs);
     $this->templatemanager->assign("page", $page);
     $this->templatemanager->assign("roles", $roles);
     $this->templatemanager->assign("types", $ctypes);
     $suffix = strtolower($content->contenttype->get()->classname);
     $this->templatemanager->set_title("Edit Content");
     $this->templatemanager->show_template("contents_edit_" . $suffix);
 }
开发者ID:lukamacun,项目名称:CMS,代码行数:34,代码来源:contents.php

示例11: copyToPartner

 /**
  * Copy current role to the given partner.
  * @param int $partnerId
  */
 public function copyToPartner($partnerId)
 {
     $newRole = new UserRole();
     $newRole->setName($this->getName());
     $newRole->setDescription($this->getDescription());
     $newRole->setStatus($this->getStatus());
     $newRole->setPermissionNames(parent::getPermissionNames());
     $newRole->setCustomData($this->getCustomData());
     $newRole->setPartnerId($partnerId);
     // set new partner id
     $newRole->setTags($this->getTags());
     return $newRole;
 }
开发者ID:AdiTal,项目名称:server,代码行数:17,代码来源:UserRole.php

示例12: itemAlias

 public static function itemAlias($type, $code = NULL)
 {
     $_items = array('UserStatus' => array(self::STATUS_NOACTIVE => UserModule::t('Not active'), self::STATUS_ACTIVE => UserModule::t('Active'), self::STATUS_BANNED => UserModule::t('Banned')), 'AdminStatus' => array('0' => UserModule::t('No'), '1' => UserModule::t('Yes')), 'UserRoleStatus' => [CHtml::listData(UserRole::model()->findAll(array('select' => 'id, user_role', 'order' => 'user_role')), 'id', 'user_role')]);
     if (isset($code)) {
         return isset($_items[$type][$code]) ? $_items[$type][$code] : false;
     } else {
         return isset($_items[$type]) ? $_items[$type] : false;
     }
 }
开发者ID:artmart,项目名称:verare,代码行数:9,代码来源:User.php

示例13: getRemoveRole

 public function getRemoveRole($user_id, $role_id)
 {
     $userroles = UserRole::find(array('user_id', '=', $user_id), array('role_id', '=', $role_id));
     foreach ($userroles as $ur) {
         if ($ur->delete()) {
             $this->flash()->success('@string/user_role_remove_success');
         }
     }
     return $this->response()->redirect();
 }
开发者ID:mermetbt,项目名称:biome,代码行数:10,代码来源:UserController.php

示例14: testUserSavesRolesOnSave

 public function testUserSavesRolesOnSave()
 {
     $model = $this->getModel();
     $model->use_username = self::USERNAME;
     $model->roles = $roles = UserRole::model()->findAll();
     $model->save(false);
     /** @var $model User */
     $model = User::model()->findByPk($model->use_id);
     $this->assertTrue(is_array($model->roles));
     $this->assertEquals(count($roles), count($model->roles));
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:11,代码来源:UserTest.php

示例15: findByUserId

 public static function findByUserId($id)
 {
     $userroles = UserRole::find(array('where' => 'user_id = :user_id', 'values' => array(':user_id' => (int) $id)));
     if (count($userroles) <= 0) {
         return false;
     }
     $roles = array();
     foreach ($userroles as $role) {
         $roles[] = Role::findById($role->role_id);
     }
     return $roles;
 }
开发者ID:ariksavage,项目名称:superior-optical-eyewear,代码行数:12,代码来源:Role.php


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