Example #1
0
/**
 * List projects that the current user has access to
 * @param integer $p_parent_id         A parent project identifier.
 * @param integer $p_project_id        A project identifier.
 * @param integer $p_filter_project_id A filter project identifier.
 * @param boolean $p_trace             Whether to trace parent projects.
 * @param boolean $p_can_report_only   If true, disables projects in which user can't report issues; defaults to false (all projects enabled).
 * @param array   $p_parents           Array of parent projects.
 * @return void
 */
function print_subproject_option_list($p_parent_id, $p_project_id = null, $p_filter_project_id = null, $p_trace = false, $p_can_report_only = false, array $p_parents = array())
{
    if (config_get('subprojects_enabled') == OFF) {
        return;
    }
    array_push($p_parents, $p_parent_id);
    $t_user_id = auth_get_current_user_id();
    $t_project_ids = user_get_accessible_subprojects($t_user_id, $p_parent_id);
    $t_can_report = true;
    foreach ($t_project_ids as $t_id) {
        if ($p_can_report_only) {
            $t_report_bug_threshold = config_get('report_bug_threshold', null, $t_user_id, $t_id);
            $t_can_report = access_has_project_level($t_report_bug_threshold, $t_id, $t_user_id);
        }
        if ($p_trace) {
            $t_full_id = join($p_parents, ';') . ';' . $t_id;
        } else {
            $t_full_id = $t_id;
        }
        echo '<option value="' . $t_full_id . '"';
        check_selected($p_project_id, $t_full_id, false);
        check_disabled($t_id == $p_filter_project_id || !$t_can_report);
        echo '>' . str_repeat('&#160;', count($p_parents)) . str_repeat('&raquo;', count($p_parents)) . ' ' . string_attribute(project_get_field($t_id, 'name')) . '</option>' . "\n";
        print_subproject_option_list($t_id, $p_project_id, $p_filter_project_id, $p_trace, $p_can_report_only, $p_parents);
    }
}
Example #2
0
/**
 * Returns an array of subprojects of the specified project to which the
 * currently logged in user has access to.
 *
 * @param project_id	Parent project id.
 * @param show_disabled	Include disabled projects.
 * @return an array of accessible sub-project ids.
 * @access public
 */
function current_user_get_accessible_subprojects($p_project_id, $p_show_disabled = false)
{
    return user_get_accessible_subprojects(auth_get_current_user_id(), $p_project_id, $p_show_disabled);
}
Example #3
0
/**
 * retun an array of sub-project IDs of all sub-projects project to which the user has access
 * @param integer $p_user_id    A valid user identifier.
 * @param integer $p_project_id A valid project identifier.
 * @return array
 */
function user_get_all_accessible_subprojects($p_user_id, $p_project_id)
{
    # @todo (thraxisp) Should all top level projects be a sub-project of ALL_PROJECTS implicitly?
    # affects how news and some summaries are generated
    $t_todo = user_get_accessible_subprojects($p_user_id, $p_project_id);
    $t_subprojects = array();
    while ($t_todo) {
        $t_elem = (int) array_shift($t_todo);
        if (!in_array($t_elem, $t_subprojects)) {
            array_push($t_subprojects, $t_elem);
            $t_todo = array_merge($t_todo, user_get_accessible_subprojects($p_user_id, $t_elem));
        }
    }
    return $t_subprojects;
}
Example #4
0
/**
 * Gets the sub-projects that are accessible to the specified user / project.
 * @param integer $p_user_id           User id.
 * @param integer $p_parent_project_id Parent Project id.
 * @param string  $p_lang              Language string.
 * @return array
 */
function mci_user_get_accessible_subprojects($p_user_id, $p_parent_project_id, $p_lang = null)
{
    if ($p_lang === null) {
        $t_lang = mci_get_user_lang($p_user_id);
    } else {
        $t_lang = $p_lang;
    }
    $t_result = array();
    foreach (user_get_accessible_subprojects($p_user_id, $p_parent_project_id) as $t_subproject_id) {
        $t_subproject_row = project_cache_row($t_subproject_id);
        $t_subproject = array();
        $t_subproject['id'] = $t_subproject_id;
        $t_subproject['name'] = $t_subproject_row['name'];
        $t_subproject['status'] = mci_enum_get_array_by_id($t_subproject_row['status'], 'project_status', $t_lang);
        $t_subproject['enabled'] = $t_subproject_row['enabled'];
        $t_subproject['view_state'] = mci_enum_get_array_by_id($t_subproject_row['view_state'], 'project_view_state', $t_lang);
        $t_subproject['access_min'] = mci_enum_get_array_by_id($t_subproject_row['access_min'], 'access_levels', $t_lang);
        $t_subproject['file_path'] = array_key_exists('file_path', $t_subproject_row) ? $t_subproject_row['file_path'] : '';
        $t_subproject['description'] = array_key_exists('description', $t_subproject_row) ? $t_subproject_row['description'] : '';
        $t_subproject['subprojects'] = mci_user_get_accessible_subprojects($p_user_id, $t_subproject_id, $t_lang);
        $t_result[] = $t_subproject;
    }
    return $t_result;
}