本文整理汇总了PHP中Role::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::get方法的具体用法?PHP Role::get怎么用?PHP Role::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::get方法的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: testRoleModification
public function testRoleModification()
{
$role = Role::get(Role::ADMINISTRATOR);
$this->assertTrue($role->hasPerm(Permission::PUBLISH_NEWS));
$this->assertFalse($this->player->hasPermission(Permission::PUBLISH_NEWS));
$this->player->addRole($role);
$this->assertTrue($this->player->hasPermission(Permission::PUBLISH_NEWS));
}
示例3: testNormalRole
public function testNormalRole()
{
$role = Role::get($this->normalRole->getId());
$this->player_b->addRole($role->getId());
$this->assertFalse($role->displayAsLeader());
$this->assertFalse($role->isProtected());
$this->assertEquals("Sample Normal Role", $role->getName());
$this->assertArrayContainsModel($role, Role::getRoles($this->player_b->getId()));
$this->wipe($role);
}
示例4: Role
function list_drop()
{
$role = new Role();
$role->get();
foreach ($role as $row) {
$data[''] = '[ User Role ]';
$data[$row->role_id] = $row->role_name;
}
return $data;
}
示例5: postAddUser
public function postAddUser($role_id)
{
$user_id = $this->request()->get('user_id');
$user = User::get($user_id);
$role = Role::get($role_id);
$user->roles[] = $role;
if ($user->save()) {
$this->flash()->success('@string/roles_user_add_success');
}
return $this->response()->redirect();
}
示例6: getCMSFields
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', UploadField::create('Photo'), 'Content');
$fields->addFieldToTab('Root.Main', UploadField::create('PDF'), 'Content');
$fields->addFieldToTab('Root.Main', PhoneNumberField::create('Phone'), 'Content');
$fields->addFieldToTab('Root.Main', EmailField::create('Email'), 'Content');
$fields->addFieldToTab('Root.Main', DropdownField::create('RoleID', 'Role', Role::get()->map('ID', 'Title'))->setEmptyString('(Select)'), 'Content');
$fields->addFieldToTab('Root.Main', DropdownField::create('DepartmentID', 'Department', Department::get()->map('ID', 'Title'))->setEmptyString('(Select)'), 'Content');
return $fields;
}
示例7: buildView
/**
* Render a list of comma-separated usernames for the user to see
*
* @param FormView $view
* @param FormInterface $form
* @param array $options
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($this->type === 'Role') {
foreach ($view->vars['choices'] as $choice) {
$role = \Role::get($choice->value);
$icon = $role->getDisplayIcon();
if ($icon !== null) {
$choice->attr['data-icon'] = $icon;
}
}
}
}
示例8: run
public function run()
{
DB::table('users')->delete();
$roles = Role::get();
// dd($roles->count());
for ($role_index = 0; $role_index < $roles->count(); $role_index++) {
$role = $roles[$role_index];
for ($user_index = 0; $user_index < $role_index + 1; $user_index++) {
User::create(array('first_name' => 'Morriel', 'last_name' => 'Aquino', 'role_id' => $role->id));
}
}
}
示例9: getAreaSelected
public function getAreaSelected()
{
$roles = Role::get();
$result = [];
foreach ($roles as $role) {
if (empty($result[$role->id])) {
$result[$role->id] = [];
}
foreach ($role->permissions as $permission) {
$result[$role->id][] = $permission->service_id;
}
}
return $result;
}
示例10: postAddRole
public function postAddRole($user_id)
{
$user = User::get($user_id);
if (count($user->roles) > 0) {
$this->flash()->error('@string/user_role_limit_reached');
return $this->response()->redirect();
}
$role_id = $this->request()->get('role_id');
$role = Role::get($role_id);
$user->roles[] = $role;
if ($user->save()) {
$this->flash()->success('@string/user_role_add_success');
}
return $this->response()->redirect();
}
示例11: saveUser
public function saveUser($sender, $params)
{
$results = $errors = array();
try {
Dao::beginTransaction();
if (!isset($params->CallbackParameter->firstName) || ($firstName = trim($params->CallbackParameter->firstName)) === '') {
throw new Exception('System Error: firstName is mandatory!');
}
if (!isset($params->CallbackParameter->lastName) || ($lastName = trim($params->CallbackParameter->lastName)) === '') {
throw new Exception('System Error: lastName is mandatory!');
}
if (!isset($params->CallbackParameter->userName) || ($userName = trim($params->CallbackParameter->userName)) === '') {
throw new Exception('System Error: userName is mandatory!');
}
if (!isset($params->CallbackParameter->roleid) || !($role = Role::get($params->CallbackParameter->roleid)) instanceof Role) {
throw new Exception('System Error: role is mandatory!');
}
$newpassword = trim($params->CallbackParameter->newpassword);
if (!isset($params->CallbackParameter->userid) || !($userAccount = UserAccount::get($params->CallbackParameter->userid)) instanceof UserAccount) {
$userAccount = new UserAccount();
$person = new Person();
if ($newpassword === '') {
throw new Exception('System Error: new password is mandatory!');
}
$newpassword = sha1($newpassword);
} else {
$person = $userAccount->getPerson();
if ($newpassword === '') {
$newpassword = $userAccount->getPassword();
} else {
$newpassword = sha1($newpassword);
}
}
//double check whether the username has been used
$users = UserAccount::getAllByCriteria('username=? and id!=?', array($userName, $userAccount->getId()), false, 1, 1);
if (count($users) > 0) {
throw new Exception('Username(=' . $userName . ') has been used by another user, please choose another one!');
}
$person->setFirstName($firstName)->setLastName($lastName)->save();
$userAccount->setUserName($userName)->setPassword($newpassword)->setPerson($person)->save();
$results = $userAccount->clearRoles()->addRole($role)->getJson();
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$params->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例12: foreach
function roles_post()
{
$requested_data = json_decode($this->post('models'));
foreach ($requested_data as $d) {
$user = new User(null, $this->entity);
$user->where('id', $d->user_id);
$user->get();
$role = new Role(null, $this->entity);
$role->where('id', $d->role_id);
$role->get();
if ($user->exists() && $role->exists()) {
if ($user->save($role)) {
$r = $user->include_related('role', NULL, TRUE)->get_raw();
$this->response(array('msg' => 'assigned successfully.', 'results' => $r->result()), 201);
} else {
$this->response(array('msg' => 'error assigning to role.', 'results' => array()), 201);
}
} else {
$this->response(array('msg' => 'either role or user does not exist', 'results' => array()), 201);
}
}
// $this->response(array('msg'=>'assigned successfully.', 'results'=>$r->result()), 201);
}
示例13: roles
function roles()
{
$role = new Role();
$total_rows = $role->count();
switch ($this->input->get('c')) {
case "1":
$data['col'] = "role_name";
break;
case "2":
$data['col'] = "role_id";
break;
default:
$data['col'] = "role_id";
}
if ($this->input->get('d') == "1") {
$data['dir'] = "DESC";
} else {
$data['dir'] = "ASC";
}
$data['title'] = "Roles";
$data['btn_add'] = anchor('users/add_role', 'Add New', "class='btn btn-primary'");
$data['btn_home'] = anchor(base_url(), 'Home', "class='btn btn-home'");
$uri_segment = 3;
$offset = $this->uri->segment($uri_segment);
$role->order_by($data['col'], $data['dir']);
$data['role_list'] = $role->get($this->limit, $offset)->all;
$config['base_url'] = site_url("users/roles");
$config['total_rows'] = $total_rows;
$config['per_page'] = $this->limit;
$config['uri_segment'] = $uri_segment;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('users/index_roles', $data);
}
示例14: list_roles
/**
* List Roles
* Will get all roles from the database
*
* @param mixed $count
* @param mixed $offset
*
*/
public function list_roles($count = 10000, $offset = 0)
{
$r = new Role();
return $r->get($count, $offset);
}
示例15: foreach
* the $siteOptions variable.
*
*/
$options = Option::get(['name', 'value']);
foreach ($options as $option) {
$o[$option->name] = $option->value;
}
View::share('siteOptions', $o);
/**
* Attach a PHP array to the window to allow JavaScript to use.
* The "URL" provider is used rather than the Laravel helper paths
* to ensure the paths are consistent across Windows and Unix platforms.
*
* @see https://github.com/laracasts/PHP-Vars-To-Js-Transformer
*/
JavaScript::put(['app_path' => URL::to('/') . '/', 'roles' => Role::get(['id', 'friendly_name']), 'services' => Service::get(['id', 'friendly_name'])]);
});
App::after(function ($request, $response) {
//
});
/*
|--------------------------------------------------------------------------
| Access Filter
|--------------------------------------------------------------------------
|
*/
Route::filter('access', function () {
if (!Access::validate(Request::segment(1))) {
return App::abort(403, 'You do not have the required access for this page');
}
});