[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/api/soap/ -> mc_enum_api.php (source)

   1  <?php
   2  # MantisConnect - A webservice interface to Mantis Bug Tracker
   3  # Copyright (C) 2004-2011  Victor Boctor - vboctor@users.sourceforge.net
   4  # This program is distributed under dual licensing.  These include
   5  # GPL and a commercial licenses.  Victor Boctor reserves the right to
   6  # change the license of future releases.
   7  # See docs/ folder for more details
   8  
   9  /**
  10   * Get all available status.
  11   *
  12   * @param string $p_username  The name of the user trying to access the enumeration.
  13   * @param string $p_password  The password of the user.
  14   * @return Array  The requested enumeration
  15   */
  16  function mc_enum_status( $p_username, $p_password ) {
  17      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
  18          return new soap_fault( 'Client', '', 'Access Denied' );
  19      }
  20  
  21      return mci_explode_to_objectref( 'status' );
  22  }
  23  
  24  /**
  25   * Get all available priorities.
  26   *
  27   * @param string $p_username  The name of the user trying to access the enumeration.
  28   * @param string $p_password  The password of the user.
  29   * @return Array  The requested enumeration
  30   */
  31  function mc_enum_priorities( $p_username, $p_password ) {
  32      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
  33          return new soap_fault( 'Client', '', 'Access Denied' );
  34      }
  35  
  36      return mci_explode_to_objectref( 'priority' );
  37  }
  38  
  39  /**
  40   * Get all available severities.
  41   *
  42   * @param string $p_username  The name of the user trying to access the enumeration.
  43   * @param string $p_password  The password of the user.
  44   * @return Array  The requested enumeration
  45   */
  46  function mc_enum_severities( $p_username, $p_password ) {
  47      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
  48          return new soap_fault( 'Client', '', 'Access Denied' );
  49      }
  50  
  51      return mci_explode_to_objectref( 'severity' );
  52  }
  53  
  54  /**
  55   * Get all available reproducibilities.
  56   *
  57   * @param string $p_username  The name of the user trying to access the enumeration.
  58   * @param string $p_password  The password of the user.
  59   * @return Array  The requested enumeration
  60   */
  61  function mc_enum_reproducibilities( $p_username, $p_password ) {
  62      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
  63          return new soap_fault( 'Client', '', 'Access Denied' );
  64      }
  65  
  66      return mci_explode_to_objectref( 'reproducibility' );
  67  }
  68  
  69  /**
  70   * Get all available projections.
  71   *
  72   * @param string $p_username  The name of the user trying to access the enumeration.
  73   * @param string $p_password  The password of the user.
  74   * @return Array  The requested enumeration
  75   */
  76  function mc_enum_projections( $p_username, $p_password ) {
  77      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
  78          return new soap_fault( 'Client', '', 'Access Denied' );
  79      }
  80  
  81      return mci_explode_to_objectref( 'projection' );
  82  }
  83  
  84  /**
  85   * Get all available etas.
  86   *
  87   * @param string $p_username  The name of the user trying to access the enumeration.
  88   * @param string $p_password  The password of the user.
  89   * @return Array  The requested enumeration
  90   */
  91  function mc_enum_etas( $p_username, $p_password ) {
  92      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
  93          return new soap_fault( 'Client', '', 'Access Denied' );
  94      }
  95  
  96      return mci_explode_to_objectref( 'eta' );
  97  }
  98  
  99  /**
 100   * Get all available resolutions.
 101   *
 102   * @param string $p_username  The name of the user trying to access the enumeration.
 103   * @param string $p_password  The password of the user.
 104   * @return Array  The requested enumeration
 105   */
 106  function mc_enum_resolutions( $p_username, $p_password ) {
 107      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
 108          return new soap_fault( 'Client', '', 'Access Denied' );
 109      }
 110  
 111      return mci_explode_to_objectref( 'resolution' );
 112  }
 113  
 114  /**
 115   * Get all available access levels.
 116   *
 117   * @param string $p_username  The name of the user trying to access the enumeration.
 118   * @param string $p_password  The password of the user.
 119   * @return Array  The requested enumeration
 120   */
 121  function mc_enum_access_levels( $p_username, $p_password ) {
 122      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
 123          return new soap_fault( 'Client', '', 'Access Denied' );
 124      }
 125  
 126      return mci_explode_to_objectref( 'access_levels' );
 127  }
 128  
 129  /**
 130   * Get all available project status.
 131   *
 132   * @param string $p_username  The name of the user trying to access the enumeration.
 133   * @param string $p_password  The password of the user.
 134   * @return Array  The requested enumeration
 135   */
 136  function mc_enum_project_status( $p_username, $p_password ) {
 137      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
 138          return new soap_fault( 'Client', '', 'Access Denied' );
 139      }
 140  
 141      return mci_explode_to_objectref( 'project_status' );
 142  }
 143  
 144  /**
 145   * Get all available project view states.
 146   *
 147   * @param string $p_username  The name of the user trying to access the enumeration.
 148   * @param string $p_password  The password of the user.
 149   * @return Array  The requested enumeration
 150   */
 151  function mc_enum_project_view_states( $p_username, $p_password ) {
 152      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
 153          return new soap_fault( 'Client', '', 'Access Denied' );
 154      }
 155  
 156      return mci_explode_to_objectref( 'project_view_state' );
 157  }
 158  
 159  /**
 160   * Get all available view states.
 161   *
 162   * @param string $p_username  The name of the user trying to access the enumeration.
 163   * @param string $p_password  The password of the user.
 164   * @return Array  The requested enumeration
 165   */
 166  function mc_enum_view_states( $p_username, $p_password ) {
 167      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
 168          return new soap_fault( 'Client', '', 'Access Denied' );
 169      }
 170  
 171      return mci_explode_to_objectref( 'view_state' );
 172  }
 173  
 174  /**
 175   * Get all available custom field types.
 176   *
 177   * @param string $p_username  The name of the user trying to access the enumeration.
 178   * @param string $p_password  The password of the user.
 179   * @return Array  The requested enumeration
 180   */
 181  function mc_enum_custom_field_types( $p_username, $p_password ) {
 182      if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
 183          return new soap_fault( 'Client', '', 'Access Denied' );
 184      }
 185  
 186      return mci_explode_to_objectref( 'custom_field_type' );
 187  }
 188  
 189  /**
 190   * Get an appropriate enumeration. (Should become an internal function.)
 191   *
 192   * @param string $p_username  The name of the user trying to access the enumeration.
 193   * @param string $p_password  The password of the user.
 194   * @param string $p_enumeration  The enumeration to get.
 195   * @return string  The requested enumeration.
 196   */
 197  function mc_enum_get( $p_username, $p_password, $p_enumeration ) {
 198      if ( ! mci_validate_enum_access($p_username, $p_password)) {
 199          return new soap_fault( 'Client', '', 'Access Denied' );
 200      }
 201      
 202      // safe to call directly after login checks
 203      $t_user_id = auth_get_current_user_id();
 204      $t_lang = mci_get_user_lang( $t_user_id );
 205      
 206      return lang_get( $p_enumeration . '_enum_string', $t_lang );
 207  }
 208  
 209  /**
 210   * Explode a configuration enumeration name into an array structure that can
 211   * be safely converted into an ObjectRef structure.
 212   *
 213   * @param string $p_enumeration_name  The name of the enumeration to convert
 214   * @return Array  The converted enumeration
 215   */
 216  function mci_explode_to_objectref( $p_enumeration_name ) {
 217  
 218      $t_config_var_name = $p_enumeration_name . '_enum_string';
 219      $t_config_var_value = config_get( $t_config_var_name );
 220      $t_translated_values = lang_get( $t_config_var_name, mci_get_user_lang( auth_get_current_user_id() ) );
 221  
 222      $t_enum_values = MantisEnum::getValues( $t_config_var_value );
 223  
 224      $t_result = array();
 225  
 226      foreach ( $t_enum_values as $t_key ) {
 227          $t_translated = MantisEnum::getLocalizedLabel( $t_config_var_value, $t_translated_values, $t_key );
 228  
 229          $t_result[] = array(
 230              'id' => $t_key,
 231              'name' => $t_translated,
 232          );
 233      }
 234      return $t_result;
 235  }
 236  
 237  /**
 238   * Validates that the user has access to the enumeration values
 239   *
 240   * @param string $p_username
 241   * @param string $p_password
 242   * @return boolean true if the user has access, false otherwise
 243   */
 244  function mci_validate_enum_access($p_username, $p_password) {
 245  
 246      $t_user_id = mci_check_login( $p_username, $p_password );
 247      if( $t_user_id === false ) {
 248          return false;
 249      }
 250      if( !mci_has_readonly_access( $t_user_id ) ) {
 251          return false;
 252      }
 253  
 254      return true;
 255  }
 256  
 257  /**
 258   * Get a localized enumeration element.
 259   *
 260   * @param integer $p_enum_id  The id of the enumeration element to retrieve.
 261   * @param String $p_enum_type  The type of the enumeration element (e.g. 'status', 'reproducibility' etc.).
 262   * @param String $p_lang  The language for the name field.
 263   * @return Array an Array containing the id and the name of the enumeration element.
 264   */
 265  function mci_enum_get_array_by_id( $p_enum_id, $p_enum_type, $p_lang ) {
 266      $t_result = array();
 267      $t_result['id'] = $p_enum_id;
 268      $t_result['name'] = mci_get_enum_element( $p_enum_type, $p_enum_id, $p_lang );
 269      return $t_result;
 270  }
 271  
 272  /**
 273   * Get the enum id given the enum label.
 274   *
 275   * @param $p_enum_string   The enum string to search in.
 276   * @param $p_label         The label to search for.
 277   *
 278   * @return The id corresponding to the given label, or 0 if not found.
 279   */
 280  function mci_get_enum_value_from_label( $p_enum_string, $p_label ) {
 281      $t_value = MantisEnum::getValue( $p_enum_string, $p_label );
 282      if ( $t_value === false ) {
 283          return 0;
 284      }
 285  
 286      return $t_value;
 287  }
 288  
 289  /**
 290   * Get the enumeration id given an object ref.  The id is set based on the following algorithm:
 291   * - id from objectref.
 292   * - id corresponding to name in object ref.
 293   * - default value for the specified enumeration, if exists in configuration.
 294   * - first id, if object ref doesn't contain an id or a name.
 295   *
 296   * @param string     $p_enum         The name of the enumeration as in the MantisBT configuration file
 297   * @param ObjectRef  $p_object_ref   An associate array with "id" and "name" keys.
 298   * @return enum id
 299   */
 300  function mci_get_enum_id_from_objectref( $p_enum, $p_object_ref ) {
 301      if( !is_null( $p_object_ref ) && isset( $p_object_ref['id'] ) && (int) $p_object_ref['id'] != 0 ) {
 302          $t_id = (int) $p_object_ref['id'];
 303      } else {
 304          $t_enum = config_get( $p_enum . '_enum_string' );
 305          if( !is_null( $p_object_ref ) && isset( $p_object_ref['name'] ) && !is_blank( $p_object_ref['name'] ) ) {
 306              $t_id = mci_get_enum_value_from_label( $t_enum, $p_object_ref['name'] );
 307              if( $t_id == 0 ) {
 308                  $t_id = config_get( 'mc_' . $p_enum . '_enum_default_when_not_found' );
 309              }
 310          } else {
 311              $t_default_id = config_get( 'default_bug_' . $p_enum, 0 );
 312              if( $t_default_id == 0 ) {
 313                  $t_array = mci_explode_to_objectref( $p_enum );
 314                  $t_id = (int) $t_array[0]['id'];
 315              } else {
 316                  $t_id = $t_default_id;
 317              }
 318          }
 319      }
 320  
 321      return $t_id;
 322  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7