本文整理汇总了PHP中ElggUser::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggUser::save方法的具体用法?PHP ElggUser::save怎么用?PHP ElggUser::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggUser
的用法示例。
在下文中一共展示了ElggUser::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Called before each test method.
*/
public function setUp()
{
$this->group = new ElggGroup();
$this->group->membership = ACCESS_PUBLIC;
$this->group->access_id = ACCESS_PUBLIC;
$this->group->save();
$this->user = new ElggUser();
$this->user->username = 'test_user_' . rand();
$this->user->save();
}
示例2: setUp
public function setUp()
{
elgg_register_notification_method('test');
$this->user1 = new ElggUser();
$this->user1->username = 'test1';
$this->user1->save();
$this->user2 = new ElggUser();
$this->user2->username = 'test2';
$this->user2->save();
$this->group = new ElggGroup();
$this->group->save();
}
示例3: __construct
/**
* Called before each test object.
*/
public function __construct()
{
parent::__construct();
$this->user = new \ElggUser();
$this->user->username = 'fake_user_' . rand();
$this->user->email = 'fake_email@fake.com' . rand();
$this->user->name = 'fake user ' . rand();
$this->user->access_id = ACCESS_PUBLIC;
$this->user->setPassword(rand());
$this->user->owner_guid = 0;
$this->user->container_guid = 0;
$this->user->save();
}
示例4: __construct
/**
* Called before each test object.
*/
public function __construct()
{
parent::__construct();
$this->user = new ElggUser();
$this->user->username = 'fake_user_' . rand();
$this->user->email = 'fake_email@fake.com' . rand();
$this->user->name = 'fake user ' . rand();
$this->user->access_id = ACCESS_PUBLIC;
$this->user->salt = _elgg_generate_password_salt();
$this->user->password = generate_user_password($this->user, rand());
$this->user->owner_guid = 0;
$this->user->container_guid = 0;
$this->user->save();
}
示例5: notification_tools_enable_for_new_user
/**
* Enable personal and friend notifications for new users
*
* We do this using 'create, user' event instead of 'register, user' plugin
* hook so that it affects also users created by an admin.
*
* @param string $event 'create'
* @param string $type 'user'
* @param ElggUser $user
* @return boolean
*/
function notification_tools_enable_for_new_user($event, $type, $user)
{
$personal = elgg_get_plugin_setting('default_personal_methods', 'notification_tools');
// Set methods for personal notifications
if ($personal) {
$personal_methods = explode(',', $personal);
foreach ($personal_methods as $method) {
$prefix = "notification:method:{$method}";
$user->{$prefix} = true;
}
}
$collection = elgg_get_plugin_setting('default_collection_methods', 'notification_tools');
// Set methods for notifications about friends' activity
if ($collection) {
$collection_methods = explode(',', $collection);
// Here we just mark the default methods. The core notification plugin
// will take care of creating the actual 'notify<method>' relationships
// between user and each friends.
foreach ($collection_methods as $method) {
$setting_name = "collections_notifications_preferences_{$method}";
// The -1 seems like a weird value but that's what the core
// is using for whatever reason.
$user->{$setting_name} = '-1';
}
}
$user->save();
return true;
}
示例6: createTestUser
protected function createTestUser($username = 'fileTest')
{
$user = new ElggUser();
$user->username = $username;
$guid = $user->save();
// load user to have access to creation time
return get_entity($guid);
}
开发者ID:ashwiniravi,项目名称:Elgg-Social-Network-Single-Sign-on-and-Web-Statistics,代码行数:8,代码来源:filestore.php
示例7: createTestUser
protected function createTestUser($username = 'fileTest')
{
// in case a test failure left the user
$user = get_user_by_username($username);
if ($user) {
return $user;
}
$user = new \ElggUser();
$user->username = $username;
$guid = $user->save();
// load user to have access to creation time
return get_entity($guid);
}
示例8: testCanEdit
public function testCanEdit()
{
$user = new \ElggUser();
$user->save();
$id = $this->entity->annotate('test', 'foo', ACCESS_LOGGED_IN, elgg_get_logged_in_user_guid());
$a = elgg_get_annotation_from_id($id);
$this->assertTrue($a->canEdit());
$this->assertFalse($a->canEdit($user->guid));
$id = $this->entity->annotate('test', 'foo2', ACCESS_LOGGED_IN, $user->guid);
$a = elgg_get_annotation_from_id($id);
$this->assertTrue($a->canEdit());
$this->assertTrue($a->canEdit($user->guid));
$user->delete();
}
示例9: __construct
/**
* Called before each test object.
*/
public function __construct()
{
elgg_set_ignore_access(true);
$this->entities = array();
$this->subtypes = array('object' => array(), 'user' => array(), 'group' => array());
// sites are a bit wonky. Don't use them just now.
$this->types = array('object', 'user', 'group');
// create some fun objects to play with.
// 5 with random subtypes
for ($i = 0; $i < 5; $i++) {
$subtype = 'test_object_subtype_' . rand();
$e = new ElggObject();
$e->subtype = $subtype;
$e->save();
$this->entities[] = $e;
$this->subtypes['object'][] = $subtype;
}
// and users
for ($i = 0; $i < 5; $i++) {
$subtype = "test_user_subtype_" . rand();
$e = new ElggUser();
$e->username = "test_user_" . rand();
$e->subtype = $subtype;
$e->save();
$this->entities[] = $e;
$this->subtypes['user'][] = $subtype;
}
// and groups
for ($i = 0; $i < 5; $i++) {
$subtype = "test_group_subtype_" . rand();
$e = new ElggGroup();
$e->subtype = $subtype;
$e->save();
$this->entities[] = $e;
$this->subtypes['group'][] = $subtype;
}
parent::__construct();
}
示例10: testElggRiverDisableEnable
public function testElggRiverDisableEnable()
{
$user = new \ElggUser();
$user->save();
$entity = new \ElggObject();
$entity->save();
$params = array('view' => 'river/relationship/friend/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $entity->guid);
$id = elgg_create_river_item($params);
$river = elgg_get_river(array('ids' => array($id)));
$this->assertIdentical($river[0]->enabled, 'yes');
$user->disable();
// should no longer be able to get the river
$river = elgg_get_river(array('ids' => array($id)));
$this->assertIdentical($river, array());
// renabling the user should re-enable the river
access_show_hidden_entities(true);
$user->enable();
access_show_hidden_entities(false);
$river = elgg_get_river(array('ids' => array($id)));
$this->assertIdentical($river[0]->enabled, 'yes');
$user->delete();
$entity->delete();
}
示例11: rand
function test_can_write_to_container()
{
$user = new \ElggUser();
$user->username = 'test_user_' . rand();
$user->name = 'test_user_name_' . rand();
$user->email = 'test@user.net';
$user->container_guid = 0;
$user->owner_guid = 0;
$user->save();
$object = new \ElggObject();
$object->save();
$group = new \ElggGroup();
$group->save();
// disable access overrides because we're admin.
$ia = elgg_set_ignore_access(false);
$this->assertFalse(can_write_to_container($user->guid, $object->guid));
global $elgg_test_user;
$elgg_test_user = $user;
// register hook to allow access
function can_write_to_container_test_hook($hook, $type, $value, $params)
{
global $elgg_test_user;
if ($params['user']->getGUID() == $elgg_test_user->getGUID()) {
return true;
}
}
elgg_register_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook');
$this->assertTrue(can_write_to_container($user->guid, $object->guid));
elgg_unregister_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook');
$this->assertFalse(can_write_to_container($user->guid, $group->guid));
$group->join($user);
$this->assertTrue(can_write_to_container($user->guid, $group->guid));
elgg_set_ignore_access($ia);
$user->delete();
$object->delete();
$group->delete();
}
示例12: login
/**
* Logs in a specified ElggUser. For standard registration, use in conjunction
* with authenticate.
*
* @see authenticate
* @param ElggUser $user A valid Elgg user object
* @param boolean $persistent Should this be a persistent login?
* @return true|false Whether login was successful
*/
function login(ElggUser $user, $persistent = false)
{
global $CONFIG;
if ($user->isBanned()) {
return false;
}
// User is banned, return false.
if (check_rate_limit_exceeded($user->guid)) {
return false;
}
// Check rate limit
$_SESSION['user'] = $user;
$_SESSION['guid'] = $user->getGUID();
$_SESSION['id'] = $_SESSION['guid'];
$_SESSION['username'] = $user->username;
$_SESSION['name'] = $user->name;
$code = md5($user->name . $user->username . time() . rand());
$user->code = md5($code);
$_SESSION['code'] = $code;
if ($persistent) {
setcookie("elggperm", $code, time() + 86400 * 30, "/");
}
if (!$user->save() || !trigger_elgg_event('login', 'user', $user)) {
unset($_SESSION['username']);
unset($_SESSION['name']);
unset($_SESSION['code']);
unset($_SESSION['guid']);
unset($_SESSION['id']);
unset($_SESSION['user']);
setcookie("elggperm", "", time() - 86400 * 30, "/");
return false;
}
// Users privilege has been elevated, so change the session id (help prevent session hijacking)
session_regenerate_id();
// Update statistics
set_last_login($_SESSION['guid']);
reset_login_failure_count($user->guid);
// Reset any previous failed login attempts
// Set admin shortcut flag if this is an admin
if (isadminloggedin()) {
global $is_admin;
$is_admin = true;
}
return true;
}
示例13: testUpdateAbilityDependsOnCanEdit
public function testUpdateAbilityDependsOnCanEdit()
{
$this->entity->access_id = ACCESS_PRIVATE;
$this->assertTrue($this->entity->save());
// even owner can't bypass permissions
elgg_register_plugin_hook_handler('permissions_check', 'object', [Elgg\Values::class, 'getFalse'], 999);
$this->assertFalse($this->entity->save());
elgg_unregister_plugin_hook_handler('permissions_check', 'object', [Elgg\Values::class, 'getFalse']);
$user = new ElggUser();
$user->save();
$old_user = $this->replaceSession($user);
$this->assertFalse($this->entity->save());
elgg_register_plugin_hook_handler('permissions_check', 'object', [Elgg\Values::class, 'getTrue']);
// even though this user can't look up the entity via the DB, permission allows update.
$this->assertFalse(has_access_to_entity($this->entity, $user));
$this->assertTrue($this->entity->save());
elgg_unregister_plugin_hook_handler('permissions_check', 'object', [Elgg\Values::class, 'getTrue']);
// can save with access ignore
$ia = elgg_set_ignore_access();
$this->assertTrue($this->entity->save());
elgg_set_ignore_access($ia);
$this->replaceSession($old_user);
$user->delete();
}
示例14: test_elgg_metadata_multiple_values
public function test_elgg_metadata_multiple_values()
{
$u1 = new ElggUser();
$u1->username = rand();
$u1->save();
$u2 = new ElggUser();
$u2->username = rand();
$u2->save();
$obj = new ElggObject();
$obj->owner_guid = $u1->guid;
$obj->container_guid = $u1->guid;
$obj->access_id = ACCESS_PUBLIC;
$obj->save();
$md_values = array('one', 'two', 'three');
// need to fake different logins.
// good times without mocking.
$original_user = elgg_get_logged_in_user_entity();
$_SESSION['user'] = $u1;
elgg_set_ignore_access(false);
// add metadata as one user
$obj->test = $md_values;
// check only these md exists
$db_prefix = elgg_get_config('dbprefix');
$q = "SELECT * FROM {$db_prefix}metadata WHERE entity_guid = {$obj->guid}";
$data = get_data($q);
$this->assertEqual(count($md_values), count($data));
foreach ($data as $md_row) {
$md = elgg_get_metadata_from_id($md_row->id);
$this->assertTrue(in_array($md->value, $md_values));
$this->assertEqual('test', $md->name);
}
// add md w/ same name as a different user
$_SESSION['user'] = $u2;
$md_values2 = array('four', 'five', 'six', 'seven');
$obj->test = $md_values2;
$q = "SELECT * FROM {$db_prefix}metadata WHERE entity_guid = {$obj->guid}";
$data = get_data($q);
$this->assertEqual(count($md_values2), count($data));
foreach ($data as $md_row) {
$md = elgg_get_metadata_from_id($md_row->id);
$this->assertTrue(in_array($md->value, $md_values2));
$this->assertEqual('test', $md->name);
}
$_SESSION['user'] = $original_user;
$obj->delete();
$u1->delete();
$u2->delete();
}
示例15: rand
/**
* Tests get_entity_statistics() with an owner
* @covers get_entity_statistics()
*/
function test_owned_get_entity_statistics()
{
$user = new \ElggUser();
$user->save();
$subtype = 'issue7845' . rand(0, 100);
$object = new \ElggObject();
$object->subtype = $subtype;
$object->owner_guid = $user->guid;
$object->save();
$stats = get_entity_statistics($user->guid);
$this->assertEqual($stats['object'][$subtype], 1);
$user->delete();
}