From af26a60db00294af093bf8e385d3e628de1c47d2 Mon Sep 17 00:00:00 2001 From: Greg Froese Date: Sat, 16 May 2009 00:16:40 +0000 Subject: counting now using annotations --- friendmostviewed.php | 13 +++++++++++++ mostrecentimages.php | 4 ++++ mostviewedimages.php | 22 +++++++++++++++------- viewimage.php | 20 +------------------- views/default/object/image.php | 31 ++++++++++++++++++++++++++++--- yourmostviewed.php | 24 ++++++++++++++---------- 6 files changed, 75 insertions(+), 39 deletions(-) diff --git a/friendmostviewed.php b/friendmostviewed.php index a196f51af..4f832b228 100644 --- a/friendmostviewed.php +++ b/friendmostviewed.php @@ -40,6 +40,19 @@ WHERE ent.owner_guid = " . $user->guid . " ORDER BY (views+0) DESC LIMIT $max"; + + $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' + WHERE ann1.owner_guid = " . $user->guid . " + GROUP BY ent.guid + ORDER BY views DESC + LIMIT $max"; + $result = get_data($sql); $entities = array(); diff --git a/mostrecentimages.php b/mostrecentimages.php index 53d8ef236..e42cea4ae 100644 --- a/mostrecentimages.php +++ b/mostrecentimages.php @@ -8,14 +8,18 @@ // Load Elgg engine include_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + include_once(dirname(__FILE__) . "/notice.php"); $max = 8; $images = list_entities("object", "image", 0, $max, false, false, true); $title = "Most recent images"; $area2 = elgg_view_title($title); + $notice = tp_notice(); + $area2 .= $notice->text; $area2 .= $images; $body = elgg_view_layout('two_column_left_sidebar', '', $area2); page_draw($title, $body); + if($notice->showMessage == true) system_message($notice->text); ?> \ No newline at end of file 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"; diff --git a/viewimage.php b/viewimage.php index 8534e3d30..3a0d42b5d 100644 --- a/viewimage.php +++ b/viewimage.php @@ -31,23 +31,6 @@ $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username); } - $views = get_metadata_byname($photo_guid, "tp_views"); - if(!$views || intval($views["value"] == 0)) $views["value"] = 0; - $views["value"] = $views["value"] + 1; //TODO: only add views for non-owner - create_metadata($photo_guid, "tp_views", $views["value"], "integer", 0, 2); - - $viewer = get_loggedin_user(); - - /* - $metadatas = get_metadata_for_entity($photo_guid); - $rating = 0; - foreach($metadatas as $metadata) { - if($metadata["owner_guid"] == $viewer["guid"]) { - if($metadata["name"] == "rating") $rating = $metadata["value"]; - } - } - */ - if (can_write_to_container(0, $album->container_guid)) { add_submenu_item( elgg_echo('image:edit'), $CONFIG->wwwroot . 'pg/photos/edit/' . $photo_guid, @@ -59,10 +42,9 @@ } - $title = $photo->title . " - views: $views[value]"; + $title = $photo->title; $area2 = elgg_view_title($title); $area2 .= elgg_view_entity($photo, true); -// $area2 .= "Rate *"; $body = elgg_view_layout('two_column_left_sidebar', '', $area2); diff --git a/views/default/object/image.php b/views/default/object/image.php index 09a121256..13a94fc7d 100644 --- a/views/default/object/image.php +++ b/views/default/object/image.php @@ -88,7 +88,26 @@ if ($photo_tags) { // //////////////////////////////////////////////////////// - + // Get view information + + $viewer = get_loggedin_user(); + + //who is viewing? + if($viewer->guid) { + $the_viewer = $viewer->guid; + } else { + $the_viewer = 0; + } + + create_annotation($file_guid, "tp_view", "1", "integer", $the_viewer, 2); + $views_a = get_annotations($file_guid, "object", "image", "tp_view"); + $views = count($views_a); + + $my_views = 0; + foreach($views_a as $view) { + if($view->owner_guid == $the_viewer && $the_viewer != 0) $my_views++; + } + // Build back and next links $back = ''; @@ -123,17 +142,19 @@ if ($photo_tags) {
- $album,) ); ?> + $album,) ); ?>
+ Views:
- +
'; ?> +
@@ -159,7 +180,11 @@ if ($photo_tags) {
$tags));?>
+
+ $vars['entity'])); ?> +
name; ?>
diff --git a/yourmostviewed.php b/yourmostviewed.php index f9a1af88a..84cc2ca10 100644 --- a/yourmostviewed.php +++ b/yourmostviewed.php @@ -13,20 +13,24 @@ 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 . "entities ent - INNER JOIN " . $prefix . "metadata md ON md.entity_guid = ent.guid - 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' - WHERE ent.owner_guid = " . $viewer->guid . " - ORDER BY (views+0) DESC LIMIT $max"; - + + $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' + WHERE ann1.owner_guid = " . $viewer->guid . " + 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 = elgg_echo("tidypics:yourmostviewed"); -- cgit v1.2.3