本文整理汇总了PHP中ElggObject::addRelationship方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggObject::addRelationship方法的具体用法?PHP ElggObject::addRelationship怎么用?PHP ElggObject::addRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggObject
的用法示例。
在下文中一共展示了ElggObject::addRelationship方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tgswire_save_post
/**
* Create a new wire post, the TGS way
*
* @param string $text The post text
* @param int $userid The user's guid
* @param int $access_id Public/private etc
* @param int $parent_guid Parent post guid (if any)
* @param string $method The method (default: 'site')
* @param int $container_guid Container guid (for group wire posts)
* @return guid or false if failure
*/
function tgswire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site", $container_guid = NULL)
{
$post = new ElggObject();
$post->subtype = "thewire";
$post->owner_guid = $userid;
$post->access_id = $access_id;
// Check if we're removing the limit
if (elgg_get_plugin_setting('limit_wire_chars', 'wire-extender') == 'yes') {
// only 200 characters allowed
$text = elgg_substr($text, 0, 200);
}
// If supplied with a container_guid, use it
if ($container_guid) {
$post->container_guid = $container_guid;
}
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if ($tags) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
add_to_river('river/object/thewire/create', 'create', $post->owner_guid, $post->guid);
// let other plugins know we are setting a user status
$params = array('entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'thewire');
elgg_trigger_plugin_hook('status', 'user', $params);
}
return $guid;
}
示例2: hypefaker_add_wire
function hypefaker_add_wire($owner, $parent = null)
{
$locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
$faker = Factory::create($locale);
$wire = new ElggObject();
$wire->subtype = 'thewire';
$wire->owner_guid = $owner->guid;
$tags = $faker->words(5);
$text = $faker->text(80);
foreach ($tags as $tag) {
$text .= " #{$tag}";
}
if ($parent) {
$wire->reply = true;
$username = $parent->getOwnerEntity()->username;
$text = "@{$username} {$text}";
}
$limit = elgg_get_plugin_setting('limit', 'thewire');
if ($limit > 0) {
$text = elgg_substr($text, 0, $limit);
}
$wire->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$wire->tags = $tags;
$wire->method = 'faker';
$wire->access_id = ACCESS_PUBLIC;
$wire->__faker = true;
if ($wire->save()) {
if ($parent) {
$wire->addRelationship($parent->guid, 'parent');
$wire->wire_thread = $parent->wire_thread;
} else {
$wire->wire_thread = $wire->guid;
}
elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $wire->owner_guid, 'object_guid' => $wire->guid));
$params = array('entity' => $wire, 'user' => $owner, 'message' => $wire->description, 'url' => $wire->getURL(), 'origin' => 'thewire');
elgg_trigger_plugin_hook('status', 'user', $params);
return $wire;
}
return false;
}
示例3: thewire_tools_save_post
/**
* Save a wire post, overrules the default function because we need to support groups
*
* @param string $text the text of the post
* @param int $userid the owner of the post
* @param int $access_id the access level of the post
* @param int $parent_guid is this a reply on another post
* @param string $method which method was used
*
* @return bool|int the GUID of the new wire post or false
*/
function thewire_tools_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
// set correct container
$container_guid = $userid;
// check the access id
if ($access_id == ACCESS_PRIVATE) {
// private wire posts aren"t allowed
$access_id = ACCESS_LOGGED_IN;
} elseif (thewire_tools_groups_enabled()) {
// allow the saving of a wire post in a group (if enabled)
if (!in_array($access_id, array(ACCESS_FRIENDS, ACCESS_LOGGED_IN, ACCESS_PUBLIC))) {
// try to find a group with access_id
$group_options = array("type" => "group", "limit" => 1, "metadata_name_value_pairs" => array("group_acl" => $access_id));
$groups = elgg_get_entities_from_metadata($group_options);
if (!empty($groups)) {
$group = $groups[0];
if ($group->thewire_enable == "no") {
// not allowed to post in this group
register_error(elgg_echo("thewire_tools:groups:error:not_enabled"));
// let creation of object fail
return false;
} else {
$container_guid = $group->getGUID();
}
}
}
}
// create the new post
$post = new ElggObject();
$post->subtype = "thewire";
$post->owner_guid = $userid;
$post->container_guid = $container_guid;
$post->access_id = $access_id;
// only xxx characters allowed (see plugin setting)
$text = elgg_substr($text, 0, thewire_tools_get_wire_length());
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, "UTF-8");
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if (!empty($tags)) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, "parent");
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
add_to_river("river/object/thewire/create", "create", $post->getOwnerGUID(), $post->getGUID());
// let other plugins know we are setting a user status
$params = array("entity" => $post, "user" => $post->getOwnerEntity(), "message" => $post->description, "url" => $post->getURL(), "origin" => "thewire");
elgg_trigger_plugin_hook("status", "user", $params);
}
return $guid;
}
示例4: thewire_save_post
/**
* Create a new wire post.
*
* @param string $text The post text
* @param int $userid The user's guid
* @param int $access_id Public/private etc
* @param int $parent_guid Parent post guid (if any)
* @param string $method The method (default: 'site')
* @return guid or false if failure
*/
function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
$post = new ElggObject();
$post->subtype = "thewire";
$post->owner_guid = $userid;
$post->access_id = $access_id;
// only 200 characters allowed
$text = elgg_substr($text, 0, 200);
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if ($tags) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
add_to_river('river/object/thewire/create', 'create', $post->owner_guid, $post->guid);
}
return $guid;
}
示例5: thewire_save_post
/**
* Create a new wire post.
*
* @param string $text The post text
* @param int $userid The user's guid
* @param int $access_id Public/private etc
* @param int $parent_guid Parent post guid (if any)
* @param string $method The method (default: 'site')
* @return guid or false if failure
*/
function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
$post = new ElggObject();
$post->subtype = "thewire";
$post->owner_guid = $userid;
$post->access_id = $access_id;
// Character limit is now from config
$limit = elgg_get_plugin_setting('limit', 'thewire');
if ($limit > 0) {
$text = elgg_substr($text, 0, $limit);
}
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if ($tags) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $post->owner_guid, 'object_guid' => $post->guid));
// let other plugins know we are setting a user status
$params = array('entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'thewire');
elgg_trigger_plugin_hook('status', 'user', $params);
}
return $guid;
}
示例6: foreach
if ($entry->save()) {
$entry->addRelationship($survey->guid, 'hearSelection');
}
}
}
if ($reason) {
foreach ($reason as $selection) {
$entry = new ElggObject();
$entry->access_id = 2;
$entry->title = $selection;
if ($entry->save()) {
$entry->addRelationship($survey->guid, 'reasonSelection');
}
}
}
if ($final8) {
foreach ($final8 as $selection) {
$entry = new ElggObject();
$entry->access_id = 2;
$entry->title = $selection;
if ($entry->save()) {
$entry->addRelationship($survey->guid, 'final8Selection');
}
}
}
system_message("Survey Submitted");
forward($survey->getURL());
} else {
register_error("Error submitting survey");
forward(REFERER);
}
示例7: threads_reply
function threads_reply($parent_guid, $text, $title = "", $params = null)
{
$topic = threads_top($parent_guid);
$topic_guid = $topic->guid;
// add the reply to the forum topic
$reply = new ElggObject();
$reply->subtype = 'topicreply';
$reply->title = $title ? $title : "Re:" . $topic->title;
$reply->description = $text;
$reply->access_id = $topic->access_id;
$reply->container_guid = $topic->container_guid;
// save parameters
if ($params) {
foreach ($params as $key => $value) {
$reply->{$key} = $value;
}
}
if ($reply->save()) {
$reply->addRelationship($parent_guid, 'parent');
$reply->addRelationship($topic_guid, 'top');
return $reply->save();
} else {
return false;
}
}
示例8: wire_save_post
/**
* Create a new wire post.
*
* @param string $text The post text
* @param int $userid The user's guid
* @param int $access_id Public/private etc
* @param int $parent_guid Parent post guid (if any)
* @param string $method The method (default: 'site')
* @return guid or false if failure
*/
function wire_save_post($text, $userid, $entity_guid, $access_id, $parent_guid = 0, $method = "site")
{
$post = new ElggObject();
$post->subtype = "wire";
$post->owner_guid = $userid;
$post->access_id = $access_id;
$post->entity_guid = $entity_guid;
// only 200 characters allowed
$text = elgg_substr($text, 0, 200);
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = wire_get_hashtags($text);
if ($tags) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
add_to_river('river/object/wire/create', 'create', $post->owner_guid, $post->guid);
// let other plugins know we are setting a user status
$params = array('entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'wire');
elgg_trigger_plugin_hook('status', 'user', $params);
}
//fordebug register_error("in save entity_guid {$post->entity_guid}");
return $guid;
}
示例9: ElggObject
if (!in_array($old_member_guid, $members)) {
$old_member = get_entity($old_member_guid);
$entity->removeMember($old_member);
}
}
// Save the first chat message
if ($description) {
$message = new ElggObject();
$message->subtype = 'chat_message';
$message->access_id = ACCESS_LOGGED_IN;
$message->container_guid = $entity->getGUID();
$message->description = $description;
if ($message->save()) {
$members = $entity->getMemberEntities();
foreach ($members as $member) {
// No unread annotation for user's own message
if ($member->getGUID() === $user->getGUID()) {
continue;
}
// Mark the message as unread
$message->addRelationship($member->getGUID(), 'unread');
// Add number of unread messages also to the chat object
$entity->increaseUnreadMessageCount($member);
}
} else {
register_error(elgg_echo('chat:error:cannot_save_message'));
forward($entity->getURL());
}
}
system_message(elgg_echo('chat:message:saved'));
forward($entity->getURL());
示例10: ElggObject
}
} else {
$entity = new ElggObject();
$entity->subtype = 'chat_message';
$entity->access_id = ACCESS_LOGGED_IN;
$entity->container_guid = $container_guid;
}
$entity->description = $message;
if ($entity->save()) {
elgg_clear_sticky_form('chat_message');
$chat = $entity->getContainerEntity();
$members = $chat->getMemberEntities();
foreach ($members as $member) {
// No unread annotations for user's own message
if ($member->getGUID() === $user->getGUID()) {
continue;
}
// Mark the message as unread
$entity->addRelationship($member->getGUID(), 'unread');
// Add number of unread messages also to the chat object
$chat->increaseUnreadMessageCount($member);
}
// @todo Should we update the container chat so we can order chats by
// time_updated? Or is it possible to order by "unread_messages" annotation?
//$chat->time_updated = time();
} else {
register_error(elgg_echo('chat:error:cannot_save_message'));
forward(REFERER);
}
system_message(elgg_echo('chat:message:chat_message:saved'));
forward($entity->getContainerEntity()->getURL());
示例11: thewire_tools_save_post
/**
* Save a wire post, overrules the default function because we need to support groups
*
* @param string $text the text of the post
* @param int $userid the owner of the post
* @param int $access_id the access level of the post
* @param int $parent_guid is this a reply on another post
* @param string $method which method was used
* @param int $reshare_guid is the a (re)share of some content item
*
* @return bool|int the GUID of the new wire post or false
*/
function thewire_tools_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site", $reshare_guid = 0)
{
// set correct container
$container_guid = $userid;
// check the access id
if ($access_id == ACCESS_PRIVATE) {
// private wire posts aren't allowed
$access_id = ACCESS_LOGGED_IN;
} elseif (thewire_tools_groups_enabled()) {
// allow the saving of a wire post in a group (if enabled)
if (!in_array($access_id, [ACCESS_FRIENDS, ACCESS_LOGGED_IN, ACCESS_PUBLIC])) {
// try to find a group with access_id
$group_options = ['type' => 'group', 'limit' => 1, 'metadata_name_value_pairs' => ['group_acl' => $access_id]];
$groups = elgg_get_entities_from_metadata($group_options);
if (!empty($groups)) {
$group = $groups[0];
if ($group->thewire_enable == 'no') {
// not allowed to post in this group
register_error(elgg_echo('thewire_tools:groups:error:not_enabled'));
// let creation of object fail
return false;
} else {
$container_guid = $group->getGUID();
}
}
}
}
// create the new post
$post = new ElggObject();
$post->subtype = 'thewire';
$post->owner_guid = $userid;
$post->container_guid = $container_guid;
$post->access_id = $access_id;
// only xxx characters allowed (see plugin setting of thewire, 0 is unlimited)
$max_length = thewire_tools_get_wire_length();
if ($max_length) {
$text = elgg_substr($text, 0, $max_length);
}
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if (!empty($tags)) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
if ($guid) {
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
// add reshare
if ($reshare_guid) {
$post->addRelationship($reshare_guid, 'reshare');
}
// add to river
elgg_create_river_item(['view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $post->getOwnerGUID(), 'object_guid' => $post->getGUID()]);
// let other plugins know we are setting a user status
$params = ['entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'thewire'];
elgg_trigger_plugin_hook('status', 'user', $params);
}
return $guid;
}
示例12: ElggObject
<?php
/**
* ElggChat - Pure Elgg-based chat/IM
*
* Action to create a chat session with specified user
*
* @package elggchat
* @author ColdTrick IT Solutions
* @copyright Coldtrick IT Solutions 2009
* @link http://www.coldtrick.com/
*
* for Elgg 1.8 and newer by iionly (iionly@gmx.de)
* @copyright iionly 2014
* @link https://github.com/iionly
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
*/
$inviteId = (int) get_input("invite");
$user = elgg_get_logged_in_user_entity();
if (($invite_user = get_user($inviteId)) && $inviteId != $user->guid) {
$session = new ElggObject();
$session->subtype = ELGGCHAT_SESSION_SUBTYPE;
$session->access_id = ACCESS_LOGGED_IN;
$session->setMetaData("tag", "");
$session->save();
$session->addRelationship($user->guid, ELGGCHAT_MEMBER);
$session->addRelationship($invite_user->guid, ELGGCHAT_MEMBER);
echo $session->guid;
}
exit;