本文整理汇总了PHP中UserGroup::create方法的典型用法代码示例。如果您正苦于以下问题:PHP UserGroup::create方法的具体用法?PHP UserGroup::create怎么用?PHP UserGroup::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserGroup
的用法示例。
在下文中一共展示了UserGroup::create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
UserGroup::create([]);
}
}
示例2: run
public function run()
{
DB::table('users_groups')->delete();
$user_id = DB::table('users')->select('id')->where('email', 'admin@localhost')->first()->id;
$group_id = DB::table('groups')->select('id')->where('name', 'Administrator')->first()->id;
UserGroup::create(array('user_id' => $user_id, 'group_id' => $group_id));
}
示例3: setup
public function setup()
{
// create test group and user
$this->acl_group = UserGroup::create( array( 'name' => 'acltest-group' ) );
$this->acl_user_alice = User::create( array( 'username' => 'acl-alice' ) );
$this->acl_user_bob = User::create( array( 'username' => 'acl-bob' ) );
$this->acl_group->add( 'acl-alice' );
$this->acl_group->add( 'acl-bob' );
}
示例4: test_get_all
public function test_get_all()
{
$groups_before = UserGroups::get_all();
UserGroup::create(array('name' => 'testcasegroup'));
$groups_after = UserGroups::get_all();
$this->assert_not_equal(count($groups_before), count($groups_after));
$this->assert_not_identical($groups_before, $groups_after);
UserGroup::get('testcasegroup')->delete();
}
示例5: test_createduplicategroup
function test_createduplicategroup()
{
// Can I create two groups with the same name?
$group = UserGroup::create('name=new dupe group');
$group2 = UserGroup::create('name=new dupe group');
assert($group2 instanceof UserGroup);
$this->assert_true(DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new dupe group')) == 1, 'Was able to create two groups with the same name.');
$group->delete();
$group2->delete();
}
示例6: _mainModelAfterSave
/**
* We're going to create a UserGroup when a new Model record is created
*
* @param Model $Model
* @param boolean $created
*/
private function _mainModelAfterSave(Model $Model, $created)
{
if ($created) {
$UserGroup = new UserGroup();
// create a UserGroup for this Course
$data = $UserGroup->create(array('title' => $Model->data[$Model->alias][$Model->displayField], 'model' => $Model->alias, 'foreign_key' => $Model->id, 'owner_id' => $Model->userId));
$UserGroup->save($data);
// make the current Auth.User a member, and the moderator, for this group
$UserGroup->UsersUserGroup->add(array('UsersUserGroup' => array('user_id' => $Model->userId, 'user_group_id' => $UserGroup->id, 'is_moderator' => 1, 'is_approved' => 1)));
}
}
示例7: test_create
public function test_create()
{
// group should have been created in the setup
$this->assert_true(
$this->group instanceof UserGroup,
'Could not create a new group named "new test group".'
);
Plugins::register( array( $this, 'filter_usergroup_insert_allow' ), 'filter','usergroup_insert_allow' );
// test the plugin hook
$this->allow_filter = false;
$second_group = UserGroup::create( array( 'name' => 'another test group' ) );
$this->assert_false(
$second_group instanceof UserGroup,
'Denial by plugin hook did not prevent creation of a new group.'
);
$this->allow_filter = true;
$second_group = UserGroup::create( array( 'name' => 'another test group' ) );
$this->assert_true(
$second_group instanceof UserGroup,
'Plugin hook illogically prevented creation of a new group.'
);
$second_group->delete();
// Can I create two groups with the same name?
$group = UserGroup::create( array( 'name' => 'new dupe group' ) );
$group2 = UserGroup::create( array( 'name' => 'new dupe group' ) );
$this->assert_true(
$group2 instanceof UserGroup,
'Could not create a group with the same name' );
$this->assert_true(
DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new dupe group')) == 1,
'Was able to create two groups with the same name.'
);
$group->delete();
$group2->delete();
}
示例8: testUserGroupCreate
/**
*/
public function testUserGroupCreate()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new UserGroup($this->savdb);
$localobject->initAsSpecimen();
$result=$localobject->create($user);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return $result;
}
示例9: update_groups
/**
* Add or delete groups.
*/
public function update_groups($handler_vars, $ajax = TRUE)
{
$wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
if (isset($handler_vars['digest']) && $handler_vars['digest'] != $wsse['digest'] || isset($handler_vars['PasswordDigest']) && $handler_vars['PasswordDigest'] != $wsse['digest']) {
Session::error(_t('WSSE authentication failed.'));
return Session::messages_get(true, 'array');
}
if (isset($handler_vars['PasswordDigest']) || isset($handler_vars['digest'])) {
if (isset($handler_vars['action']) && $handler_vars['action'] == 'add' || isset($handler_vars['newgroup'])) {
if (isset($handler_vars['newgroup'])) {
$name = trim($handler_vars['new_groupname']);
} else {
$name = trim($handler_vars['name']);
}
$settings = array('name' => $name);
$this->theme->addform = $settings;
if (UserGroup::exists($name)) {
Session::notice(sprintf(_t('The group %s already exists'), $name));
if ($ajax) {
return Session::messages_get(true, 'array');
} else {
return;
}
} elseif (empty($name)) {
Session::notice(_t('The group must have a name'));
if ($ajax) {
return Session::message_get(true, 'array');
} else {
return;
}
} else {
$groupdata = array('name' => $name);
$group = UserGroup::create($groupdata);
Session::notice(sprintf(_t('Added group %s'), $name));
// reload the groups
$this->theme->groups = UserGroups::get_all();
$this->theme->addform = array();
}
if ($ajax) {
return Session::messages_get(true, 'array');
} else {
if (!$ajax) {
Utils::redirect(URL::get('admin', 'page=groups'));
}
}
}
if (isset($handler_vars['action']) && $handler_vars['action'] == 'delete' && $ajax == true) {
$ids = array();
foreach ($_POST as $id => $delete) {
// skip POST elements which are not group ids
if (preg_match('/^p\\d+$/', $id) && $delete) {
$id = (int) substr($id, 1);
$ids[] = array('id' => $id);
}
}
$count = 0;
if (!isset($ids)) {
Session::notice(_t('No groups deleted.'));
return Session::messages_get(true, 'array');
}
foreach ($ids as $id) {
$id = $id['id'];
$group = UserGroup::get_by_id($id);
$group->delete();
$count++;
}
if (!isset($msg_status)) {
$msg_status = sprintf(_t('Deleted %d groups.'), $count);
}
Session::notice($msg_status);
return Session::messages_get(true, 'array');
}
}
}
示例10:
$superadmin_reg = !UserList::getCount();
if (!$superadmin_reg && !$session->allow_registrations) {
return;
}
// Handle new user registrations
if (isset($_POST['register_usr']) && isset($_POST['register_pwd']) && isset($_POST['register_pwd2'])) {
$reg = UserHandler::getInstance();
$user_id = $reg->register($_POST['register_usr'], $_POST['register_pwd'], $_POST['register_pwd2']);
if ($user_id) {
if ($superadmin_reg) {
if (!UserGroup::getAll()) {
// If no UserGroup:s exist, create them
UserGroup::create('Webmasters', 1);
UserGroup::create('Admins', 2);
$sadmin_id = UserGroup::create('Super Admins', 3);
} else {
$grp = UserGroup::getByName('Super Admins');
$sadmin_id = $grp['groupId'];
}
if (!$sadmin_id) {
throw new \Exception('super admin group not found');
}
// Add this user to Super Admin group
UserGroupHandler::addToGroup($user_id, $sadmin_id);
}
if ($session->login($_POST['register_usr'], $_POST['register_pwd'])) {
$session->showStartPage();
}
}
// after form submit failed, put focus back to the register form <div> to show error
示例11: upgrade_db_post_3236
private function upgrade_db_post_3236()
{
// Add a default to the number of posts of a feed
$atom_entries = Options::get('atom_entries');
if (empty($atom_entries)) {
Options::set('atom_entries', '5');
}
// Create the default authenticated group
$authenticated_group = UserGroup::get_by_name(_t('authenticated'));
if (!$authenticated_group instanceof UserGroup) {
$authenticated_group = UserGroup::create(array('name' => _t('authenticated')));
}
$authenticated_group->grant('post_entry', 'read');
$authenticated_group->grant('post_page', 'read');
$authenticated_group->grant('comment');
}
示例12: array
//print_r($ldapgroup);
if ($group->id > 0) {
// Group update
print $langs->transnoentities("GroupUpdate") . ' # ' . $key . ': name=' . $group->name;
$res = $group->update();
if ($res > 0) {
print ' --> Updated group id=' . $group->id . ' name=' . $group->name;
} else {
$error++;
print ' --> ' . $res . ' ' . $group->error;
}
print "\n";
} else {
// Group creation
print $langs->transnoentities("GroupCreate") . ' # ' . $key . ': name=' . $group->name;
$res = $group->create();
if ($res > 0) {
print ' --> Created group id=' . $group->id . ' name=' . $group->name;
} else {
$error++;
print ' --> ' . $res . ' ' . $group->error;
}
print "\n";
}
//print_r($group);
// Gestion des utilisateurs associés au groupe
// 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr
$userList = array();
$userIdList = array();
foreach ($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) {
if ($key === 'count') {
示例13: rebuild_permissions
/**
* Reset premissions to their default state
*/
public static function rebuild_permissions($user = null)
{
// Clear out all permission-related values
DB::query('DELETE FROM {tokens}');
DB::query('DELETE FROM {group_token_permissions}');
//DB::query( 'DELETE FROM {groups}' );
DB::query('DELETE FROM {post_tokens}');
DB::query('DELETE FROM {user_token_permissions}');
//DB::query('DELETE FROM {users_groups}');
// Create initial groups if they don't already exist
$admin_group = UserGroup::get_by_name(_t('admin'));
if (!$admin_group instanceof UserGroup) {
$admin_group = UserGroup::create(array('name' => _t('admin')));
}
$anonymous_group = UserGroup::get_by_name(_t('anonymous'));
if (!$anonymous_group instanceof UserGroup) {
$anonymous_group = UserGroup::create(array('name' => _t('anonymous')));
}
// Add all users or the passed user to the admin group
if (empty($user)) {
$users = Users::get_all();
$ids = array();
foreach ($users as $user) {
$ids[] = $user->id;
}
$admin_group->add($ids);
} else {
$admin_group->add($user);
}
// create default permissions
self::create_default_tokens();
// Make the admin group all superusers
$admin_group->grant('super_user');
// Add entry and page read access to the anonymous group
$anonymous_group->grant('post_entry', 'read');
$anonymous_group->grant('post_page', 'read');
$anonymous_group->grant('comment');
$anonymous_group->deny('post_unpublished');
// Add the anonymous user to the anonymous group
$anonymous_group->add(0);
// Create the default authenticated group
$authenticated_group = UserGroup::get_by_name(_t('authenticated'));
if (!$authenticated_group instanceof UserGroup) {
$authenticated_group = UserGroup::create(array('name' => _t('authenticated')));
}
$authenticated_group->grant('post_entry', 'read');
$authenticated_group->grant('post_page', 'read');
$authenticated_group->grant('comment');
}
示例14: UserGroup
function ircube_rebuild()
{
$this->out(__('Cleaning acos table ...'));
//$this->Aco->query('TRUNCATE acos');
$this->aco_sync();
$this->out(__('Rebuilding UserGroups table ...'));
App::import('Model', 'UserGroup');
$UserGroup = new UserGroup();
$this->out(sprintf(__('Cleaning UserGroup (%s) table', true), $UserGroup->table));
$UserGroup->query('TRUNCATE ' . $UserGroup->table);
Configure::write('debug', 2);
/* Membres inherits Guests, Modérateurs inherits Membres, Administrateurs inherits Modérateur */
$groups = array(array('UserGroup' => array('id' => 1, 'title' => 'Guest', 'parent_id' => 0)), array('UserGroup' => array('id' => 2, 'title' => 'Membre', 'parent_id' => 1)), array('UserGroup' => array('id' => 3, 'title' => 'Modérateur', 'parent_id' => 2)), array('UserGroup' => array('id' => 4, 'title' => 'Administrateur', 'parent_id' => 3)));
foreach ($groups as $g) {
$UserGroup->create($g);
$UserGroup->save($g, false);
$this->out(sprintf(__('Saved user group %s (id %d)', true), $g['UserGroup']['title'], $g['UserGroup']['id']));
}
$this->out('');
$this->out('Cleaning aros table ...');
$this->Aro->query("TRUNCATE aros");
$this->out('Creating aros ...');
foreach ($groups as $g) {
$this->Aro->create();
$this->Aro->save(array('model' => 'UserGroup', 'foreign_key' => $g['UserGroup']['id'], 'parent_id' => $g['UserGroup']['parent_id'], 'alias' => $g['UserGroup']['title']));
$this->out('Aro ' . $g['UserGroup']['title'] . ' created, inherits Aro ' . implode(', ', Set::extract('/UserGroup[id=' . $g['UserGroup']['parent_id'] . ']/title', $groups)));
}
$this->out('');
$this->out('Cleaning permissions table ...');
$this->Aro->query("TRUNCATE aros_acos");
$this->out('Building permissions ...');
/* Allow everything for everyone */
$this->Acl->allow('Administrateur', 'controllers');
$this->Acl->allow('Membre', 'controllers');
$this->Acl->allow('Modérateur', 'controllers');
$this->Acl->allow('Guest', 'controllers');
/* user_pictures */
$this->Acl->deny('Guest', 'UserPictures');
$this->Acl->allow('Membre', 'UserPictures');
$this->Acl->allow('Guest', 'UserPictures/gallery');
$this->Acl->allow('Guest', 'UserPictures/avatar');
/* Admin panel */
$this->Acl->deny('Guest', 'news/admin_index');
$this->Acl->allow('Membre', 'news/admin_index');
$this->Acl->deny('Guest', 'news/admin_edit');
$this->Acl->allow('Membre', 'news/admin_edit');
$this->Acl->deny('Guest', 'news/admin_delete');
$this->Acl->allow('Membre', 'news/admin_delete');
$this->Acl->deny('Guest', 'news/admin_publish');
$this->Acl->allow('Membre', 'news/admin_publish');
$this->Acl->deny('Guest', 'news/admin_unpublish');
$this->Acl->allow('Membre', 'news/admin_unpublish');
}