]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
moved the count comments and likes functions into the ElggEntity class
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 6 Feb 2011 19:56:06 +0000 (19:56 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 6 Feb 2011 19:56:06 +0000 (19:56 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8047 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggEntity.php
engine/lib/elgglib.php
engine/lib/views.php
mod/blog/views/default/object/blog.php
mod/file/views/default/object/file.php
mod/groups/views/default/object/groupforumtopic.php
mod/pages/views/default/object/page_top.php
views/default/core/likes/display.php

index 5e43ab5824ecd84093cf4bdf8db288468add238f..13b08a122eae5bc3397a9e2428afb91b29c1d833 100644 (file)
@@ -592,6 +592,40 @@ abstract class ElggEntity extends ElggData implements
                return get_annotations_max($this->getGUID(), "", "", $name);
        }
 
+       /**
+        * Count the number of comments attached to this entity.
+        *
+        * @return int Number of comments
+        * @since 1.8.0
+        */
+       function countComments() {
+               $type = $this->getType();
+               $params = array('entity' => $this);
+               $number = elgg_trigger_plugin_hook('comments:count', $type, $params, false);
+               if ($number) {
+                       return $number;
+               } else {
+                       return count_annotations($this->getGUID(), "", "", "generic_comment");
+               }
+       }
+
+       /**
+        * Count how many people have liked this entity.
+        *
+        * @return int Number of likes
+        * @since 1.8.0
+        */
+       function countLikes() {
+               $type = $this->getType();
+               $params = array('entity' => $this);
+               $number = elgg_trigger_plugin_hook('likes:count', $type, $params, false);
+               if ($number) {
+                       return $number;
+               } else {
+                       return count_annotations($this->getGUID(), "", "", "likes");
+               }
+       }
+
        /**
         * Gets an array of entities with a relationship to this entity.
         *
@@ -887,8 +921,11 @@ abstract class ElggEntity extends ElggData implements
         * @param string $size The size its for.
         *
         * @return bool
+        * @deprecated 1.8 See getIconURL() for the plugin hook to use
         */
        public function setIcon($url, $size = 'medium') {
+               elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
+
                $url = sanitise_string($url);
                $size = sanitise_string($size);
 
index 3e8b9d43d4fa61df55b8f1e977ab1babff18c170..66477785e22b5e92fc91196f157785714cf6a526 100644 (file)
@@ -333,59 +333,6 @@ function elgg_get_external_file($type, $location) {
        return array();
 }
 
-/**
- * Returns the HTML for "likes" and "like this" on entities.
- *
- * @param ElggEntity $entity The entity to like
- *
- * @return string|false The HTML for the likes, or false on failure
- *
- * @since 1.8
- * @see @elgg_view core/likes/display
- */
-function elgg_view_likes($entity) {
-       if (!($entity instanceof ElggEntity)) {
-               return false;
-       }
-
-       $params = array('entity' => $entity);
-
-       return elgg_view('core/likes/display', $params);
-}
-
-/**
- * Count the number of likes attached to an entity
- *
- * @param ElggEntity $entity The entity to count likes for
- *
- * @return int Number of likes
- * @since 1.8
- */
-function elgg_count_likes($entity) {
-       if ($likeno = elgg_trigger_plugin_hook('likes:count', $entity->getType(),
-               array('entity' => $entity), false)) {
-               return $likeno;
-       } else {
-               return count_annotations($entity->getGUID(), "", "", "likes");
-       }
-}
-
-/**
- * Count the number of comments attached to an entity
- *
- * @param ElggEntity $entity The entity to count comments for
- *
- * @return int Number of comments
- */
-function elgg_count_comments($entity) {
-       if ($commentno = elgg_trigger_plugin_hook('comments:count', $entity->getType(),
-               array('entity' => $entity), false)) {
-               return $commentno;
-       } else {
-               return count_annotations($entity->getGUID(), "", "", "generic_comment");
-       }
-}
-
 /**
  * Returns a list of files in $directory.
  *
index 72cfeb2b6640f3c0c8ec0e323e7c0436f217fcb6..d76456d831acd09fc44d7c5bea40b7421a1e001a 100644 (file)
@@ -1098,6 +1098,27 @@ function elgg_view_latest_comments($owner_guid, $type = 'object', $subtype = '',
        );
        return elgg_view('layout/objects/module', $params);
 }
+
+/**
+ * Returns the HTML for "likes" on entities.
+ *
+ * @param ElggEntity $entity The entity to like
+ *
+ * @return string|false The HTML for the likes, or false on failure
+ *
+ * @since 1.8.0
+ * @see @elgg_view core/likes/display
+ */
+function elgg_view_likes($entity) {
+       if (!($entity instanceof ElggEntity)) {
+               return false;
+       }
+
+       $params = array('entity' => $entity);
+
+       return elgg_view('core/likes/display', $params);
+}
+
 /**
  * Wrapper function for the image block display pattern.
  *
index 3c5003310095b30662450d6960753c81fd872a45..78470d6be2838d3b510dade0be747c13301812f4 100644 (file)
@@ -28,7 +28,7 @@ $date = elgg_view_friendly_time($blog->publish_date);
 
 // The "on" status changes for comments, so best to check for !Off
 if ($blog->comments_on != 'Off') {
-       $comments_count = elgg_count_comments($blog);
+       $comments_count = $blog->countComments();
        //only display if there are commments
        if ($comments_count != 0) {
                $text = elgg_echo("comments") . " ($comments_count)";
index 89367feb30e6244b782de363a12c829156fa5298..5fcd2a023f934cda6c363a30715c7f4943a57287 100644 (file)
@@ -37,7 +37,7 @@ $file_icon = elgg_view('file/icon', array(
 $tags = elgg_view('output/tags', array('tags' => $file->tags));
 $date = elgg_view_friendly_time($file->time_created);
 
-$comments_count = elgg_count_comments($file);
+$comments_count = $file->countComments();
 //only display if there are commments
 if ($comments_count != 0) {
        $text = elgg_echo("comments") . " ($comments_count)";
index c6f9da4b40f386387d1fc0ee95796836d9a5e459..6d4902c87d7f03dfee7f9fcbfdca96fdd365815b 100644 (file)
@@ -28,7 +28,7 @@ $date = elgg_view_friendly_time($topic->time_created);
 
 $comments_link = '';
 $comments_text = '';
-$num_comments = elgg_count_comments($topic);
+$num_comments = $topic->countComments();
 if ($num_comments != 0) {
        $last_comment = $topic->getAnnotations("generic_comment", 1, 0, "desc");
        $commenter = $last_comment[0]->getOwnerEntity();
index 9770dce238ba818328e6d3c584ccb3bc02194b2a..89ef255729a6c31a161602bdd36059c24ba44483 100644 (file)
@@ -39,7 +39,7 @@ $date = elgg_view_friendly_time($annotation->time_created);
 $editor_text = elgg_echo('pages:strapline', array($date, $editor_link));
 $tags = elgg_view('output/tags', array('tags' => $page->tags));
 
-$comments_count = elgg_count_comments($page);
+$comments_count = $page->countComments();
 //only display if there are commments
 if ($comments_count != 0 && !$revision) {
        $text = elgg_echo("comments") . " ($comments_count)";
index 6804868633a51a321ccb3458b1b077e21eea06c4..5b59c7215204bd7c854913047ad06e1e06411288 100644 (file)
@@ -38,7 +38,7 @@ if (!elgg_annotation_exists($guid, 'likes')) {
 }
 
 $list = '';
-$num_of_likes = elgg_count_likes($vars['entity']);
+$num_of_likes = $vars['entity']->countLikes();
 if ($num_of_likes) {
        // display the number of likes
        if ($num_of_likes == 1) {