Example #1
0
/**
 * Return an array of ids of custom fields bound to the specified project
 *
 * The ids will be sorted based on the sequence number associated with the binding
 * @param int $p_project_id project id
 * @return array
 * @access public
 */
function custom_field_get_linked_ids($p_project_id = ALL_PROJECTS)
{
    global $g_cache_cf_linked, $g_cache_custom_field;
    if (!isset($g_cache_cf_linked[$p_project_id])) {
        $t_custom_field_table = db_get_table('custom_field');
        $t_custom_field_project_table = db_get_table('custom_field_project');
        if (ALL_PROJECTS == $p_project_id) {
            $t_project_user_list_table = db_get_table('project_user_list');
            $t_project_table = db_get_table('project');
            $t_user_table = db_get_table('user');
            $t_user_id = auth_get_current_user_id();
            $t_pub = VS_PUBLIC;
            $t_priv = VS_PRIVATE;
            $t_private_access = config_get('private_project_threshold');
            if (is_array($t_private_access)) {
                if (1 == count($t_private_access)) {
                    $t_access_clause = '= ' . array_shift($t_private_access) . ' ';
                } else {
                    $t_access_clause = 'IN (' . implode(',', $t_private_access) . ')';
                }
            } else {
                $t_access_clause = ">= {$t_private_access} ";
            }
            # select only the ids that the user has some access to
            #  e.g., all fields in public projects, or private projects where the user is listed
            #    or private projects where the user is implicitly listed
            $query = "SELECT DISTINCT cft.id\n                    FROM {$t_custom_field_table} cft, {$t_user_table} ut, {$t_project_table} pt, {$t_custom_field_project_table} cfpt\n                        LEFT JOIN {$t_project_user_list_table} pult\n                            on cfpt.project_id = pult.project_id and pult.user_id = {$t_user_id}\n                    WHERE cft.id = cfpt.field_id AND cfpt.project_id = pt.id AND ut.id = {$t_user_id} AND\n                        ( pt.view_state = {$t_pub} OR\n                        ( pt.view_state = {$t_priv} and pult.user_id = {$t_user_id} ) OR\n                        ( pult.user_id is null and ut.access_level {$t_access_clause} ) )";
        } else {
            if (is_array($p_project_id)) {
                if (1 == count($p_project_id)) {
                    $t_project_clause = '= ' . array_shift($p_project_id) . ' ';
                } else {
                    $t_project_clause = 'IN (' . implode(',', $p_project_id) . ')';
                }
            } else {
                $t_project_clause = '= ' . $p_project_id;
            }
            $query = "SELECT cft.id\n\t\t\t\t\t  FROM {$t_custom_field_table} cft, {$t_custom_field_project_table} cfpt\n\t\t\t\t\t  WHERE cfpt.project_id {$t_project_clause} AND\n\t\t\t\t\t\t\tcft.id = cfpt.field_id\n\t\t\t\t\t  ORDER BY sequence ASC, name ASC";
        }
        $result = db_query($query);
        $t_row_count = db_num_rows($result);
        $t_ids = array();
        for ($i = 0; $i < $t_row_count; $i++) {
            $row = db_fetch_array($result);
            array_push($t_ids, $row['id']);
        }
        custom_field_cache_array_rows($t_ids);
        $g_cache_cf_linked[$p_project_id] = $t_ids;
    } else {
        $t_ids = $g_cache_cf_linked[$p_project_id];
    }
    return $t_ids;
}
Example #2
0
/**
 * Return an array of ids of custom fields bound to the specified project
 *
 * The ids will be sorted based on the sequence number associated with the binding
 * @param integer $p_project_id A project identifier.
 * @return array
 * @access public
 */
