本文整理汇总了PHP中ElggGroup::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggGroup::save方法的具体用法?PHP ElggGroup::save怎么用?PHP ElggGroup::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggGroup
的用法示例。
在下文中一共展示了ElggGroup::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: testSqlAdditionalSelectsAsVolatileDataWithCache
/**
* Checks if additional select columns are readable as volatile data even if we hit the cache while fetching entity.
*
* https://github.com/Elgg/Elgg/issues/5544
*/
public function testSqlAdditionalSelectsAsVolatileDataWithCache()
{
// remove ignore access as it disables entity cache
$access = elgg_set_ignore_access(false);
// may not have groups in DB - let's create one
$group = new ElggGroup();
$group->name = 'test_group';
$group->access_id = ACCESS_PUBLIC;
$this->assertTrue($group->save() !== false);
foreach (array('site', 'user', 'group', 'object') as $type) {
$entities = elgg_get_entities(array('type' => $type, 'selects' => array('42 as added_col3'), 'limit' => 1));
$entity = array_shift($entities);
$this->assertTrue($entity instanceof ElggEntity);
$this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity));
$this->assertEqual($entity->getVolatileData('select:added_col3'), 42);
// make sure we have cached the entity
$this->assertNotEqual(false, _elgg_retrieve_cached_entity($entity->guid));
}
// run these again but with different value to make sure cache does not interfere
foreach (array('site', 'user', 'group', 'object') as $type) {
$entities = elgg_get_entities(array('type' => $type, 'selects' => array('64 as added_col3'), 'limit' => 1));
$entity = array_shift($entities);
$this->assertTrue($entity instanceof ElggEntity);
$this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity));
$this->assertEqual($entity->getVolatileData('select:added_col3'), 64, "Failed to overwrite volatile data in cached entity");
}
elgg_set_ignore_access($access);
$group->delete();
}
示例3: CreateLTIGroup
function CreateLTIGroup($user, $name, $context_id, $consumer_key)
{
$group_guid = 0;
$group = new ElggGroup($group_guid);
// Set the group properties that we can!
$group->name = $name;
$group->context_id = $context_id;
// This is a unique identifier from the consumer for this context
$group->consumer_key = $consumer_key;
// Which consumer is creating this group
$group->membership = ACCESS_PRIVATE;
$group->access_id = ACCESS_PUBLIC;
$group->briefdescription = elgg_echo('LTI:provision:group');
$consumer_instance = new LTI_Tool_Consumer_Instance($group->consumer_key, elgg_get_config('dbprefix'));
$context = new LTI_Context($consumer_instance, $group->context_id);
$group->description = $context->title;
$group->save();
$group->join($user);
// Add images
$prefix = 'groups/' . $group->guid;
$filename = GetImage($consumer_key, '.jpg');
$thumbtiny = get_resized_image_from_existing_file($filename, 25, 25, true);
$thumbsmall = get_resized_image_from_existing_file($filename, 40, 40, true);
$thumbmedium = get_resized_image_from_existing_file($filename, 100, 100, true);
$thumblarge = get_resized_image_from_existing_file($filename, 200, 200, false);
if ($thumbtiny) {
$thumb = new ElggFile();
$thumb->owner_guid = $group->owner_guid;
$thumb->setMimeType('image/jpeg');
$thumb->setFilename($prefix . "tiny.jpg");
$thumb->open("write");
$thumb->write($thumbtiny);
$thumb->close();
$thumb->setFilename($prefix . "small.jpg");
$thumb->open("write");
$thumb->write($thumbsmall);
$thumb->close();
$thumb->setFilename($prefix . "medium.jpg");
$thumb->open("write");
$thumb->write($thumbmedium);
$thumb->close();
$thumb->setFilename($prefix . "large.jpg");
$thumb->open("write");
$thumb->write($thumblarge);
$thumb->close();
$group->icontime = time();
}
// return the URL
return $group;
}
示例4: __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();
}
示例5: foreach
//$dgroup->files_enable = get_input('files_enable', 'yes');
//$dgroup->pages_enable = get_input('pages_enable', 'yes');
//$dgroup->forum_enable = get_input('forum_enable', 'yes');
// Set dgroup tool options
if (isset($CONFIG->dgroup_tool_options)) {
foreach ($CONFIG->dgroup_tool_options as $dgroup_option) {
$dgroup_option_toggle_name = $dgroup_option->name . "_enable";
if ($dgroup_option->default_on) {
$dgroup_option_default_value = 'yes';
} else {
$dgroup_option_default_value = 'no';
}
$dgroup->{$dgroup_option_toggle_name} = get_input($dgroup_option_toggle_name, $dgroup_option_default_value);
}
}
$dgroup->save();
if (!$dgroup->isMember($user)) {
$dgroup->join($user);
}
// Creator always a member
// Now see if we have a file icon
if (isset($_FILES['icon']) && substr_count($_FILES['icon']['type'], 'image/')) {
$prefix = "dgroups/" . $dgroup->guid;
$filehandler = new ElggFile();
$filehandler->owner_guid = $dgroup->owner_guid;
$filehandler->setFilename($prefix . ".jpg");
$filehandler->open("write");
$filehandler->write(get_uploaded_file('icon'));
$filehandler->close();
$thumbtiny = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 25, 25, true);
$thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 40, 40, true);
示例6: testJoinLeaveGroupACL
public function testJoinLeaveGroupACL()
{
if (!elgg_is_active_plugin('groups')) {
return;
}
$group = new ElggGroup();
$group->name = 'Test group';
$group->save();
$result = $group->join($this->user);
$this->assertTrue($result);
// disable security since we run as admin
$ia = elgg_set_ignore_access(false);
// need to set the page owner to emulate being in a group context.
// this is kinda hacky.
elgg_set_page_owner_guid($group->getGUID());
if ($result) {
$can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
$this->assertTrue($can_edit);
}
$result = $group->leave($this->user);
$this->assertTrue($result);
if ($result) {
$can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
$this->assertFalse($can_edit);
}
elgg_set_ignore_access($ia);
$group->delete();
}
示例7: foreach
foreach (array(hypefaker_get_group_content_access_mode('members_only'), hypefaker_get_group_content_access_mode('unrestricted')) as $content_access_mode) {
foreach (array(ACCESS_PRIVATE, ACCESS_PUBLIC) as $membership) {
for ($i = 0; $i < $count; $i++) {
$users = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => 1, 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
$owner = $users[0];
$group = new ElggGroup();
$group->name = $faker->sentence(5);
$group->owner_guid = $owner->guid;
$group->container_guid = $owner->guid;
$group->description = $faker->text(500);
$group->briefdescription = $faker->bs;
$group->interests = $faker->words(10);
$group->access_id = ACCESS_PUBLIC;
$group->membership = $membership;
$group->content_access_mode = $content_access_mode;
$guid = $group->save();
if (!$guid) {
$errors++;
continue;
}
if ($visibility != ACCESS_PUBLIC && $visibility != ACCESS_LOGGED_IN) {
$visibility = $group->group_acl;
}
if ($group->access_id != $visibility) {
$group->access_id = $visibility;
}
$group->__faker = true;
// store this flag so we can easily find fake entities
$group->join($owner);
$icon_sizes = elgg_get_config('icon_sizes');
$files = array();
示例8: testElggObjectContainer
public function testElggObjectContainer()
{
$this->assertEqual($this->entity->getContainerGUID(), elgg_get_logged_in_user_guid());
// create and save to group
$group = new \ElggGroup();
$guid = $group->save();
$this->assertTrue($this->entity->setContainerGUID($guid));
// check container
$this->assertEqual($this->entity->getContainerGUID(), $guid);
$this->assertIdenticalEntities($group, $this->entity->getContainerEntity());
// clean up
$group->delete();
}
示例9: testElggObjectContainer
public function testElggObjectContainer()
{
$this->assertEqual($this->entity->getContainer(), get_loggedin_userid());
// fals when container not a group
$this->assertFalse($this->entity->getContainerEntity());
// create and save to group
$group = new ElggGroup();
$guid = $group->save();
$this->assertTrue($this->entity->setContainer($guid));
// check container
$this->assertEqual($this->entity->getContainer(), $guid);
$this->assertIdentical($group, $this->entity->getContainerEntity());
// clean up
$group->delete();
}
开发者ID:ashwiniravi,项目名称:Elgg-Social-Network-Single-Sign-on-and-Web-Statistics,代码行数:15,代码来源:objects.php
示例10: createGroups
/**
* createGroups Create the groups in Elgg
*
* @return boolean
*/
function createGroups($post_data)
{
global $CONFIG;
$final_report = array();
/// Final report of the creation process
$this->headers = explode(',', $post_data['header']);
/// Create the groups from the $groups array
for ($i = 0; $i < $post_data['num_of_groups']; $i++) {
/// Get the group details from POST data for all headers
foreach ($this->headers as $header) {
$group[$header] = $post_data[$header][$i];
}
/// Add the basic fields to the report
$report = array('name' => $group['name'], 'subtype' => $group['subtype'], 'description' => $group['description'], 'membership' => $group['membership'], 'visibility' => $group['visibility'], 'container_guid' => $group['container_guid']);
/// Try to create the group
try {
$user = elgg_get_logged_in_user_entity();
$new_group = new ElggGroup();
$new_group->name = $group['name'];
$new_group->subtype = $group['subtype'];
$new_group->membership = $group['membership'];
$new_group->container_guid = $group['container_guid'];
$new_group->owner_guid = $user->guid;
$new_group->access_id = $group['visibility'];
$guid = $new_group->save();
if ($guid) {
elgg_set_page_owner_guid($group->guid);
$new_group->join($user);
add_to_river('river/group/create', 'create', $user->guid, $new_group->guid);
if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') {
$visibility = $group['visibility'];
if ($visibility != ACCESS_PUBLIC && $visibility != ACCESS_LOGGED_IN) {
$visibility = $new_group->group_acl;
}
if ($new_group->access_id != $visibility) {
$new_group->access_id = $visibility;
$new_group->save();
}
}
/// Add all other fields as metadata
foreach ($this->headers as $header) {
if (in_array($header, array('name', 'subtype', 'membership', 'visibility', 'description', 'container_guid'))) {
continue;
}
/// Metadata could be a comma separated list if the delimiter is something else than a comma
if ($this->delimiter != ',' && strpos($group[$header], ',')) {
/// Multiple tags found
$tags = string_to_tag_array($group[$header]);
foreach ($tags as $tag) {
create_metadata($guid, $header, $tag, 'text', $guid, ACCESS_PRIVATE, true);
}
} else {
create_metadata($guid, $header, $group[$header], 'text', $guid);
}
/// Add this metadata field to the report
$report[$header] = $group[$header];
}
/// Add status message to the report
$report['status'] = elgg_echo('upload_groups:success');
}
} catch (RegistrationException $r) {
//register_error($r->getMessage());
$report['status'] = '<span class="error">' . $r->getMessage() . '</span>';
$report['password'] = '';
/// Reset password in failed cases
$this->number_of_failed_groups++;
}
$final_report[] = $report;
}
$this->creation_report = $final_report;
return true;
}
示例11: test_extra_columns_dont_appear_in_attributes
/**
* Ensure additional select columns do not end up in entity attributes.
*
* https://github.com/Elgg/Elgg/issues/5538
*/
public function test_extra_columns_dont_appear_in_attributes()
{
global $ENTITY_CACHE;
// may not have groups in DB - let's create one
$group = new ElggGroup();
$group->name = 'test_group';
$group->access_id = ACCESS_PUBLIC;
$this->assertTrue($group->save() !== false);
// entity cache interferes with our test
$ENTITY_CACHE = array();
foreach (array('site', 'user', 'group', 'object') as $type) {
$entities = elgg_get_entities(array('type' => $type, 'selects' => array('1 as _nonexistent_test_column'), 'limit' => 1));
if (!$this->assertTrue($entities, "Query for '{$type}' did not return an entity.")) {
continue;
}
$entity = $entities[0];
$this->assertNull($entity->_nonexistent_test_column, "Additional select columns are leaking to attributes for '{$type}'");
}
$group->delete();
}
示例12: forward
if (!$request instanceof \Groups\Requests\Request) {
register_error(elgg_echo('group_requests:not_found'));
forward(REFERER);
}
$user = $request->getOwnerEntity();
if ($action == 'deny') {
$subject = elgg_echo('group_requests:denied:title', array(), $user->language);
$body = elgg_echo('group_requests:denied:body', array($user->name, $request->title), $user->language);
notify_user($request->owner_guid, elgg_get_site_entity()->guid, $subject, $body);
$request->delete();
system_message(elgg_echo('group_requests:deny:success'));
forward(REFERER);
}
$group = new ElggGroup();
$group->owner_guid = $request->owner_guid;
$group->container_guid = $request->container_guid;
$group->name = $request->title;
$group->access_id = ACCESS_PUBLIC;
if ($group->save()) {
// Besides being owner, user also needs to be a member
$group->join($user);
$subject = elgg_echo('group_requests:approved:title', array(), $user->language);
$body = elgg_echo('group_requests:approved:body', array($user->name, $group->name, elgg_normalize_url("groups/edit/{$group->guid}")), $user->language);
$params = array('action' => 'create', 'object' => $group);
notify_user($user->guid, elgg_get_site_entity()->guid, $subject, $body, $params);
$request->delete();
system_message(elgg_echo('group_requests:approve:success'));
} else {
register_error(elgg_echo('group_requests:approve:error'));
}
forward(REFERER);
示例13: group_tools_transfer_group_ownership
/**
* Helper function to transfer the ownership of a group to a new user
*
* @param ElggGroup $group the group to transfer
* @param ElggUser $new_owner the new owner
*
* @return bool
*/
function group_tools_transfer_group_ownership(ElggGroup $group, ElggUser $new_owner)
{
if (!$group instanceof ElggGroup || !$group->canEdit()) {
return false;
}
if (!$new_owner instanceof ElggUser) {
return false;
}
$loggedin_user = elgg_get_logged_in_user_entity();
// register plugin hook to make sure transfer can complete
elgg_register_plugin_hook_handler('permissions_check', 'group', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
$old_owner = $group->getOwnerEntity();
// transfer ownership
$group->owner_guid = $new_owner->getGUID();
$group->container_guid = $new_owner->getGUID();
if (!$group->save()) {
return false;
}
// make sure user is added to the group
$group->join($new_owner);
// remove existing group administrator role for new owner
remove_entity_relationship($new_owner->getGUID(), 'group_admin', $group->getGUID());
// check for group icon
if (!empty($group->icontime)) {
$prefix = "groups/{$group->getGUID()}";
$sizes = elgg_get_icon_sizes($group->getType());
$ofh = new ElggFile();
$ofh->owner_guid = $old_owner->getGUID();
$nfh = new ElggFile();
$nfh->owner_guid = $group->getOwnerGUID();
foreach ($sizes as $size => $info) {
// set correct file to handle
$ofh->setFilename("{$prefix}{$size}.jpg");
if (!$ofh->exists()) {
// file doesn't exist
continue;
}
$nfh->setFilename("{$prefix}{$size}.jpg");
// open files
$ofh->open('read');
$nfh->open('write');
// copy file
$nfh->write($ofh->grabFile());
// close file
$ofh->close();
$nfh->close();
// cleanup old file
$ofh->delete();
}
$group->icontime = time();
}
// move metadata of the group to the new owner
$options = ['guid' => $group->getGUID(), 'limit' => false];
$metadata = elgg_get_metadata($options);
if (!empty($metadata)) {
foreach ($metadata as $md) {
if ($md->owner_guid == $old_owner->getGUID()) {
$md->owner_guid = $new_owner->getGUID();
$md->save();
}
}
}
// notify new owner
if ($new_owner->getGUID() !== $loggedin_user->getGUID()) {
$subject = elgg_echo('group_tools:notify:transfer:subject', [$group->name]);
$message = elgg_echo('group_tools:notify:transfer:message', [$new_owner->name, $loggedin_user->name, $group->name, $group->getURL()]);
notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
}
// unregister plugin hook to make sure transfer can complete
elgg_unregister_plugin_hook_handler('permissions_check', 'group', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
return true;
}
示例14: ElggUser
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();
}
示例15: foreach
$metadata = elgg_get_metadata(array('guid' => $group_guid, 'limit' => false));
if ($metadata) {
foreach ($metadata as $md) {
if ($md->owner_guid == $old_owner_guid) {
$md->owner_guid = $new_owner_guid;
$md->save();
}
}
}
// @todo Remove this when #4683 fixed
$owner_has_changed = true;
$old_icontime = $group->icontime;
}
}
$must_move_icons = $owner_has_changed && $old_icontime;
$group->save();
// Invisible group support
// @todo this requires save to be called to create the acl for the group. This
// is an odd requirement and should be removed. Either the acl creation happens
// in the action or the visibility moves to a plugin hook
if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') {
$visibility = (int) get_input('vis', '', false);
if ($visibility != ACCESS_PUBLIC && $visibility != ACCESS_LOGGED_IN) {
$visibility = $group->group_acl;
}
if ($group->access_id != $visibility) {
$group->access_id = $visibility;
}
}
$group->save();
// group saved so clear sticky form