本文整理汇总了PHP中add_entity_relationship函数的典型用法代码示例。如果您正苦于以下问题:PHP add_entity_relationship函数的具体用法?PHP add_entity_relationship怎么用?PHP add_entity_relationship使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_entity_relationship函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
/**
* {@inheritdoc}
*/
public function post(ParameterBag $params)
{
$user = elgg_get_logged_in_user_entity();
$group = get_entity($params->guid);
// join or request
$join = false;
if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
// anyone can join public groups and admins can join any group
$join = true;
} else {
if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
// user has invite to closed group
$join = true;
}
}
if ($join) {
if (groups_join_group($group, $user)) {
$msg = elgg_echo("groups:joined");
} else {
throw new GraphException(elgg_echo("groups:cantjoin"));
}
} else {
if (!add_entity_relationship($user->guid, 'membership_request', $group->guid)) {
throw new GraphException(elgg_echo("groups:joinrequestnotmade"));
}
$owner = $group->getOwnerEntity();
$url = elgg_normalize_url("groups/requests/{$group->guid}");
$subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language);
$body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language);
// Notify group owner
notify_user($owner->guid, $user->getGUID(), $subject, $body);
$msg = elgg_echo("groups:joinrequestmade");
}
return array('nodes' => array('member' => check_entity_relationship($user->guid, 'member', $group->guid), 'invited' => check_entity_relationship($group->guid, 'invited', $user->guid), 'membership_request' => check_entity_relationship($user->guid, 'membership_request', $group->guid)));
}
示例2: file_tools_object_handler
function file_tools_object_handler($event, $type, $object)
{
if (!empty($object) && elgg_instanceof($object, "object", "file")) {
$folder_guid = (int) get_input("folder_guid", 0);
if (!empty($folder_guid)) {
if ($folder = get_entity($folder_guid)) {
if (!elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE)) {
unset($folder_guid);
}
} else {
unset($folder_guid);
}
}
// remove old relationships
remove_entity_relationships($object->getGUID(), FILE_TOOLS_RELATIONSHIP, true);
if (!empty($folder_guid)) {
add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $object->getGUID());
//update parent folders last_action attribute
update_entity_last_action($folder_guid);
$parent_guid = get_entity($folder_guid)->parent_guid;
if ($parent_guid) {
update_parent_folder_last_action($parent_guid);
}
}
}
}
示例3: group_tools_join_group_event
function group_tools_join_group_event($event, $type, $params)
{
static $auto_notification;
// only load plugin setting once
if (!isset($auto_notification)) {
$auto_notification = false;
if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") {
$auto_notification = true;
}
}
if (!empty($params) && is_array($params)) {
$group = elgg_extract("group", $params);
$user = elgg_extract("user", $params);
if ($user instanceof ElggUser && $group instanceof ElggGroup) {
if ($auto_notification) {
// enable email notification
add_entity_relationship($user->getGUID(), "notifyemail", $group->getGUID());
if (elgg_is_active_plugin("messages")) {
// enable site/messages notification
add_entity_relationship($user->getGUID(), "notifysite", $group->getGUID());
}
}
// cleanup invites
if (check_entity_relationship($group->getGUID(), "invited", $user->getGUID())) {
remove_entity_relationship($group->getGUID(), "invited", $user->getGUID());
}
// and requests
if (check_entity_relationship($user->getGUID(), "membership_request", $group->getGUID())) {
remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID());
}
}
}
}
示例4: roles_set_role
/**
* Assigns a role to a particular user
*
* @param ElggRole $role The role to be assigned
* @param ElggUser $user The user the role needs to be assigned to
* @return mixed True if the role change was successful, false if could not update user role, and null if there was no change in user role
*/
function roles_set_role($role, $user = null)
{
if (!elgg_instanceof($role, 'object', 'role')) {
return false;
// Couldn't set new role
}
$user = $user ? $user : elgg_get_logged_in_user_entity();
if (!elgg_instanceof($user, 'user')) {
return false;
// Couldn't set new role
}
$current_role = roles_get_role($user);
if ($role != $current_role) {
remove_entity_relationships($user->guid, 'has_role');
if ($role->name != DEFAULT_ROLE && $role->name != ADMIN_ROLE) {
if (!add_entity_relationship($user->guid, 'has_role', $role->guid)) {
return false;
// Couldn't set new role
}
}
return true;
// Role has been changed
}
return null;
// There was no change necessary, old and new role are the same
}
示例5: widget_manager_create_object_handler
/**
* Performs action when a widget is created
*
* @param string $event name of the system event
* @param string $object_type type of the event
* @param mixed $object object related to the event
*
* @return void
*/
function widget_manager_create_object_handler($event, $object_type, $object)
{
if (elgg_instanceof($object, "object", "widget", "ElggWidget")) {
$owner = $object->getOwnerEntity();
// Updates access for privately created widgets in a group or on site
if ((int) $object->access_id === ACCESS_PRIVATE) {
$old_ia = elgg_set_ignore_access();
if ($owner instanceof ElggGroup) {
$object->access_id = $owner->group_acl;
$object->save();
} elseif ($owner instanceof ElggSite) {
$object->access_id = ACCESS_PUBLIC;
$object->save();
}
elgg_set_ignore_access($old_ia);
}
// Adds a relation between a widget and a multidashboard object
$dashboard_guid = get_input("multi_dashboard_guid");
if ($dashboard_guid && widget_manager_multi_dashboard_enabled()) {
$dashboard = get_entity($dashboard_guid);
if (elgg_instanceof($dashboard, "object", MultiDashboard::SUBTYPE, "MultiDashboard")) {
add_entity_relationship($object->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP, $dashboard->getGUID());
}
}
}
}
示例6: post
/**
* {@inheritdoc}
*/
public function post(ParameterBag $params)
{
$user = get_entity($params->guid);
$friend = $params->friend_uid ? $this->graph->get($params->friend_uid) : null;
if (!$user instanceof ElggUser || !$friend instanceof ElggUser) {
throw new GraphException("User or friend not found", HttpResponse::HTTP_NOT_FOUND);
}
if (!$user->canEdit()) {
throw new GraphException("You are not allowed to modify this user's friends list", HttpResponse::HTTP_FORBIDDEN);
}
if ($user->guid == $friend->guid) {
throw new GraphException("You are trying to friend yourself", HttpResponse::HTTP_BAD_REQUEST);
}
if (check_entity_relationship($user->guid, 'friend', $friend->guid)) {
throw new GraphException("Already a friend", HttpResponse::HTTP_BAD_REQUEST);
}
if (!add_entity_relationship($user->guid, 'friend', $friend->guid)) {
throw new GraphException("Unable to create friendship");
}
$river_id = elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->guid, 'object_guid' => $friend->guid));
$return = array('nodes' => array('friend' => check_entity_relationship($user->guid, 'friend', $friend->guid), 'friend_of' => check_entity_relationship($friend->guid, 'friend', $user->guid)));
if (!empty($river_id)) {
$river = elgg_get_river(array('ids' => $river_id));
$return['nodes']['activity'] = $river ? $river[0] : $river_id;
}
return $return;
}
示例7: markCorrect
/**
* Mark answer as correct
*
* @return bool
*/
public function markCorrect()
{
if (questions_close_on_marked_answer()) {
$this->getQuestion()->setStatus('closed');
}
return add_entity_relationship($this->getQuestion()->guid, "correctAnswer", $this->guid);
}
示例8: add_site_object
/**
* Add an object to a site.
*
* @param int $site_guid Site GUID
* @param int $object_guid Object GUID
*
* @return mixed
*/
function add_site_object($site_guid, $object_guid)
{
global $CONFIG;
$site_guid = (int) $site_guid;
$object_guid = (int) $object_guid;
return add_entity_relationship($object_guid, "member_of_site", $site_guid);
}
示例9: hj_framework_set_ancestry
/**
* Retrieve ancestry relationships / update if they have changed
*
* @param int $guid
* @param mixed $subtypes
* @return boolean|array
*/
function hj_framework_set_ancestry($guid)
{
$entity = get_entity($guid);
if (!$entity) {
return false;
}
$ia = elgg_set_ignore_access(true);
// Build an hierarchy from [0]highest to [X]lowest
$ancestry = array();
$ancestry_guids = array();
$container = $entity->getContainerEntity();
while (elgg_instanceof($container)) {
array_unshift($ancestry, $container);
array_unshift($ancestry_guids, $container->guid);
$container = $container->getContainerEntity();
}
// Store as a hash so we don't unnecessarily update the hierarchy every time save() is calleed
if (!isset($entity->hierarchy_hash) || $entity->hierarchy_hash != sha1(serialize($ancestry_guids))) {
remove_entity_relationships($entity->guid, 'descendant', false);
foreach ($ancestry as $ancestor) {
if (elgg_instanceof($ancestor, 'object')) {
update_entity_last_action($ancestor->guid, $entity->time_created);
}
if (!check_entity_relationship($entity->guid, 'descendant', $ancestor->guid)) {
add_entity_relationship($entity->guid, 'descendant', $ancestor->guid);
}
}
$entity->hierarchy_hash = sha1(serialize($ancestry_guids));
}
elgg_set_ignore_access($ia);
return $ancestry;
}
示例10: addSubscription
/**
* Subscribe a user to notifications about a target entity
*
* This method will return false if the subscription already exists.
*
* @param int $userGuid The GUID of the user to subscribe to notifications
* @param string $method The delivery method of the notifications
* @param int $targetGuid The entity to receive notifications about
* @return boolean
*/
public function addSubscription($userGuid, $method, $targetGuid)
{
if (!in_array($method, $this->methods)) {
return false;
}
$prefix = self::RELATIONSHIP_PREFIX;
return add_entity_relationship($userGuid, "{$prefix}{$method}", $targetGuid);
}
示例11: group_tools_join_group_event
/**
* When a user joins a group
*
* @param string $event join
* @param string $type group
* @param array $params array with the user and the user
*
* @return void
*/
function group_tools_join_group_event($event, $type, $params)
{
global $NOTIFICATION_HANDLERS;
static $auto_notification;
// only load plugin setting once
if (!isset($auto_notification)) {
$auto_notification = array();
if (isset($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) {
if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") {
// Backwards compatibility
$auto_notification = array("email", "site");
}
foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
if (elgg_get_plugin_setting("auto_notification_" . $method, "group_tools") == "1") {
$auto_notification[] = $method;
}
}
}
}
if (!empty($params) && is_array($params)) {
$group = elgg_extract("group", $params);
$user = elgg_extract("user", $params);
if ($user instanceof ElggUser && $group instanceof ElggGroup) {
// check for the auto notification settings
if (!empty($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) {
foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
if (in_array($method, $auto_notification)) {
add_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID());
}
}
}
// cleanup invites
remove_entity_relationship($group->getGUID(), "invited", $user->getGUID());
// and requests
remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID());
// cleanup email invitations
$options = array("annotation_name" => "email_invitation", "annotation_value" => group_tools_generate_email_invite_code($group->getGUID(), $user->email), "limit" => false);
if (elgg_is_logged_in()) {
elgg_delete_annotations($options);
} elseif ($annotations = elgg_get_annotations($options)) {
group_tools_delete_annotations($annotations);
}
// welcome message
$welcome_message = $group->getPrivateSetting("group_tools:welcome_message");
$check_message = trim(strip_tags($welcome_message));
if (!empty($check_message)) {
// replace the place holders
$welcome_message = str_ireplace("[name]", $user->name, $welcome_message);
$welcome_message = str_ireplace("[group_name]", $group->name, $welcome_message);
$welcome_message = str_ireplace("[group_url]", $group->getURL(), $welcome_message);
// notify the user
notify_user($user->getGUID(), $group->getGUID(), elgg_echo("group_tools:welcome_message:subject", array($group->name)), $welcome_message);
}
}
}
}
示例12: widget_manager_create_object_handler
/**
* Adds a relation between a widget and a multidashboard object
*
* @param unknown_type $event
* @param unknown_type $type
* @param unknown_type $object
*/
function widget_manager_create_object_handler($event, $type, $object)
{
if (elgg_instanceof($object, "object", "widget", "ElggWidget")) {
if ($dashboard_guid = get_input("multi_dashboard_guid")) {
if (($dashboard = get_entity($dashboard_guid)) && elgg_instanceof($dashboard, "object", MultiDashboard::SUBTYPE, "MultiDashboard")) {
add_entity_relationship($object->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP, $dashboard->getGUID());
}
}
}
}
示例13: save_answer
function save_answer($elgg_question, $answer_body)
{
$answer = new ElggObject();
$answer->subtype = "answer";
$answer->description = $answer_body;
$answer->question_guid = $elgg_question->getGUID();
$answer->save();
add_entity_relationship($elgg_question->getGUID(), "answer", $answer->getGUID());
return $answer;
}
示例14: interactions_20141231a
/**
* Reverses 'attached' relationship for old comments
* @return void
*/
function interactions_20141231a()
{
$comments = new \ElggBatch('elgg_get_entities', array('types' => 'object', 'subtypes' => 'hjcomment', 'limit' => 0, 'callback' => false));
foreach ($comments as $comment) {
$attachments = new \ElggBatch('elgg_get_entities_from_relationship', array('relationship' => 'attached', 'relationship_guid' => $comment->guid, 'inverse_relationship' => true, 'limit' => 0, 'callback' => false));
foreach ($attachments as $attachment) {
add_entity_relationship($comment->guid, 'attached', $attachment->guid);
}
}
}
示例15: save
/**
* Save the relationship
*
* @return int the relationship id
*/
public function save()
{
if ($this->id > 0) {
delete_relationship($this->id);
}
$this->id = add_entity_relationship($this->guid_one, $this->relationship, $this->guid_two);
if (!$this->id) {
throw new IOException(elgg_echo('IOException:UnableToSaveNew', array(get_class())));
}
return $this->id;
}