예제 #1
0
function printRecentChanges($projects, $print_project_headlines = true)
{
    global $PH;
    global $auth;
    /**
     * first get all changelines for projects to filter out projects without changes
     */
    $projects_with_changes = array();
    # array with projects
    $project_changes = array();
    # hash with project id and changelist
    foreach ($projects as $project) {
        /**
         * first query all unviewed changes
         */
        $options = array('project' => $project->id, 'unviewed_only' => false, 'limit_rowcount' => confGet('MAX_CHANGELINES') + 1, 'limit_offset' => 0, 'type' => array(ITEM_TASK, ITEM_FILE));
        if ($auth->cur_user->settings & USER_SETTING_FILTER_OWN_CHANGES) {
            $options['not_modified_by'] = $auth->cur_user->id;
        }
        if ($changes = ChangeLine::getChangeLines($options)) {
            $projects_with_changes[] = $project;
            $project_changes[$project->id] = $changes;
        }
    }
    if ($auth->cur_user->settings & USER_SETTING_FILTER_OWN_CHANGES) {
        $link_name = __("Also show yours", "E.i. also show your changes");
    } else {
        $link_name = __("Hide yours", "E.i. Filter out your changes");
    }
    $block = new PageBlock(array('title' => __('Recent changes'), 'id' => 'recentchanges', 'headline_links' => array($PH->getLink('personToggleFilterOwnChanges', $link_name, array('person' => $auth->cur_user->id)))));
    $block->render_blockStart();
    ### no changes
    if (0 == count($projects_with_changes)) {
        echo "<div class=text>" . __("No changes yet") . "</div>";
        ### more options ###
        echo "<p class=more>";
        echo $PH->getLink('personToggleFilterOwnChanges', $link_name, array('person' => $auth->cur_user->id));
        echo "</p>";
        $block->render_blockEnd();
    } else {
        $changelines_per_project = confGet('MAX_CHANGELINES_PER_PROJECT');
        if (count($projects_with_changes) < confGet('MAX_CHANGELINES') / confGet('MAX_CHANGELINES_PER_PROJECT')) {
            $changelines_per_project = confGet('MAX_CHANGELINES') / count($projects_with_changes) - 1;
        }
        /**
         * count printed changelines to keep size of list
         */
        $printed_changelines = 0;
        foreach ($projects_with_changes as $project) {
            echo "<div class=post_list_entry>";
            $changes = $project_changes[$project->id];
            if ($print_project_headlines) {
                echo '<h3>' . sprintf(__("%s project", "links to project in recent changes list"), $PH->getLink('projView', $project->name, array('prj' => $project->id))) . "</h3>";
            }
            echo "<ul id='changesOnProject_{$project->id}'>";
            $lines = 0;
            foreach ($changes as $c) {
                $lines++;
                printChangeLine($c);
                $printed_changelines++;
                if ($lines >= $changelines_per_project) {
                    break;
                }
            }
            echo "</ul>";
            ### more options ###
            echo "<p class=more>";
            if ($auth->cur_user->settings & USER_SETTING_FILTER_OWN_CHANGES) {
                $link_name = __("Also show your changes");
            } else {
                $link_name = __("Hide your changes");
            }
            if ($lines < count($changes)) {
                echo " | ";
                echo "<a href='javascript:getMoreChanges({$project->id}, " . ($lines - 1) . ", " . confGet('MORE_CHANGELINES') . ");' " . '>' . __('Show more') . '</a>';
            }
            echo "</p>";
            /**
             * limit number of projects
             */
            if ($printed_changelines >= confGet('MAX_CHANGELINES')) {
                break;
            }
            echo "</div>";
        }
        $block->render_blockEnd();
    }
}
예제 #2
0
/**
* get recent changes for ajax request from home @ingroup pages
*
* @Params
* - prj
* - start
* - count
*
* @NOTE
* This page function was formerly a part of home.inc.php but since it will
* be used in other places as well, item_ajax might be a better place for it.
*/
function AjaxMoreChanges()
{
    require_once confGet('DIR_STREBER') . 'std/class_changeline.inc.php';
    require_once confGet('DIR_STREBER') . 'lists/list_recentchanges.inc.php';
    global $auth;
    header("Content-type: text/html; charset=utf-8");
    if (!($project = Project::getVisibleById(get('prj')))) {
        return;
    }
    $start = is_null(get('start')) ? 0 : intval(get('start'));
    $count = is_null(get('count')) ? 20 : intval(get('count'));
    $options = array('project' => $project->id, 'unviewed_only' => false, 'limit_rowcount' => $count, 'limit_offset' => $start, 'type' => array(ITEM_TASK, ITEM_FILE));
    if ($auth->cur_user->settings & USER_SETTING_FILTER_OWN_CHANGES) {
        $options['not_modified_by'] = $auth->cur_user->id;
    }
    /**
     * first query all unviewed changes
     */
    if ($changes = ChangeLine::getChangeLines($options)) {
        $lines = 0;
        foreach ($changes as $c) {
            printChangeLine($c);
        }
    }
}