]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Cleaned up the likes interface a bit.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 25 Mar 2010 21:39:17 +0000 (21:39 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 25 Mar 2010 21:39:17 +0000 (21:39 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@5508 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/annotations.php
engine/lib/elgglib.php

index f1cec6cc9dd66345692d281574914c22983ac0a0..c545682d538a756bc46071084bbd322d58672c30 100644 (file)
@@ -1178,7 +1178,7 @@ function clear_annotations($guid, $name = "") {
                        return delete_data($query);
                }
        }
-       
+
        return FALSE;
 }
 
@@ -1253,25 +1253,32 @@ function get_annotation_url($id) {
 /**
  * Check to see if a user has already created an annotation on an object
  *
- * @param ElggEntity $entity
+ * @param int $entity_guid
+ * @param string $annotation_type
+ * @param int $owner_guid Defaults to logged in user.
+ *
  * @return true | false
  */
-function elgg_already_created_annotation($entity_guid, $annotation_type) {
+function elgg_annotation_exists($entity_guid, $annotation_type, $owner_guid = NULL) {
        global $CONFIG;
+
+       if (!$owner_guid && !($owner_guid = get_loggedin_userid())) {
+               return FALSE;
+       }
+
        $entity_guid = (int)$entity_guid;
        $annotation_type = sanitise_string($annotation_type);
-       $owner_guid = get_loggedin_userid();
+
        $sql = "select a.id" .
-                       " FROM {$CONFIG->dbprefix}annotations a, {$CONFIG->dbprefix}metastrings m " .
-                       " WHERE a.owner_guid={$owner_guid} AND a.entity_guid={$entity_guid} " . 
-                       " AND a.name_id=m.id AND m.string='{$annotation_type}'";
-       //get the annotation type id
-       $check_annotation = get_data_row($sql);
-       //check to see if the user has already liked
-       if($check_annotation)
-               return true;
-       else
-               return false;
+                       " FROM {$CONFIG->dbprefix}annotations a, {$CONFIG->dbprefix}metastrings m " .
+                       " WHERE a.owner_guid={$owner_guid} AND a.entity_guid={$entity_guid} " .
+                       " AND a.name_id=m.id AND m.string='{$annotation_type}'";
+
+       if ($check_annotation = get_data_row($sql)) {
+               return TRUE;
+       }
+
+       return FALSE;
 }
 
 /**
index e33fdab6f346d3b252c844bf86d0b1f2df578a8e..04e04fbbc50637a30d581ad97e33fd55138b6d72 100644 (file)
@@ -1012,11 +1012,11 @@ function elgg_view_likes($entity){
        if (!($entity instanceof ElggEntity)) {
                return false;
        }
-       if ($likes = trigger_plugin_hook('likes',$entity->getType(),array('entity' => $entity),false)) {
+       if ($likes = trigger_plugin_hook('likes', $entity->getType(), array('entity' => $entity), false)) {
                return $likes;
        } else {
                //display the form
-               $likes = elgg_view('likes/forms/edit',array('entity' => $entity));
+               $likes = elgg_view('likes/forms/edit', array('entity' => $entity));
                return $likes;
        }
 }