Why $USER doesn't contain description?

Why $USER doesn't contain description?

'mei a dan k - 'aho
Number of replies: 3

Hey guys,

I'm trying to retrieve user description our of their profile, but for some reason

$USER -> description doesn't exist

descriptionformat exists but not descritpion...

any ideas?


cheers

dan

Average of ratings: -
In reply to dan k

Re: Why $USER doesn't contain description?

'mei a Tim Hunt - 'aho
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Because $USER is loaded into memory on every page and stored in the session, and ->description may be very large. So, we don't load it automatically for performance reasons.

I don't know the 'right' way to get ->description when you need it. I suggest you search the code for 'description' to see what is done elsewhere.

In reply to dan k

Re: Why $USER doesn't contain description?

'mei a kamesh veerachamy - 'aho
Hi dan k

I have post the code for how to  get user description.

you Just put the below code , you can get user description in anywhere.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
global $USER;
$user = $DB->get_record('user', array('id' => $USER->id));
$usercontext = context_user::instance($uid, MUST_EXIST);
    
$description = ''; // user description

if ($user->description && !isset($hiddenfields['description'])) {
                                    if (!empty($CFG->profilesforenrolledusersonly) && !$currentuser &&
                                                    !$DB->record_exists('role_assignments', array('userid' => $user->id))) {
                                                    $description = get_string('profilenotshown', 'moodle');
                                    } else {
                                                    $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user',
                                                                                                                                                                                                                                                            'profile', null);
                                                    $options = array('overflowdiv' => true);
                                                    $description = format_text($user->description, $user->descriptionformat, $options);
                                    }
     }
    
     echo $description; // this is user description

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 Thanks
 Kamesh.V


(Edited by Helen Foster to remove signature, since they are not allowed in the forums according to the site policy - original submission Thursday, 18 June 2015, 12:07 PM)

Average of ratings: Useful (1)
In reply to kamesh veerachamy

Re: Why $USER doesn't contain description?

'mei a dan k - 'aho

Awesome!

That works! thanks!