Ejemplo n.º 1
0
/**
 * Lists entities by the totals of a particular kind of annotation AND
 * the value of a piece of metadata
 *
 * @param string  $entity_type    Type of entity.
 * @param string  $entity_subtype Subtype of entity.
 * @param string  $name           Name of annotation.
 * @param string  $mdname         Metadata name
 * @param string  $mdvalue        Metadata value
 * @param int     $limit          Maximum number of results to return.
 * @param int     $owner_guid     Owner.
 * @param int     $group_guid     Group container. Currently only supported if entity_type is 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 $listtypetoggle Can the 'gallery' view can be displayed (default: no)
 * @param boolean $pagination     Display pagination
 * @param string  $orderdir       'desc' or 'asc'
 *
 * @deprecated 1.8 Use elgg_list_entities_from_annotation_calculation().
 *
 * @return string Formatted entity list
 */
function list_entities_from_annotation_count_by_metadata($entity_type = "", $entity_subtype = "", $name = "", $mdname = '', $mdvalue = '', $limit = 10, $owner_guid = 0, $group_guid = 0, $asc = false, $fullview = true, $listtypetoggle = false, $pagination = true, $orderdir = 'desc')
{
    $msg = 'list_entities_from_annotation_count_by_metadata() is deprecated by elgg_list_entities_from_annotation_calculation().';
    elgg_deprecated_notice($msg, 1.8);
    $options = array();
    $options['calculation'] = 'sum';
    if ($entity_type) {
        $options['types'] = $entity_type;
    }
    if ($entity_subtype) {
        $options['subtypes'] = $entity_subtype;
    }
    $options['annotation_names'] = $name;
    if ($mdname) {
        $options['metadata_name'] = $mdname;
    }
    if ($mdvalue) {
        $options['metadata_value'] = $mdvalue;
    }
    if ($owner_guid) {
        if (is_array($owner_guid)) {
            $options['owner_guids'] = $owner_guid;
        } else {
            $options['owner_guid'] = $owner_guid;
        }
    }
    $options['full_view'] = $fullview;
    $options['list_type_toggle'] = $listtypetoggle;
    $options['pagination'] = $pagination;
    $options['limit'] = $limit;
    $options['order_by'] = "annotation_calculation {$orderdir}";
    return elgg_get_entities_from_annotation_calculation($options);
}
 /**
  * Get a count of entities annotated with the same name => value annotation pairs
  * Irrespective of the calculation
  *
  * @covers elgg_get_entities_from_annotation_calculation()
  */
 public function testElggGetEntitiesFromAnnotationCalculationCountFromAnnotationNameValuesPairs()
 {
     $subtypes = $this->getRandomValidSubtypes(array('object'), 3);
     $value = rand(0, 9999);
     $name = 'test_annotation_egefacnv';
     $options = array('type' => 'object', 'subtypes' => $subtypes, 'limit' => 3);
     $es = elgg_get_entities($options);
     foreach ($es as $e) {
         $e->annotate($name, $value);
     }
     $options = array('type' => 'object', 'subtypes' => $subtypes, 'annotation_name' => $name, 'annotation_value' => $value, 'count' => true);
     $calculations = array('sum', 'avg', 'min', 'max');
     foreach ($calculations as $calculation) {
         $options['calculation'] = $calculation;
         $count = elgg_get_entities_from_annotation_calculation($options);
         $this->assertIdentical(3, $count);
     }
 }
Ejemplo n.º 3
0
<?php

