/** * Get the version_id, given the project_id and $p_version_id * returns false if not found, otherwise returns the id. * @param string $p_version * @param int $p_project_id * @param mixed $p_inherit true to look for version in parent projects, false not to, null to use default configuration. * @return int */ function version_get_id($p_version, $p_project_id = null, $p_inherit = null) { global $g_cache_versions; if ($p_project_id === null) { $c_project_id = helper_get_current_project(); } else { $c_project_id = db_prepare_int($p_project_id); } foreach ($g_cache_versions as $t_version) { if ($t_version['version'] === $p_version && $t_version['project_id'] == $c_project_id) { return $t_version['id']; } } $t_project_where = version_get_project_where_clause($c_project_id, $p_inherit); $t_project_version_table = db_get_table('project_version'); $query = "SELECT id FROM {$t_project_version_table}\n\t\t\t\t\tWHERE " . $t_project_where . " AND\n\t\t\t\t\t\tversion=" . db_param(); $result = db_query_bound($query, array($p_version)); if (0 == db_num_rows($result)) { return false; } else { return db_result($result); } }
/** * Get the version_id, given the project_id and $p_version_id * returns false if not found, otherwise returns the id. * @param string $p_version A version string to look up. * @param integer $p_project_id A valid project identifier. * @param mixed $p_inherit True to look for version in parent projects, false not to, null to use default configuration. * @return integer */ function version_get_id( $p_version, $p_project_id = null, $p_inherit = null ) { global $g_cache_versions; if( $p_project_id === null ) { $c_project_id = helper_get_current_project(); } else { $c_project_id = (int)$p_project_id; } foreach( $g_cache_versions as $t_version ) { if( ( $t_version['version'] === $p_version ) && ( $t_version['project_id'] == $c_project_id ) ) { return $t_version['id']; } } $t_project_where = version_get_project_where_clause( $c_project_id, $p_inherit ); $t_query = 'SELECT id FROM {project_version} WHERE ' . $t_project_where . ' AND version=' . db_param(); $t_result = db_query( $t_query, array( $p_version ) ); if( $t_row = db_result( $t_result ) ) { return $t_row; } else { return false; } }