]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #650. Replaced calls to get_annotations() by elgg_get_annotations().
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 22:39:46 +0000 (22:39 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 22:39:46 +0000 (22:39 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8182 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggEntity.php
engine/lib/annotations.php
engine/lib/views.php
engine/tests/objects/entities.php
mod/messageboard/history.php
views/default/core/likes/display.php
views/default/core/river/controls.php
views/default/core/river/footer.php

index 8a7c45648c699838f9a778e67bab046c96c6c5ea..1154fd89af616fcf2083f9c2b875798ac06069c5 100644 (file)
@@ -519,13 +519,25 @@ abstract class ElggEntity extends ElggData implements
         * @param string $name   Annotation name
         * @param int    $limit  Limit
         * @param int    $offset Offset
-        * @param string $order  asc or desc
+        * @param string $order  Order by time: asc or desc
         *
         * @return array
         */
        function getAnnotations($name, $limit = 50, $offset = 0, $order = "asc") {
                if ((int) ($this->guid) > 0) {
-                       return get_annotations($this->getGUID(), "", "", $name, "", 0, $limit, $offset, $order);
+
+                       $options = array(
+                               'guid' => $this->guid,
+                               'annotation_name' => $name,
+                               'limit' => $limit,
+                               'offset' => $offset,
+                       );
+
+                       if ($order == 'desc') {
+                               $options['order_by'] = 'n_table.time_created desc';
+                       }
+
+                       return elgg_get_annotations($options);
                } else {
                        return $this->temp_annotations[$name];
                }
index a3f8f0bb9a9de6fcbedb565b447a8b73362eccd3..a148533596f72384f814b6c315ef29abe312e481 100644 (file)
@@ -507,7 +507,10 @@ function export_annotation_plugin_hook($hook, $entity_type, $returnvalue, $param
        $guid = (int)$params['guid'];
        $name = $params['name'];
 
-       $result = get_annotations($guid);
+       $result = elgg_get_annotations(array(
+               'guid' => $guid,
+               'limit' => 0
+       ));
 
        if ($result) {
                foreach ($result as $r) {
index 21d606e013835c34ceb858b2036c1b7cf2f27d91..d1782acc2d677701b193acdfb9d596b287678b31 100644 (file)
@@ -1088,13 +1088,21 @@ function elgg_view_comments($entity, $add_comment = true) {
  */
 function elgg_view_latest_comments($owner_guid, $type = 'object', $subtype = '', $number = 4) {
        $title = elgg_echo('generic_comments:latest');
-       $comments = get_annotations(0, $type, $subtype, 'generic_comment', '', 0, $number, 0, 'desc', 0, 0, $owner_guid);
+       $options = array(
+               'annotation_name' => 'generic_comment',
+               'owner_guid' => $owner_guid,
+               'order_by' => 'n_table.time_created desc',
+               'limit' => $number
+
+       );
+       $comments = elgg_get_annotations($options);
+
        $body = elgg_view('layout/objects/list', array(
                'items' => $comments,
                'pagination' => false,
                'list_class' => 'elgg-latest-comments',
        ));
-       
+
        return elgg_view_module('aside', $title, $body);
 }
 
index 590e404d8a1f4eb7cf423cdc45e114eb61bd7f97..67dd0259628a9511c82fb2ab69b0408405bd26b6 100644 (file)
@@ -119,18 +119,18 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
                $this->assertIdentical($annotations[0]->name, 'non_existent');
                $this->assertEqual($this->entity->countAnnotations('non_existent'), 1);
 
-               $this->assertIdentical($annotations, get_annotations($this->entity->getGUID()));
-               $this->assertIdentical($annotations, get_annotations($this->entity->getGUID(), 'site'));
-               $this->assertIdentical($annotations, get_annotations($this->entity->getGUID(), 'site', 'testing'));
-               $this->assertIdentical(FALSE, get_annotations($this->entity->getGUID(), 'site', 'fail'));
+               $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID())));
+               $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site')));
+               $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site', 'subtype' => 'testing')));
+               $this->assertIdentical(FALSE, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site', 'subtype' => 'fail')));
 
                //  clear annotation
                $this->assertTrue($this->entity->clearAnnotations());
                $this->assertEqual($this->entity->countAnnotations('non_existent'), 0);
 
-               $this->assertIdentical(array(), get_annotations($this->entity->getGUID()));
-               $this->assertIdentical(array(), get_annotations($this->entity->getGUID(), 'site'));
-               $this->assertIdentical(array(), get_annotations($this->entity->getGUID(), 'site', 'testing'));
+               $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID())));
+               $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site')));
+               $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'site', 'subtype' => 'testing')));
 
                // clean up
                $this->assertTrue($this->entity->delete());
