/** * Handles voting on an entity * * @param integer $guid The entity guid being voted on * @param integer $vote The vote * @return string A status message to be returned to the client */ function elggx_fivestar_vote($guid, $vote) { $entity = get_entity($guid); $annotation_owner = elgg_get_logged_in_user_guid(); $msg = null; if ($annotation = elgg_get_annotations(array('guid' => $entity->guid, 'type' => $entity->type, 'annotation_name' => 'fivestar', 'annotation_owner_guid' => $annotation_owner, 'limit' => 1))) { if ($vote == 0 && (int) elgg_get_plugin_setting('change_cancel', 'elggx_fivestar', 1)) { if (!elgg_trigger_plugin_hook('elggx_fivestar:cancel', 'all', array('entity' => $entity), false)) { elgg_delete_annotations(array('annotation_id' => $annotation[0]->id)); $msg = elgg_echo('elggx_fivestar:deleted'); } } else { if ((int) elgg_get_plugin_setting('change_cancel', 'elggx_fivestar', 1)) { update_annotation($annotation[0]->id, 'fivestar', $vote, 'integer', $annotation_owner, 2); $msg = elgg_echo('elggx_fivestar:updated'); } else { $msg = elgg_echo('elggx_fivestar:nodups'); } } } else { if ($vote > 0) { if (!elgg_trigger_plugin_hook('elggx_fivestar:vote', 'all', array('entity' => $entity), false)) { $entity->annotate('fivestar', $vote, 2, $annotation_owner); } } else { $msg = elgg_echo('elggx_fivestar:novote'); } } elggx_fivestar_setRating($entity); return $msg; }
/** * Handles voting on an entity * * @param integer $guid The entity guid being voted on * @param integer $vote The vote * @return string A status message to be returned to the client */ function fivestar_vote($guid, $vote) { $entity = get_entity($guid); $msg = null; if ($annotation = get_annotations($entity->guid, $entity->type, $entity->subtype, 'fivestar', '', $_SESSION['user']->guid, 1)) { if ($vote == 0 && (int) get_plugin_setting('change_cancel')) { delete_annotation($annotation[0]->id); $msg = elgg_echo('fivestar:deleted'); } else { if (get_plugin_setting('change_cancel')) { update_annotation($annotation[0]->id, 'fivestar', $vote, 'integer', $_SESSION['user']->guid, 2); $msg = elgg_echo('fivestar:updated'); } else { $msg = elgg_echo('fivestar:nodups'); } } } else { if ($vote > 0) { $entity->annotate('fivestar', $vote, 2); } else { $msg = elgg_echo('fivestar:novote'); } } return $msg; }
/** * Handles voting on an entity * * @param integer $guid The entity guid being voted on * @param integer $vote The vote * @return string A status message to be returned to the client */ function elggx_fivestar_vote($guid, $vote) { $result = false; // do we have an entity if (!empty($guid) && ($entity = get_entity($guid))) { // do we have a logged in user if ($user_guid = elgg_get_logged_in_user_guid()) { $vote = sanitise_int($vote, false); $annotation_options = array("guid" => $entity->getGUID(), "type" => $entity->getType(), "annotation_name" => "fivestar", "annotation_owner_guid" => $user_guid, "limit" => 1); // already voted? if ($annotations = elgg_get_annotations($annotation_options)) { // yes // are we allowed the change/cancel our vote // 1 = yes // 0 = no $change_cancel = (int) elgg_get_plugin_setting("change_cancel", "elggx_fivestar"); // check if we want to cancel (vote = 0) if ($vote == 0 && $change_cancel) { // fire a hook to allow other plugins to halt the action $params = array("entity" => $entity, "vote" => $vote, "user_guid" => $user_guid); if (!elgg_trigger_plugin_hook("elggx_fivestar:cancel", "all", $params, false)) { // nobody stopped us, so remove the annotation $annotations[0]->delete(); // let the user know $result = elgg_echo("elggx_fivestar:deleted"); } } else { if ($change_cancel) { // we want to update update_annotation($annotations[0]->id, "fivestar", $vote, "integer", $user_guid, ACCESS_PUBLIC); $result = elgg_echo("elggx_fivestar:updated"); } else { // not allowed to update/cancel $result = elgg_echo("elggx_fivestar:nodups"); } } } elseif ($vote > 0) { // no, and wish to vote // fire a hook to allow other plugins to halt the action $params = array("entity" => $entity, "vote" => $vote, "user_guid" => $user_guid); if (!elgg_trigger_plugin_hook("elggx_fivestar:vote", "all", $params, false)) { // nobody stopped us, so save the vote $entity->annotate("fivestar", $vote, ACCESS_PUBLIC, $user_guid); } } else { // incorrect vote $result = elgg_echo("elggx_fivestar:novote"); } // update the avarage vote on the entity elggx_fivestar_set_rating($entity); } } return $result; }
/** * Save this instance * * @return int an object id */ function save() { if ($this->id > 0) { return update_annotation($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); } else { $this->id = create_annotation($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); if (!$this->id) { throw new IOException(sprintf(elgg_new('IOException:UnableToSaveNew'), get_class())); } return $this->id; } }
/** * Save this instance * * @return int an object id * * @throws IOException */ public function save() { if ($this->id > 0) { return update_annotation($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); } else { $this->id = create_annotation($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); if (!$this->id) { throw new IOException("Unable to save new " . get_class()); } return $this->id; } }
public function editAction() { $ann = new Annotation(); foreach ($_POST as $key => $value) { $ann->{$key} = $value; } $result = update_annotation($ann); if ($result["success"] == TRUE) { echo "Annotation inserted successfully"; } else { echo "Failed to insert annotation \n QUERY:{$result['sql']}"; } //echo $result; }
public function updateAnswerFromUser($event, $new_answer, $user_guid = null) { if (empty($user_guid)) { $user_guid = elgg_get_logged_in_user_guid(); } if (($old_answer = $this->getAnswerFromUser($user_guid)) && get_user($user_guid)) { if (!empty($new_answer)) { update_annotation($old_answer->id, 'answer_to_event_registration', $new_answer, '', $user_guid, $event->access_id); } else { delete_annotation($old_answer->id); } } else { $this->annotate('answer_to_event_registration', $new_answer, $event->access_id, $user_guid); } }
/** * Update the last view time for this entity to the current time * * @param $entity_guid * @param $user_guid */ function update_last_view_time($entity_guid, $user_guid) { $entity = get_entity($entity_guid); if (!($user = get_entity($user_guid))) { $user = elgg_get_logged_in_user_entity(); } if ($entity && $user) { // Get the last view annotation that has the last view time saved $options = array('types' => array($entity->type), 'guids' => array($entity_guid), 'annotation_owner_guids' => array($user->guid), 'annotation_names' => array('last_view_time')); if ($entity->getSubtype()) { $options['subtypes'] = array($entity->getSubtype()); } $last_view_time = elgg_get_annotations($options); // It should exists only one annotation that has the last view time $last_view_time = $last_view_time[0]; if ($last_view_time) { // Update the value of last view time with the current time return update_annotation($last_view_time->id, 'last_view_time', time(), 'integer', $user->guid, 2); } else { // Create one annotation with the current time that means the last view time return create_annotation($entity->guid, 'last_view_time', time(), 'integer', $user->guid, 2); } } }
<?php /** * Profile Counter - enables tracking * * @package profile_counter * @author ColdTrick IT Solutions * @copyright Coldtrick IT Solutions 2009 * @link http://www.coldtrick.com/ */ $page_owner = page_owner_entity(); $current_count = $page_owner->getAnnotations("profilecount"); if (!$current_count) { $page_owner->annotate('profilecount', 1, 2); } else { $updateable = true; if (isloggedin()) { if (get_loggedin_user()->getGUID() == $page_owner->getGUID()) { // dont count own profile visits $updateable = false; } } if ($updateable) { update_annotation($current_count[0]->id, "profilecount", $current_count[0]->value + 1, $current_count[0]->value_type, $current_count[0]->owner_guid, $current_count[0]->access_id); } }
forward(); } // Check the user is a dgroup member $dgroup_guid = get_input('dgroup'); $dgroup_entity = get_entity($dgroup_guid); if (!$dgroup_entity->isMember($vars['user'])) { forward(); } //get the required variables $post = get_input("post"); $field_num = get_input("field_num"); $post_comment = get_input("postComment{$field_num}"); $annotation = get_annotation($post); $commentOwner = $annotation->owner_guid; $access_id = $annotation->access_id; $topic = get_input("topic"); if ($annotation) { //can edit? Either the comment owner or admin can if (dgroups_can_edit_discussion($annotation, page_owner_entity()->owner_guid)) { update_annotation($post, "dgroup_topic_post", $post_comment, "", $commentOwner, $access_id); system_message(elgg_echo("dgroups:forumpost:edited")); } else { system_message(elgg_echo("dgroups:forumpost:error")); } } else { system_message(elgg_echo("dgroups:forumpost:error")); } // Forward to the dgroup forum page global $CONFIG; $url = $CONFIG->wwwroot . "mod/dgroups/topicposts.php?topic={$topic}&dgroup_guid={$dgroup_guid}/"; forward($url);
// Otherwise, save the forum } else { $topic->access_id = $access; // Set its title $topic->title = $title; // if no tags are present, clear existing ones if (is_array($tagarray)) { $topic->tags = $tagarray; } else { $topic->clearMetadata('tags'); } // edit metadata $topic->status = $status; // the current status i.e sticky, closed, resolved // now let's edit the message annotation update_annotation($message_id, "dgroup_topic_post", $message, "", $user, $access); // save the changes if (!$topic->save()) { // register_error(elgg_echo("forumtopic:error")); } // Success message system_message(elgg_echo("dgroups:forumtopic:edited")); } } } // Forward to the dgroup forum page global $CONFIG; $url = $CONFIG->wwwroot . "pg/dgroups/forum/{$dgroup_guid}/"; forward($url); ?>
<?php $vote = get_input('vote'); $guid = get_input('guid'); $comment = get_input('vote_comment'); $entity = get_entity($guid); $user = elgg_get_logged_in_user_entity(); if (!$entity->canAnnotate(0, 'votes')) { register_error(elgg_echo('proposals:votes:cannot')); forward(REFERER); } if ($vote == 'block' && $comment == '') { register_error(elgg_echo('proposals:votes:mandatoryfield')); forward(REFERER); } $options = array('guid' => (int) $guid, 'annotation_name' => 'votes', 'annotation_owner_guid' => $user->guid); $annotations = elgg_get_annotations($options); if ($comment) { $comment = create_annotation($guid, 'vote_comments', $comment, "", $user->guid, $entity->access_id); } if (is_array($annotations) && count($annotations)) { $annotation = $annotations[0]; $id = $annotation->id; update_annotation($id, 'votes', $vote, "", $user->guid, $entity->access_id); system_message(elgg_echo("proposals:vote:update", array($vote))); } else { $annotation = create_annotation($guid, 'votes', $vote, "", $user->guid, $entity->access_id); system_message(elgg_echo("proposals:vote:create", array($vote))); } forward(REFERER);
<?php //get the required variables $annotation_id = get_input("annotation_id"); $post_comment = get_input("postComment"); $annotation = get_annotation($annotation_id); $commentOwner = $annotation->owner_guid; $access_id = $annotation->access_id; if ($annotation && $annotation->canEdit()) { //can edit? Either the comment owner or admin can $result = update_annotation($annotation_id, "generic_comment", $post_comment, "", $commentOwner, $access_id); if ($result) { system_message(elgg_echo("comment:edited")); forward($annotation->getEntity()->getURL()); } } else { system_message(elgg_echo("comment:error")); } forward(REFERER);
/** * {@inheritdoc} */ public function handle(\ElggEntity $entity) { $shortname = $this->getShortname(); $current_annotations = elgg_get_annotations(array('guids' => (int) $entity->guid, 'annotation_names' => $shortname)); if (is_array($current_annotations) && count($current_annotations)) { foreach ($current_annotations as $ann) { $current_annotations_ids[] = $ann->id; } } if (!is_array($current_annotations_ids)) { $current_annotations_ids = array(); } $future_annotations = get_input($this->getShortname(), array()); $params = array('field' => $this, 'entity' => $entity, 'annotation_name' => $shortname, 'value' => $current_annotations, 'future_value' => $future_annotations); // Allow plugins to prevent annotation from being changed if (!elgg_trigger_plugin_hook('handle:annotation:before', 'prototyper', $params, true)) { return $entity; } $future_annotations_ids = elgg_extract('id', $future_annotations, array()); $to_delete = array_diff($current_annotations_ids, $future_annotations_ids); foreach ($to_delete as $id) { elgg_delete_annotation_by_id($id); } $keys = array_keys(elgg_extract('name', $future_annotations, array())); $ids = array(); foreach ($keys as $i) { $id = $future_annotations['id'][$i]; $name = $future_annotations['name'][$i]; $value = $future_annotations['value'][$i]; if ($this->getValueType() == 'tags') { $value = string_to_tag_array($value); } $access_id = $future_annotations['access_id'][$i]; $owner_guid = $future_annotations['owner_guid'][$i]; if (!is_array($value)) { if ($id) { update_annotation($id, $name, $value, '', $owner_guid, $access_id); } else { $id = create_annotation($entity->guid, $name, $value, '', $owner_guid, $access_id); } $ids[] = $id; } else { if ($id) { elgg_delete_annotation_by_id($id); } foreach ($value as $val) { $ids[] = create_annotation($entity->guid, $name, $val, '', $owner_guid, $access_id); } } } $params = array('field' => $this, 'entity' => $entity, 'annotation_name' => $shortname, 'value' => count($ids) ? elgg_get_annotations(array('annotation_ids' => $ids)) : array(), 'previous_value' => $current_annotations); elgg_trigger_plugin_hook('handle:annotation:after', 'prototyper', $params, true); return $entity; }