$week_ago = time() - 60 * 60 * 24 * 7;
// Get entities that have been liked within a week
$liked_entities = elgg_get_entities_from_annotation_calculation(array('annotation_names' => 'likes', 'calculation' => 'count', 'wheres' => array("n_table.time_created > {$week_ago}")));
if ($liked_entities) {
    // Order the entities by like count
    $guids_to_entities = array();
    $guids_to_like_count = array();
    foreach ($liked_entities as $entity) {
        if ($entity->getType() != 'group') {
            $guids_to_entities[$entity->guid] = $entity;
            $guids_to_like_count[$entity->guid] = $entity->countAnnotations('likes');
        }
    }
    arsort($guids_to_like_count);
    $entities = array();
    foreach ($guids_to_like_count as $guid => $like_count) {
        $entities[] = $guids_to_entities[$guid];
    }
    // We must use a customized list view since there is no standard for list items in widget context
    $items = '';
    foreach ($entities as $entity) {
        $id = "elgg-{$entity->getType()}-{$entity->getGUID()}";
        $item = elgg_view('activity/entity', array('entity' => $entity));
        $items .= "<li id=\"{$id}\" class=\"elgg-item\">{$item}</li>";
    }
    $html = "<ul class=\"elgg-list\">{$items}</ul>";
} else {
    $text = elgg_echo('activity:module:weekly_likes:none');
    $html = "<p>{$text}</p>";
Ejemplo n.º 4
0
/**
 * Get a list of users ordered by their total score
 * 
 * @param int $time_lower
 * @param int $time_upper
 */
function get_leaderboard($time_lower = null, $time_upper = null, $limit = 10, $offset = 0)
{
    $options = array('types' => 'user', 'annotation_names' => 'gm_score', 'annotation_created_time_lower' => $time_lower, 'annotation_created_time_upper' => $time_upper, 'limit' => $limit, 'offset' => $offset);
    return elgg_get_entities_from_annotation_calculation($options);
}
 public function testElggGetEntitiesFromAnnotationsCalculateX()
 {
     $types = array('sum', 'avg', 'min', 'max');
     foreach ($types as $type) {
         $subtypes = $this->getRandomValidSubtypes(array('object'), 5);
         $name = 'test_annotation_' . rand(0, 9999);
         $values = array();
         $options = array('types' => 'object', 'subtypes' => $subtypes, 'limit' => 5);
         $es = elgg_get_entities($options);
         foreach ($es as $e) {
             $value = rand(0, 9999);
             $e->annotate($name, $value);
             $value2 = rand(0, 9999);
             $e->annotate($name, $value2);
             switch ($type) {
                 case 'sum':
                     $calc_value = $value + $value2;
                     break;
                 case 'avg':
                     $calc_value = ($value + $value2) / 2;
                     break;
                 case 'min':
                     $calc_value = min(array($value, $value2));
                     break;
                 case 'max':
                     $calc_value = max(array($value, $value2));
                     break;
             }
             $values[$e->guid] = $calc_value;
         }
         arsort($values);
         $order = array_keys($values);
         $options = array('types' => 'object', 'subtypes' => $subtypes, 'limit' => 5, 'annotation_name' => $name, 'calculation' => $type);
         $es = elgg_get_entities_from_annotation_calculation($options);
         foreach ($es as $i => $e) {
             $value = 0;
             $as = $e->getAnnotations($name);
             // should only ever be 2
             $this->assertEqual(2, count($as));
             $value = $as[0]->value;
             $value2 = $as[1]->value;
             switch ($type) {
                 case 'sum':
                     $calc_value = $value + $value2;
                     break;
                 case 'avg':
                     $calc_value = ($value + $value2) / 2;
                     break;
                 case 'min':
                     $calc_value = min(array($value, $value2));
                     break;
                 case 'max':
                     $calc_value = max(array($value, $value2));
                     break;
             }
             $this->assertEqual($e->guid, $order[$i]);
             $this->assertEqual($values[$e->guid], $calc_value);
         }
     }
 }
Ejemplo n.º 6
0
Archivo: content.php Proyecto: n8b/VMN
        $entities = elgg_get_entities_from_annotations($options);
        break;
    case "most_liked":
        // most liked in specific container
        if (in_array($widget_context, array("dashboard", "profile"))) {
            // personal
            $options["owner_guid"] = $widget->owner_guid;
        } elseif ($widget_context == "groups") {
            // group
            $options["container_guid"] = $widget->container_guid;
        }
        $entities = elgg_get_entities_from_annotation_calculation($options);
        break;
    case "recently_liked":
        // recently like in specific container
        if (in_array($widget_context, array("dashboard", "profile"))) {
            // personal
            $options["owner_guid"] = $widget->owner_guid;
        } elseif ($widget_context == "groups") {
            // group
            $options["container_guid"] = $widget->container_guid;
        }
        $entities = elgg_get_entities_from_annotation_calculation($options);
        break;
}
if ($entities) {
    $list_options = array("offset" => 0, "limit" => $limit, "full_view" => false, "pagination" => false, "list_type_toggle" => false);
    echo elgg_view_entity_list($entities, $list_options);
} else {
    echo elgg_echo("notfound");
}
 public function testElggGetEntitiesFromAnnotationCalculationCount()
 {
     // add two annotations with a unique name to an entity
     // then count the number of entities with that annotation name
     $subtypes = $this->getRandomValidSubtypes(array('object'), 1);
     $name = 'test_annotation_' . rand(0, 9999);
     $values = array();
     $options = array('type' => 'object', 'subtypes' => $subtypes, 'limit' => 1);
     $es = elgg_get_entities($options);
     $entity = $es[0];
     $value = rand(0, 9999);
     $entity->annotate($name, $value);
     $value = rand(0, 9999);
     $entity->annotate($name, $value);
     $options = array('type' => 'object', 'subtypes' => $subtypes, 'annotation_name' => $name, 'calculation' => 'count', 'count' => true);
     $count = elgg_get_entities_from_annotation_calculation($options);
     $this->assertEqual(1, $count);
 }
Ejemplo n.º 8
0
}
if (elgg_instanceof($page_owner, 'user')) {
    $owner_guid = $page_owner->guid;
    $container_guid = ELGG_ENTITIES_ANY_VALUE;
} else {
    if (elgg_instanceof($page_owner, 'group')) {
        $owner_guid = ELGG_ENTITIES_ANY_VALUE;
        $container_guid = $page_owner->guid;
    } else {
        $owner_guid = ELGG_ENTITIES_ANY_VALUE;
        $container_guid = ELGG_ENTITIES_ANY_VALUE;
    }
}
$annotation_names = elgg_stars_get_rating_annotation_names();
$entity_rating = array('types' => $widget->content_type, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'annotation_names' => $annotation_names, 'calculation' => 'avg', 'order_by' => 'annotation_calculation desc', 'limit' => $widget->num_display);
$entities = elgg_get_entities_from_annotation_calculation($entity_rating);
elgg_push_context('starrating');
foreach ($entities as $entity) {
    $title = elgg_view('output/url', array('text' => isset($entity->title) ? $entity->title : $entity->name, 'href' => $entity->getURL(), 'is_trusted' => true));
    if (!empty($entity->description)) {
        $desc = elgg_view('output/longtext', array('value' => elgg_get_excerpt($entity->description)));
    } else {
        $desc = '';
    }
    $icon = elgg_view_entity_icon($entity, 'small');
    $entity_rating = elgg_stars_get_entity_rating_values($entity, $annotation_names);
    $rating = elgg_view('output/stars', array('value' => $entity_rating['value']));
    $rating .= '<div class="elgg-stars-rating-caption">' . elgg_echo('stars:stats', array($entity_rating['value'], $entity_rating['max'], $entity_rating['count'])) . '</div>';
    $list .= '<li>' . elgg_view_image_block($icon, $title . $desc, array('image_alt' => $rating)) . '</li>';
}
elgg_pop_context();