index 648e45a784976d17b2d7a776a301cdb7648614a0..3134165a8b4451da6b32e2a6d5028a712e541366 100644 (file)
@@ -14,11 +14,21 @@ require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
 $current_user = elgg_get_logged_in_user_guid();
 
 // this is the user how has posted on your messageboard that you want to display your history with
-$history_user = get_input('user'); 
+$history_user = get_input('user');
 
 $users_array = array($current_user, $history_user);
 
-$contents = get_annotations($users_array, "user", "", "messageboard", $value = "", $users_array, $limit = 10, $offset = 0, $order_by = "desc");
+$options = array(
+       'guids' => $users_array,
+       'type' => 'user',
+       'annotation_name' => 'messageboard',
+       'owner_guids' => $users_array,
+       'limit' => 10,
+       'offset' => 0,
+       'order_by' => 'n_table.time_created desc'
+);
+
+$contents = elgg_get_annotations($options);
 
 // Get the content to display
 $area2 = elgg_view_title(elgg_echo('messageboard:history:title'));
index 209b6de2d6aa6a3e6736983b36f2699e8ac1537e..a2f6b7799b683a129318393952d94b7609c7a22a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Elgg likes display 
+ * Elgg likes display
  *
  * @package Elgg
  *
@@ -25,7 +25,12 @@ if (!elgg_annotation_exists($guid, 'likes')) {
        );
        $likes_button = elgg_view('output/url', $params);
 } else {
-       $likes = get_annotations($guid, '', '', 'likes', '', elgg_get_logged_in_user_guid());
+       $options = array(
+               'guid' => $guid,
+               'annotation_name' => 'likes',
+               'owner_guid' => get_logged_in_user_guid()
+       );
+       $likes = elgg_get_annotations($options);
        $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}";
        $params = array(
                'href' => $url,
index 7c5e9458181f7efec696193414df5d5bfa6e497a..dd9de656d62db1b38df3a435492f06cc07063c32 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Controls on an river item
- * 
+ *
  *
  * @uses $vars['item']
  */
@@ -18,7 +18,7 @@ if (elgg_is_logged_in()) {
                        'internalid' => "elgg-toggler-{$object->getGUID()}",
                );
                echo elgg_view('output/url', $params);
-               
+
                // like this
                if (!elgg_annotation_exists($object->getGUID(), 'likes')) {
                        $url = "action/likes/add?guid={$object->getGUID()}";
@@ -29,7 +29,12 @@ if (elgg_is_logged_in()) {
                        );
                        echo elgg_view('output/url', $params);
                } else {
-                       $likes = get_annotations($guid, '', '', 'likes', '', elgg_get_logged_in_user_guid());
+                       $options = array(
+                               'guid' => $guid,
+                               'annotation_name' => 'likes',
+                               'owner_guid' => get_logged_in_user_guid()
+                       );
+                       $likes = elgg_get_annotations($options);
                        $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}";
                        $params = array(
                                'href' => $url,
index 1b0d14987b4b2965d7586ca715cd86fd52484be7..04f7d8daab8e0a246cc998ca27ef445f64bb8481 100644 (file)
@@ -13,8 +13,18 @@ if ($item->annotation_id != 0 || !$object) {
 
 $comment_count = count_annotations($object->getGUID(), '', '', 'generic_comment');
 
-$comments = get_annotations($object->getGUID(), "", "", 'generic_comment', "", "", 3, 0, "desc");
+$options = array(
+       'guid' => $object->getGUID(),
+       'annotation_name' => 'generic_comment',
+       'limit' => 3,
+       'order_by' => 'n_table.time_created desc'
+);
+$comments = elgg_get_annotations($options);
+
 if ($comments) {
+       // why is this reversing it? because we're asking for the 3 latest
+       // comments by sorting desc and limiting by 3, but we want to display
+       // these comments with the latest at the bottom.
        $comments = array_reverse($comments);
 
 ?>
@@ -38,6 +48,6 @@ if ($comments) {
 
 // inline comment form
 echo elgg_view_form('comments/inline', array(
-       'action' => 'action/comments/add', 
-       'internalid' => "elgg-togglee-{$object->getGUID()}", 
+       'action' => 'action/comments/add',
+       'internalid' => "elgg-togglee-{$object->getGUID()}",
 ), array('entity' => $object));