aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-01-20 17:40:15 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-01-20 17:40:15 +0000
commitc1778720682bef79c7324cb1a1319d370a9c8d32 (patch)
treeb44469b348974dc674054ef522a29c56cde134e4
parent3507d60c147340536420e81a4f7c93e8a738bd93 (diff)
downloadelgg-c1778720682bef79c7324cb1a1319d370a9c8d32.tar.gz
elgg-c1778720682bef79c7324cb1a1319d370a9c8d32.tar.bz2
Added to and fixed the list by annotation count functions.
git-svn-id: https://code.elgg.org/elgg/trunk@2586 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/annotations.php66
1 files changed, 57 insertions, 9 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 29100d414..6136ea4b0 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -613,10 +613,11 @@
* @param $entity_type string
* @param $entity_subtype string
* @param $name string
+ * @param $limit int
* @param string $orderdir Default: asc - the sort order
* @return unknown
*/
- function __get_entities_from_annotations_calculate_x($sum = "sum", $entity_type = "", $entity_subtype = "", $name = "", $owner_guid = 0, $orderdir = 'desc')
+ function __get_entities_from_annotations_calculate_x($sum = "sum", $entity_type = "", $entity_subtype = "", $name = "", $owner_guid = 0, $limit = 10, $offset = 0, $orderdir = 'desc', $count = false)
{
global $CONFIG;
@@ -624,6 +625,8 @@
$entity_type = sanitise_string($entity_type);
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
$name = get_metastring_id($name);
+ $limit = (int) $limit;
+ $offset = (int) $offset;
$owner_guid = (int) $owner_guid;
if (empty($name)) return 0;
@@ -641,16 +644,29 @@
if ($sum != "count")
$where[] = "a.value_type='integer'"; // Limit on integer types
-
- $query = "SELECT distinct e.*, $sum(ms.string) as sum from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}annotations a on a.entity_guid = e.guid JOIN {$CONFIG->dbprefix}metastrings ms on a.value_id=ms.id WHERE ";
+
+ if (!$count) {
+ $query = "SELECT distinct e.*, $sum(ms.string) as sum ";
+ } else {
+ $query = "SELECT count(e.guid) as num, $sum(ms.string) as sum ";
+ }
+ $query .= " from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}annotations a on a.entity_guid = e.guid JOIN {$CONFIG->dbprefix}metastrings ms on a.value_id=ms.id WHERE ";
foreach ($where as $w)
$query .= " $w and ";
$query .= get_access_sql_suffix("a"); // now add access
$query .= ' and ' . get_access_sql_suffix("e"); // now add access
$query .= ' group by e.guid';
- $query .= ' order by sum ' . $orderdir;
-
- return get_data($query, "entity_row_to_elggstar");
+
+ if (!$count) {
+ $query .= ' order by sum ' . $orderdir;
+ $query .= ' limit ' . $offset . ' , ' . $limit;
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($row = get_data_row($query)) {
+ return $row->num;
+ }
+ }
+ return false;
}
/**
@@ -659,12 +675,44 @@
* @param unknown_type $entity_type
* @param unknown_type $entity_subtype
* @param unknown_type $name
- * @param unknown_type $value
* @param unknown_type $owner_guid
+ * @param int $limit
+ * @param int $offset
+ * @param true|false $count
* @return unknown
*/
- function get_entities_from_annotation_count($entity_type = "", $entity_subtype = "", $name = "", $owner_guid = 0) {
- return __get_entities_from_annotations_calculate_x('sum',$entity_type,$entity_subtype,$name,$owner_guid);
+ function get_entities_from_annotation_count($entity_type = "", $entity_subtype = "", $name = "", $owner_guid = 0, $limit = 10, $offset = 0, $count = false) {
+ return __get_entities_from_annotations_calculate_x('sum',$entity_type,$entity_subtype,$name,$owner_guid,$limit, $offset, $count);
+ }
+
+ /**
+ * Lists entities by the totals of a particular kind of annotation
+ *
+ * @param string $entity_type Type of entity.
+ * @param string $entity_subtype Subtype of entity.
+ * @param string $name Name of annotation.
+ * @param int $limit Maximum number of results to return.
+ * @param int $owner_guid Owner.
+ * @param int $group_guid Group container. Currently this is only supported if $entity_type == 'object'
+ * @param boolean $asc Whether to list in ascending or descending order (default: desc)
+ * @param boolean $fullview Whether to display the entities in full
+ * @param boolean $viewtypetoggle Determines whether or not the 'gallery' view can be displayed (default: no)
+ * @return string Formatted entity list
+ */
+ function list_entities_from_annotation_count($entity_type = "", $entity_subtype = "", $name = "", $limit = 10, $owner_guid = 0, $group_guid = 0, $asc = false, $fullview = true, $viewtypetoggle = false) {
+
+ if ($asc) {
+ $asc = "asc";
+ } else {
+ $asc = "desc";
+ }
+
+ $offset = (int) get_input("offset",0);
+ $count = get_entities_from_annotation_count($entity_type, $entity_subtype, $name, $owner_guid, $limit, $offset, true);
+ $entities = get_entities_from_annotation_count($entity_type, $entity_subtype, $name, $owner_guid, $limit, $offset, true);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle);
+
}
/**