Page 1 of 1

Obtain the name of an user or a category from its id

Posted: 11 Feb 2019, 16:02
by JorG
Hi all!

I'm developing a plugin in mantisBT.
What i want to do is hook the event when a bug is reported( Created ). Everything is fine and done , but at the time of extracting the info of the Bug report object i got the id of the handler, reporter or the category instead of the name.

What i want to do is transform the id of that person ( for example : 0001) into its real name ( for example : Roger Smith) is there any way/ function / method of doing that??


Thank you very much in advance :).
King regards

Re: Obtain the name of an user or a category from its id

Posted: 11 Feb 2019, 16:30
by atrol
Use function user_get_name for it

Code: Select all

/**
 * Return the user's name for display.
 *
 * The name is determined based on the following sequence:
 * - if the user does not exist, returns the user ID prefixed by a localized
 *   string (prefix_for_deleted_users, "user" by default);
 * - if user_show_realname() is true and realname is not empty, return the user's Real Name;
 * - Otherwise, return the username
 *
 * NOTE: do not use this function to retrieve the user's username
 * @see user_get_username()
 *
 * @param integer $p_user_id A valid user identifier.
 *
 * @return string
 */
function user_get_name( $p_user_id )
 

Re: Obtain the name of an user or a category from its id

Posted: 11 Feb 2019, 17:25
by JorG
Thank you very much! It helped a lot :)

Does it also exist for the project and the category too?

Re: Obtain the name of an user or a category from its id

Posted: 11 Feb 2019, 18:58
by atrol

Code: Select all

/**
 * Return the name of the project
 * Handles ALL_PROJECTS by returning the internationalized string for All Projects
 * @param integer $p_project_id     A project identifier.
 * @param boolean $p_trigger_errors Whether to trigger errors.
 * @return string
 */
function project_get_name( $p_project_id, $p_trigger_errors = true ) 

Code: Select all

/**
 * Given a category id, this function returns the category name.
 * An error will be triggered for a non-existent category id or category id = 0.
 * @param integer $p_category_id A category identifier.
 * @return string category name
 * @access public
 */
function category_get_name( $p_category_id )
I recommend to look at the source under "core" directory, to get an impression of Mantis internals.