Exemplo n.º 1
0
/**
 * Gets the number of entities by a the number of entities related to them in a particular way.
 * This is a good way to get out the users with the most friends, or the groups with the
 * most members.
 *
 * @deprecated 1.8 Use elgg_get_entities_from_relationship_count()
 *
 * @param string $relationship         The relationship eg "friends_of"
 * @param bool   $inverse_relationship Inverse relationship owners
 * @param string $type                 The type of entity (default: all)
 * @param string $subtype              The entity subtype (default: all)
 * @param int    $owner_guid           The owner of the entities (default: none)
 * @param int    $limit                Limit
 * @param int    $offset               Offset
 * @param bool   $count                Return a count instead of entities
 * @param int    $site_guid            Site GUID
 *
 * @return array|int|false An array of entities, or the number of entities, or false on failure
 */
function get_entities_by_relationship_count($relationship, $inverse_relationship = true, $type = "", $subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $count = false, $site_guid = 0)
{
    elgg_deprecated_notice('get_entities_by_relationship_count() is deprecated by elgg_get_entities_from_relationship_count()', 1.8);
    $options = array();
    $options['relationship'] = $relationship;
    // this used to default to true, which is wrong.
    // flip it for the new function
    $options['inverse_relationship'] = !$inverse_relationship;
    if ($type) {
        $options['types'] = $type;
    }
    if ($subtype) {
        $options['subtypes'] = $subtype;
    }
    if ($owner_guid) {
        $options['owner_guid'] = $owner_guid;
    }
    $options['limit'] = $limit;
    if ($offset) {
        $options['offset'] = $offset;
    }
    if ($site_guid) {
        $options['site_guid'];
    }
    if ($count) {
        $options['count'] = $count;
    }
    return elgg_get_entities_from_relationship_count($options);
}
 echo '<ul class="category-top">';
 $group_entity = $vars['entity'];
 $owner = $group->getOwnerEntity();
 $group_owner_title .= elgg_echo("groups:owner");
 $group_owner .= '<br>';
 $group_owner .= elgg_view('output/url', array('text' => $owner->name, 'value' => $owner->getURL(), 'is_trusted' => true));
 echo "<li class='elgg-menu-item-blog'>{$group_owner_title} : {$group_owner} </li>";
 // insert site-wide navigation
 // echo elgg_view_menu('site');
 /*  
  	$num_members = $group_entity->getMembers(array('count' => true));
   echo elgg_echo('groups:members') . ": " . $num_members;
 */
 $groups_yours_menu .= elgg_echo('groups:yours');
 $groups_yours_menu .= ' (';
 $groups_yours_menu .= elgg_get_entities_from_relationship_count(array('type' => 'group', 'relationship' => 'member', 'relationship_guid' => elgg_get_page_owner_guid(), 'full_view' => false, 'view_toggle_type' => false, 'count' => true));
 $groups_yours_menu .= ')';
 echo "<li class='elgg-menu-item-blog'> {$groups_yours_menu} </li>";
 $groups_friends_menu .= '<br>';
 $groups_friends_menu .= elgg_echo('friends');
 $groups_friends_menu .= ' (';
 $groups_friends_menu .= elgg_get_entities_from_relationship(array('relationship' => 'friend', 'relationship_guid' => elgg_get_page_owner_guid(), 'types' => 'user', 'count' => true));
 $groups_friends_menu .= ')';
 echo "<li class='elgg-menu-item-blog'>{$content_friends_menu}</li>";
 $groups_friends_of_menu .= '<br>';
 $groups_friends_of_menu .= elgg_echo('friends:of');
 $groups_friends_of_menu .= ' (';
 $groupst_friends_of_menu .= elgg_get_entities_from_relationship(array('relationship' => 'friend', 'relationship_guid' => elgg_get_page_owner_guid(), 'inverse_relationship' => TRUE, 'types' => 'user', 'count' => true));
 $groups_friends_of_menu .= ')';
 echo "<li class='elgg-menu-item-blog'>{$groups_friends_of_menu}</li>";
 $group_timecreated_menu .= elgg_echo('usersettings:statistics:label:membersince');
 public function testElggGetEntitiesFromRelationshipCount()
 {
     $entities = $this->entities;
     $relationships = array();
     $count = count($entities);
     $max = $count - 1;
     $relationship_name = 'test_relationship_' . rand(0, 1000);
     for ($i = 0; $i < $count; $i++) {
         do {
             $popular_entity = $entities[array_rand($entities)];
         } while (array_key_exists($popular_entity->guid, $relationships));
         $relationships[$popular_entity->guid] = array();
         for ($c = 0; $c < $max; $c++) {
             do {
                 $fan_entity = $entities[array_rand($entities)];
             } while ($fan_entity->guid == $popular_entity->guid || in_array($fan_entity->guid, $relationships[$popular_entity->guid]));
             $relationships[$popular_entity->guid][] = $fan_entity->guid;
             add_entity_relationship($fan_entity->guid, $relationship_name, $popular_entity->guid);
         }
         $max--;
     }
     $options = array('relationship' => $relationship_name, 'limit' => $count);
     $entities = elgg_get_entities_from_relationship_count($options);
     foreach ($entities as $e) {
         $options = array('relationship' => $relationship_name, 'limit' => 100, 'relationship_guid' => $e->guid, 'inverse_relationship' => true);
         $fan_entities = elgg_get_entities_from_relationship($options);
         $this->assertEqual(count($fan_entities), count($relationships[$e->guid]));
         foreach ($fan_entities as $fan_entity) {
             $this->assertTrue(in_array($fan_entity->guid, $relationships[$e->guid]));
             $this->assertNotIdentical(false, check_entity_relationship($fan_entity->guid, $relationship_name, $e->guid));
         }
     }
 }
Exemplo n.º 4
0
         $meta_description = substr($clear, 0, 200);
         $meta_description = str_replace(array("\r", "\n"), '', $meta_description);
         $title = $title . " from " . $user->name . " - " . $user->location;
     } else {
         $meta_description = "Bookmarks on " . $site_name . " You can use this to share interesting links with other people or friends or just for yourself";
         $title = $title . " - " . $site_name . " - Bookmarks";
     }
     break;
 case 'members':
     switch ($title) {
         case 'Popular Members':
             $options['relationship'] = 'friend';
             $options['inverse_relationship'] = false;
             $options['offset'] = $offset;
             $options['limit'] = 10;
             $users = elgg_get_entities_from_relationship_count($options);
             $meta_description = "Positions " . $offset . " - " . (10 + $offset) . ": ";
             foreach ($users as $u) {
                 $u->name = str_replace(',', "", $u->name);
                 $meta_description = $meta_description . "" . $u->name . ", ";
             }
             $title = $title . " - " . $site_name . " - Social Network";
             break;
     }
     break;
 case 'profile':
     switch ($user) {
         case empty($user->name):
             $meta_description = $title . " - " . elgg_get_plugin_setting("mainpage_description", "metatags");
             $title = $title . " - " . elgg_get_plugin_setting("mainpage_title", "metatags");
             break;