Skip to content

Commit

Permalink
In addition to these changes, I added space between function (yes, ba…
Browse files Browse the repository at this point in the history
…d Julian, bad Julian)

* core/project_api.php
  (project_cache_row): convert the id to an int before using it as an array key
  (project_cache_all): new function to pull all project rows from the db into
    the cache
  (project_clear_cache): convert the id to an int before using it as an array
    key
  (project_get_all_rows): new public function to return all the project rows


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1815 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
Julian Fitzell committed Feb 9, 2003
1 parent 9c08468 commit a3f5ca5
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions core/project_api.php
Expand Up @@ -6,7 +6,7 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: project_api.php,v 1.29 2003-02-09 10:30:07 jfitzell Exp $
# $Id: project_api.php,v 1.30 2003-02-09 21:55:53 jfitzell Exp $
# --------------------------------------------------------

$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -34,7 +34,7 @@
# If the second parameter is true (default), trigger an error
# if the project can't be found. If the second parameter is
# false, return false if the project can't be found.
function project_cache_row( $p_project_id, $p_trigger_errors=true) {
function project_cache_row( $p_project_id, $p_trigger_errors=true ) {
global $g_cache_project;

$c_project_id = db_prepare_int( $p_project_id );
Expand All @@ -60,10 +60,33 @@ function project_cache_row( $p_project_id, $p_trigger_errors=true) {

$row = db_fetch_array( $result );

$g_cache_project[$c_project_id] = $row;
$g_cache_project[(int)$p_project_id] = $row;

return $row;
}

# --------------------
# Cache all project rows and return an array of them
function project_cache_all() {
global $g_cache_project;

$t_project_table = config_get( 'mantis_project_table' );

$query = "SELECT *
FROM $t_project_table";
$result = db_query( $query );

$count = db_num_rows( $result );

for ( $i = 0 ; $i < $count ; $i++ ) {
$row = db_fetch_array( $result );

$g_cache_project[(int)$row['id']] = $row;
}

return $g_cache_project;
}

# --------------------
# Clear the project cache (or just the given id if specified)
function project_clear_cache( $p_project_id = null ) {
Expand All @@ -72,8 +95,7 @@ function project_clear_cache( $p_project_id = null ) {
if ( null === $p_project_id ) {
$g_cache_project = array();
} else {
$c_project_id = db_prepare_int( $p_project_id );
unset( $g_cache_project[$c_project_id] );
unset( $g_cache_project[(int)$p_project_id] );
}

return true;
Expand All @@ -97,6 +119,7 @@ function project_exists( $p_project_id ) {
return true;
}
}

# --------------------
# check to see if project exists by id
# if it doesn't exist then error
Expand All @@ -106,6 +129,7 @@ function project_ensure_exists( $p_project_id ) {
trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
}
}

# --------------------
# check to see if project exists by name
function project_is_name_unique( $p_name ) {
Expand All @@ -124,6 +148,7 @@ function project_is_name_unique( $p_name ) {
return false;
}
}

# --------------------
# check to see if project exists by id
# if it doesn't exist then error
Expand All @@ -133,6 +158,7 @@ function project_ensure_name_unique( $p_name ) {
trigger_error( ERROR_PROJECT_NAME_NOT_UNIQUE, ERROR );
}
}

# --------------------
# check to see if the user/project combo already exists
# returns true is duplicate is found, otherwise false
Expand Down Expand Up @@ -191,6 +217,7 @@ function project_create( $p_name, $p_description, $p_status, $p_view_state=PUBLI
# return the id of the new project
return db_insert_id();
}

# --------------------
# Delete a project
function project_delete( $p_project_id ) {
Expand Down Expand Up @@ -230,6 +257,7 @@ function project_delete( $p_project_id ) {
# db_query() errors on failure so:
return true;
}

# --------------------
# Update a project
function project_update( $p_project_id, $p_name, $p_description, $p_status, $p_view_state, $p_file_path, $p_enabled ) {
Expand Down Expand Up @@ -284,6 +312,12 @@ function project_get_row( $p_project_id ) {
return project_cache_row( $p_project_id );
}

# --------------------
# Return all rows describing all projects
function project_get_all_rows() {
return project_cache_all();
}

# --------------------
# Return the specified field of the specified project
function project_get_field( $p_project_id, $p_field_name ) {
Expand All @@ -296,6 +330,7 @@ function project_get_field( $p_project_id, $p_field_name ) {
return '';
}
}

# --------------------
# Return the user's local (overridden) access level on the project or false
# if the user is not listed on the project
Expand All @@ -320,6 +355,7 @@ function project_get_local_user_access_level( $p_project_id, $p_user_id ) {
return false;
}
}

# --------------------
# return the descriptor holding all the info from the project user list
# for the specified project
Expand All @@ -343,6 +379,7 @@ function project_get_local_user_rows( $p_project_id ) {

return $t_user_rows;
}

# --------------------
# Return an array of info about users who have access to the the given project
# For each user we have 'id', 'username', and 'access_level' (overall access level)
Expand Down Expand Up @@ -396,6 +433,8 @@ function project_get_all_user_rows( $p_project_id ) {

return multi_sort( array_values($t_users), 'username' );
}


#===================================
# Data Modification
#===================================
Expand All @@ -420,6 +459,7 @@ function project_add_user( $p_project_id, $p_user_id, $p_access_level ) {
# db_query errors on failure so:
return true;
}

# --------------------
# update entry
# must make sure entry exists beforehand
Expand All @@ -440,6 +480,7 @@ function project_update_user_access( $p_project_id, $p_user_id, $p_access_level
# db_query errors on failure so:
return true;
}

# --------------------
# update or add the entry as appropriate
# This function involves one more db query than project_update_user_acces()
Expand All @@ -451,6 +492,7 @@ function project_set_user_access( $p_project_id, $p_user_id, $p_access_level ) {
return project_add_user( $p_project_id, $p_user_id, $p_access_level );
}
}

# --------------------
# remove user from project
function project_remove_user( $p_project_id, $p_user_id ) {
Expand All @@ -468,6 +510,7 @@ function project_remove_user( $p_project_id, $p_user_id ) {
# db_query errors on failure so:
return true;
}

# --------------------
# delete all users from the project user list for a given project
# this is useful when deleting or closing a project
Expand All @@ -484,6 +527,7 @@ function project_remove_all_users( $p_project_id ) {
# db_query errors on failure so:
return true;
}

# --------------------
# Copy all users and their permissions from the source project to the
# destination project
Expand All @@ -503,6 +547,7 @@ function project_copy_users( $p_destination_id, $p_source_id ) {
}
}
}

# --------------------
# Delete all files associated with a project
function project_delete_all_files( $p_project_id ) {
Expand Down

0 comments on commit a3f5ca5

Please sign in to comment.