diff options
author | Greg Froese <greg.froese@gmail.com> | 2009-05-16 00:16:40 +0000 |
---|---|---|
committer | Greg Froese <greg.froese@gmail.com> | 2009-05-16 00:16:40 +0000 |
commit | af26a60db00294af093bf8e385d3e628de1c47d2 (patch) | |
tree | ee5c659b777a01ea178939065523892e8afaa991 /mostviewedimages.php | |
parent | 711c6040d3a5e3b479a1326c5afc6c3a689c8ad5 (diff) | |
download | elgg-af26a60db00294af093bf8e385d3e628de1c47d2.tar.gz elgg-af26a60db00294af093bf8e385d3e628de1c47d2.tar.bz2 |
counting now using annotations
Diffstat (limited to 'mostviewedimages.php')
-rw-r--r-- | mostviewedimages.php | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/mostviewedimages.php b/mostviewedimages.php index 8831dc33e..5bbbcf5e7 100644 --- a/mostviewedimages.php +++ b/mostviewedimages.php @@ -12,18 +12,26 @@ global $CONFIG; $prefix = $CONFIG->dbprefix; $max = 24; - //grab the top views (metadata 'tp_views') for $max number of entities - //ignores entity subtypes - $sql = "select md.entity_guid, md.owner_guid, md.enabled, ms.string as views from " . $prefix . "metadata md - inner join " . $prefix . "metastrings ms on md.value_id = ms.id - inner join " . $prefix . "metastrings ms2 on md.name_id = ms2.id and ms2.string = 'tp_views' - order by (views+0) desc LIMIT $max"; + + //this works but is wildly inefficient + //$annotations = get_annotations(0, "object", "image", "tp_view", "", "", 5000); + + $sql = "SELECT ent.guid, count( * ) AS views + FROM `my_elggentities` ent + INNER JOIN " . $prefix . "entity_subtypes sub ON ent.subtype = sub.id + AND sub.subtype = 'image' + INNER JOIN " . $prefix . "annotations ann1 ON ann1.entity_guid = ent.guid + INNER JOIN " . $prefix . "metastrings ms ON ms.id = ann1.name_id + AND ms.string = 'tp_view' + GROUP BY ent.guid + ORDER BY views DESC + LIMIT $max"; $result = get_data($sql); $entities = array(); foreach($result as $entity) { - $entities[] = get_entity($entity->entity_guid); + $entities[] = get_entity($entity->guid); } $title = "Most viewed images"; |