[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/ -> project_hierarchy_api.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: project_hierarchy_api.php,v 1.7.16.1 2007-10-13 22:35:41 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      ### Project Hierarchy API ###
  25  
  26      $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
  27  
  28      # --------------------
  29  	function project_hierarchy_add( $p_child_id, $p_parent_id ) {
  30          if ( in_array( $p_parent_id, project_hierarchy_get_all_subprojects( $p_child_id ) ) ) {
  31              trigger_error( ERROR_PROJECT_RECURSIVE_HIERARCHY, ERROR );
  32          }
  33  
  34          $t_project_hierarchy_table = config_get( 'mantis_project_hierarchy_table' );
  35  
  36          $c_child_id  = db_prepare_int( $p_child_id  );
  37          $c_parent_id = db_prepare_int( $p_parent_id );
  38  
  39          $query = "INSERT INTO $t_project_hierarchy_table
  40                          ( child_id, parent_id )
  41                          VALUES
  42                          ( $c_child_id, $c_parent_id )";
  43  
  44          db_query($query);
  45      }
  46  
  47      # --------------------
  48  	function project_hierarchy_remove( $p_child_id, $p_parent_id ) {
  49          $t_project_hierarchy_table = config_get( 'mantis_project_hierarchy_table' );
  50  
  51          $c_child_id  = db_prepare_int( $p_child_id  );
  52          $c_parent_id = db_prepare_int( $p_parent_id );
  53  
  54          $query = "DELETE FROM $t_project_hierarchy_table
  55                          WHERE child_id = $c_child_id
  56                          AND parent_id = $c_parent_id";
  57  
  58          db_query($query);
  59      }
  60  
  61      # --------------------
  62  	function project_hierarchy_remove_all( $p_project_id ) {
  63          $t_project_hierarchy_table = config_get( 'mantis_project_hierarchy_table' );
  64  
  65          $c_project_id = db_prepare_int( $p_project_id );
  66  
  67          $query = "DELETE FROM $t_project_hierarchy_table
  68                          WHERE child_id = $c_project_id
  69                            OR parent_id = $c_project_id";
  70  
  71          db_query($query);
  72      }
  73  
  74      # --------------------
  75  	function project_hierarchy_is_toplevel( $p_project_id ) {
  76          global $g_cache_project_hierarchy;
  77  
  78          if ( null === $g_cache_project_hierarchy ) {
  79              project_hierarchy_cache();
  80          }
  81  
  82          if ( isset( $g_cache_project_hierarchy[ ALL_PROJECTS ] ) ) {
  83              return in_array( $p_project_id, $g_cache_project_hierarchy[ ALL_PROJECTS ] );
  84          } else {
  85              return false;
  86          }
  87      }
  88  
  89      $g_cache_project_hierarchy = null;
  90  
  91      # --------------------
  92  	function project_hierarchy_cache( $p_show_disabled = false ) {
  93          global $g_cache_project_hierarchy;
  94  
  95          $t_project_table            = config_get( 'mantis_project_table' );
  96          $t_project_hierarchy_table    = config_get( 'mantis_project_hierarchy_table' );
  97          $t_enabled_clause = $p_show_disabled ? '1=1' : 'p.enabled = 1';
  98  
  99          $query = "SELECT DISTINCT p.id, ph.parent_id, p.name
 100                    FROM $t_project_table p
 101                    LEFT JOIN $t_project_hierarchy_table ph
 102                      ON ph.child_id = p.id
 103                    WHERE $t_enabled_clause
 104                    ORDER BY p.name";
 105  
 106          $result = db_query( $query );
 107          $row_count = db_num_rows( $result );
 108  
 109          $g_cache_project_hierarchy = array();
 110  
 111          for ( $i=0 ; $i < $row_count ; $i++ ){
 112              $row = db_fetch_array( $result );
 113  
 114              if ( null === $row['parent_id'] ) {
 115                  $row['parent_id'] = ALL_PROJECTS;
 116              }
 117  
 118              if ( isset( $g_cache_project_hierarchy[ $row['parent_id'] ] ) ) {
 119                  $g_cache_project_hierarchy[ $row['parent_id'] ][] = $row['id'];
 120              } else {
 121                  $g_cache_project_hierarchy[ $row['parent_id'] ] = array( $row['id'] );
 122              }
 123          }
 124      }
 125  
 126  
 127      # --------------------
 128  	function project_hierarchy_get_subprojects( $p_project_id, $p_show_disabled = false ) {
 129          global $g_cache_project_hierarchy;
 130  
 131          if ( ( null === $g_cache_project_hierarchy ) || ( $p_show_disabled ) ) {
 132              project_hierarchy_cache( $p_show_disabled );
 133          }
 134  
 135          if ( isset( $g_cache_project_hierarchy[ $p_project_id ] ) ) {
 136              return $g_cache_project_hierarchy[ $p_project_id ];
 137          } else {
 138              return array();
 139          }
 140      }
 141  
 142      # --------------------
 143  	function project_hierarchy_get_all_subprojects( $p_project_id ) {
 144          $t_todo        = project_hierarchy_get_subprojects( $p_project_id );
 145          $t_subprojects = Array();
 146  
 147          while ( $t_todo ) {
 148              $t_elem = array_shift( $t_todo );
 149              if ( !in_array( $t_elem, $t_subprojects ) ) {
 150                  array_push( $t_subprojects, $t_elem );
 151                  $t_todo = array_merge( $t_todo, project_hierarchy_get_subprojects( $t_elem ) );
 152              }
 153          }
 154  
 155          return $t_subprojects;
 156      }
 157  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics