本文整理汇总了PHP中elgg_get_annotation_from_id函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_get_annotation_from_id函数的具体用法?PHP elgg_get_annotation_from_id怎么用?PHP elgg_get_annotation_from_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_get_annotation_from_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unserialize
/**
* Unserializes the event object stored in the database
*
* @param string $serialized Serialized string
* @return string
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
if (isset($data->action)) {
$this->action = $data->action;
}
if (isset($data->object_id) && isset($data->object_type)) {
switch ($data->object_type) {
case 'object':
case 'user':
case 'group':
case 'site':
$this->object = get_entity($data->object_id);
break;
case 'annotation':
$this->object = elgg_get_annotation_from_id($data->object_id);
break;
case 'metadata':
$this->object = elgg_get_metadata_from_id($data->object_id);
break;
case 'relationship':
$this->object = get_relationship($data->object_id);
}
}
if (isset($data->actor_guid)) {
$this->actor = get_entity($data->actor_guid);
}
}
示例2: createRandomAnnotations
/**
* Creates random annotations on $entity
*
* @param \ElggEntity $entity
* @param int $max
*/
protected function createRandomAnnotations($entity, $max = 1)
{
$annotations = array();
for ($i = 0; $i < $max; $i++) {
$name = 'test_annotation_name_' . rand();
$value = rand();
$id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID());
$annotations[] = elgg_get_annotation_from_id($id);
}
return $annotations;
}
示例3: 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();
}
示例4: messageboard_add
/**
* Add messageboard post
*
* @param ElggUser $poster User posting the message
* @param ElggUser $owner User who owns the message board
* @param string $message The posted message
* @param int $access_id Access level (see defines in elgglib.php)
* @return bool
*/
function messageboard_add($poster, $owner, $message, $access_id = ACCESS_PUBLIC)
{
$result_id = $owner->annotate('messageboard', $message, $access_id, $poster->guid);
if (!$result_id) {
return false;
}
elgg_create_river_item(array('view' => 'river/object/messageboard/create', 'action_type' => 'messageboard', 'subject_guid' => $poster->guid, 'object_guid' => $owner->guid, 'access_id' => $access_id, 'annotation_id' => $result_id));
// Send notification only if poster isn't the owner
if ($poster->guid != $owner->guid) {
$subject = elgg_echo('messageboard:email:subject', array(), $owner->language);
$body = elgg_echo('messageboard:email:body', array($poster->name, $message, elgg_get_site_url() . "messageboard/owner/" . $owner->username, $poster->name, $poster->getURL()), $owner->language);
$params = ['action' => 'create', 'object' => elgg_get_annotation_from_id($result_id)];
notify_user($owner->guid, $poster->guid, $subject, $body, $params);
}
return $result_id;
}
示例5: get
/**
* {@inheritdoc}
*/
public function get($uid = '')
{
switch ($uid) {
case 'me':
$uid = "ue" . elgg_get_logged_in_user_guid();
break;
case 'site':
$uid = "se" . elgg_get_site_entity()->guid;
break;
}
$abbr = substr($uid, 0, 2);
switch ($abbr) {
case 'an':
$id = (int) substr($uid, 2);
$object = elgg_get_annotation_from_id($id);
break;
case 'md':
$id = (int) substr($uid, 2);
$object = elgg_get_metadata_from_id($id);
break;
case 'rl':
$id = (int) substr($uid, 2);
$object = get_relationship($id);
break;
case 'rv':
$id = (int) substr($uid, 2);
$river = elgg_get_river(array('ids' => sanitize_int($id)));
$object = $river ? $river[0] : false;
break;
case 'ue':
case 'se':
case 'oe':
case 'ge':
$id = (int) substr($uid, 2);
$object = get_entity($id);
break;
default:
$object = get_user_by_username($uid);
if (!$object && is_numeric($uid)) {
$object = get_entity($uid);
}
}
if (!$this->isExportable($object)) {
return false;
}
return $object;
}
示例6: getObject
/**
* Get the object of the event
*
* @return \ElggData
*/
public function getObject()
{
switch ($this->object_type) {
case 'object':
case 'user':
case 'site':
case 'group':
return get_entity($this->object_id);
break;
case 'relationship':
return get_relationship($this->object_id);
break;
case 'annotation':
return elgg_get_annotation_from_id($this->object_id);
break;
}
return null;
}
示例7: post
/**
* {@inheritdoc}
*/
public function post(ParameterBag $params)
{
$entity_guid = (int) $params->guid;
//check to see if the user has already liked the item
if (elgg_annotation_exists($entity_guid, 'likes')) {
throw new GraphException(elgg_echo("likes:alreadyliked"), HttpResponse::HTTP_NOT_MODIFIED);
}
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
throw new GraphException(elgg_echo("likes:notfound"), HttpResponse::HTTP_NOT_FOUND);
}
// limit likes through a plugin hook (to prevent liking your own content for example)
if (!$entity->canAnnotate(0, 'likes')) {
// plugins should register the error message to explain why liking isn't allowed
throw new GraphException(elgg_echo("likes:notallowed"), HttpResponse::HTTP_FORBIDDEN);
}
$user = elgg_get_logged_in_user_entity();
$annotation_id = create_annotation($entity->guid, 'likes', "likes", "", $user->guid, $entity->access_id);
// tell user annotation didn't work if that is the case
if (!$annotation_id) {
throw new GraphException(elgg_echo("likes:failure"));
}
// notify if poster wasn't owner
if ($entity->owner_guid != $user->guid) {
$owner = $entity->getOwnerEntity();
$annotation = elgg_get_annotation_from_id($annotation_id);
$title_str = $entity->getDisplayName();
if (!$title_str) {
$title_str = elgg_get_excerpt($entity->description);
}
$site = elgg_get_site_entity();
$subject = elgg_echo('likes:notifications:subject', array($user->name, $title_str), $owner->language);
$body = elgg_echo('likes:notifications:body', array($owner->name, $user->name, $title_str, $site->name, $entity->getURL(), $user->getURL()), $owner->language);
notify_user($entity->owner_guid, $user->guid, $subject, $body, array('action' => 'create', 'object' => $annotation));
}
return array('nodes' => array(elgg_get_annotation_from_id($annotation_id)));
}
示例8: get_input
<?php
/**
* Elgg delete like action
*
*/
// Support deleting by id in case we're deleting another user's likes
$id = (int) get_input('id');
$like = NULL;
if ($id) {
$like = elgg_get_annotation_from_id($id);
}
if (!$like) {
$likes = elgg_get_annotations(array('guid' => (int) get_input('guid'), 'annotation_owner_guid' => elgg_get_logged_in_user_guid(), 'annotation_name' => 'likes'));
$like = $likes[0];
}
if ($like && $like->canEdit()) {
$entity = $like->getEntity();
$like->delete();
system_message(elgg_echo("likes:deleted"));
if ($entity && elgg_is_xhr()) {
$num_of_likes = likes_count($entity);
if ($num_of_likes == 1) {
$likes_string = elgg_echo('likes:userlikedthis', array($num_of_likes));
} else {
$likes_string = elgg_echo('likes:userslikedthis', array($num_of_likes));
}
echo json_encode(['text' => $likes_string, 'selector' => "[data-likes-guid={$entity->guid}]", 'num_likes' => $num_of_likes]);
}
forward(REFERER);
}
示例9: get_annotation
/**
* Get a specific annotation.
*
* @param int $annotation_id Annotation ID
*
* @return ElggAnnotation
* @deprecated 1.8 Use elgg_get_annotation_from_id()
*/
function get_annotation($annotation_id)
{
elgg_deprecated_notice('get_annotation() is deprecated by elgg_get_annotation_from_id()', 1.8);
return elgg_get_annotation_from_id($annotation_id);
}
示例10: get_input
<?php
/**
* Elgg delete comment action
*
* @package Elgg
*/
// Make sure we can get the comment in question
$annotation_id = (int) get_input('annotation_id');
$comment = elgg_get_annotation_from_id($annotation_id);
if ($comment && $comment->canEdit()) {
$comment->delete();
system_message(elgg_echo("generic_comment:deleted"));
} else {
register_error(elgg_echo("generic_comment:notdeleted"));
}
forward(REFERER);
示例11: elgg_get_metadata_from_id
}
$m = new \ElggMetadata();
$m->value = $v;
$m->name = $id_or_name;
$m->entity_guid = $guid;
$m->time_created = $entity->time_created;
$m->time_updated = $entity->time_updated;
$m->owner_guid = $entity->owner_guid;
$m->id = $id_or_name;
$m->type = "attr";
break;
case 'metadata':
$m = elgg_get_metadata_from_id($id_or_name);
break;
case 'annotation':
$m = elgg_get_annotation_from_id($id_or_name);
break;
case 'relationship':
$r = get_relationship($id_or_name);
break;
case 'volatile':
$m = elgg_trigger_plugin_hook('volatile', 'metadata', array('guid' => $guid, 'varname' => $id_or_name));
break;
default:
$msg = "Sorry, I don't know how to export '" . $type . "'";
throw new \InvalidParameterException($msg);
}
// Render metadata or relationship
if (!$m && !$r) {
throw new \InvalidParameterException("Could not find any data.");
}
示例12: create
/**
* Create a new annotation.
*
* @param int $entity_guid GUID of entity to be annotated
* @param string $name Name of annotation
* @param string $value Value of annotation
* @param string $value_type Type of value (default is auto detection)
* @param int $owner_guid Owner of annotation (default is logged in user)
* @param int $access_id Access level of annotation
*
* @return int|bool id on success or false on failure
*/
function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE)
{
$result = false;
$entity_guid = (int) $entity_guid;
$value_type = detect_extender_valuetype($value, $value_type);
$owner_guid = (int) $owner_guid;
if ($owner_guid == 0) {
$owner_guid = _elgg_services()->session->getLoggedInUserGuid();
}
$access_id = (int) $access_id;
$time = time();
$value_id = elgg_get_metastring_id($value);
if (!$value_id) {
return false;
}
$name_id = elgg_get_metastring_id($name);
if (!$name_id) {
return false;
}
// @todo we don't check that the entity is loaded which means the user may
// not have access to the entity
$entity = get_entity($entity_guid);
if (_elgg_services()->events->trigger('annotate', $entity->type, $entity)) {
$result = _elgg_services()->db->insertData("INSERT INTO {$this->CONFIG->dbprefix}annotations\n\t\t\t\t(entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES\n\t\t\t\t({$entity_guid}, {$name_id}, {$value_id}, '{$value_type}', {$owner_guid}, {$time}, {$access_id})");
if ($result !== false) {
$obj = elgg_get_annotation_from_id($result);
if (_elgg_services()->events->trigger('create', 'annotation', $obj)) {
return $result;
} else {
// plugin returned false to reject annotation
elgg_delete_annotation_by_id($result);
return false;
}
}
}
return $result;
}
示例13: group_forum_delete_reply
/**
* Web service delete a reply
*
* @param string $username username
* @param string $id Annotation ID of reply
*
* @return bool
*/
function group_forum_delete_reply($id, $username)
{
$reply = elgg_get_annotation_from_id($id);
if (!$reply || $reply->name != 'group_topic_post') {
$msg = elgg_echo('discussion:reply:error:notdeleted');
throw new InvalidParameterException($msg);
}
if (!$username) {
$user = get_loggedin_user();
} else {
$user = get_user_by_username($username);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
}
if (!$reply->canEdit($user->guid)) {
$msg = elgg_echo('discussion:error:permissions');
throw new InvalidParameterException($msg);
}
$result = $reply->delete();
if ($result) {
$return['success'] = true;
$return['message'] = elgg_echo('discussion:reply:deleted');
} else {
$msg = elgg_echo('discussion:reply:error:notdeleted');
throw new InvalidParameterException($msg);
}
return $return;
}
示例14: create
/**
* Create a new annotation.
*
* @param int $entity_guid GUID of entity to be annotated
* @param string $name Name of annotation
* @param string $value Value of annotation
* @param string $value_type Type of value (default is auto detection)
* @param int $owner_guid Owner of annotation (default is logged in user)
* @param int $access_id Access level of annotation
*
* @return int|bool id on success or false on failure
*/
function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE)
{
$result = false;
$entity_guid = (int) $entity_guid;
$value_type = detect_extender_valuetype($value, $value_type);
$owner_guid = (int) $owner_guid;
if ($owner_guid == 0) {
$owner_guid = $this->session->getLoggedInUserGuid();
}
$access_id = (int) $access_id;
// @todo we don't check that the entity is loaded which means the user may
// not have access to the entity
$entity = get_entity($entity_guid);
if ($this->events->trigger('annotate', $entity->type, $entity)) {
$sql = "INSERT INTO {$this->db->prefix}annotations\n\t\t\t\t(entity_guid, name, value, value_type, owner_guid, time_created, access_id)\n\t\t\t\tVALUES\n\t\t\t\t(:entity_guid, :name, :value, :value_type, :owner_guid, :time_created, :access_id)";
$result = $this->db->insertData($sql, [':entity_guid' => $entity_guid, ':name' => $name, ':value' => $value, ':value_type' => $value_type, ':owner_guid' => $owner_guid, ':time_created' => $this->getCurrentTime()->getTimestamp(), ':access_id' => $access_id]);
if ($result !== false) {
$obj = elgg_get_annotation_from_id($result);
if ($this->events->trigger('create', 'annotation', $obj)) {
return $result;
} else {
// plugin returned false to reject annotation
elgg_delete_annotation_by_id($result);
return false;
}
}
}
return $result;
}
示例15: update
/**
* Update an annotation.
*
* @param int $annotation_id Annotation ID
* @param string $name Name of annotation
* @param string $value Value of annotation
* @param string $value_type Type of value
* @param int $owner_guid Owner of annotation
* @param int $access_id Access level of annotation
*
* @return bool
*/
function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
$annotation_id = (int) $annotation_id;
$annotation = elgg_get_annotation_from_id($annotation_id);
if (!$annotation) {
return false;
}
if (!$annotation->canEdit()) {
return false;
}
$name = trim($name);
$value_type = detect_extender_valuetype($value, $value_type);
$owner_guid = (int) $owner_guid;
if ($owner_guid == 0) {
$owner_guid = _elgg_services()->session->getLoggedInUserGuid();
}
$access_id = (int) $access_id;
$value_id = elgg_get_metastring_id($value);
if (!$value_id) {
return false;
}
$name_id = elgg_get_metastring_id($name);
if (!$name_id) {
return false;
}
$result = _elgg_services()->db->updateData("UPDATE {$this->CONFIG->dbprefix}annotations\n\t\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\t\tWHERE id = {$annotation_id}");
if ($result !== false) {
// @todo add plugin hook that sends old and new annotation information before db access
$obj = elgg_get_annotation_from_id($annotation_id);
_elgg_services()->events->trigger('update', 'annotation', $obj);
}
return $result;
}