function helper_get_current_project() { global $g_project_override, $g_cache_current_project; if ($g_project_override !== null) { return $g_project_override; } if ($g_cache_current_project === null) { $t_cookie_name = config_get('project_cookie'); $t_project_id = gpc_get_cookie($t_cookie_name, null); if (null === $t_project_id) { $t_pref_row = user_pref_cache_row(auth_get_current_user_id(), ALL_PROJECTS, false); if (false === $t_pref_row) { $t_project_id = ALL_PROJECTS; } else { $t_project_id = $t_pref_row['default_project']; } } else { $t_project_id = split(';', $t_project_id); $t_project_id = $t_project_id[count($t_project_id) - 1]; } if (!project_exists($t_project_id) || 0 == project_get_field($t_project_id, 'enabled') || !access_has_project_level(VIEWER, $t_project_id)) { $t_project_id = ALL_PROJECTS; } $g_cache_current_project = (int) $t_project_id; } return $g_cache_current_project; }
/** * return the user's preferences in a UserPreferences object * @param int $p_user_id * @param int $p_project_id * @return UserPreferences */ function user_pref_get( $p_user_id, $p_project_id = ALL_PROJECTS ) { static $t_vars; global $g_cache_current_user_pref; if ( isset( $g_cache_current_user_pref[(int)$p_project_id] ) && auth_is_user_authenticated() && auth_get_current_user_id() == $p_user_id ) { return $g_cache_current_user_pref[(int)$p_project_id]; } $t_prefs = new UserPreferences( $p_user_id, $p_project_id ); $row = user_pref_cache_row( $p_user_id, $p_project_id, false ); # If the user has no preferences for the given project if( false === $row ) { if( ALL_PROJECTS != $p_project_id ) { # Try to get the prefs for ALL_PROJECTS (the defaults) $row = user_pref_cache_row( $p_user_id, ALL_PROJECTS, false ); } # If $row is still false (the user doesn't have default preferences) if( false === $row ) { # We use an empty array $row = array(); } } if ($t_vars == null ) { $t_vars = getClassProperties( 'UserPreferences', 'protected'); } $t_row_keys = array_keys( $row ); # Check each variable in the class foreach( $t_vars as $var => $val ) { # If we got a field from the DB with the same name if( in_array( $var, $t_row_keys, true ) ) { # Store that value in the object $t_prefs->$var = $row[$var]; } } if ( auth_is_user_authenticated() && auth_get_current_user_id() == $p_user_id ) { $g_cache_current_user_pref[ (int)$p_project_id ] = $t_prefs; } return $t_prefs; }
function user_pref_get($p_user_id, $p_project_id = ALL_PROJECTS) { global $g_default_mapping; $t_prefs = new UserPreferences(); $row = user_pref_cache_row($p_user_id, $p_project_id, false); # If the user has no preferences for the given project if (false === $row) { if (ALL_PROJECTS != $p_project_id) { # Try to get the prefs for ALL_PROJECTS (the defaults) $row = user_pref_cache_row($p_user_id, ALL_PROJECTS, false); } # If $row is still false (the user doesn't have default preferences) if (false === $row) { # We use an empty array $row = array(); } } $t_row_keys = array_keys($row); $t_vars = get_object_vars($t_prefs); # Check each variable in the class foreach ($t_vars as $var => $val) { # If we got a field from the DB with the same name if (in_array($var, $t_row_keys, true)) { # Store that value in the object $t_prefs->{$var} = $row[$var]; } else { $t_prefs->{$var} = $t_prefs->Get($var); } } return $t_prefs; }