本文整理汇总了PHP中ElggGroup类的典型用法代码示例。如果您正苦于以下问题:PHP ElggGroup类的具体用法?PHP ElggGroup怎么用?PHP ElggGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ElggGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: transferIcons
/**
* Transfer group icons to new filestore location
* Before 3.0, group icons where owned by the group owner
* and located in /groups/<guid><size>.jpg
* relative to group owner's filestore directory
* In 3.0, we are moving these to default filestore location
* relative to group's filestore directory
*
* @param \ElggGroup $group Group entity
* @param \Elgg\Upgrade\Result $result Upgrade result
* @return \Elgg\Upgrade\Result
*/
public function transferIcons(\ElggGroup $group, \Elgg\Upgrade\Result $result)
{
$sizes = elgg_get_icon_sizes('group', $group->getSubtype());
$dataroot = elgg_get_config('dataroot');
$dir = (new \Elgg\EntityDirLocator($group->owner_guid))->getPath();
$prefix = 'groups/';
foreach ($sizes as $size => $opts) {
$filename = "{$group->guid}{$size}.jpg";
$filestorename = "{$dataroot}{$dir}{$prefix}{$filename}";
if (!file_exists($filestorename)) {
// nothing to move
continue;
}
$icon = $group->getIcon($size);
// before transferring the file, we need to make sure
// the directory structure of the new filestore location exists
$icon->open('write');
$icon->close();
if (!rename($filestorename, $icon->getFilenameOnFilestore())) {
$result->addError("\n\t\t\t\t\tFailed to transfer file from '{$filestorename}'\n\t\t\t\t\tto {$icon->getFilenameOnFilestore()}\n\t\t\t\t");
$error = true;
}
}
if ($error) {
$result->addFailures();
} else {
$result->addSuccesses();
}
return $result;
}
示例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: csv_exporter_get_last_group_activity
/**
* Get the latest activity of this group based on the river
*
* @param ElggGroup $entity the group to check
*
* @return int the UNIX timestamp of the latest activity
*/
function csv_exporter_get_last_group_activity(ElggGroup $entity)
{
$result = 0;
if (!$entity instanceof ElggGroup) {
return $result;
}
$dbprefix = elgg_get_config('dbprefix');
$query = 'SELECT max(r.posted) as posted';
$query .= " FROM {$dbprefix}river r";
$query .= " INNER JOIN {$dbprefix}entities e ON r.object_guid = e.guid";
$query .= " WHERE (e.container_guid = {$entity->getGUID()})";
$query .= " OR (r.object_guid = {$entity->getGUID()})";
$data = get_data($query);
if (!empty($data)) {
$result = (int) $data[0]->posted;
}
return $result;
}
示例5: group_tools_invite_email
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
$result = false;
if (!empty($group) && $group instanceof ElggGroup && !empty($email) && is_email_address($email) && ($loggedin_user = elgg_get_logged_in_user_entity())) {
// get site secret
$site_secret = get_site_secret();
// generate invite code
$invite_code = md5($site_secret . $email . $group->getGUID());
if (!group_tools_check_group_email_invitation($invite_code, $group->getGUID()) || $resend) {
// make site email
$site = elgg_get_site_entity();
if (!empty($site->email)) {
if (!empty($site->name)) {
$site_from = $site->name . " <" . $site->email . ">";
} else {
$site_from = $site->email;
}
} else {
// no site email, so make one up
if (!empty($site->name)) {
$site_from = $site->name . " <noreply@" . get_site_domain($site->getGUID()) . ">";
} else {
$site_from = "noreply@" . get_site_domain($site->getGUID());
}
}
if (!$resend) {
// register invite with group
$group->annotate("email_invitation", $invite_code, ACCESS_LOGGED_IN, $group->getGUID());
}
// make subject
$subject = elgg_echo("group_tools:groups:invite:email:subject", array($group->name));
// make body
$body = elgg_echo("group_tools:groups:invite:email:body", array($loggedin_user->name, $group->name, $site->name, $text, $site->name, elgg_get_site_url() . "register", elgg_get_site_url() . "groups/invitations/?invitecode=" . $invite_code, $invite_code));
$result = elgg_send_email($site_from, $email, $subject, $body);
} else {
$result = null;
}
}
return $result;
}
示例6: __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();
}
示例7: groups_register_profile_buttons
/**
* Registers the buttons for title area of the group profile page
*
* @param ElggGroup $group
*/
function groups_register_profile_buttons($group)
{
$actions = array();
// group owners
if ($group->canEdit()) {
// edit and invite
$url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}";
$actions[$url] = 'groups:edit';
$url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}";
$actions[$url] = 'groups:invite';
}
// group members
if ($group->isMember(elgg_get_logged_in_user_entity())) {
if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
// leave
$url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}";
$url = elgg_add_action_tokens_to_url($url);
$actions[$url] = 'groups:leave';
}
} elseif (elgg_is_logged_in()) {
// join - admins can always join.
$url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}";
$url = elgg_add_action_tokens_to_url($url);
if ($group->isPublicMembership() || $group->canEdit()) {
$actions[$url] = 'groups:join';
} else {
// request membership
$actions[$url] = 'groups:joinrequest';
}
}
if ($actions) {
foreach ($actions as $url => $text) {
elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
}
}
}
示例8: subgroups_page_handler
/**
* Dispatches subgroups pages.
* URLs take the form of
*
* Group view subgroups: subgroups/owner/<group_guid>
* Group manage subgroups: subgroups/manage/<group_guid>
*
* @param array $page
* @return NULL
*/
function subgroups_page_handler($page)
{
$pages_path = elgg_get_plugins_path() . "subgroups/pages";
switch ($page[0]) {
case 'add':
case 'edit':
elgg_set_page_owner_guid($page[1]);
include $pages_path . "/subgroups/edit.php";
break;
case 'owner':
elgg_set_page_owner_guid($page[1]);
include $pages_path . "/subgroups/owner.php";
break;
case 'new':
$group = new ElggGroup((int) $page[1]);
if (!$group->guid) {
register_error(elgg_echo('error:default'));
return false;
}
elgg_load_library('elgg:groups');
$title = elgg_echo('subgroups:new:of', array($group->name));
elgg_push_breadcrumb(elgg_echo('groups'), "groups/all");
elgg_push_breadcrumb($group->name, $group->getURL());
elgg_push_breadcrumb(elgg_echo('subgroups:new'));
set_input('container_guid', $group->guid);
$body = elgg_view_layout('content', array('content' => elgg_view('groups/edit'), 'title' => $title, 'filter' => ''));
echo elgg_view_page($title, $body);
break;
default:
return false;
}
return true;
}
示例9: set_time_limit
break;
}
}
set_time_limit(0);
$success = $error = 0;
$count = (int) get_input('count');
$featured_count = (int) get_input('featured_count');
$locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
$faker = Factory::create($locale);
foreach (array(ACCESS_PRIVATE, ACCESS_LOGGED_IN, ACCESS_PUBLIC) as $visibility) {
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) {
示例10: groups_join_group
/**
* Join a user to a group, add river event, clean-up invitations
*
* @param ElggGroup $group
* @param ElggUser $user
* @return bool
*/
function groups_join_group($group, $user)
{
// access ignore so user can be added to access collection of invisible group
$ia = elgg_set_ignore_access(TRUE);
$result = $group->join($user);
elgg_set_ignore_access($ia);
if ($result) {
// flush user's access info so the collection is added
get_access_list($user->guid, 0, true);
// Remove any invite or join request flags
remove_entity_relationship($group->guid, 'invited', $user->guid);
remove_entity_relationship($user->guid, 'membership_request', $group->guid);
elgg_create_river_item(array('view' => 'river/relationship/member/create', 'action_type' => 'join', 'subject_guid' => $user->guid, 'object_guid' => $group->guid));
return true;
}
return false;
}
示例11: _elgg_html_decode
} else {
$input[$shortname] = _elgg_html_decode($input[$shortname]);
}
if ($valuetype == 'tags') {
$input[$shortname] = string_to_tag_array($input[$shortname]);
}
}
$input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8');
$user = elgg_get_logged_in_user_entity();
$group_guid = (int) get_input('group_guid');
$is_new_group = $group_guid == 0;
if ($is_new_group && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) {
register_error(elgg_echo("groups:cantcreate"));
forward(REFERER);
}
$group = new ElggGroup($group_guid);
// load if present, if not create a new group
if ($group_guid && !$group->canEdit()) {
register_error(elgg_echo("groups:cantedit"));
forward(REFERER);
}
// Assume we can edit or this is a new group
if (sizeof($input) > 0) {
foreach ($input as $shortname => $value) {
// update access collection name if group name changes
if (!$is_new_group && $shortname == 'name' && $value != $group->name) {
$group_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
$ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $group_name);
$acl = get_access_collection($group->group_acl);
if ($acl) {
// @todo Elgg api does not support updating access collection name
示例12: test_can_write_to_container
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();
}
示例13: array
$input = array();
foreach ($CONFIG->dgroup as $shortname => $valuetype) {
$input[$shortname] = get_input($shortname);
if ($valuetype == 'tags') {
$input[$shortname] = string_to_tag_array($input[$shortname]);
}
}
$user_guid = get_input('user_guid');
$user = NULL;
if (!$user_guid) {
$user = $_SESSION['user'];
} else {
$user = get_entity($user_guid);
}
$dgroup_guid = get_input('dgroup_guid');
$dgroup = new ElggGroup($dgroup_guid);
// load if present, if not create a new dgroup
$dgroup->subtype = 'dgroup';
if ($dgroup_guid && !$dgroup->canEdit() && !isadminloggedin()) {
register_error(elgg_echo("dgroups:cantedit"));
forward($_SERVER['HTTP_REFERER']);
exit;
}
// Assume we can edit or this is a new dgroup
if (sizeof($input) > 0) {
foreach ($input as $shortname => $value) {
$dgroup->{$shortname} = $value;
}
}
// Validate create
if (!$dgroup->name) {
示例14: zhgroups_add_user
/**
* Add a user to a group
*
* @param ElggGroup $group the group to add the user to
* @param ElggUser $user the user to be added
* @param string $text (optional) extra text for the notification
*
* @return boolean true if successfull
*/
function zhgroups_add_user(ElggGroup $group, ElggUser $user, $text = "")
{
$result = false;
$loggedin_user = elgg_get_logged_in_user_entity();
if (!empty($user) && $user instanceof ElggUser && !empty($group) && $group instanceof ElggGroup && !empty($loggedin_user)) {
// make sure all goes well
$ia = elgg_set_ignore_access(true);
if ($group->join($user)) {
// Remove any invite or join request flags
remove_entity_relationship($group->getGUID(), "invited", $user->getGUID());
remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID());
// notify user
$subject = elgg_echo("zhgroups:groups:invite:add:subject", array($group->name));
$msg = elgg_echo("zhgroups:groups:invite:add:body", array($user->name, $loggedin_user->name, $group->name, $text, $group->getURL()));
$params = array("group" => $group, "inviter" => $loggedin_user, "invitee" => $user);
//to do?
$msg = elgg_trigger_plugin_hook("invite_notification", "zhgroups", $params, $msg);
if (notify_user($user->getGUID(), $group->getOwnerGUID(), $subject, $msg, null, "email")) {
$result = true;
}
}
// restore access
elgg_set_ignore_access($ia);
}
return $result;
}
示例15: event_manager_can_create_group_events
/**
* Checks if a certain user can create group events
*
* @param $group Group to check rights for
* @param $user User to check rights for
*
* @return bool
*/
function event_manager_can_create_group_events(\ElggGroup $group, $user = null)
{
if (empty($user)) {
$user = elgg_get_logged_in_user_entity();
}
if (!$group instanceof \ElggGroup || !$user instanceof \ElggUser) {
return false;
}
$who_create_group_events = elgg_get_plugin_setting('who_create_group_events', 'event_manager');
// group_admin, members
switch ($who_create_group_events) {
case 'group_admin':
return $group->canEdit($user->guid);
case 'members':
if ($group->isMember($user)) {
return true;
} else {
return $group->canEdit($user->guid);
}
}
return false;
}