Пример #1
0
/**
 * Lists entities
 *
 * @see elgg_view_entity_list
 * 
 * @param string $entity_type Type of entity.
 * @param string $entity_subtype Subtype of entity.
 * @param string $name Name of annotation.
 * @param string $value Value 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_annotations($entity_type = "", $entity_subtype = "", $name = "", $value = "", $limit = 10, $owner_guid = 0, $group_guid = 0, $asc = false, $fullview = true, $viewtypetoggle = false)
{
    if ($asc) {
        $asc = "asc";
    } else {
        $asc = "desc";
    }
    $count = get_entities_from_annotations($entity_type, $entity_subtype, $name, $value, $owner_guid, $group_guid, null, null, $asc, true);
    $offset = (int) get_input("offset", 0);
    $entities = get_entities_from_annotations($entity_type, $entity_subtype, $name, $value, $owner_guid, $group_guid, $limit, $offset, $asc);
    return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle);
}
<?php

// Latest forum discussion for the group home page
//check to make sure this group forum has been activated
if ($vars['entity']->forum_enable != 'no') {
    ?>

<div class="contentWrapper">
<h2><?php 
    echo elgg_echo('groups:latestdiscussion');
    ?>
</h2>
<?php 
    $forum = get_entities_from_annotations("object", "groupforumtopic", "group_topic_post", "", 0, $vars['entity']->guid, 4, 0, "desc", false);
    if ($forum) {
        foreach ($forum as $f) {
            $count_annotations = $f->countAnnotations("group_topic_post");
            echo "<div class=\"forum_latest\">";
            echo "<div class=\"topic_owner_icon\">" . elgg_view('profile/icon', array('entity' => $f->getOwnerEntity(), 'size' => 'tiny', 'override' => true)) . "</div>";
            echo "<div class=\"topic_title\"><p><a href=\"{$vars['url']}mod/groups/topicposts.php?topic={$f->guid}&group_guid={$vars['entity']->guid}\">" . $f->title . "</a></p> <p class=\"topic_replies\"><small>" . elgg_echo('groups:posts') . ": " . $count_annotations . "</small></p></div>";
            echo "</div>";
        }
    } else {
        echo "<div class=\"forum_latest\">";
        echo elgg_echo("grouptopic:notcreated");
        echo "</div>";
    }
    ?>
<div class="clearfloat" /></div>
</div>
<?php 
$form = $vars['form'];
$form_view = $vars['form_view'];
$username = $vars['username'];
if ($username) {
    $user = get_user_by_username($username);
} else {
    $user = get_loggedin_user();
}
$form_id = $form->getGUID();
$offset = (int) get_input('offset', 0);
$limit = 10;
$entities = array();
if ($form_view == 'recommendations') {
    // get all the form data with recommendations, sorted with the most recommended at the top
    // TODO: replace with more efficient SQL
    $all_entities = get_entities_from_annotations("object", "form_data", "form:recommendation", "", 0, 0, 5000);
    if ($all_entities) {
        $entity_list = array();
        foreach ($all_entities as $entity) {
            if ($entity->form_id == $form_id) {
                $count = count_annotations($entity->getGUID(), "object", "form_data", "form:recommendation");
                $item = new StdClass();
                $item->entity = $entity;
                $item->count = $count;
                $entity_list[] = $item;
            }
        }
        $sorted = form_vsort($entity_list, 'count', true);
        foreach ($sorted as $item) {
            $entities[] = $item->entity;
        }
Пример #4
0
/**
 * Get an array of the most recent edits watched by a group or user
 * 
 * @param int $entity group or user doing the watching
 * @param int $num The number of results to return (code supports at most 50)
 * @param boolean $minor If FALSE returns only major edits
 * 
 * @return array An array of objects describing edits
 */
function mediawiki_get_watched_edits($entity, $num, $minor = TRUE)
{
    $max_num = 50;
    $edits = array();
    if ($entity instanceof ElggGroup) {
        $group_guid = $entity->getGUID();
        // work around for core Elgg bug #934
        // see: http://trac.elgg.org/elgg/ticket/934
        if (!get_metastring_id($group_guid)) {
            return $edits;
        }
        // end of workaround
        $watches = get_entities_from_annotations("object", "mediawiki_watch", "group", $group_guid);
    } else {
        // should be a personal watch then
        $watches = get_entities_from_annotations("object", "mediawiki_watch", "personal", "yes", $entity->getGUID());
    }
    if ($watches) {
        $mediawiki_digest_interval = get_plugin_setting('digest_interval', 'mediawiki');
        if ($mediawiki_digest_interval) {
            $digest_interval = $mediawiki_digest_interval * 60;
        } else {
            $digest_interval = 0;
        }
        foreach ($watches as $watch) {
            if (!$minor) {
                $watch_edits = get_annotations($watch->getGUID(), "object", "mediawiki_watch", "edit", "major", 0, $max_num);
            } else {
                $watch_edits = $watch->getAnnotations('edit', $max_num);
            }
            if ($watch_edits) {
                $previous_edit = new stdClass();
                foreach ($watch_edits as $watch_edit) {
                    $edit = new stdClass();
                    $edit->page = $watch->page;
                    $edit->update_time = $watch_edit->time_created;
                    $edit->user_guid = $watch_edit->owner_guid;
                    $edit->status = $watch_edit->value;
                    // collapse multiple consecutive edits by the same person if within the digest interval
                    if ($digest_interval && isset($previous_edit->update_time) && $previous_edit->user_guid == $edit->user_guid && $edit->update_time - $previous_edit->update_time <= $digest_interval) {
                        array_pop($edits);
                    }
                    $edits[] = $edit;
                    $previous_edit = $edit;
                }
            }
        }
    }
    return array_slice(mediawiki_vsort($edits, 'update_time', TRUE), 0, $num);
}