本文整理汇总了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;
}
示例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;
}
示例3: mapDtoToUserRole
public function mapDtoToUserRole(RoleDto $roleDto)
{
$userRole = new UserRole();
$userRole->setId($roleDto->getId());
$userRole->setName($roleDto->getName());
return $userRole;
}
示例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());
}
示例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);
}
示例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']));
}
示例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;
}
示例8: selectAllByUserId
public function selectAllByUserId($id)
{
$criteria = new CDbCriteria();
$criteria->condition = 'user_id=:id';
$criteria->params = array(':id' => $id);
return UserRole::model()->findAll($criteria);
}
示例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>";
}
示例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);
}
示例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;
}
示例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;
}
}
示例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();
}
示例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));
}
示例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;
}