function custom_field_get_linked_ids($p_project_id = ALL_PROJECTS)
{
    global $g_cache_cf_linked;
    if (!isset($g_cache_cf_linked[$p_project_id])) {
        db_param_push();
        if (ALL_PROJECTS == $p_project_id) {
            $t_user_id = auth_get_current_user_id();
            # Select only the ids of custom fields in projects the user has access to
            #  - all custom fields in public projects,
            #  - those in private projects where the user is listed
            #  - in private projects where the user is implicitly listed
            $t_query = 'SELECT DISTINCT cft.id
				FROM {custom_field} cft
					JOIN {custom_field_project} cfpt ON cfpt.field_id = cft.id
					JOIN {project} pt
						ON pt.id = cfpt.project_id AND pt.enabled = ' . db_prepare_bool(true) . '
					LEFT JOIN {project_user_list} pult
						ON pult.project_id = cfpt.project_id AND pult.user_id = ' . db_param() . '
					, {user} ut
				WHERE ut.id = ' . db_param() . '
					AND (  pt.view_state = ' . VS_PUBLIC . '
						OR pult.user_id = ut.id
						';
            $t_params = array($t_user_id, $t_user_id);
            # Add private access clause and related parameter
            $t_private_access = config_get('private_project_threshold');
            if (is_array($t_private_access)) {
                if (1 == count($t_private_access)) {
                    $t_access_clause = '= ' . db_param();
                    $t_params[] = array_shift($t_private_access);
                } else {
                    $t_access_clause = 'IN (';
                    foreach ($t_private_access as $t_elem) {
                        $t_access_clause .= db_param() . ',';
                        $t_params[] = $t_elem;
                    }
                    $t_access_clause = rtrim($t_access_clause, ',') . ')';
                }
            } else {
                $t_access_clause = '>=' . db_param();
                $t_params[] = $t_private_access;
            }
            $t_query .= 'OR ( pult.user_id IS NULL AND ut.access_level ' . $t_access_clause . ' ) )';
        } else {
            if (is_array($p_project_id)) {
                if (1 == count($p_project_id)) {
                    $t_project_clause = '= ' . db_param();
                    $t_params[] = array_shift($p_project_id);
                } else {
                    $t_project_clause = 'IN (';
                    foreach ($p_project_id as $t_project) {
                        $t_project_clause .= db_param() . ',';
                        $t_params[] = $t_project;
                    }
                    $t_project_clause = rtrim($t_project_clause, ',') . ')';
                }
            } else {
                $t_project_clause = '= ' . db_param();
                $t_params[] = $p_project_id;
            }
            $t_query = 'SELECT cft.id
				FROM {custom_field} cft
					JOIN {custom_field_project} cfpt ON cfpt.field_id = cft.id
				WHERE cfpt.project_id ' . $t_project_clause . '
				ORDER BY sequence ASC, name ASC';
        }
        $t_result = db_query($t_query, $t_params);
        $t_ids = array();
        while ($t_row = db_fetch_array($t_result)) {
            array_push($t_ids, $t_row['id']);
        }
        custom_field_cache_array_rows($t_ids);
        $g_cache_cf_linked[$p_project_id] = $t_ids;
    } else {
        $t_ids = $g_cache_cf_linked[$p_project_id];
    }
    return $t_ids;
}
Example #3
0
/**
 * Return an array of ids of custom fields bound to the specified project
 *
 * The ids will be sorted based on the sequence number associated with the binding
 * @param int $p_project_id project id
 * @return array
 * @access public
 */
function custom_field_get_linked_ids($p_project_id = ALL_PROJECTS)
{
    global $g_cache_cf_linked, $g_cache_custom_field;
    if (!isset($g_cache_cf_linked[$p_project_id])) {
        $t_custom_field_table = db_get_table('custom_field');
        $t_custom_field_project_table = db_get_table('custom_field_project');
        if (ALL_PROJECTS == $p_project_id) {
            $t_project_user_list_table = db_get_table('project_user_list');
            $t_project_table = db_get_table('project');
            $t_user_table = db_get_table('user');
            $t_user_id = auth_get_current_user_id();
            # Select only the ids of custom fields in projects the user has access to
            #  - all custom fields in public projects,
            #  - those in private projects where the user is listed
            #  - in private projects where the user is implicitly listed
            $t_query = "\n\t\t\t\tSELECT DISTINCT cft.id\n\t\t\t\tFROM {$t_custom_field_table} cft\n\t\t\t\t\tJOIN {$t_custom_field_project_table} cfpt ON cfpt.field_id = cft.id\n\t\t\t\t\tJOIN {$t_project_table} pt\n\t\t\t\t\t\tON pt.id = cfpt.project_id AND pt.enabled = " . db_prepare_bool(true) . "\n\t\t\t\t\tLEFT JOIN {$t_project_user_list_table} pult\n\t\t\t\t\t\tON pult.project_id = cfpt.project_id AND pult.user_id = " . db_param() . "\n\t\t\t\t\t, {$t_user_table} ut\n\t\t\t\tWHERE ut.id = " . db_param() . "\n\t\t\t\t\tAND (  pt.view_state = " . VS_PUBLIC . "\n\t\t\t\t\t\tOR pult.user_id = ut.id\n\t\t\t\t\t\t";
            $t_params = array($t_user_id, $t_user_id);
            # Add private access clause and related parameter
            $t_private_access = config_get('private_project_threshold');
            if (is_array($t_private_access)) {
                if (1 == count($t_private_access)) {
                    $t_access_clause = '= ' . db_param();
                    $t_params[] = array_shift($t_private_access);
                } else {
                    $t_access_clause = 'IN (';
                    foreach ($t_private_access as $t_elem) {
                        $t_access_clause .= db_param() . ',';
                        $t_params[] = $t_elem;
                    }
                    $t_access_clause = rtrim($t_access_clause, ',') . ')';
                }
            } else {
                $t_access_clause = '>=' . db_param();
                $t_params[] = $t_private_access;
            }
            $t_query .= "OR ( pult.user_id IS NULL AND ut.access_level {$t_access_clause} ) )";
        } else {
            if (is_array($p_project_id)) {
                if (1 == count($p_project_id)) {
                    $t_project_clause = '= ' . db_param();
                    $t_params[] = array_shift($p_project_id);
                } else {
                    $t_project_clause = 'IN (';
                    foreach ($p_project_id as $t_project) {
                        $t_project_clause .= db_param() . ',';
                        $t_params[] = $t_project;
                    }
                    $t_project_clause = rtrim($t_project_clause, ',') . ')';
                }
            } else {
                $t_project_clause = '= ' . db_param();
                $t_params[] = $p_project_id;
            }
            $t_query = "\n\t\t\t\tSELECT cft.id\n\t\t\t\tFROM {$t_custom_field_table} cft\n\t\t\t\t\tJOIN {$t_custom_field_project_table} cfpt ON cfpt.field_id = cft.id\n\t\t\t\tWHERE cfpt.project_id {$t_project_clause}\n\t\t\t\tORDER BY sequence ASC, name ASC";
        }
        $result = db_query_bound($t_query, $t_params);
        $t_row_count = db_num_rows($result);
        $t_ids = array();
        for ($i = 0; $i < $t_row_count; $i++) {
            $row = db_fetch_array($result);
            array_push($t_ids, $row['id']);
        }
        custom_field_cache_array_rows($t_ids);
        $g_cache_cf_linked[$p_project_id] = $t_ids;
    } else {
        $t_ids = $g_cache_cf_linked[$p_project_id];
    }
    return $t_ids;
}